Performance of RenderStates switches

Started by
7 comments, last by DBX 19 years, 5 months ago
Hi, I'd like to know something about render states. Imagine an application where I need to changes my render states a lot. What's the best way of doing it ? I mean, I can do it like : d3dDevice->SetRenderState(...); or, I can use a state block to store many render states in 1 block, or I can use the following : DWORD lightingStatus; d3dDevice->GetRenderState(D3DRS_LIGHTING, &lightingStatus); if (lightingStatus) d3dDevice->SetRenderState(D3DRS_LIGHTING, false); // render stuff here if (lightingStatus) d3dDevice->SetRenderState(D3DRS_LIGHTING, true); I'm curious to know if the last method is more efficient than using state blocks ? because even with state block, there are a lot of redundant SetRenderStates that occure, and with the last method, there is none ... If someone has a clue, please let me know ^^ .:: Paic Citron ::.
Advertisement
According to what I know, DX stores the renderstates internally, so that before performing a render state change, it can check if it isn't redundant.

So, (again, according to what I know,) setting a render state to what it is already set to wouldn't cause any significant performance loss, since it's only done somewhere in the DX code and never actually reaches the gpu, which is the bottleneck in this opperation (when is it not?).

So, if you're looking to cut renderstate setting time, your best bet would be to batch the polygons together, so you need to change the renderstates less times during a frame.
Sirob Yes.» - status: Work-O-Rama.
Your last remark is right, I already did it ^^

The fact is that when I put DirectX debugging at max, I have a LOT of redundant state change warnings to the debugging output of Visual. So much that my app is running at a very low speed !
So, I guess that DirectX do the render state change everytime. If not, I wouldn't have all these warnings, would I ?

One other funny thing : D3DXCreateTextureFromFile() and most of the D3DX functions are responsible for these warnings ...

.:: Paic Citron ::.
I think the fact the D3DX functions do the redundant changes should show you that these arn't really a problem. If Microsoft is doing it, they must know what they're doing... (yes, a lot can be said about this last sentance :)).

Anywho, if you compile your project in release mode, the debug warnings arn't even added to the code, so they wouldn't hurt performance. So, all in all, you shouldn't get too much of an impact from these redundant changes.
Sirob Yes.» - status: Work-O-Rama.
Um...

AFAIK the D3DX guys are to be used as a GENERIC 3d library, and as such need to do certain things to keep their generality (like make a lot of state changes to make sure they are in some certain state), at the price of performance. If your app is still slowing down in release mode, then I would check your D3DX calls as well.
D3D will only check state changes if you aren't running a pure device.
But, you should not send redundant state. Why would you? Your app is in a much better position to judge these things than either the driver or D3D.

Ideally you want to aim for ZERO warnings from D3D while your app runs. Not that many games do that, but hey ....
Thx for the replies, but I might have asked my question in a wrong way.
I was just wondering WHY DirectX was reporting warnings when doing redundant state changes. If redundant state changes were really NOT important, why would DirectX report them as a warning ??

So, starting from this remark, I asked myself what would be the best way to handle my state changes : using state blocks, or using a sort of state manager that detect if a state to change it only if it's not set the way I need it to be ?

But from your replies, I think using state blocks would be better.

And, Sirob : you're right, a lot can be said on what you said about Microsoft ^__^

.:: Paic Citron ::.
What about texture stage state changes? I'm a bit more worried about those because there aren't any redundant changes for them.
Quote:Original post by paic
If redundant state changes were really NOT important, why would DirectX report them as a warning ??


They ARE important. That's why you get the warning.

This topic is closed to new replies.

Advertisement