shader optimisation

Started by
1 comment, last by EvilDecl81 19 years, 6 months ago
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
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).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
EvilDecl81

This topic is closed to new replies.

Advertisement