Cannot Sample a 16bit Texture format in my shaders

Started by
4 comments, last by BenS1 13 years, 4 months ago
Hi

I have a heightmap that has 16bit height values that I want to pass to my shaders as a texture.

Up until now I've been passing the heightmap as an R8G8B8 texture, which has been working fine but wastes memory.

So, I just tried creating my textures in DXGI_FORMAT_R16_UINT format, which seemed to work fine when I created the texture, but when I try to use it I get the following errors:

D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: The Shader Resource View in slot 0 of the Domain Shader unit is using the Format (R16_UINT). This format does not support 'Sample', 'SampleLevel', 'SampleBias' or 'SampleGrad', at least one of which may being used on the Resource by the shader. This mismatch 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 ]

D3D11: ERROR: ID3D11DeviceContext::DrawIndexed: The resource return type for component 0 declared in the shader code (FLOAT) is not compatible with the Shader Resource View format bound to slot 0 of the Domain Shader unit (UINT). This mismatch 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 ]

I am indeed using SampleLevel from my Shader code to try and read values from the texture.

I can't see anything int he documentation that says that SampleLevel only supports certain formats, or what the supproted formats are.

So, how do I has a texture of 16bit values to my shaders? I'm sure other people must be doing it (Maybe 8bit heightmaps are more common, but I would have thought the support would have been the same).

Thanks
Ben
Advertisement
Perhaps you want R16_UNORM, if you sample as a float.
You can see D3D11 format support here: Hardware Support for Direct3D 11 Formats. Below the table is an explanation of each column, which states that column 10 represents Shader sample (any filter), and R16_UINT is not checked on column 10. R16_UNORM however is.
Thanks Erik

I hadn't seen that table before... very useful.

The values in my texture are unsigned shorts (0-65536), so I can't use the float format.

I see R16_UNORM is supported... but I'm not 100% clear on what this is. The help file describes this as "A single-component, 16-bit unsigned-integer format.", which is exactly the same description as for R16_UINT... so what's the difference?

Thanks
Ben

Also I note that column 6 shows that you can create textures of absolutely any format... but if you can't sample them (Column 10) then whats the point?

What can you do with a texture other than sample it?

Thanks
Ben
I believe you can use the Load instruction instead of the Sample instruction to read it, according to column 9.

With R16_UNORM you sample your texture as a float between 0.0 and 1.0 in your shader, where 0 maps to 0.0 and 65535 maps to 1.0. If you want it from 0.0 to 65535.0 then try simply multiplying with 65535.0 in the shader.
Thanks again Erik

Thats what I thought about the UNORM version. That'll do fine... multiplying the result by 65535 solves my problem.

Thanks
Ben

This topic is closed to new replies.

Advertisement