I’m currently trying to pass an IndirectArguments buffer to a ComputeShader.DispatchIndrect call,
but I’ve noticed a new problem that I was not encountering in Unity 5.6.
It doesn’t seem to be allowing me to write to the buffer from a shader. Or shall I say, I can, BUT, it’s only allowing me to write to the first index of the buffer.
In the case of the IndirectsArguments buffer that I’m initializing as thus:
argsBuffer = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);
And writing to from a compute shader like this:
args[0] = count;
args[1] = dataWidth / 8;
args[2] = (dataHeight + 7) / 8;
args[3] = 1;
The only line that seems to register is
args[0] = count;
Not only is this an issue I haven’t experience in the previous versions, I can also say that when I simply change the buffer type of the above example, the other indexes of the buffer are then able to be written to.
So clearly this is an issue unique to the IndirectArguments type. And this presents a really annoying problem because in order for me to write to the IndrectArguments buffer properly, without full access to the buffer from the GPU, I’d have to do it from the CPU end. Which would involve needing to fetch data from the GPU back to the CPU, and I know that is a slow operation to do.