Dropping shaders when no longer needed

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Dropping shaders when no longer needed

Post by Mel »

Is it posible to do such a thing? so far, when we compile a shader, it stays from the compilation moment to the end of the program execution, but what if, for some reason, we wanted to get rid of one? a posible scenario, for instance, could be authoring shaders, think of a tool that creates them, say, via nodes (it is just a suposition, such tool doesn't exist) During the execution, it must compile every created shader, if the old shaders aren't replaced, i guess that sooner or later, you run out of resources. So, is it posible to update, or replace, or delete them? Couldn't it be a feature useful for Irrlicht?

Think that, for instance, it was posible to replace the fixed function materials, with the proper provisions so the engine suffered the least, just by dropping them, and creating new shaders with better functionality.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Dropping shaders when no longer needed

Post by devsh »

It is possible, but the irrlicht system binds shader program objects to integer IDs, so its very hard to signal to SMaterials that the material type they are using is not alive anymore.

So it would basically have to create a "default" shader, which could be solid as it is now for all invalid IDs or even better a full "render discard" shader (throwing all vertices to same position off-screen, if possible using geometry shader to kill them, and discard any pixels).

But then you'd have a problem of gaps in the list of assigned IDs, and if shaders were assigned the smallest value item in the gap then you'd have a problem of random integer IDs which wouldnt play nice (you'd have to respecify ALL of your SMaterials with new Material IDs, everytime you delete or replace a shader).

So I'd suggest a "add"/"replace"/"delete" system, where you effectively fuse delete+add so that your new shader keeps the irrlicht integer ID of the one you've dropped.


This is all possible in OpenGL with glDeleteProgram() etc., so it would take you 45 minutes to implement yourself if you read the openGL wiki.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Dropping shaders when no longer needed

Post by Mel »

Hmm, from the looks of it, D3D doesn't have a way to drop shaders.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Dropping shaders when no longer needed

Post by Mel »

I don't need anything more complex either :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Dropping shaders when no longer needed

Post by devsh »

Just adding this feature to my fork (recompiling post processing shaders on screen resize)
Post Reply