# Pipeline state: in HLSL or C++ ?

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

## Recommended Posts

Hi everyone

I'm wondering what's the difference(s) between defining pipeline states in the C++ program or in the shader program.

For example, the difference between

 pass P0 { ...... SetBlendState( ....); ..... } 
And that:
 ..... somewhere in the C++ program .... pd3dDevice->OMSetBlendState(....) .... 

Is there any performance difference?
What's your style (and Why): All states defined in the HLS ? the minimum of states defined in the HLSL ?...

Thanks!

##### Share on other sites
From a strictly results point of view, it should make no difference. The same code will happen when you begin the pass or technique. But now it's data driven, which means you can keep all of the state for a shader together and in sync with that shader. You can also update it without having to dig through code, recompile, etc. On the other hand, I have to imagine that having it there makes batching very difficult, since the states aren't really exposed to your application anymore.

##### Share on other sites

From a strictly results point of view, it should make no difference. The same code will happen when you begin the pass or technique. But now it's data driven, which means you can keep all of the state for a shader together and in sync with that shader. You can also update it without having to dig through code, recompile, etc. On the other hand, I have to imagine that having it there makes batching very difficult, since the states aren't really exposed to your application anymore.

OK thanks. To conclude, they are nearly the sames. It's not a question of performance but rather of program architecture (how effects are managed).

##### Share on other sites
It's purely organizational. At the end of the day, all states have to be set from the CPU by calling D3D functions. So either you can have the effects framework call those functions by defining the states in your effect file, or you can do it yourself in your C++ code.