Initial lag with shaders?
Hey there, I'd like to ask for your help.
I'm encountering a rather odd phenomena with my shaders. I noticed it first that sometimes, the game I worked on had been randomly lagging up, when I'd move about. Later I figured that this was caused when I'd begin rendering a shader for the first time after I had initialized it. If I don't render using shaders at all, the game runs fine, with no lagspikes at all. Problem is, this hangup is really noticeable.
Has anyone else encountered this problem?
Are you compiling and linking your shaders first before starting rendering?
Originally Posted by MagnumOpus
What GPU are you running?
Couple things come to mind. One is you might be lazy compiling/linking your shaders (easy solution: don't do that). Another is that the textures your shaders are using might not be on the GPU yet (you have to force-render with them on startup to ensure that they're on the GPU). Another is that if you've got an old, oold GPU (~7 generations old or more) then some of them did dynamic "optimization" of the shader code based on the current uniform settings, and you really needed to prerender with them as well. Another is that you may be overrunning GPU memory and it takes it a few frames to "swap unused data off the board" to make room for the textures/shaders you want to be rendering with right now.
Try prerendering with your shaders/textures and see if that doesn't help. You can also use the vendor "memory query" extensions to ensure that you're not blowing past GPU memory (NVX_gpu_memory_info or ATI_meminfo).
Thanks for the fast reply. I wrote all of my shaders in ARBfp1.0/ARBvp1.0 and I load all of them straight from the code at initialization. I don't think ARBfp/vp the issue, as I am having the same trouble in Team Fortress 2 for example, so I guess it might be my GPU, I'm running on Geforce 6600, 256 mb vram.
Eventually it came to mind that I should bind all my shaders in every possible shader bind configuration at the first frame of rendering, and render them to avoid this darn issue. I'll try a bit more around this, see how I can manipulate things and make it turn out, hopefully I can get prerendering to fully fix this problem. Also thanks for the meminfo, I'll make good use of that too.
I tried to pre-render the shaders, combining in every possible way, but the hiccups are still present. I'm gonna look into the memory later, but meanwhile I'm hoping that someone has any input on this, some similar experience.
Last edited by MagnumOpus; 02-04-2013 at 11:47 AM.
Yeah, GeForce 6 and 7 were GPUs where I got first-render shader hick-ups, even after pre-rendering with the textures. Pre-rendering with the shaders after uniforms were setup before flipping to user-interaction mode seemed to hide that. I think this issue was resolved with GeForce 8+.
Originally Posted by MagnumOpus
Vague memory but there was speculation at the time that the compiler was folding in certain "nice" uniform values into the shader code (0, 0.5, 1, etc.) after uniform set before first draw with it. Don't know if that's it or if that was mere speculation. Just something for you to consider as you investigate.
Alright, I've been doing tests, and came to the conclusion that my video card is absolute junk. I've been trying everything to get this problem fixed, but not even running the exact same drawing routines at the first frame fixes the hiccups, and if that does not work then I have no clue what to do. I'm gonna check the memory, but seeing as how I never, ever have any kind of graphics issues or memory problems otherwise with OGL, I doubt that's the problem in this case.
Thanks for your help with all of this.
To be fair, your graphics card is a GeForce 6600, which is approximately 9 years old. GeForce cards of that era were well known for loving nothing more than recompiling shaders every time you changed a uniform. Especially if you changed a uniform to 0 or 1, and sometimes 0.5. That's apparently because that generation of cards didn't actually have "uniforms" as distinct from the shader code; changing a uniform was like patching the shader. So they'd patch the shader on uniform changes and also do some recompiling of it, to optimize the code better.