How get hidden counter instantly

Started by ducc · one year ago · 1 reply · 56 views

#1
ducc
Banned
JoinedSep 2022 Posts101 Score155

How do I get the hidden counter value of a structured buffer as quickly as possible?

Within a render block, I'm doing the following: 
  1. Dispatch a compute shader that increments the hidden counter of a GpuBuffer.
  2. In C#, read the hidden counter value of that buffer.
  3. Dispatch another compute shader using the value of that hidden counter as the number of X threads.
The problem I have is that when reading the hidden counter value for the first time, it is always zero. I must wait until the next frame until the value is available.

Is it expected that the first value returned is zero? 
  • If not, I can make an issue.
  • If so, should any caller of GpuBuffer.CopyStructureCount just keep checking every frame for when the value returned is greater than zero?
Is there (or will there be) a way for me to perform an indirect dispatch to work around this limitation in the future?
  • If not, I can make a feature request for that.
  • I believe this would allow me to skip reading back the hidden counter value entirely.

#2
matt
Facepunch
JoinedApr 2021 Posts267 Score2,045
I would guess you're copying the structure count before the compute shader has fully dispatched. Have you put appropriate resource barriers in place? Ideally you don't really want to introduce that barrier, you don't want to be waiting on a GPU -> CPU sync.

I dunno why we wouldn't be able to add indirect dispatch, feel free to make a feature request for it.
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.