# FX files slow? (DirectX)

## Recommended Posts

Hey Guys, I recently converted some code from using shaders to using FX files and it now runs really slow, it's really weird. Here's my rendering process (pseudocode)
for each object that isn't frustum culled
{
set the cull mode, zfunc, FVF, alpha function stuff and some material stuff (legacy code from fixed function pipeline but haven't cleaned it up yet).

set the world matrix

pass some values like the world view projection matrix and the texture to the effect the object uses

set the stream source

find a valid technique

set the technique

start the technique

for each pass
{
begin current pass

call DrawPrimitive on the stream source to render the object

end current pass
}

stop the technique
}


Can anyone see why changing from shaders to fx files would cause a slow down? I was thinking, maybe previously when it was told to bind a shader it already had bound maybe it would just ignore the call, but now with fx files it's unable to tell that it's the same shader? Does that sound right or do you guys think it's something else? Thanks you guys for any help, this is a bummer!! :/

##### Share on other sites
The "find valid technique" is potentially expensive. If you search a technique by name each time, it will result in a lot of string comparisons. Instead, store the technique handle outside the innermost rendering loop. Using handles to effect objects is very efficient. This also applies to effect variables.

You should also sort your renderable objects based on the resources that they use, so as to avoid GPU memory trashing and unnecessary state changes. For example, if several of your objects use the same technique, you can render them in one group. This is not Effect-specific advice, but good practice nevertheless.

Finally, you should use PIX to pinpoint performance issues in D3D. It enables you to see where your frame time goes.

##### Share on other sites
Thanks i'll try going the handles route and see if that doesn't speed it up.

It's strange cause yeah there is major room for improvement in that rendering process, but with shaders it was (for a specific scene) still pegged at 60fps, but now its down to about 10fps.

i was surprised to see it drop so much

##### Share on other sites
Nik wow!!!

I moved the find next valid technique to the initialization stage and stored off the handle it gave me and WOW it's back up to the 60fps mark.

i wonder if it was re-compiling the shader each time i asked for a technique or something??

Thanks a ton, i rated you up, that was most helpful!

##### Share on other sites
The act of "finding a next valid technique" requires that the system checks all the shader signatures (and other resource requirements) of each technique in the effect to see that your hardware can run them. This can take a relatively long time as compared to just applying an already-validated technique.

At apply time, the effect system does a minimal amount of sanity checking, but by that time it assumes that the device with which the effect was bound at creation can actually run your stuff.

Finding a technique by name is similarly relatively slow, but for a different reason - it searches the internal map of the Effect by using string comparisons. This doesn't require revalidation of the techniques, but it is still clearly slower than just using the handle (no search necessary).

The source for Effect11 system is available in the latest SDK. It is a bit different from the D3D9 era system, but the basic tasks it performs are the same. You can find the source at %DXSDK_DIR%\Utilities\Source\Effects11 . Studying it can give you valuable insights on how the Effect system works.

Have fun!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628307
• Total Posts
2981972

• 9
• 13
• 11
• 12
• 11