Best way to clear values in a computebuffer?

I have a compute buffer:
RWStructuredBuffer

I 'm using InterlockedOr to perform scene voxelization.

This buffer never needs to leave the GPU.

I’ve tried a couple approaches:

A 1D compute shader that just sets all values to zero. This takes a ms or two - I think I can schedule this at the AFTER rendering completes, though, and it shouldn’t have a large impact.
_MyBuffer[id] = 0;

Setting empty data every frame - this gets costly
buffer.SetData(emptyData);

Is there something else I should consider? Something clever? Or something obvious? The GL.Clear() equivalent for a buffer?

Maybe I should just clear them in the compute shader after I’ve used them?

There is no clear function like GL Clear for compute. You will have to use a compute shader to manually clear the contents.

1 Like

Thanks - doing it in compute is easy enough.