Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading from RWTexture2D<float4> in a compute shader

I understand there's a limitation in HLSL shader model 5.0 where one cannot load data from a non-scalar typed RWTexture2D resource. That is to say, the following is illegal:

    RWTexture2D<float4> __color;
    float4 c = __color[PixelCoord];  // error here

So what exactly is the workaround? I'm trying to accumulate into a float4 buffer in a compute shader, like so:

    c = computeColor( ... );
    __color[PixelCoord] += c;
like image 401
Fooberman Avatar asked Mar 19 '26 03:03

Fooberman


1 Answers

Try doing:

float4 c = __color.Load( int3( UV, 0 ) );

Where UV is the xy coordinate in screen space (0 -> Resolution) of the texel you want to sample.

If you need to write to it, make sure it is bound from a UAV and not a shader resource view.

like image 70
Jason Avatar answered Mar 22 '26 00:03

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!