Sign in to follow this  
Stenky

ID3DXEffect + compile_X_Y question.

Recommended Posts

There are some apparent optimizations in later shader versions (2.0+) that provide speed increases over earlier versions (1.1) even for shaders that can run in the instruction limit of shader 1.1. Therefore our goal should be to compile our shaders at the highest possible shader level the hardware can support. My question is this: If I specify "compile vs_1_1 or compile ps_1_1" for a shader, will the effects framework be smart enough to check the device caps and render it at a higher shader version than 1.1 if it is provided? Or must I do the validation myself in my application whether by doing my own query on the caps or through serial validation of the techniques? I can't see why the effects framework would not check for a higher shader value and prevent the requirement of its users from declaring a seperate technique for each possible shader version and test for the highest available one. However, if the effects framework did in fact compile under the hardware's maximum version, I wonder why we would have to specify the shader version if the effects framework does the testing itself internally. My own experiments suggest the effects framework does indeed internally compile under the highest shader version the hardware is capable of (I used a somewhat cumbersome (10 instruction) pixel shader under the shader interface, manually selecting shader 3.0 vs shader 1.1 and compared it to the same test under the effects framework) and discovered a significant performance hit under direct shader management and no performance hit whatsoever changing from 3.0 to 1.1 using the effects framework. However, I am far from always correct on my conclusions of experiments and I would like to ensure that isn't the case here. Does anyone know from their own personal experiences or from something they read that the effects framework does indeed compile under the highest possible shader version? I try to keep my work short and sweet, and I would prefer to avoid convoluting my project with unneccesary validations - however I am unwilling to sacrifice any performance if anyone believes the effects framework leaves the shader version management up to the application. Thanks for taking the time to read this far fellas, -Shaun

Share this post


Link to post
Share on other sites
Quote:
Original post by Stenky
My question is this: If I specify "compile vs_1_1 or compile ps_1_1" for a shader, will the effects framework be smart enough to check the device caps and render it at a higher shader version than 1.1 if it is provided? Or must I do the validation myself in my application whether by doing my own query on the caps or through serial validation of the techniques?


If you tell it to compile for vs_1_1, then it will simply create code that a vs1.1 supporting GPU can understand. It will not create vs2.0 code even if the graphics card supports. You can do that however by having multiple techniques in an effect file, then use the function FindNextValidTechnique to get a handle to a technique that is valid.


ps11func()
{
}

ps14func()
{
}

ps20func()
{
}

technique one
{
PixelShader = compile ps_2_0 ps20func();
}

technique two
{
PixelShader = compile ps_1_4 ps14func();
}

technique three
{
PixelShader = compile ps_1_1 ps11func();
}


In the above effect file, depending on the hardwar eyou are running the effect on, you will get the best implementation (technology wise). Calling the function FindNextValidTechnique will return a handle to the first technique that can be verified on the current hardware being used. So if you ran the function on a geforce 4, youd get a handle to technique three, because two and one would fail validation. On a gf fx, youd get a handle to technique one, because that's the first valid techniqueu you've listed.

The function will seach for techniques in a linear fashion from top to down.

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