When using RWTexture3d as output in a compute shader the following doesn’t accumulate values as it does when using a StructuredBuffer.
//The following outputs a constant value of 1 without accumulating
RWTexture3d Output :
Output[idx] += 1.0;
//The following works,outputs and integrated values if using a structured buffer instead of a texture3d.
RWStructuredBuffer Output : BACKBUFFER ;
Output[idx] += 1.0;
Is this a real limitation, I searched a lot in non vvvv dx11 code and thought is supposed to work.
I hope I’m doing something wrong and it really is posible.
I’m trying to setup a 3dvolume simulation and I think I can make it work with buffers but it would be much easier to do advection, gradients and other calculations with samplers on texture3d.
I will try pinponging 2 textures next but I was hoping to do it as simple as with the buffers.
Is it posible with some extra setting I’m missing or its a real limitation?
if you’re trying to accumulate multiple elements of sources into one or few simple += is not recommended or plain not working at all. in that case there’s a race condition between multiple threads which means some desired operations depending on others might be overwritten by “competing” threads. in English that means some operations might get ignored. if you want to accumulate in a massively parallel system like in a compute shader you have to use memory barriers so each thread will have to wait until when they can read and write to a certain address. thankfully there’s already couple of intrinsic functions for that for uint called InterlockedAdd/-Exchange/etc… and for floats there are utility functions in mp.fxh
this is of course far slower than regular += so if your shader pipeline doesn’t have massive race conditions you can stick to +=