Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:12:18+00:00 2026-05-27T23:12:18+00:00

I have an OpenGL shader written in glsl. I have a globally defined array

  • 0

I have an OpenGL shader written in glsl. I have a globally defined array at the top of the header like this:

const int permutations[256] = int[256](
    64 ,  34 ,  36 , 137 , 120 , 122 , 246 ,  46 ,  79 ,  10 ,  37 , 181,
    ...
    );

When I start the program, it is extremely slow, meaning I have only like 1 frame per second, when displaying a simple teapot using the shader.

However, as soon as I remove the “const” from the above declaration, everything works fine, and I’m back at interactive frame rates.

So, the “problem” is actually already solved… but I was wondering, why this could be the case? Very counterintuitive, as in my experience, using consts usually makes programs faster.


Update

I actually tried to use a Uniform first instead of the const int array, with exactly the same code everywhere else. However, in this case compiling the shader crashes with:

Internal error: assembly compile error for fragment shader at offset
34609:
-- error message -- line 651, column 22:  error: invalid local parameter number
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:12:19+00:00Added an answer on May 27, 2026 at 11:12 pm

    That’s very strange. Most probably you’re having driver issues. I’ve ran included shader code on my Nvidia 540M under windows, and let it run in cycle. In that cycle I called shader program once and measured time (also I had checked with transform feedback if shader is working correctly). Most of cycles ended in 2-3 miliseconds, with some peaks at 25 ms. However removing const identifier had no effect on performance. These are quite small values to measure, but from your description the performance hit of const should be observable even here.

    #version 150
    const int permutations[256] = int[256](
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
    ...
    246, 247, 248, 249, 250, 251, 252, 253, 254, 255
    );
    
    flat out int num1[32];
    
    void main(){
        for(int i = 0; i < 32; i++){
            num1[i] = (permutations[2*i]+permutations[2*i+1])*(permutations[2*i+2]+permutations[2*i+3]);
        }
    }
    

    Maybe if you wouldn’t mind I could try to run your program on my hardware, but it would have to be compiled for windows and please include all dynamic libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hopefully a simple question: I have an OpenGL texture and would like
I seem to have a curious problem. I set up OpenGL like this: glViewport(0,
So this one is a doozie; I've got a pretty large OpenGL solution, written
I am working on a OpenGL ES 2.0 shader and I have tightly packed
I have a problem somehow similar to this post : glTexGen in OpenGL ES
So I am working on openGL ES2.0 and GLSL and I have a question
Suppose I have 5 GLSL shaders that I successfully loaded in my opengl program.
I have a simple OpenGL program and trying to draw an instanced array that
I'm writing my own shader with OpenGL, and I am stumped why this shader
I'm looking for a way to access OpenGL states from a shader. The GLSL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.