Sign in to follow this  
shaq

Technique in effect file

Recommended Posts

shaq    122
Hi, I'm trying to make shader library. and I'm stuck into Technique setting. my question is when to use technique and when to use effect. Because I think 2 more technique in one effect could be seperated into different effect files. In my shader library, I sorted shader so if the same effect It doesn't call effect->begin() becuase of minimizing state change.. you know... but if I make two more technique in one effect. I realized that I need to call effect->begin() when technique is changed in the same effect. Is it cause performance problem? I read similar issue in this forum but I don't still get it. could you please advice me?

Share this post


Link to post
Share on other sites
remigius    1172
I'm not entirely sure, but I'd imagine switching techniques is less costly than switching effects. Still, as long as you're not using large numbers of effects or techniques (>10) I don't think this is something to worry about. I only use multiple techniques when they 'belong together' in one effect, like the setup and lighting passes in a deferred shading effect.

[edited]

Sorry, I misread your post because of all the linebreaks [smile] If you're worried about minimizing state changes, there should be a flag you can pass as a parameter into effect->begin() telling it not to save state. There's also a CommitChanges() method in the effect interface (at least in MDX) to apply any changes you made explicitly. I don't know for sure if this will also switch techniques, but I'd imagine it does.

Share this post


Link to post
Share on other sites
gunning    749
I'm also not sure which is faster, but I'd agree with remigus that you should group techniques together as much as possible. It's also simpler to share shader constants across techniques within an effect than across different effects. (You may also want to consider the #include directive to combine effects instead of actually loading more than one effect. Not sure about performance there, but I know it's definitely not horrible because that's what I do.)

Quote:
Original post by remigius
If you're worried about minimizing state changes, there should be a flag you can pass as a parameter into effect->begin() telling it not to save state.


Yeah you should probably be doing that, but I want to say that the effect system has a not-so-good state manager. I was debugging and noticed it constantly makes redudant state changes (mostly with texture stages iirc), and I'm not the only one to make this comment (see the ms directx forums). To use a pure device with effects you're going to have to implement the ID3DXEffectStateManager interface and call SetStateManager on your effect.

Share this post


Link to post
Share on other sites
stanlo    212
You can make a single effect with every technique you'll ever need, or a separate effect for every single technique you make; it's up to you, and you'll want something in between. I prefer to group techniques for rendering a specific object in different ways into the same effect file. Different objects with special techinques would get their own effects.

If you want to render stuff with an effect it should look like this:

Set technique
Begin effect & get pass count
Begin pass i
Draw stuff
End pass i
End effect
(possibly commit changes somewhere between begin / end)
[Start a new effect]


It should almost always look like this.


Commiting changes is costly, as well as flushing the things to your video card by changing effects. These two things will definately kill your batching, and makes the difference between drawing a few dozen objects and hundreds or thousands of objects at 60fps.

In general, change effects or commmit changes as little as possible. Managing your state will help to some extent (which decreases state changes & improves batching), but if you have poor batching in other areas anyway it won't do any miracle speed boosts.

Share this post


Link to post
Share on other sites
gunning    749
Quote:
Original post by stanlo
Set technique
Begin effect & get pass count
Begin pass i
Draw stuff
End pass i
End effect
(possibly commit changes somewhere between begin / end)
[Start a new effect]


Do you mean

Set technique
Begin effect & get pass count
For each pass i
...Begin pass i
...Draw stuff
...End pass i
End effect
[Start a new effect]

?

Share this post


Link to post
Share on other sites
shaq    122
thanks all of you.

Now I'm wondering if I need to sort techniques, too.
If technique is changed, I need to call effect->begin()
And I know "effect->begin()" could be harmful in performance.
If so I need to sort it.
Anyway I think I should record current technique -
maybe it could be technique ID - and compare next technique.
And only when it is different, effect->begin() called.
Am I right?

It seems like that completing shader library is far away from me...^^;

Share this post


Link to post
Share on other sites
remigius    1172
Sorting by technique may be useful, but allow me to be so bold to suggest you get your effect system up and running first and only then start to optimize it.

This way you can just profile you application to find out if switching techniques is a real bottleneck and if it is even worthwhile to optimize that part. Sure, it may be one of the more expensive calls, but eventually you will have to make some expensive calls one way or the other. Avoiding them like the plague will do you no good if it harms the flexiblity or robustness of your system.

As my good old datastructure coursebook put it, "premature optimization is the root of all evil" [wink]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this