GLSL constant list of integers

Started by
3 comments, last by rewolfer 13 years, 6 months ago
Hi, I'm needing to create an array of constant integers in my GLSL shader.

In order to avoid branching and other slow things, I require an array of numbers that the shader lookup from using a calculated index. This array would need to be a few hundred numbers in length.

I understand that one cannot statically initialize arrays though, so how would one go about creating a constant array. If this is possible, how can I find the limit on the static/constant memory ?

thanks
Advertisement
Have you considered just a uniform array or texture? I don't think glsl is designed to support large variable arrays like that, it has a small space for variables.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I guess I was being too hopeful. uniforms are my next step.

thanks :)
I might just go for a texture, I think its more suited to a fairly large lookup table. If you want to arrange these as uniforms you're only guaranteed 512 minimum components in the vertex shader and only 64 in the fragment shader.

When I say components too these are packaged into sets of four, so you either have to pack your values into vec4's (ugly), or if you leave them as individual floats, in which you're wasting a lot of space and you're only guaranteed 128 float uniforms in the vertex shader or 16 in the fragment.



[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I'm trying to minimize the number of texture reads in my shader. It's for a Geometry Shader and it's going to require up to 27 lookups per execution (9 if I pack multiple numbers into a single integer). I understand that texture cache should reduce this in that it should read close neighbours into texture cache for spatial locality exploitation, but I'm not sure how big this chunk it loads would be.

This is why I was hoping for storing it in constant memory as one would in CUDA, because the cache is around 64KB. But I'm not sure how GLSL maps to the compute architecture..

I will definitely try texture memory now, because any execution of the GS will only use values from within 9*4 bytes of one another and Uniforms weren't much of an improvement.

Thanks for the advice

This topic is closed to new replies.

Advertisement