Jump to content
  • Advertisement
Sign in to follow this  
BenS1

Cannot Sample a 16bit Texture format in my shaders

This topic is 2766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!