Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using ComputeBuffer from SRP

Discussion in 'Graphics Experimental Previews' started by Hyp-X, Aug 10, 2019.

  1. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    421
    Hi!

    To use computer buffer counter functionality there's ComputeBuffer.SetCounterValue and ComputeBuffer.CopyCount to use from the main thread.

    However with Scriptable Render Pipeline I need CommandBuffer versions of these calls.
    Now there's CommandBuffer.CopyCounterValue, but I found no equivalent of SetCounterValue.

    Using the main thread version sort-of works, but causes random flickering because of concurrency issues.

    Does anyone knows if it exists, and maybe I just somehow missed it?
     
  2. VVVasilchuk

    VVVasilchuk

    Joined:
    Jan 28, 2019
    Posts:
    1
    Hi! Can anyone suggest a solution? Still relevant for Unity 2020
     
  3. Hyp-X

    Hyp-X

    Joined:
    Jun 24, 2015
    Posts:
    421
    I stopped using Append altogether, and using atomic operations in a raw buffer instead.

    I use
    RWByteAddressBuffer _CounterBuffer;
    with
    _CounterBuffer.InterlockedAdd(offset, 1, originalValue);

    I use a compute shader to clear the counters, and one to copy to the _IndirectArgsBuffer
    But in a simple use case you could clear and update your _IndirectArgsBuffer directly.
    Please note that _IndirectArgsBuffer needs to be declared as RWStructuredBuffer<uint> the byte address version doesn't work on some platforms...

    Hope this helps