glsl-optimizer icon indicating copy to clipboard operation
glsl-optimizer copied to clipboard

Optimize multiple vec* into array of vec*

Open paveyry opened this issue 8 years ago • 11 comments

Hi,

is there a feature that automagically optimizes the uniforms memory layout to group them in arrays of the corresponding type ?

For example:

uniform vec2 firstUniform;
uniform vec2 secondUniform;
uniform vec2 thirdUniform;

would become:

uniform vec2[3] vec2Uniforms;

That would save a lot of glUniform* calls on platforms that don't support uniform buffers (OpenGL ES2 / WebGL for example).

Thank you,

paveyry avatar Sep 22 '15 16:09 paveyry

You can do that manually (don't use anything other than vec4 for storing uniforms):

uniform vec4 data[2];
#define firstUniform  data[0].xy
#define secondUniform data[0].zw
#define thirdUniform  data[1].xy

bkaradzic avatar Sep 22 '15 22:09 bkaradzic

Interesting trick, but not scalable IMHO. Mostly because setting/binding uniforms will be very complex since we lose the naming. How can the app know how my vec*[] are mapped/organized?

I'd rather have the optimizer do it for me: it will probably do it a lot better and can provide a map that keeps the glUniform* calls automation possible.

paveyry avatar Sep 23 '15 09:09 paveyry

You could create .h file that contains layout and can be included in both shader and C/C++ code.

bkaradzic avatar Sep 23 '15 15:09 bkaradzic

You could create .h file that contains layout and can be included in both shader and C/C++ code.

I'm sure you'll understand that writing additional (C header) code doesn't comply with our need for automation or scalability.

paveyry avatar Sep 23 '15 15:09 paveyry

I'm just telling you what are things you can use right now without any changes to compiler. Not sure how submitting GitHub issue and waiting someone to implement it for you, with no ETA, solves "automation and scalability"?

bkaradzic avatar Sep 23 '15 16:09 bkaradzic

I'm not asking anyone to implement anything. I'm asking if such feature exists or is planned.

paveyry avatar Sep 23 '15 16:09 paveyry

This sounds like a good feature request. I would have thought GLSL Optimizer to be able to do that already actually.

warrenseine avatar Sep 23 '15 16:09 warrenseine

It's a good feature request, but not implemented right now.

I would like to do it at some point if I had too much spare time... alas... :/

aras-p avatar Sep 25 '15 10:09 aras-p

I'd like to implement this. I'm working on integrating this optimizer in MonoGame's shader building pipeline so we can support GLSL natively and we really want to do an optimization like this to keep glUniform calls to a minimum. MonoGame currently uses MojoShader to translate HLSL to GLSL and MojoShader does an optimization like this by packing uniforms in 3 arrays: one for bools, one for ints and one for floats. So that's what we're looking to do too. I'll be sure to contribute back if I ever manage to complete this :) I haven't looked into the code yet, so any pointers are very much appreciated!

Jjagg avatar Sep 26 '16 22:09 Jjagg

Any update on this?

JMLX42 avatar May 22 '17 17:05 JMLX42

Nope. I successfully integrated the optimizer in the MonoGame content pipeline, but didn't implement this. No one is actively working on GLSL support in MonoGame right now and there are a lot of higher priority issues.

Jjagg avatar May 22 '17 19:05 Jjagg