Qualifiers
Use highp for positions/texture coordinates on large textures, mediump for colors and normals on mobile for performance.
8.1 Storage qualifiers
compile-time constant (or read-only function parameter) input to the stage (vertex attributes, interpolated values from the previous stage) output from the stage value set by the application, constant across a draw call shader storage buffer (read/write, GLSL 4.30+) variable shared within a compute workgroup attribute, varying legacy (GLSL ES 1.00 / ≤ 1.20)
8.2 Layout qualifiers
layout (location = 0) in vec3 aPos; // attribute / varying location
layout (location = 0) out vec4 outColor; // fragment output (render target index)
layout (binding = 2) uniform sampler2D uAlbedo; // texture unit (GLSL 4.20+)
layout (std140, binding = 0) uniform Camera { mat4 view; mat4 proj; };
layout (std430, binding = 1) buffer Particles { vec4 pos[]; };
layout (local_size_x = 16, local_size_y = 16) in; // compute workgroup size
layout (rgba32f, binding = 0) uniform image2D uImg; // image format
layout (triangles) in; layout (triangle_strip, max_vertices = 3) out; // geometry shader
layout (early_fragment_tests) in; // force early depth test
layout (origin_upper_left) in vec4 gl_FragCoord; // (compatibility) change origin
layout (set = 0, binding = 1) uniform ...; // Vulkan descriptor set/binding
layout (push_constant) uniform PC { mat4 model; }; // Vulkan push constants
layout (constant_id = 0) const int KERNEL = 5; // Vulkan specialization constant
layout (depth_greater) out float gl_FragDepth; // conservative depth8.3 Interpolation qualifiers (stage outputs/inputs)
smooth (default) linear interpolation in screen space no interpolation — value from the provoking vertex (required for integer varyings) sample within the covered area (MSAA, avoids extrapolation) per-sample interpolation (forces per-sample shading)
flat out int vMaterialID;
noperspective out vec3 vBarycentric;
centroid out vec2 vUV;8.4 Precision qualifiers (GLSL ES; no effect on desktop)
Use highp for positions/texture coordinates on large textures, mediump for colors and normals on mobile for performance.
precision highp float; // default for the whole shader (REQUIRED in ES fragment shaders)
precision mediump int;
mediump vec3 color; // at least 16-bit float (range ±2^14, ~10 bits mantissa)
lowp vec4 tint; // at least ~8-10 bits — colors
highp vec4 position; // 32-bit float8.5 Parameter & invariance qualifiers
void f(in vec3 a, out vec3 result, inout float accum); // in (default), out, inout
invariant gl_Position; // guarantee identical results across shaders (multi-pass rendering)
precise float t = a * b + c; // prevent reordering/fusing (GLSL 4.00+)8.6 Memory qualifiers (images & buffers)
coherent, volatile, restrict, readonly, writeonly:
layout (std430, binding = 0) readonly buffer In { float data[]; };
layout (rgba8, binding = 1) writeonly uniform image2D uOut;