Fooberman
Fooberman

Reputation: 646

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;

Upvotes: 4

Views: 5260

Answers (1)

Jason
Jason

Reputation: 5307

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.

Upvotes: 1

Related Questions