shader programs management

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

shader programs management

Post by REDDemon »

I think irrlicht actually lack some extra features for shaders:

1) there's no way for removing a compiled shader from GPU (this will be very usefull since lots of graphics card has a limit to the maximum number of shaders, mine is 64).
2) query maximum number of shaders programs.
3) query used shader programs.

.. I know that removing a shader requires massive changes to Smaterial interface, but maybe is possible to skip that problem by simpli giving the chance to replace one material's shader with another shader? I figured out some simple solutions but I don't really know how hard can become implement something similiar in irrlicht. I'm still trying to do the same with a simple OpenGL application and see if it would be hard to do that.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: shader programs management

Post by devsh »

REDDemon.... I believe 64 is your number of shader cores. I think you can have as many shader programs as you like, because they get precompiled and only upload into cache of your GPU when you bind them/set them active (that is setMaterial through IVideoDriver), this is why everyone advises to sort render order by material as the process of loading and unloading the shader programs (state change) is quite long. They sit around in your computer memory and wait for use.

As for deletion, irrlicht employs reference counting which means that shaders which are not used by any materials are deleted automatically (I am not quite sure).
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Re: shader programs management

Post by 3DModelerMan »

If the shaders were a class that had a conversion operator to SMaterial then we could just create a shader and pass it into the SMaterial function. Is there any way to set constants at initialization time for shaders? Or do you have to set constants each frame?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: shader programs management

Post by shadowslair »

3DModelerMan wrote:Is there any way to set constants at initialization time for shaders? Or do you have to set constants each frame?
Not 100% sure I understand your question, but if we set them all at init time, how`re they gonna be updated? The camera position, transf martices etc. usually change?
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: shader programs management

Post by devsh »

you need to update the constants every frame, even more so every time we set the material. This is because the shader got unloaded from gpu cache and so did it's uniforms from the gpu uniform cache.. but we could set most of the stuff in the OnSetMaterial rather than OnSetConstants.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: shader programs management

Post by REDDemon »

Materials are not reference counted. After reached the maximum number of shaders the engine just stops to compile further shaders. (this is the only way i Found to get this number using irrlicht, but the problem is that the only way to remove those shaders is to close the device. So if a game want to find out that number it must initialized the device twice (a little bit long with DirectX or OpengL). I don't know if it is the same on other machines. I'm not compiling obviously the same shader. I procerudally generate N shaders (very simple way. Just change filename ^^)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: shader programs management

Post by hybrid »

I don't know of any such limit. Quickly looking over all OpenGL constants I also didn't see any number that could help. But removing a shader should become possible in the future. Not yet under implementation, though.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: shader programs management

Post by REDDemon »

Yeah that's mean some design change. Anyway I think that rarely someone will end up all the shaders.. XD
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: shader programs management

Post by hybrid »

What would that mean? end up all the shaders?
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Re: shader programs management

Post by 3DModelerMan »

I think he means use all the shader slots up.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: shader programs management

Post by robmar »

almost 4 years later I´m also trying to find out how to drop shaders correctly!!

... there must be a way... I see them deleted when Irrlich is deleted, but where is the API call to manade earlier deletion?

for more complex applications this is an important issue, otherwise the device has to be deleted and reloaded..
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Re: shader programs management

Post by ent1ty »

4 years later? Hä?
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: shader programs management

Post by robmar »

yeah! so how about a little help here?

from what I´ve seen it seems works like this:

Under OpenGL, shader programs and callbacks are registered and Irrlicht deletes them in COpenGLSLMaterialRenderer::~COpenGLSLMaterialRenderer()

However, if they the callback classes are deleted before Irrlicht is deleted, when Irrlicht´s destructor is called, it still tries to delete them, as the tables are not updated when callbacks were dropped.

So... how to call deleteMaterialRenders? There is a driver independent method to delete shader programs and their callbacks?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: shader programs management

Post by robmar »

Management of shader programs

It seems that Irrlicht has no generic deleteRenderMaterials functions, so the best thing is to load up all shaders at program start and leave them there.

If anyone has hundreds of massive shaders that need to be loaded at different times, unlikely I guess, adding the call to the drivers would be easy.

Maybe an Irrlicht guro could comment just to leave this thread correctly closed?
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: shader programs management

Post by REDDemon »

I solved this problem using custom materials renderers. You can just use 1 material renderer as wrapper for multiple shaders on wich you have total control. Of course this will be API dependent (Dx or GL?) but this is not a problem since shader programs are already API dependent. The good thing of that is that it works without API changes to irrlicht
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply