Sign in to follow this  
#Include Graphics

Too large shaders - micro specializations.

Recommended Posts

Hey all,

 

There has been assaulting me some doubts about how to manage better the drawcalls. Actually I am using a vast generic effect which commsumate all the possible materials but .... I have several object types that are very similar, should I have to specialize some materials for each "object type" branch for having less material state changes?, does it really affect performance so much?.

 

I saw that at least for DX9, the dynamic branching isnt very good carried and all the branches seems to be executed... that carried me to think about real object material specializations.

 

May you spare some knowledge with me?, thanks in advance. smile.png

Share this post


Link to post
Share on other sites

Have you profiled your application to see if the CPU is the bottleneck?  If it isn't the bottleneck, then reducing draw calls probably won't help much - so you should start there.  Regarding your question about having a number of similar effects being soaked up into one, I would take a close look at the effects and see why they are different.  Is it a substantial difference, or is it something that is just a superficial difference?  The effort and effects of combining them depend greatly on how similar they are, so it is hard to give a good answer to your question...

Share this post


Link to post
Share on other sites

Jason is spot on here, if the shaders are not the bottle neck then no need to try to fix it!

I would recommend Intel's GPA  (graphics performance analyzer) if you want a pretty easy profiling solution. Just run it then run your app and boom - useful stats.

(You can even override your shader with a really simple one, so right away you get feedback without having to write a line of code yourself)

Share this post


Link to post
Share on other sites

The cpu and gpu are alternatively my bottleneck, it depends a lot every frame, so I am spending a little time on optimizing both and trying to upgrade synchronizations.

 

But I reached to have no more ideas and thought on cpu wait times for the gpu...I hope the render calls and material states would be multithreaded, can they be parallelized? I am thinking on a gpu which saves the info of the threads that are calling it and launch execution when a whole drawcall loop is completed. Maybe a dream?

Share this post


Link to post
Share on other sites


Have you profiled your application to see if the CPU is the bottleneck?  If it isn't the bottleneck, then reducing draw calls probably won't help much - so you should start there. 
That depends on his batch sizes, doesn't it? If he's submitting large blocks of polygons then sure, but if we're talking about small batches and frequent effect changes, then he's going to see GPU side inefficiency stemming from that too.

Share this post


Link to post
Share on other sites

 


Have you profiled your application to see if the CPU is the bottleneck?  If it isn't the bottleneck, then reducing draw calls probably won't help much - so you should start there. 
That depends on his batch sizes, doesn't it? If he's submitting large blocks of polygons then sure, but if we're talking about small batches and frequent effect changes, then he's going to see GPU side inefficiency stemming from that too.

 

 

So, this is what alarms more to me:

 

- I always apply the materials begin/end with each object which is being drawn, no matter if it has exactly the same material as before.

 

I know this is not the best way to do, how is this affecting my cpu/gpu?

 

 

- I am drawing about 58 type of different materials each frame!

 

Is this normal?, Do i have to try to compact some effects to make this state changes less at the expense of having some more branches in some shaders?

Share this post


Link to post
Share on other sites

The cpu and gpu are alternatively my bottleneck, it depends a lot every frame, so I am spending a little time on optimizing both and trying to upgrade synchronizations.

 

But I reached to have no more ideas and thought on cpu wait times for the gpu...I hope the render calls and material states would be multithreaded, can they be parallelized? I am thinking on a gpu which saves the info of the threads that are calling it and launch execution when a whole drawcall loop is completed. Maybe a dream?

 

Answering to myself <Gollum mode on>:

 

This is not a  dream myself....this is done at the API level in DX11. The technology advances, thanks god.

 

<Gollum mode off>

Share this post


Link to post
Share on other sites


- I am drawing about 58 type of different materials each frame!
It is a very affordable amount. What's about the '!' ?

Personally if I would still have to be stuck in D3D9 I'd drop all optimizations. It's not going anywhere.

Share this post


Link to post
Share on other sites

I am not giving you my opinion. I am giving you my experience.

My render loop can draw 80+ materials, over 20k tris total without even pulling the CPU out of the energy saving mode.

You are cracking your head open, spending your time which will never came back... to optimize for an API which is dead in the water and has been for quite a while.

But... you are free to make your choices.

Share this post


Link to post
Share on other sites

I am not giving you my opinion. I am giving you my experience.

My render loop can draw 80+ materials, over 20k tris total without even pulling the CPU out of the energy saving mode.

You are cracking your head open, spending your time which will never came back... to optimize for an API which is dead in the water and has been for quite a while.

But... you are free to make your choices.

 

There are lots of people that are still supporting DX9, and I think it makes perfect sense to optimize a rendering sequence in an existing program.  The algorithm runs on the same GPU regardless of which API you use, it is just a different API so I don't really see why you are pushing so hard about DX9 being dead.  The API still exists, and will continue to exist more or less forever in the Desktop environment.  Small batches cause issues at some point in DX9, but there are many ways to address those types of problems.

 

@Promit: You are right of course.  The general case is that in D3D9 if you are doing lots of small batches that the CPU will become the bottleneck pretty quickly.  However, in some cases it could be possible that you are also causing the GPU to be inefficient.  I guess this is why you need to profile before you can find and fix the problems!

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