Seemingly insignificant shader attribute causing massive framerate drop
Edit: This appears to have been the fault of a driver present on both rx 480 machines I've tested. Sorry to waste anyone's time.
I'm having an issue where adding an additional attribute to my existing shader is causing a massive drop in framerate (from 500+ without this attribute to 15). This issue does not seem to be happening on all machines, but it does happen on a radeon rx 480, and does not happen on a gtx 1060.
I'm using glsl 1.2, and generally targeting OpenGL 2.1.
vertex shader
attribute float in_selectflags;
varying float v_selectflags;
...
v_selectflags = in_selectflags;
fragment shader
varying float v_selectflags;
...
if (v_selectflags == 1.0)
color = mix(color,vec3(0.5,0.5,0.5), 0.25);
here is a github gist of the full shaders. There's one other use of v_selectflags in the gist, but in my testing removing the use of it there makes no difference.
If it matters at all, the attribute is passed from a byte in memory.
Simply not using glEnableVertexAttribArray on the attribute and not setting it up resumes expected behavior of around 500 fps again. I'm very confused, and I'm sorry if this is the wrong place to ask. I've tried a lot of different things to narrow it down or fix, and I'm truly lost.
Thank you for your time.
Posted Jun 7, 2018, 5:29 PM UTC · edited
The symptoms suggest that
v_selectflagsbeing dynamic causes the driver to resort to software rendering (or to output an exceptionally bad shader).Try removing as much branching as possible, that might help.
It does sound exactly like the driver is resorting to software rendering! I have this tested on another machine with a significantly better cpu and it reaches 50-70 fps! I tried making the fragment shader branchless gist here minus the uniforms which as I understand are okay to branch with, and I still have the same result. Hmm.
In your vertex shader: line 23 is not standard:in_selectflagsis avec2whilev_selectflagsis a float. It might have something to do with that.I have been playing with it on my own, it's my fault.
I'm not seeing that, on line 7 it's declared as a float. Is there something I'm not seeing?
My fault, sorry.
Are you using
glDebugMessageCallback?Did you try running the program in renderdoc ?