Sign in to follow this  
cippyboy

Have you used GL_ARB_shader_subroutine or DX Dynamic Shader Linking ?

Recommended Posts

cippyboy    223

Have you used GL_ARB_shader_subroutine or DX Dynamic Shader Linking ?

 

I'm curious to know the performance advantages/disadvantages you got from implementing this over a bigger number of shader swaps. So far I've only tested this on a Shadow Map pass where I write only to the Z buffer, and made a shader that has skinning on/off based on the subroutines. I only got 1 skinned object though and 100 other ones. This was the quickest change I could make to observe the performance difference and to my surprise I have 1% lower overall performance. I imagine there's a number of shader swaps at which point it's faster to use subroutines. I'm also using an AMD HD7850 and I noticed lower GPU usage ratio when using subroutines, as if the driver is doing more work. This is very similar with separate shader objects where I observe a 50% drop in performance and a 50% drop in GPU usage while driver calls like glBindProgramPipeline take a whole lot more than glUseProgram, so I'm also questioning driver quality for this feature.

Share this post


Link to post
Share on other sites
cippyboy    223

Ok, so after a lot more work I managed to set up subroutines for all my 60 or so monolithic shaders. So basically instead of swapping 60 different shaders it uses a single shader with around 5 subroutine types ( skinning on/off, normals/lighting on/off, texturing on/off and alpha testing on/off ), 2 in VS and 3 in FS (the normals one is in both VS and FS). My conclusion is that it's slower even though I get 98% GPU usage.

 

I now get 118 FPS with subroutines versus 163 FPS without them.

 

However, there's some slight differences. Especially in the skinning department. Since the shader takes bone indices and weights for ALL objects, I assume there's some wasted caching involved when the current object does not present indices & weights, even though they're not used by the active subroutines set up, they might be fetched.

 

I also tried testing the shader without any object skinning, so the only difference in inputs is with and without normals/texcoords. Still about 50+ shader swaps, different camera angle though, the perf is 148 with subroutines vs 180 without. Still in the minus with performance, so I'm really wondering what is the threshold for a performance boost, or if the AMD driver is just really poor.

Share this post


Link to post
Share on other sites
Kaptein    2224

I honestly would just build the shaders using #ifdefs, as it's the safest bet. You don't have to do alot of extra work just to see if it works. I combine shaders by implementing my own #include preprocessor statement, and since I do this before sending the shader to OpenGL I can be sure it will the fastest. I also use #ifdefs liberally mostly from configuration settings. So if a setting has changed, I'd have to recompile the shader, but it's trivial. smile.png

 

I also have to wonder if this is something that could get better in the future. The GPU is lots of weaker cores running in parallell, so with that in mind the fastest solution will always be the one that can run sequentially on many cores in parallell. Imagining that the driver makers have abstracted this functionality into shader --> subshader[0], subshader[1], all it would do is introduce another (albeit small) step when binding a shader. It's what I would do anyways, as it sounds like a ridicolous feature. :P

Edited by Kaptein

Share this post


Link to post
Share on other sites
cippyboy    223

I already have macros, that's my standard way of getting 50 different shader combinations out of an uber shader that has it all. The number is larger purely because in GL you need to have a monolithic program. In DX it's more like 30.

 

Ideally, the subroutines should just be jumps in the shader code, or even better, when the shader code is copied from GPU memory to L1 cache or whatever for instruction interpretation, it should copy only the currently bound subroutines' code.

Share this post


Link to post
Share on other sites
cippyboy    223

 


The number is larger purely because in GL you need to have a monolithic program.

 

Uhm, no. http://www.opengl.org/registry/specs/ARB/separate_shader_objects.txt

 

Subroutines are available in 4.0 and separate shader objects are available in 4.1, so if you are already using one its not much of a stretch to use the other.

 

 

Have you ever used separate shader objects ? I already said in this post I get a negative performance benefit of 50% if I use them on AMD hardware.

Share this post


Link to post
Share on other sites
Chris_F    3030

Have you ever used separate shader objects ? I already said in this post I get a negative performance benefit of 50% if I use them on AMD hardware.

 

I missed that. That doesn't sound right at all. You could try posting on the AMD devguru website, but I wouldn't hold my breath for a response. I was having so many issues with AMD and OpenGL that I just gave up and bought a new GPU from Nvidia.

Edited by Chris_F

Share this post


Link to post
Share on other sites
cippyboy    223

 


Have you ever used separate shader objects ? I already said in this post I get a negative performance benefit of 50% if I use them on AMD hardware.

 

I missed that. That doesn't sound right at all. You could try posting on the AMD devguru website, but I wouldn't hold my breath for a response. I was having so many issues with AMD and OpenGL that I just gave up and bought a new GPU from Nvidia.

 

 

So what is your performance difference on Nvidia hardware with separate shader object ? The same ? faster/slower ?

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