Hello,
I am working on a shader, and I need to store some data (just a pair of float4) to use in calculation check in the next frame.
I use StructuredBuffers for other things, and I found some literature about RWBuffers
The doubt I have is: all examples I have seen are Compute buffers, where the RW shader is filled from C#, modified in GPU and then read back in C#.
My case is a bit different: I need to store and read my data just inside the shader, with no C# work involved (I don’t need to do anything in CPU, and it will be slow).
So, my doubt is, can I read and write a RWBuffer inside a shader?
In case I can, how I should initialize it?
In case I cannot, is there any workaround?
I have achieved to implement something. I store all the data I need on a register using SetRandomWriteTarget. The sad part:
I use this shader in an object that instantiates some meshes. If I initialize more of those objects, some instances of the previous ones will stop to work (but only a part, not everyone).
I presume that this is due to always being setting the Write target to the same register
Bbut the fact that if I turn on the instancing objects in a determined order, everything works fine, confuses me. It doesn’t seem like its rewriting the register (since only a part of the previous instances are affected), but obviously there’s something that is messing with it.
How exactly GPU registers work? What I am missing here?