Search Unity

AsyncGPUReadbackRequest with traces

Discussion in 'General Graphics' started by victor_apihtin, Jul 16, 2021.

  1. victor_apihtin

    victor_apihtin

    Unity Technologies

    Joined:
    Mar 2, 2021
    Posts:
    28
    So assuming I have a RWStructuredBuffer<int> in a compute shader, that I am writing to and reading from.
    I am using command buffer's RequestAsyncReadback to get the data on the CPU.

    The list has been growing, so the readback is now taking a significant amount of time, so I have decided to read by chunks instead. I am updating my command buffer to read a chunk of, for example, 10 elements, every frame, and shift the offset.

    The problem though is that the rendering is multithreaded, so the onComplete callback is 1 frame delayed, and might not be, or there could be a few frames delay i guess?

    Receiving a NativeArray of 10 elements I am having a trouble to identify which offset index it is. The Update function (where I am requesting the readback) might happen before the callback with the data from the last frame, thus ruining the indexing.

    Ways around would be.. writing the index every 10'th element of the array. Or having another dispatch and readback, that would increment framecount on the GPU side.

    Would have been lots easier though, if the callback would give some information on what has been requested.
     
  2. victor_apihtin

    victor_apihtin

    Unity Technologies

    Joined:
    Mar 2, 2021
    Posts:
    28
    a little nicier way to do it, i suppose, is having a structure of a pair, where the pair is <index, value>..
    Which is fine and a generic solution. Not as tight and optimal as it could though, since now 2x data needs to be transported to cpu
     
    Last edited: Jul 16, 2021