I know this is a shader pipeline thing with bound resources and one thread not knowing what the other one does.
However, I tried writing my current data to another RWTexture2D with the same dimensions as my shader and reading from it later on. The compiler did not throw an error but it did not work.
uint2 this = tid.xy;
uint2 next = tid.xy+uint2(1,0);
tex2[tid.xy] = col;
col.r = tex2[this].r + tex2[next].r;
I thought I could access textures like arrays with xy? Is there another way to do this?
You need to use Load4 for textures like that
The code above valid only for buffers…
Also Load is bit expensive on my taste, I’ve would recommend using samplelevel and generate texcoords…
RWTexture2D texOut : BACKBUFFER;
RWTexture2D tex;
-code-
tex[tid.xy] = col;
col = float4(0,0,0,0);
col = tex.Load(tid.xy);
//col = tex[tid.xy]; //this works, so the data got written
texOut[tid.xy] = col;
no error, but no output either. To read and write to the texture is has to bebound from a UAV. Do I have to declare that somewhere explicitly? I also found an article claiming that in compute load from UAV is just allowed for DXGI_FORMAT_R32_FLOAT. I tried it with an RWTexture2d < float > but no output either.
I also tried your second suggestion, but the RWTexture2D has no SampleLevel or Sample function, it works just for Texture2D and I can’t write to that resource type.
To write from CS to texture you need specific setup, normally you’d write from texture to buffer, e.g.:
Use Load4 or SampleLevel to read from texture
Use [] to read write from buffer