Jump to content
  • Advertisement
Sign in to follow this  
conman

shader optimisation

This topic is 5110 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 wrote two versions of a billboard vertex shader. One got a pre-rotated object transform matrix in it's constant memory, which I calculated in c++ for every billboard object. The other shader does this calculations in his shader program, so nothing is done in c++ (only the camera and object transformations are given to the shader) The second solution seems to be not so good because every vertex calculates the same rotation matrix. My question is now, is there perhaps a way to tell the HLSL compiler that he should only process once the part of the shader program that is not depending on the vertex data? Or is the best solution to do this preprocessing in c++ and let the shader access this data? Or does the HLSL compiler this automatically? Tx in advance! -- constantin

Share this post


Link to post
Share on other sites
Advertisement
While it might seem obvious that doing the calculation once on the CPU is faster than doing the same calculation for every vertex, it really depends on who is waiting for who. If the GPU sits idle while the CPU is doing things like calculating the matrix, then moving some work to the GPU can speed everything up, even if it is wasteful. Likewise, if the CPU is waiting for the GPU, then moving some work to the CPU can speed everything up.

I don't think there is a way to do a calculation in the shader once and use the results for the remaining vertexes, but I could be wrong (maybe it is possible in the latest or future shader hardware).

Share this post


Link to post
Share on other sites
Quote:
Original post by conman
Hi!

I wrote two versions of a billboard vertex shader.

One got a pre-rotated object transform matrix in it's constant memory, which I calculated in c++ for every billboard object.

The other shader does this calculations in his shader program,
so nothing is done in c++ (only the camera and object transformations are given to the shader)

The second solution seems to be not so good because every vertex calculates the same rotation matrix.

My question is now, is there perhaps a way to tell the HLSL compiler that he should only process once the part of the shader program that is not depending on the vertex data?

Or is the best solution to do this preprocessing in c++ and let the shader access this data?

Or does the HLSL compiler this automatically?

Tx in advance!
-- constantin


If you use the Effect Framework, it will automatically preshade. That is, any constant calculation like a matrix multiply will be done on the host CPU rather then the GPU.

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!