Jump to content
  • Advertisement
Sign in to follow this  
Makubab

Shader Model 5.0 - Doubles

This topic is 2530 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

Hello,

I am working on some shaders in DirectX 11, Shader Model 5.0 and am messing around with double precision. However, it does not seem to be doing anything. I have verified that my video card supports double precision shaders, both in code and through the Caps Viewer. But all my doubles seem to function as floats all the same. Below is the code I am using to test:



double var1 = 0.333333333;
float var2 = 0.33333333;
if(var1 == var2)
{
//I set the output color to be magenta.
}



This happens in the pixel shader, and as stated, I set the output color to be magenta as opposed to another color. The output is always magenta. Unfortunately I cannot find any documentation or examples pertaining to double precision with shaders. I've even tried converting var2 to a double to ensure var1 is not being truncated to a float.

Any help would be greatly appreciated,
Thank you.

Share this post


Link to post
Share on other sites
Advertisement
To define double literals, use "L" suffix (for example, 3.14159265358979L). The default data type of floating-point literals is float on HLSL.

For historic reasons, the vast majority of HLSL literals are actually float. The history is that SM5 is the first D3D shader model to support doubles at all.

The double precision can be used relatively freely on hardware that supports it. Shaders that use doubles on unsupported hardware will fail on creation.

One major issue is that you can't use doubles as external constants that you would set from the host (nor load them directly from a shader resource), but you can pack your external data to two uints and expand them to double in the shader by using the asdouble function.Asuint function can be used to reverse effect, when you want to write the double out of the shader.

DX SDK has a sample called "BasicCompute11" which exhibits actual use of doubles on a shader.

Share this post


Link to post
Share on other sites
Thank you very much for the information. It's working great, such a small thing. I already foresaw issues with moving doubles into the shader, but never came across those two functions, they will help. Thanks again.

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!