• Advertisement
Sign in to follow this  

Various questions about HLSL with DX9

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

Hello everybody ... ! -- I'm writing some shaders for my engine, and in order to Unify the lighting computation over all the shaders i've created several fonctions like: (i work with per pixel lighting, so erverything is done in the pixel shader) ComputeDirLight(Material Mat, Light Li ....) ComputePointLight(Material Mat, Light Li ....) All of these fonctions, takes as arguments, some very big structures ( maybe 25 octets ) descripting the models attributes ... I whant to know if there is any performances cost when passing such a structures as a parameters during functions call... -- Also, in some of these fonctions, i use something like: if(dot(Normal, Light) > 0) { Do the lighting stuff... } in order to reduce the amout of pixel computed.... But i do not see ANY performances gain with this little hack .. even, if the light illuminate only a little part of a model ... Does the If Statment is very expensive under Shader Model 2.0 ?? -- By know i light a little scene ( consisting of a simple octogonal room with some other stuff ) with 4 Directionnal spot light, shadow mapping and Bump mapping for the 4 lights, and i run at around 450 fps under a Athlon 3600 and a GForce 6600 . Is it possible to compare my result against yours ?? Just to know if i'm on a good way ... :) ??? Thanks a lot Gamedev ;) Clem

Share this post


Link to post
Share on other sites
Advertisement
The shader compiler will inline your function calls. Because of this the number of parameters you need for a call will have no impact on the shader speed itself. But using many parameters can force the compiler to use many temps to save current values. This can have an impact.

As shadermodel 2 does not support branches an “if” will you buy nothing. It will make more worse because it have to execute additional code that “emulates” the “if”.

Share this post


Link to post
Share on other sites
What do you mean by: "Shader Model 2.0 do not support If statment" ???
even if it emulate the statement, the code inside the IF is NOT Executed ?
i'm i right ?

Clem

Share this post


Link to post
Share on other sites
No, the code inside the if statement will still be executed.
What he meant is that shader model 2.0 does not have a native "if" instruction, but the "if" is still executed through some kind of emulation that adds more code to your shader.

Share this post


Link to post
Share on other sites
Basically the way it works in PS2.0 is both sides of the conditional are executed and the conditional chooses between the result, hence no performance win. Take a look at the assembly to see exactly what's going on. In PS3.0 you can use true branching but it has massive overhead, and if your branching coherency is low, which it will be since you are comparing N.L per-pixel, then the shader will be very inefficient.

Bad news, but at least you know what PS2.0 conditionals are good for.

Share this post


Link to post
Share on other sites
Quote:
Original post by jamesw
In PS3.0 you can use true branching but it has massive overhead, and if your branching coherency is low, which it will be since you are comparing N.L per-pixel, then the shader will be very inefficient.


There's a serious overhead on NVIDIA chips but ATI is more efficient with branches. You still need coherence to be efficient (i.e., nearby pixels should take the same branch), but this seems likely to happen for lighting. (Don't know why James thinks coherence will be low.)

Share this post


Link to post
Share on other sites
High coherency I mean =) You know, where large groups of pixels take the same branch.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement