Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL maximum number of instructions

Tags:

glsl

Is there a maximum number of assembly language instructions to be loaded into the fragment program unit? I have an algorithm on to port from cpu to gpu and apparently it doesn't fit on the gpu.

like image 867
Alin Avatar asked Apr 11 '10 17:04

Alin


People also ask

How do I optimize GLSL?

One way to speed up GLSL code, is by marking some variables constant at compile-time. This way the compiler may optimize code (e.g. unroll loops) and remove unused code (e.g. if hard shadows are disabled). The drawback is that changing these constant variables requires that the GLSL code is compiled again.

What is the difference between GLSL and HLSL?

In GLSL, you apply modifiers (qualifiers) to a global shader variable declaration to give that variable a specific behavior in your shaders. In HLSL, you don't need these modifiers because you define the flow of the shader with the arguments that you pass to your shader and that you return from your shader.

What is gl_Position in GLSL?

gl_Position is a special variable that holds the position of the vertex in clip space. Since a vertex shader's main output is the position in clip space, it must always set gl_Position. This vertex shader just transforms each vertex position (by the VP matrix).

How does GLSL shaders work?

Shaders use GLSL (OpenGL Shading Language), a special OpenGL Shading Language with syntax similar to C. GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders.


1 Answers

There are several hard and soft limits, some of which are not immediately obvious:

  • Instruction slots: The total number of instructions that the hardware can accomodate in local memory.
  • Executed instructions: The maximum number of instructions that will execute (including instructions that run several times in a loop)
  • A single GLSL instruction can map to a dozen or more instructions
  • Several GLSL instructions can map to a single instruction depending on the optimizer's quality (e.g. multiply-add, dot, lerp)
  • Limited temp registers (only 32) may require more instructions than necessary on pre-SM4 hardware (no such problem with 4096).
  • Swizzling usually does not cost extra instructions nowadays, but does on some older hardware, and may in some situations on some hardware (esp. gl_FragColor is such a candidate)
  • Regardless of actual instructions, OpenGL 2.0 compatible hardware is limited to 8 dependent texture fetches (unlimited on hardware that can do OpenGL 2.1 or better)

You have these guaranteed minimums (most cards have more):

  • 512 instruction slots for vertex and pixel shaders on OpenGL 2.x (SM3) capable hardware
    • 65536 executed instructions
  • 4096 vertex and 65536 pixel shader instruction slots on 3.x (SM4) hardware
    • 65536 executed vertex shader instructions, unlimited pixel shader instructions
  • At least 24 dynamic branches possible on 2.x (SM3) hardware
  • Fully dynamic branching (no limits) on SM4 hardware
  • Only conditional move available on SM2.x, everything else must be accomodated by code duplication and loop unrolling, or must fail
like image 144
Damon Avatar answered Oct 21 '22 07:10

Damon