Inline expansion for function calls in shaders

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Hotshot5000
OGRE Contributor
OGRE Contributor
Posts: 263
Joined: Thu Oct 14, 2010 12:30 pm
x 69

Inline expansion for function calls in shaders

Post by Hotshot5000 »

Is there any way to force a function to be inlined when the shader file gets created from the shader template?

I am asking because I found another retarded bug in Adreno drivers (Android GLES3): I am using texture animations with animation matrices. That means that there is a second call to UNPACK_MAT4 in the line

Code: Select all

textureMatrix = UNPACK_MAT4( animationMatrixBuf, (instance.materialIdx[finalInstancedId].x << 4u) + 0u );
after

Code: Select all

worldViewProj = UNPACK_MAT4( worldMatBuf, finalInstancedId );
. The worldViewProj is working fine but the next UNPACK_MAT4 does weird inexplicable things. I've manually inlined the call and now it works just fine. So I'm thinking to automatically inline all function calls just to be safe because the compiler doesn't seem to do it (or does it badly).
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5588
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1413
Contact:

Re: Inline expansion for function calls in shaders

Post by dark_sylinc »

No, the only two solutions are:

1. Use GLSL Optimizer
2. Rewrite the functions as a macro. We have our own macro parser (that's good because it guarantees you won't hit driver bugs with the parser bugs) but it does not support multi-line macros (and may have bugs on its own, but the good news is that these bugs would reproduce everywhere because it's in Ogre's code)

Although the macro is probably going to end up looking horribly unreadable, it would work fine.
Post Reply