Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

The ComputeBuffer IndirectArguments type no longer allows me to write to it from shader correctly

Discussion in '2017.2 Beta' started by Colt-Zero, Aug 13, 2017.

  1. Colt-Zero

    Colt-Zero

    Joined:
    Jun 24, 2016
    Posts:
    4
    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.
     
    Last edited: Aug 13, 2017
  2. Colt-Zero

    Colt-Zero

    Joined:
    Jun 24, 2016
    Posts:
    4
    Okay... Apparently this was a false alarm... Sorry.

    I brought the project back to 5.6 but was still encountering the same problem. And it turns out, the fix to the problem was changing the buffer size (which isn't a particularly obvious thing to do to "fix" it).

    Now the issue is I don't know exactly why...

    Thing is...

    A buffer size (number of elements) of 4 should definitely work, since the indirect arguments only needs 3 arguments and in my Dispatch call I was only shifting the argument offset by 4 bytes (1 element of the argument buffer) so it should definitely of been picking up the 3 it needed.

    And even then, forgetting the actual DispatchIndirect call, what about the simple fact that my output wasn't reflecting any updates to any of the data past the first 4 bytes? Even though I was clearly trying to update them.

    My only guess to why changing the size worked is because the buffer was stuck in some kind of glitched state on the GPU and changing the size finally broke it out of that glitched state.