invocationSubgroupIndex
In a compute shader, provides the current thread with a unique integer index within its hardware subgroup (typically 32 or 64 threads), used for extreme low-level performance optimization.
Core Advantages
Its core value is unlocking hardware-level parallel computing capabilities. It allows threads within a subgroup to exchange data directly via specialized high-speed instructions (like shuffle), bypassing slower shared memory and synchronization barriers, thus achieving maximum performance for parallel algorithms.
Common Uses
In ultra-efficient parallel reduction, as a high-speed data exchanger for rapid summation using subgroup instructions.
In parallel scan (prefix sum) algorithms, as a coordinator for efficient data shuffling.
In histogram calculation, to optimize performance by pre-aggregating within the subgroup to reduce atomic operation contention.
How to adjust
This node is a read-only built-in variable and cannot be adjusted. Its effect is understood through visualization: normalize the index value to a grayscale color. If a workgroup contains multiple subgroups (e.g., a 256-thread workgroup has 8 subgroups of size 32), the output texture will show multiple, shorter, repeating gradient patterns within each workgroup's area, clearly revealing the hardware subgroup structure.
Code Examples
1// Assuming subgroupSize is 32, normalize the index from the [0, 31] range
2const factor = invocationSubgroupIndex.tofloat().div( 31.0 );
3
4// Create a grayscale color for debugging based on the factor
5const debugColor = vec3( factor );