Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize multiple vec* into array of vec* #112

Open
paveyry opened this issue Sep 22, 2015 · 11 comments
Open

Optimize multiple vec* into array of vec* #112

paveyry opened this issue Sep 22, 2015 · 11 comments

Comments

@paveyry
Copy link

paveyry commented Sep 22, 2015

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,

@bkaradzic
Copy link
Contributor

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

@paveyry
Copy link
Author

paveyry commented Sep 23, 2015

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.

@bkaradzic
Copy link
Contributor

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

@paveyry
Copy link
Author

paveyry commented Sep 23, 2015

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.

@bkaradzic
Copy link
Contributor

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"?

@paveyry
Copy link
Author

paveyry commented Sep 23, 2015

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

@warrenseine
Copy link

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

@aras-p
Copy link
Owner

aras-p commented Sep 25, 2015

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... :/

@Jjagg
Copy link

Jjagg commented Sep 26, 2016

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!

@JMLX42
Copy link
Contributor

JMLX42 commented May 22, 2017

Any update on this?

@Jjagg
Copy link

Jjagg commented May 22, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants