Sign in to follow this  
lomateron

HLSL d3dcompiler_47 problems

Recommended Posts

lomateron    491

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 this post


Link to post
Share on other sites
Erik Rufelt    5901

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 this post


Link to post
Share on other sites
ericrrichards22    2434

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this