Page 1 of 1

Dropping shaders when no longer needed

Posted: Fri Jan 15, 2016 2:38 pm
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.

Re: Dropping shaders when no longer needed

Posted: Fri Jan 15, 2016 3:28 pm
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.

Re: Dropping shaders when no longer needed

Posted: Wed Jan 20, 2016 11:21 am
by Mel
Hmm, from the looks of it, D3D doesn't have a way to drop shaders.

Re: Dropping shaders when no longer needed

Posted: Wed Jan 20, 2016 12:32 pm
by devsh
well,, stop using D3D

Re: Dropping shaders when no longer needed

Posted: Thu Jan 21, 2016 9:58 am
by Mel
I don't need anything more complex either :)

Re: Dropping shaders when no longer needed

Posted: Tue Jan 26, 2016 11:42 am
by devsh
Just adding this feature to my fork (recompiling post processing shaders on screen resize)