4

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;
Fooberman
  • 626
  • 5
  • 14
  • There's different ways to work around this, but that depends on what you exactly need to do. You could use 2 textures and do ping pong (probably the easiest way if it applies to you), another way is to use StructuredBuffers, which haven't got this limitation, but are 1 dimension (it's not very hard to modify offsets from 2d to 1d tho). – mrvux Jan 29 '13 at 20:32

1 Answers1

1

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.

Jason
  • 5,277
  • 4
  • 17
  • 12