Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualHodgman

Posted 18 April 2013 - 08:25 AM

A branch will have a cost, say a dozen clock cycles per pixel/vertex, just for existing. If nearby pixels each take different paths, then all those pixels will pay the cost of executing both paths.

When you switch shaders, there's the small CPU cost of making extra GL function calls, and there's the cost GPU command to change the current program, which is interesting:
The GPU is heavily pipelined, doing large work batches at once. As long as the previous shader has been used to process enough work (say, a few hundred pixels), then there will be pretty much no overhead in switching shaders - it's free. If the previous shader was not used for enough work, then you'll create a pipeline bubble, which acts as if the previous shader did perform a lot of work (i.e. if you use 100 shaders but each is only used to fill 1 pixel, it may take as long as if each shader was used to fill 500 pixels -- that's 100 pixels worth of shading costing as much as 50000 pixels worth).

So yes, you want to have several specialized shaders, but not so many that each is only used on a tiny part of the screen. You want to draw as much stuff as possible with each shader before moving on to the next one, so be sure to sort your objects by their material/shader type.

#2Hodgman

Posted 18 April 2013 - 08:24 AM

A branch will have a cost, say a dozen clock cycles, per pixel/vertex just for existing. If nearby pixels each take different paths, then all those pixels will pay the cost of executing both paths.

When you switch shaders, there's the small CPU cost of making extra GL function calls, and there's the cost GPU command to change the current program, which is interesting: the GPU is heavily pipelined, doing large work batches at once. As long as the previous shader has been used to process enough work (say, a few hundred pixels), then there will be pretty much no overhead in switching shaders - it's free. If the previous shader was not used for enough work, then you'll create a pipeline bubble, which acts as if the previous shader did perform a lot of work (i.e. if you use 100 shaders but each is only used to fill 1 pixel, it may take as long as if each shader was used to fill 500 pixels -- that's 100 pixels worth of shading costing as much as 50000 pixels worth).

So yes, you want to have several specialized shaders, but not so many that each is only used on a tiny part of the screen. You want to draw as much stuff as possible with each shader before moving on to the next one, so be sure to sort your objects by their material/shader type.

#1Hodgman

Posted 18 April 2013 - 08:22 AM

A branch will have a cost, say a dozen clock cycles, per pixel/vertex just for existing. If nearby pixels each take different paths, then all those pixels will pay the cost of executing both paths.

When you switch shaders, there's the small CPU cost of making extra GL function calls, and there's the cost GPU command to change the current program, which is interesting: the GPU is heavily pipelined, doing large work batches at once. As long as the previous shader has been used to process enough work (say, a few hundred pixels), then there will be pretty much no overhead in switching shaders - it's free. If the previous shader was not used for enough work, then you'll create a pipeline bubble, which acts as if the previous shader did perform a lot of work (i.e. if you use 100 shaders but each is only used to fill 1 pixel, it may take as long as if each shader was used to fill 500 pixels -- that's 100 pixels worth of shading costing as much as 50000 pixels worth).

PARTNERS