Have you used GL_ARB_shader_subroutine or DX Dynamic Shader Linking ?

Started by
6 comments, last by cippyboy 10 years, 2 months ago

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.

Relative Games - My apps

Advertisement

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.

Relative Games - My apps

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

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.

Relative Games - My apps


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.


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.

Relative Games - My apps


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.


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 ?

Relative Games - My apps

This topic is closed to new replies.

Advertisement