This topic is 2897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Well I am trying to do something like this:

 half4 mainPS( uniform const style ) : COLOR { if( style == 0){ //do one thing } else if( style == 1){ //do another } else if( style == 3){ //and another } } Technique PS_Style0 { Pass P0 { PixelShader = compile ps_2_0 mainPS( 0 ); } } Technique PS_Style1 { Pass P0 { PixelShader = compile ps_2_0 mainPS( 1 ); } } Technique PS_Style2 { Pass P0 { PixelShader = compile ps_2_0 mainPS( 2 ); } } 

I am compiling it using fxc.exe, I specify the main entry point as mainPS, but it shows the parameter as taking up a register rather than compiling it with the parameter I set. Is there a way to compile specify techniques one at a time, rather than specifying an entry point can I specify a technique to compile instead?

##### Share on other sites
If you're compiling an effect file, you don't have to specify an entry point, i.e. you don't need the \E flag. It will always compile all techniques.
See here for a brief summerization on offline compiling. The flags are described here.

##### Share on other sites
Would it be possible to compile each technique as a separate pixel shader, that's what I'm trying to do.

##### Share on other sites
You can probably compile a technique that contains only the pixel shader, but then the pass.apply doesn't set a vertex shader. You would have to do this after the the apply call manually.
How do you plan to bind the shaders? Do you use the effect framework for that or are you doing it manually, using PSSetShaders etc.?

##### Share on other sites
I am using setPixelShader and setVertexShader, so I was hoping I can use the compiler to compile the techniques into pixel shaders since I have more than 1 parameter and about 20 pixel shaders in one file with the settings. So rather than having 20 files to compile and have different parameters in each, it'd be easier and more efficient.

##### Share on other sites
Ah, I see. If you use Dx11 you could look into dynamic shader linkage. Its purpose is to handle many shader permutations of codepaths, by linking functions at bind time (goodbye übershaders ). This not only makes coding and maintaining the shaders easier, it also uses optimal register count. (Otherwise the compiler would always count the registers for the worst-case codepath.)

If you don't have Dx11 hardware at hand, you could define the shaders in techniques as you already have and compile them as effects. In your application you can iterate over all techniques and try to extract the pixel shaders. You'd probably have to write a getter in the effect framework and compile it again. Instead you could also simply bind the shader via pass.apply, before binding anything else (constant buffers, shader resource views, vertex shader, samplers, states, ...), unless you let the effect framework bind these things.

##### Share on other sites
You can retrieve manually the Vertex and Pixel shader bytecode directly from a compiled effect and setup the pipeline yourself.
The steps are:
1) Compile your effect with the profile fx_2_0. Using fxc.exe and/or whatever D3DXCreateEffect / D3DXCreateEffectFromFile function that fits your needs.
2) Iterate on all techniques and passes
3) Get the D3DXPASS_DESC description for each pass using ID3DXBaseEffect::GetPassDesc
4) From this description you can retrieve the pointer to the vertex shader and pixel shader
5) Then you can instantiate the PixelShader from the bytecode, using IDirect3DDevice9::CreatePixelShader and passing the pointer you got from step 4.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 18
• 13
• 9
• 9