Skip to main content
GameDev.net gamedev.net
🔒 Locked

cgGLBindProgram performance issue

Started by godmodder Mar 10, 2007 at 11:41 AM 2 replies 2.3k views
Original Post
godmodder
godmodder
Hello, I've been experimenting with Cg shaders in my engine for quite some time now, but I've mostly been using them on a limited amount of objects (boxes etc...) When I modified my program to apply a Cg shader to each object, I get an AMAZING performance drop from 200FPS --> 20FPS. I narrowed the problem down to the cgGLBindProgram() function that get's called for every object. Why does this happen? PS: another problem --> Why don't my shaders work in display lists? Is this impossible? System Specs: Geforce 7800GS and Windows Vista Thanx for helping me out, Jeroen
Sneftel
Sneftel
Binding a shader is by far the most time-consuming thing you can do to a GPU. It forces the GPU to completely flush its pipeline, vertex cache, and texture cache. You only do it when you absolutely have to. You certainly do NOT call it for every object; you sort them so that all the objects which use the same program are drawn at once.

And shaders work fine with display lists, as long as you aren't actually trying to put CG calls in the display list.
SirKnight
SirKnight
In addition to binding the program, cgGLBindProgram also sets up parameters and textures. So it's definately a function you want to minimize calling.
godmodder
godmodder
Thanx for the quick replies! I think sorting the objects will have a significant impact on performance, but having 10 kinds of different materials will still have a large performance drop. (10 calls to cgGLBindProgram drop the framerate from 200FPS--> 110FPS) These cgGL function calls are really heavy on resources. Using the fixed function pipeline is always at least 25% faster than using basic shaders that emulate the FFP.
Is there really nothing I can do about this?

Jeroen

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.