nonameforgood

I'm getting a 4.5 seconds long freeze when a series of pixel shaders are used for the first time.

When all of the 500 effects of my test case select a different PS, the application freezes 4.5 seconds and then continues. The overhead appears when DrawIndexedPrimitive or SetPixelShaderConstantF are called.

- I'm not using the multithread flag
- I'm not getting any errors or warning msg
- no help from PIX
- Shaders are compiled when the data is packaged at export time, no compilation at run-time.
- The PS & VS are created at load time, not when needed

So I tried a simpler test case:
All PS are returning a random value -> the app freezes for ~1.5 seconds and the overhead occurs in DrawIndexedPrimitive.

float4 Main( ) : COLOR0
{
float4 returnv = float4(0,0,0,0);
returnv.b += 0.909146; <- random value for each PS
return returnv;
}


The VS is equaly simple and only outputs the projected position.

any help greatly appreciated.

thanks!



Re: Game Technologies: Graphics 4.5s of overhead when pixel shaders are set

Robert Dunlop

Have you been able to duplicate this on other video cards I tried my own test, and even *instantiating* and setting 100 vertex and pixel shaders in a single frame I was unable to see any real performance hit.

Are you running with the debug runtimes If so, try switching to the release runtimes, maybe there is some validation of the shader that is going on the first time it is set. Or it might be device dependant, maybe there is some conversion of shader byte code to a native instruction set when it is first used





Re: Game Technologies: Graphics 4.5s of overhead when pixel shaders are set

Alexey Barkovoy

Each time new shader is used it needs to be recompiled from DirectX asm format to IHV dependant fromat by video card driver. So, probably, this is what you are seeing.



Re: Game Technologies: Graphics 4.5s of overhead when pixel shaders are set

nonameforgood

I ran my app under VTune and the time seems to be spent in "DdEntry5".

I searched for that and it apparently means driver time.

right

If so, I'll try Robert's suggestion of trying the code on the "other" chipset.

But this won't resolve my issue as I need to support my current chipset.




Re: Game Technologies: Graphics 4.5s of overhead when pixel shaders are set

Robert Dunlop

It would seem apparent that you need to find a way to lessen the impact you are seeing by changing to all of those previously unused pixel shaders in a single frame. I can see three ways to do this:

1. Minimize the number of pixel shaders, by re-using shaders with the same code path and using shader constants to handle parameteric differences.

2. If there is no way around so many shaders, and you can predict the need for new shaders many frames in advance, then identify the minimum code needed to cause a shader to initialize and perform this on upcoming shaders spread out over enough frames to make the hit acceptable.

3. Cause all shaders to be pre-compiled to the hardware in the loading phase of your application, taking the hit up front rather than during game rendering.