HLSL d3dcompiler_47 problems

Recommended Posts

Just wana say that I just discovered that using length(), distance() and "/" division operator  is a bad idea, using dot() and pow() is faster and more accurate. Why is the compiler not optimizing that?

to get the length of a vector "v"

l = pow(dot(v,v),0.5f);

if you need to divide a position by the length of "v"

p*pow(dot(v,v),-0.5f)

Share on other sites

How do you know it's not optimizing it?

Did you actually benchmark the different methods, and if so what GPU and driver were you using?

Any output from the HLSL compiler is some form of cross-platform ASM and I'm pretty sure the driver will re-arrange it in all kinds of ways depending on the underlying architecture.

Share on other sites

Curious what kind of hardware this is running on.  If there is really any difference, I would suspect that is comes down to particular optimizations in the hardware or possibly the drivers.

Assuming that you can naively expand things out algebraically, these should be the same, barring any specific hardware optimized to compute vector dot-products or exponentiation.

I will admit I am not overly familiar with specialized silicon-level components, beyond the simple adder and multiplier circuits I had to learn in my computer architecture courses.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628282
• Total Posts
2981812

• 9
• 10
• 11
• 17
• 15