I tried to draw a 2D texture of R8G8B8A8_UINT format. Each texel is packed with the code
UINT *pt = texels;
unsigned char *pp = (unsigned char *)pixels;
for ( int i = 0; i < height; i++ )
for ( int j = 0; j < width; j++ ) {
r = UINT(*pp++);
g = UINT(*pp++);
b = UINT(*pp++);
a = UINT(*pp++);
*pt++ = r<<24 | g<<16 | b<<8 | a;
}
and unpacked in pixel shader like
float4 texPS(float4 posH : SV_POSITION,
float2 oTexC : TEXCOORD) : SV_Target
{
uint diffuse = gDiffuseMap.Sample( gTextureSampler, oTexC );
uint a = (diffuse & 0x000000FF);
uint b = (diffuse & 0x0000FF00) >> 8;
uint g = (diffuse & 0x00FF0000) >> 16;
uint r = (diffuse & 0xFF000000) >> 24;
return float4(r, g, b, a) / 255.0f;
}
Unfortunately this does not work, the error message triggered by DrawIndex function is:
[indent=1]D3D10: ERROR: ID3D10Device::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the resource type bound to slot 0 of the Pixel Shader unit (UINT). This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #361: DEVICE_DRAW_RESOURCE_RETURN_TYPE_MISMATCH ]
[indent=1]D3D10: ERROR: ID3D10Device::DrawIndexed: The Shader Resource View in slot 0 of the Pixel Shader unit is using the Format (R8G8B8A8_UINT). This format does not support 'Sample', 'SampleLevel', 'SampleBias' or 'SampleGrad', at least one of which is being used on the Resource by the shader. This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #371: DEVICE_DRAW_RESOURCE_FORMAT_SAMPLE_UNSUPPORTED ]
I change the texture format to R32_UINT but still fails with similar error message:
[indent=1]D3D10: ERROR: ID3D10Device::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the resource type bound to slot 0 of the Pixel Shader unit (UINT). This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #361: DEVICE_DRAW_RESOURCE_RETURN_TYPE_MISMATCH ]
[indent=1]D3D10: ERROR: ID3D10Device::DrawIndexed: The Shader Resource View in slot 0 of the Pixel Shader unit is using the Format (R32_UINT). This format does not support 'Sample', 'SampleLevel', 'SampleBias' or 'SampleGrad', at least one of which is being used on the Resource by the shader. This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #371: DEVICE_DRAW_RESOURCE_FORMAT_SAMPLE_UNSUPPORTED ]
It seems that Texture2D::Sample function does not support R32_UINT and R8G8B8A8_UINT format.