### Ray Query Initialization Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_query.txt This example shows the usage of rayQueryInitializeEXT, which takes ray flags as an argument. The flags control the ray traversal behavior. ```glsl rayQueryInitializeEXT(query, accelerationStructure, rayFlags, sbtRecordOffset, sbtRecordStride, payloadLocation); ``` -------------------------------- ### GLSL Uniform and Non-Uniform Control Flow Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/basics.adoc Illustrates uniform control flow at the start, divergence within an if-else block, and reconvergence afterwards. Use this to understand how conditional statements affect control flow uniformity. ```glsl main() { float a = ...; // this is uniform control flow if (a < b) { // this expression is true for some fragments, not all ...; // non-uniform control flow } else { ...; // non-uniform control flow } ...; // uniform control flow again } ``` -------------------------------- ### Example: Ray Generation and Callable Shader Usage Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_tracing.txt A practical example demonstrating the use of `traceRayEXT` and `executeCallableEXT` in a ray generation shader, along with a basic callable shader structure. ```APIDOC ## Example: Ray Generation and Callable Shader ### Ray Generation Shader ```glsl #version 460 core #extension GL_EXT_ray_tracing : enable layout(location = 0) rayPayloadEXT vec4 payload; layout(location = 0) callableDataEXT float blendColor; layout(binding = 0, set = 0) uniform accelerationStructureEXT acc; layout(binding = 1, rgba32f) uniform image2D img; layout(binding = 2, set = 0) uniform rayParams { vec3 rayOrigin; vec3 rayDir; uint sbtOffset; uint sbtStride; uint missIndex; uint callableSbtIndex; }; vec3 computeDir(vec3 inDir, uvec3 launchID, uvec3 launchSize) { // ... compute direction ... return inDir; } void main() { vec4 imgColor = vec4(0); traceRayEXT(acc, gl_RayFlagsOpaqueEXT, 0xff, sbtOffset, sbtStride, missIndex, rayOrigin, 0.0f, computeDir(rayDir, gl_LaunchIDEXT, gl_LaunchSizeEXT), 100.0f, 0 /* payload */); executeCallableEXT(callableSbtIndex, 0 /* blendColor */); imgColor = payload + vec4(blendColor) ; imageStore(img, ivec2(gl_LaunchIDEXT), imgColor); } ``` ### Callable Shader (Structure) ```glsl #version 460 core // ... callable shader content ... ``` ``` -------------------------------- ### Example Docker Image Line Source: https://github.com/khronosgroup/glsl/blob/main/BUILD.adoc This is an example of the line you will find in the .gitlab-ci.yml file, indicating the Docker image and its SHA256 hash. Everything following 'image: ' is the image name to use. ```yaml image: khronosgroup/docker-images@sha256:42123ba13792c4e809d037b69152c2230ad97fbf43b677338075ab9c928ab6ed ``` -------------------------------- ### GLSL Variable Declarations for Packing Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/iocounting.adoc Example GLSL code demonstrating various variable types and arrays to illustrate the packing algorithm. Note that some types may be too large to fit. ```glsl out vec4 a; // top left out mat3 b; // align to left, lowest numbered rows out mat2x3 c; // same size as mat3, align to left out vec2 d[6]; // align to left, lowest numbered rows out vec2 e[4]; // Cannot align to left so align to z column, highest // numbered rows out vec2 f; // Align to left, lowest numbered rows. out float g[3] // Column with minimum space out float h[2]; // Column with minimum space (choice of 3, any // can be used) out float i; // Column with minimum space ``` -------------------------------- ### GLSL Ray Tracing Example with Reordering Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_shader_invocation_reorder.txt An example demonstrating ray tracing with custom intersection, hit object manipulation, and thread reordering based on hit object and material ID hint. It utilizes several GLSL extensions for ray tracing and shader invocation reordering. ```glsl #version 460 #extension GL_EXT_ray_tracing : enable #extension GL_EXT_buffer_reference_uvec2 : enable #extension GL_NV_shader_invocation_reorder : enable layout(binding = 0) uniform accelerationStructureEXT as; layout(binding = 1, rgba32f) uniform image2D img; layout(binding = 2) uniform RayParams { vec3 origin; }; layout(location = 0) rayPayloadEXT vec4 Color; layout(buffer_reference, hitobjectshaderrecordnv) buffer SRB { uint materialId; }; layout(location = 0) hitObjectAttributeNV vec3 sphereAABB; void main() { //Trace rays executing custom intersection/any-hit vec4 outputColor = vec4(0); hitObjectNV hObj; //Initialize to an empty hit object hitObjectRecordEmptyNV(hObj); hitObjectTraceRayNV(hObj, as, 0, 0, 0, 4, 0, origin + vec3(gl_LaunchIDEXT.xyz), 0.0f, origin + vec3(gl_LaunchIDEXT.xyz) + vec3(0,0,1.0f), 1.0f, 0); uint materialIdHint = 0; if (hitObjectIsHitNV(hObj)) { uvec2 handle = hitObjectGetShaderRecordBufferHandleNV(hObj); materialIdHint = SRB(handle).materialId; } //Reorder threads based on hit object and additional hint on material type //Use 3 LSB bits only reorderThreadNV(hObj, materialIdHint, 3); //Execute closest-hit shaders only if (hitObjectIsHitNV(hObj)) { //Get Attributes of intersection hitObjectGetAttributesNV(hObj, 0); hitObjectExecuteShaderNV(hObj, 0); outputColor = vec4(Color.x + distance(sphereAABB, vec3(0))); } imageStore(img, ivec2(gl_LaunchIDEXT.xy), outputColor); } ``` -------------------------------- ### Example Usage of NV_push_constant_bank Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_push_constant_bank.txt Demonstrates how to use the 'bank' and 'member_offset' layout qualifiers for push constant uniform blocks. The first block uses the default bank (0) and offset, while the second specifies bank 4 and a starting byte offset of 128. ```glsl #version 460 // Push constant in bank 0 at default offset layout(push_constant) uniform PushDataA { mat4 modelMatrix; }; // Push constant in bank 4 starting at byte offset 128 layout(push_constant, bank=4, member_offset=128) uniform PushDataB { vec4 b; }; ``` -------------------------------- ### Subgroup Partitioning Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GL_NV_shader_subgroup_partitioned.txt Example demonstrating the use of subgroup partitioning functions where 'value' is unique per invocation and 'ballot' defines the partition. The scan/reduce is computed independently for each subset of the partition. ```glsl float value = ...; // unique for each subgroup invocation uvec4 ballot; ``` -------------------------------- ### GL_EXT_ray_tracing Callable Shader Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_tracing.txt Example of a callable shader using GL_EXT_ray_tracing. It demonstrates reading from callableDataInEXT and writing to outColor, utilizing shaderRecordEXT buffer for blend weights. ```glsl #extension GL_EXT_ray_tracing : enable layout(location = 0) callableDataInEXT float outColor; layout(shaderRecordEXT) buffer block { uvec2 blendWeight; }; void main() { outColor = float((blendWeight.x >> 5U) & 0x7U + blendWeight.y & 0x3U); } ``` -------------------------------- ### GLSL Geometry Shader Input Declaration Examples Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Examples demonstrating legal and illegal input array declarations and layout qualifiers in GLSL geometry shaders, highlighting size consistency requirements. ```glsl in vec4 Color1[]; // legal, size still unknown in vec4 Color2[2]; // legal, size is 2 in vec4 Color3[3]; // illegal, input sizes are inconsistent layout(lines) in; // legal for Color2, input size is 2, matching Color2 in vec4 Color4[3]; // illegal, contradicts layout of lines layout(lines) in; // legal, matches other layout() declaration layout(triangles) in; // illegal, does not match earlier layout() declaration ``` -------------------------------- ### Ray Generation Shader Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_tracing.txt Example of a ray generation shader using GL_EXT_ray_tracing extension. It demonstrates tracing rays, executing callable shaders, and storing results in an image. Requires specific layout qualifiers for payload, callable data, acceleration structure, and uniforms. ```glsl #version 460 core #extension GL_EXT_ray_tracing : enable layout(location = 0) rayPayloadEXT vec4 payload; layout(location = 0) callableDataEXT float blendColor; layout(binding = 0, set = 0) uniform accelerationStructureEXT acc; layout(binding = 1, rgba32f) uniform image2D img; layout(binding = 2, set = 0) uniform rayParams { vec3 rayOrigin; vec3 rayDir; uint sbtOffset; uint sbtStride; uint missIndex; uint callableSbtIndex; }; vec3 computeDir(vec3 inDir, uvec3 launchID, uvec3 launchSize) { inDir = ... return inDir; } void main() { vec4 imgColor = vec4(0); traceRayEXT(acc, gl_RayFlagsOpaqueEXT, 0xff, sbtOffset, sbtStride, missIndex, rayOrigin, 0.0, computeDir(rayDir, gl_LaunchIDEXT, gl_LaunchSizeEXT), 100.0f, 0 /* payload */); executeCallableEXT(callableSbtIndex, 0 /* blendColor */); imgColor = payload + vec4(blendColor) ; imageStore(img, ivec2(gl_LaunchIDEXT), imgColor); } ``` -------------------------------- ### GLSL Atomic Counter Declarations Examples Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Demonstrates various valid and invalid declarations of atomic counters with different binding points, offsets, and array sizes. Includes examples of correct usage and potential errors like overlapping or misaligned offsets. ```glsl layout(binding = 2, offset = 4) uniform atomic_uint; // Sets binding's default // offset = 4 layout(binding = 2) uniform atomic_uint a; // offset 4 layout(binding = 2) uniform atomic_uint b; // offset 8 layout(binding = 3) uniform atomic_uint c[2]; // offsets 0, 4 layout(binding = 2) uniform atomic_uint d; // offset 12 layout(binding = 4, offset = 16) uniform atomic_uint e; // offset 16 layout(binding = 4) uniform atomic_uint f; // offset 20 layout(offset = 8) uniform atomic_uint ea; // error, no binding // specified layout(binding = 2, offset = 6) uniform atomic_uint eb; // error, offset not aligned layout(binding = 3, offset = 4) uniform atomic_uint ec; // error, overlaps c[1] layout(binding = 3, offset = 4) uniform atomic_uint; // OK, no counter declared layout(binding = 3) uniform atomic_uint ed; // error, overlaps c[1] ``` -------------------------------- ### GLSL Function Declaration with Output Parameter Source: https://github.com/khronosgroup/glsl/blob/main/chapters/statements.adoc Example of a function declaration including an input parameter and an output parameter. ```glsl float myfunc (float f, // f is an input parameter out float g); // g is an output parameter ``` -------------------------------- ### GLSL Declaration vs. Definition Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Provides examples of GLSL declarations and definitions. A declaration introduces a name, while a definition fully defines it. ```glsl int f();// declaration; int f() {return 0;}// declaration and definition int x; // declaration and definition int a[4];// array declaration and definition struct S {int x;};// structure declaration and definition ``` -------------------------------- ### GLSL Push Constant Block Example with Mat4 Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_push_constant_bank.txt Example of a push constant block starting at byte 0 in bank 4, containing a mat4. ```glsl layout(push_constant, bank=4) uniform BlockX { mat4 m; }; ``` -------------------------------- ### Get ARM Tensor Dimension Size Source: https://github.com/khronosgroup/glsl/blob/main/extensions/arm/GL_ARM_tensors.txt Return the size of a specific dimension of a tensor. The dimension index starts from 0 for the outermost dimension. ```GLSL uint tensorSizeARM(tensorARM t, uint dim); ``` -------------------------------- ### GLSL Equivalent Matrix Initializations Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Demonstrates equivalent ways to initialize a mat2x2 matrix using constructor, initializer list of vectors, and nested initializer lists. ```glsl mat2x2 a = mat2( vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) ); mat2x2 b = { vec2( 1.0, 0.0 ), vec2( 0.0, 1.0 ) }; mat2x2 c = { { 1.0, 0.0 }, { 0.0, 1.0 } }; ``` -------------------------------- ### Enable GL_EXT_null_initializer Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_null_initializer.txt Include this line in your shader to enable the GL_EXT_null_initializer extension. Behavior is determined by the specifier. ```glsl #extension GL_EXT_null_initializer : ``` -------------------------------- ### GLSL.std.450 spirv_literal example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_spirv_intrinsics.txt Example usage of `spirv_literal` in a GLSL shader. ```APIDOC ## GLSL.std.450 spirv_literal example ### Description An example demonstrating the use of `spirv_literal` for embedding SPIR-V instructions in GLSL. ### Code Example ```glsl #version 450 core #extension GL_EXT_spirv_intrinsics: enable spirv_instruction(id = 61) // ... rest of the shader code ``` ``` -------------------------------- ### Run Podman Image for GLSL Spec Build Source: https://github.com/khronosgroup/glsl/blob/main/BUILD.adoc Execute this command from the specification repository root to build the GLSL and ESSL specifications using the Khronos-provided Docker image on a Linux podman host. ```bash scripts/runPodman ``` -------------------------------- ### GLSL Variable Scope Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc A basic example illustrating variable declaration and scope within a GLSL code block. ```glsl int x = 1; { ``` -------------------------------- ### Get Vector Length in GLSL Source: https://github.com/khronosgroup/glsl/blob/main/chapters/operators.adoc Use the .length() method on vectors to get the number of components. The result is a constant integer. ```glsl vec3 v; const int L = v.length(); ``` -------------------------------- ### Using nonuniformEXT with texture sampling Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_nonuniform_qualifier.txt Demonstrates how to use the nonuniformEXT constructor syntax with a texture sampler when the texture index might be dynamically uniform. This ensures correct handling of nonuniform texture access. ```glsl layout(location = 0) flat in int i; layout(set = 0, binding = 0) uniform sampler2D tex[2]; color = texture(tex[nonuniformEXT(i)], ...); ``` -------------------------------- ### Build GLSL and ESSL Specifications Source: https://github.com/khronosgroup/glsl/blob/main/BUILD.adoc After entering the Docker container or setting up a local build environment, run 'make' to generate HTML5 and PDF outputs for the GLSL and ESSL 4.60 specifications. ```bash cd /glsl make ``` -------------------------------- ### Get Matrix Column Count in GLSL Source: https://github.com/khronosgroup/glsl/blob/main/chapters/operators.adoc Use the .length() method on matrices to get the number of columns. The result is a constant integer. ```glsl mat3x4 v; const int L = v.length(); ``` -------------------------------- ### Geometry Shader Input Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_fragment_shader_barycentric.txt Example of a geometry shader input variable declared as an array to receive per-vertex data from the previous stage. ```glsl in float foo[]; // geometry shader input for vertex "out float foo" ``` -------------------------------- ### Enable GL_EXT_integer_dot_product Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_integer_dot_product.txt Include this line in your shader to enable the GL_EXT_integer_dot_product extension. Behavior is controlled by standard extension behavior. ```glsl #extension GL_EXT_integer_dot_product : ``` -------------------------------- ### Compatibility Profile Per-Vertex Redeclaration Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/builtins.adoc Example of redeclaring the gl_PerVertex block in a compatibility profile shader to explicitly include members like gl_Position. ```glsl out gl_PerVertex { vec4 gl_Position; // will use gl_Position ``` -------------------------------- ### Enable 64-bit Indexing with Pragma Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_shader_64bit_indexing.txt Use this pragma to request 64-bit indexing, as defined in the Vulkan specification. This is useful for ensuring correct behavior with large arrays. ```glsl #pragma shader_64bit_indexing ``` -------------------------------- ### SPIR-V Literal Example (GLSL) Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_spirv_intrinsics.txt An example GLSL shader snippet demonstrating the use of 'spirv_instruction' with an ID, typically used for defining custom SPIR-V instructions or entry points. ```glsl #version 450 core #extension GL_EXT_spirv_intrinsics: enable spirv_instruction(id = 61) ``` -------------------------------- ### GLSL Array Initialization with Constructors Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Shows how to initialize arrays using constructors, including inferring the size of unsized arrays from the constructor arguments. The syntax 'type[]' can also be used for constructors. ```glsl float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1); float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1); // Constructor also of type float[5] ``` -------------------------------- ### Fragment Shader Per-Vertex Input Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_fragment_shader_barycentric.txt Example of a fragment shader input variable qualified with 'pervertexEXT', declared as an unsized array to access per-vertex outputs from the previous stage. ```glsl pervertexEXT in vec4 perVertexAttr[]; ``` -------------------------------- ### Example GLSL Ray Tracing with Shader Invocation Reordering Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_shader_invocation_reorder.txt Demonstrates tracing rays, reordering threads based on hit object and material ID hint, and executing closest-hit shaders. It utilizes functions from `GL_EXT_ray_tracing` and `GL_EXT_shader_invocation_reorder`. ```glsl #version 460 #extension GL_EXT_ray_tracing : enable #extension GL_EXT_buffer_reference_uvec2 : enable #extension GL_EXT_shader_invocation_reorder : enable layout(binding = 0) uniform accelerationStructureEXT as; layout(binding = 1, rgba32f) uniform image2D img; layout(binding = 2) uniform RayParams { vec3 origin;}; layout(location = 0) rayPayloadEXT vec4 Color; layout(buffer_reference, hitobjectshaderrecordnv) buffer SRB { uint materialId; }; layout(location = 0) hitObjectAttributeEXT vec3 sphereAABB; void main() { //Trace rays executing custom intersection/any-hit vec4 outputColor = vec4(0); hitObjectEXT hObj; //Initialize to an empty hit object hitObjectRecordEmptyEXT(hObj); hitObjectTraceRayEXT(hObj, as, 0, 0, 0, 4, 0, origin + vec3(gl_LaunchIDEXT.xyz), 0.0f, origin + vec3(gl_LaunchIDEXT.xyz) + vec3(0,0,1.0f), 1.0f, 0); uint materialIdHint = 0; if (hitObjectIsHitEXT(hObj)) { uvec2 handle = hitObjectGetShaderRecordBufferHandleEXT(hObj); materialIdHint = SRB(handle).materialId; } //Reorder threads based on hit object and additional hint on material type //Use 3 LSB bits only reorderThreadEXT(hObj, materialIdHint, 3); //Execute closest-hit shaders only if (hitObjectIsHitEXT(hObj)) { //Get Attributes of intersection hitObjectGetAttributesEXT(hObj, 0); hitObjectExecuteShaderEXT(hObj, 0); outputColor = vec4(Color.x + distance(sphereAABB, vec3(0))); } imageStore(img, ivec2(gl_LaunchIDEXT.xy), outputColor); } ``` -------------------------------- ### Enable GL_EXT_shader_64bit_indexing Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_shader_64bit_indexing.txt Include this line in your shader to enable the features of the GL_EXT_shader_64bit_indexing extension. The behavior is determined by the specified . ```glsl #extension GL_EXT_shader_64bit_indexing : ``` -------------------------------- ### Run Docker Image for GLSL Spec Build Source: https://github.com/khronosgroup/glsl/blob/main/BUILD.adoc Execute this command from the specification repository root to build the GLSL and ESSL specifications using the Khronos-provided Docker image on a Linux host. ```bash scripts/runDocker ``` -------------------------------- ### Build HTML Specification Output Source: https://github.com/khronosgroup/glsl/blob/main/BUILD.adoc Use the 'html' target with make to build only the HTML specification output. ```bash make html ``` -------------------------------- ### GLSL Callable Shader Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_ray_tracing.txt Example of a GLSL callable shader using GL_NV_ray_tracing. It defines input data and shader record buffer, and calculates a color value based on blend weights. ```glsl #version 460 core #extension GL_NV_ray_tracing : enable layout(location = 0) callableDataInNV float outColor; layout(shaderRecordNV) buffer block { uvec2 blendWeight; }; void main() { outColor = float((blendWeight.x >> 5U) & 0x7U + blendWeight.y & 0x3U); } ``` -------------------------------- ### Enable GL_EXT_shader_tile_image Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_shader_tile_image.txt Include this line in your shader to enable the features described in the GL_EXT_shader_tile_image extension. The behavior is determined by the specified . ```glsl #extension GL_EXT_shader_tile_image : ``` -------------------------------- ### Enable GL_EXT_control_flow_attributes2 Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_control_flow_attributes2.txt Include this line in your shader to enable the GL_EXT_control_flow_attributes2 extension. Replace with the desired behavior setting. ```glsl #extension GL_EXT_control_flow_attributes2 : ``` -------------------------------- ### Annotating Entry Points with subgroup_uniform_control_flow Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_subgroup_uniform_control_flow.txt Use the '[[subgroup_uniform_control_flow]]' attribute syntax to annotate entry points, indicating that subgroups should reconverge uniformly. This is typically applied to the 'main' function. ```glsl void main() [[subgroup_uniform_control_flow]] { ... } ``` -------------------------------- ### GLSL Uniform Block Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc An example of a GLSL uniform block named 'Transform' containing matrix and float variables. Uniform blocks group related uniform variables for easier management. ```glsl uniform Transform { mat4 ModelViewMatrix; mat4 ModelViewProjectionMatrix; uniform mat3 NormalMatrix; // allowed restatement of qualifier float Deformation; }; ``` -------------------------------- ### Ray Generation Shader Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_ray_tracing.txt Example of a Ray Generation Shader using GLSL with ray tracing extensions enabled. It declares ray payload and callable data, and binds acceleration structures and images. ```glsl #version 460 core #extension GL_NV_ray_tracing : enable layout(location = 0) rayPayloadNV vec4 payload; layout(location = 0) callableDataNV float blendColor; layout(binding = 0, set = 0) uniform accelerationStructureNV acc; layout(binding = 1, rgba32f) uniform image2D img; ``` -------------------------------- ### Enable GL_EXT_buffer_reference2 Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_buffer_reference2.txt Include this line in your shader to enable the GL_EXT_buffer_reference2 extension. Enabling this extension also implicitly enables GL_EXT_buffer_reference. ```glsl #extension GL_EXT_buffer_reference2 : ``` -------------------------------- ### Enable GL_NV_shader_subgroup_partitioned Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GL_NV_shader_subgroup_partitioned.txt Include this line in your shader to enable the GL_NV_shader_subgroup_partitioned extension. Enabling this extension also implicitly enables GL_KHR_shader_subgroup_basic. ```glsl #extension GL_NV_shader_subgroup_partitioned : ``` -------------------------------- ### GLSL Array Length() Method Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Shows how to use the .length() method to get the number of elements in an array. The return type is 'int'. The method can be called on multi-dimensional arrays to get the size of specific dimensions. ```glsl float a[5]; a.length(); // returns 5 vec4 a[3][2]; a.length() // returns 3 a[x].length() // returns 2 ``` -------------------------------- ### Enable GL_EXT_demote_to_helper_invocation Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_demote_to_helper_invocation.txt Include this line in your shader to enable the demote to helper invocation extension. Replace with the desired behavior specifier. ```glsl #extension GL_EXT_demote_to_helper_invocation : ``` -------------------------------- ### GLSL Undefined Behavior Examples Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Illustrates scenarios in GLSL where behavior is undefined due to side effects within expressions or indexing out of bounds. Use these examples to understand potential pitfalls and ensure code correctness. ```glsl float a, b; float[2](a=3.0, ++b).length(); // Behavior undefined. Illegal side effects float c[5][3]; c[7].length(); // Error. Static indexing out of bounds. c[i].length(); // Valid, returns 3 even if i < 0 or i >= 5 at runtime. struct S { float a[3]; } s[5]; s[i+3].a.length(); // Valid. Returns 3 for all inputs i. s[i++].a.length(); // Behavior undefined. Illegal side-effects. buffer B { float x[3]; float y[]; } b[5]; b[i++].x.length(); // Behaviour undefined. Illegal side-effects. b[i++].y.length(); // Valid. i is incremented and b dereferenced. The runtime size // of y is returned if 0 <= x < 5, behavior undefined if not. ``` -------------------------------- ### Enable GL_EXT_ray_tracing Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_tracing.txt Include this line in a shader to enable features described in the GL_EXT_ray_tracing extension. The behavior is determined by the specified . ```glsl #extension GL_EXT_ray_tracing : ``` -------------------------------- ### GLSL Ray Generation Shader Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_ray_tracing.txt Example of a GLSL ray generation shader using GL_NV_ray_tracing. It defines ray parameters, a function to compute direction, and the main function to initiate ray tracing and callable shaders. ```glsl layout(binding = 1, set = 0) uniform rayParams { vec3 rayOrigin; vec3 rayDir; uint sbtOffset; uint sbtStride; uint missIndex; uint callableSbtIndex; }; vec3 computeDir(vec3 inDir) { inDir.x = inDir.x + float(gl_LaunchIDNV.x / gl_LaunchSizeNV.x); inDir.y = inDir.y + float(gl_LaunchIDNV.y / gl_LaunchSizeNV.y); return inDir; } void main() { vec4 imgColor = vec4(0); traceNV(acc, gl_RayFlagsOpaqueNV, 0xff, sbtOffset, sbtStride, missIndex, rayOrigin, 0.0, computeDir(rayDir), 100.0f, 0 /* payload */); executeCallableNV(callableSbtIndex, 0 /* blendColor */); imgColor = payload + vec4(blendColor) ; imageStore(img, ivec2(gl_LaunchIDNV), imgColor); } ``` -------------------------------- ### Enable GL_EXT_opacity_micromap Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_opacity_micromap.txt Include this line in your shader to enable the GL_EXT_opacity_micromap extension. The behavior can be controlled by specifying ''. ```glsl #extension GL_EXT_opacity_micromap : ``` -------------------------------- ### Enable GL_EXT_shader_image_int64 Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_shader_image_int64.txt Include this line in your shader to enable the features of the GL_EXT_shader_image_int64 extension. Replace with the desired behavior as specified in the GLSL specification. ```glsl #extension GL_EXT_shader_image_int64 : ``` -------------------------------- ### Get World Ray Direction Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_query.txt Retrieves the world-space direction of the ray for the ray query. ```glsl vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT q); ``` -------------------------------- ### Get World Ray Origin Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_query.txt Retrieves the world-space origin of the ray for the ray query. ```glsl vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT q); ``` -------------------------------- ### Enable GL_EXT_debug_printf Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_debug_printf.txt Include this line in your shader to enable the GL_EXT_debug_printf extension. The behavior is determined by the specified . ```glsl #extension GL_EXT_debug_printf : ``` -------------------------------- ### Get Ray Query Flags Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_query.txt Retrieves the ray flags associated with the ray query. ```glsl uint rayQueryGetRayFlagsEXT(rayQueryEXT q); ``` -------------------------------- ### Interface Block Qualifier Example Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_fragment_shader_barycentric.txt Demonstrates the 'pervertexEXT' qualifier being used with an interface block in GLSL. ```glsl interface-qualifier: ... pervertexEXT in ... ``` -------------------------------- ### Get Ray Query tMin Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_query.txt Retrieves the minimum parametric distance (tMin) for the ray query. ```glsl float rayQueryGetRayTMinEXT(rayQueryEXT q); ``` -------------------------------- ### Uniform Location Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Demonstrates the use of layout location specifiers for uniform variables and input variables. Note that uniform locations are logical and do not conflict, while input locations can conflict. ```glsl layout(location = 2) uniform mat4 x; layout(location = 3) uniform mat4 y; // No overlap with x layout(location = 2) in mat4 x; layout(location = 3) in mat4 y; // Error, locations conflict with x ``` -------------------------------- ### Enable GL_EXT_shader_realtime_clock Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_shader_realtime_clock.txt Include this line in your shader to enable the GL_EXT_shader_realtime_clock extension. Replace with the desired behavior, typically 'enable'. ```glsl #extension GL_EXT_shader_realtime_clock : ``` -------------------------------- ### GLSL Precision Qualifier Examples Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Demonstrates the declaration and usage of variables with different precision qualifiers in GLSL. ```glsl lowp float color; out mediump vec2 P; lowp ivec2 foo(lowp mat3); highp mat4 m; ``` -------------------------------- ### Enable Ray Tracing Position Fetch Extension in GLSL Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GLSL_EXT_ray_tracing_position_fetch.txt Include this line in your GLSL shader to enable the GL_EXT_ray_tracing_position_fetch extension. Replace with the desired behavior (e.g., 'enable'). ```glsl #extension GL_EXT_ray_tracing_position_fetch : ``` -------------------------------- ### ESSL Input Variable Location Assignment Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Example of assigning ESSL input variables to a specific location. ```glsl layout(location = 3) in vec4 normal; ``` -------------------------------- ### GLSL Transform Feedback Offset Error Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc This example demonstrates a compile-time or link-time error due to an offset that would require a stride larger than specified. The offset for 'd' (24) plus its size (12) exceeds the implied stride based on 'c' (12 + 12 = 24), and the total size needed would be 36, which is not compatible with a stride of 32. ```glsl layout(xfb_buffer = 2, xfb_stride = 32) out block3 { layout(xfb_offset = 12) vec3 c; layout(xfb_offset = 24) vec3 d; // ERROR, requires stride of 36 layout(xfb_offset = 0) vec3 g; // okay, increasing order not required }; ``` -------------------------------- ### Enable GLSL Extensions Source: https://github.com/khronosgroup/glsl/blob/main/extensions/ext/GL_EXT_float8_e5m2_e4m3.txt Include these lines in your shader to enable the new floating-point types. Replace with the desired extension behavior. ```glsl #extension GL_EXT_float_e5m2 : #extension GL_EXT_float_e4m3 : ``` -------------------------------- ### Hit Kind and Attribute Retrieval Source: https://github.com/khronosgroup/glsl/blob/main/extensions/nv/GLSL_NV_shader_invocation_reorder.txt Functions to get the hit kind and extract shader attributes from a hit object. ```APIDOC ## uint hitObjectGetHitKindNV(hitObjectNV hitObject) ### Description Returns values as defined in EXT_ray_tracing specification for gl_HitKindEXT. ### Method uint ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response - **uint** (uint) - The hit kind value. ## void hitObjectGetAttributesNV(hitObjectNV hitObject, int attributeLocation) ### Description Extracts the attributes encoded in the hit object and writes to 'hitObjectAttributeNV' storage class decorated variable selected using 'attributeLocation' as specified below. is a compile-time constant to select a shader defined structure used to populate with attributes associated with this hit object. It is possible for a shader to contain multiple invocations 'hitObjectGetAttributesNV' with different attribute types. Different attribute types are chosen based on the different values of the compile-time constant which correspond to the hitObjectAttributeNV qualified variables having the same value for the location layout qualifier. ### Method void ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Enable GL_ARM_shader_core_builtins Extension Source: https://github.com/khronosgroup/glsl/blob/main/extensions/arm/GLSL_ARM_shader_core_builtins.txt Include this line in your shader to enable the GL_ARM_shader_core_builtins extension. Replace with the desired behavior as specified in section 3.3 of the OpenGL Shading Language. ```glsl #extension GL_ARM_shader_core_builtins : ``` -------------------------------- ### GLSL Layout Qualifier Example Source: https://github.com/khronosgroup/glsl/blob/main/chapters/variables.adoc Demonstrates the cascading effect of multiple layout qualifiers in a GLSL declaration. Qualifiers applied later override earlier ones. ```glsl layout(row_major, column_major) ```