Sign in to follow this  

GLSL constant list of integers

This topic is 2634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 2634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this