Jump to content
  • Advertisement
Sign in to follow this  
Mr_Fox

HLSL: mad vs separate multiply add

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

Hey Guys,

 

Does anyone know the detail about HLSL intrinsic function 'mad'? According to MSDN this should be preferable than use separate multiply add both in terms of precision and performance. However, I didn't see this got used widely (from my humble experience...) so should we follow MSDN guidance use mad over multiply/add whenever possible or there are some cases where we should hold back?

 

Thanks

 

Share this post


Link to post
Share on other sites
Advertisement
I just tried it and the compiler (fxc.exe) emits a mad for a * b + c if you don't force IEEE strictness (/Gis) or disable optimizations (/Od). Edited by Mona2000

Share this post


Link to post
Share on other sites

It's similar to an SSE intrinsic where it's more explicit than using standard arithmetic operators. In other words if you use the intrinsic you're explicitly telling the compiler "please emit a mad instruction", whereas if you don't use the intrinsic it's more like "I just need you to multiply and add these numbers, and I don't really care how you do it". 

 

The intrinsic is useful if you want to ensure the same results from two different pieces of code. For instance if you have a vertex shader for a depth prepass then another vertex shader for a full forward pass, you'll want to make sure both shaders produce the exact same transformed positions from the same input positions (otherwise you would get Z fighting).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!