I wanna use a 32-bit R8G8B8A8 texture format. I want to write data to it in compute shader and then read that data in pixel shader, but I can't get it working at all. First of all I cannot use format like DXGI_FORMAT_R8G8B8A8_UNORM because it's not possible to specify appropriate RWTexture2D in compute shader. So I decided to use DXGI_FORMAT_R8G8B8A8_UINT format, pack by 8-bit components to that in compute, and read in pixel shader. No success.
Packing code:
RWTexture2D<uint> texture: register(u0);
[numthreads(16, 16, 1)]
void main(uint3 dtID: SV_DispatchThreadID)
{
uint r = 255;
uint g = 255 << 8;
uint b = 255 << 16;
uint a = 255 << 24;
texture[int2(dtID.x, dtID.y)] = r | g | b | a;
}
Unpacking code:
...
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT output;
uint value = texture.Load(int3(0, 0, 0));
uint r = (value & 0x000000FF);
uint g = (value & 0x0000FF00) >> 8;
uint b = (value & 0x00FF0000) >> 16;
uint a = (value & 0xFF000000) >> 24;
output.color = float4(r, g, b, a) / 255.0f;
return output;
}
Is there anything wrong I'm doing? Isn't there a simple way for four 8-bit components treatment in compute shaders?








