Hybrid View

GLSL initialized uniform block members

Prerequisite - My terminology may be slightly off or bad, please excuse and correct me where ever necessary. Please also excuse that this is my first post. I have often lurked these forums and haven't made an account until recently.

Proposal
I propose that uniforms inside uniform blocks may be initialized by other block members. These initialized uniform block members don't take up user accesses memory (you can't issue a command to change them directly.)

In the above code ModelViewMatrix's value changes every time ModelMatrix or ViewMatrix is updated. Certain vendor implementations may already kind of do this implicitly when just initializing in the main function[1], but being explicit about the initialization would be nice.

What do you think? I am aware that you usually just initialize something like ModelViewMatrix on the cpu and pass it to opengl, but this is a different approach which I believe is much more shader flexible.

[1] - I actually have no idea if they do or if it's a trivial optimization.

Prerequisite - My terminology may be slightly off or bad, please excuse and correct me where ever necessary. Please also excuse that this is my first post. I have often lurked these forums and haven't made an account until recently.

Proposal
I propose that uniforms inside uniform blocks may be initialized by other block members. These initialized uniform block members don't take up user accesses memory (you can't issue a command to change them directly.)

In the above code ModelViewMatrix's value changes every time ModelMatrix or ViewMatrix is updated. Certain vendor implementations may already kind of do this implicitly when just initializing in the main function[1], but being explicit about the initialization would be nice.

What do you think?

[1] - I actually have no idea if they do or if it's a trivial optimization.

I don't think this will work because uniform blocks are backed by a buffer object. In order for this to work, the buffer object would then need to be written to each time the program is bound. That is not a good thing since the buffer object backing a uniform block is supposed to be read only. Moreover, one of the points behind UBO's is that the same buffer object can be used by multiple programs which use the same block type.

makes the suggestion doable; this is so because GL maintains the values of the uniforms as part of GLProgram state, thus changing the value of ViewMatrix would then trigger a change to ModelViewMatrix.

Now for the funny part: it is quite likely that for non-block uniforms, if the compiler detects a variable value which is assigned only once as an expression coming solely from non-block uniforms, it is quite likely a GL implementation would then make a "hidden uniform" holding that value. This is my suspicion.