Name Strings
SPV_KHR_subgroup_vote
Contact
To report problems with this extension, please open a new issue at:
Contributors
-
Kerch Holt, NVIDIA
-
Daniel Koch, NVIDIA
-
Ashwin Kolhe, NVIDIA
-
John Kessenich, Google
-
David Neto, Google
Notice
Copyright (c) 2016 The Khronos Group Inc. Copyright terms at http://www.khronos.org/registry/speccopyright.html
Status
-
Complete
-
Approved by the SPIR Working Group: 2016-10-18
-
Ratified by the Khronos Board: 2017-01-11
Version
Last Modified Date |
2016-10-05 |
Revision |
6 |
Dependencies
This extension is written against the SPIR-V Specification, Version 1.1 Revision 1.
This extension requires SPIR-V 1.0.
Overview
This extension adds three new subgroup instructions: OpSubgroupAllKHR, OpSubgroupAnyKHR, and OpSubgroupAllEqualKHR to support the OpenGL GL_ARB_shader_group_vote extension in SPIR-V.
Each of these instructions computes a boolean function over boolean values contributed by the set of invocations in a subgroup.
The new functionality is enabled under the SubgroupVoteKHR capability.
Extension Name
To use this extension within a SPIR-V module, the following OpExtension must be present in the module:
OpExtension "SPV_KHR_subgroup_vote"
New Capabilities
This extension introduces a new capability:
SubgroupVoteKHR
New Builtins
None.
New Instructions
Instructions added under SubgroupVoteKHR capability:
OpSubgroupAllKHR OpSubgroupAnyKHR OpSubgroupAllEqualKHR
Token Number Assignments
OpSubgroupAllKHR |
4428 |
OpSubgroupAnyKHR |
4429 |
OpSubgroupAllEqualKHR |
4430 |
SubgroupVoteKHR |
4431 |
Modifications to the SPIR-V Specification, Version 1.1
- (Add a new Section 2.21, Subgroup Vote)
-
This functionality is available on the OpSubgroupAllKHR, OpSubgroupAnyKHR, and OpSubgroupAllEqualKHR instructions. The SubgroupVoteKHR capability must be declared in any module where these instructions are used.
These operations may be executed within dynamically non-uniform control flow. In groups where some invocations do not execute the instruction, the value returned is not affected by any invocation not executing the instruction, even when Predicate is well-defined for that invocation.
Since these instructions depend on the values of Predicate in an implementation-defined group of invocations (the Subgroup), the value returned by these instructions is implementation-defined. However, OpSubgroupAnyKHR is guaranteed to return true if Predicate evaluates to true, and OpSubgroupAllKHR is guaranteed to return false if Predicate evaluates false.
Note: Implementations are not required to combine invocations into groups of any specific size. When SubgroupSize is 1, OpSubgroupAnyKHR and OpSubgroupAllKHR will return Predicate and OpSubgroupAllEqualKHR will return true.
For fragment shaders, invocations in a subgroup may include invocations corresponding to pixels that are covered by a primitive being rasterized, as well as invocations corresponding to neighboring pixels not covered by the primitive. The invocations for these neighboring pixels (HelperInvocation) may be created so that differencing can be used to evaluate derivative instructions like OpDPdx and OpDPdy (section 3.32.16) and implicit derivatives used by OpImageSampleImplicitLod and related functions (section 3.32.10). The value of Predicate for such HelperInvocations contribute to the value returned by OpSubgroupAllKHR, OpSubgroupAnyKHR, and OpSubgroupAllEqualKHR.
- (Modify Section 3.31, Capability, adding a row to the Capability table)
-
Capability Depends On 4431
SubgroupVoteKHR
- (Modify Section 3.32.21, Group Instructions, adding to the end of the list of instructions)
-
OpSubgroupAllKHR
Evaluates a predicate for all invocations in the current Subgroup that execute the same dynamic instance of this instruction, resulting in true if Predicate evaluates to true for all such invocations, otherwise the result is false. See Subgroup Vote.
Result Type must be a Boolean type.
Predicate must be a Boolean type.Capability:
SubgroupVoteKHR4
4428
<id>
Result TypeResult <id>
<id> Predicate
OpSubgroupAnyKHR
Evaluates a predicate for all invocations in the current Subgroup that execute the same dynamic instance of this instruction, resulting in true if Predicate evaluates to true for any such invocations, otherwise the result is false. See Subgroup Vote.
Result Type must be a Boolean type.
Predicate must be a Boolean type.Capability:
SubgroupVoteKHR4
4429
<id>
Result TypeResult <id>
<id> Predicate
OpSubgroupAllEqualKHR
Evaluates a predicate for all invocations in the current Subgroup that execute the same dynamic instance of this instruction, resulting in true if Predicate evaluates the same for such invocations, otherwise the result is false. See Subgroup Vote.
Result Type must be a Boolean type.
Predicate must be a Boolean type.Capability:
SubgroupVoteKHR4
4430
<id>
Result TypeResult <id>
<id> Predicate
Validation Rules
An OpExtension must be added to the SPIR-V for validation layers to check legal use of this extension:
OpExtension "SPV_KHR_subgroup_vote"
Issues
-
SPIR-V 1.1 already has OpGroupAny and OpGroupAll, are these sufficient?
RESOLVED: OpGroupAllEqual(predicate) could be emulated in a compiler front-end as (OpGroupAll(predicate) || !OpGroupAny(predicate)). However if the underlying hardware’s instruction set actually has a native AllEqual instruction this would result in either a) reduced performance since it must execute two instructions instead of one, or b) complicated compiler heuristics to detect the above pattern and collapse it back to one instruction. In order to give the full expressiveness of the higher level languages (such as GLSL), we’ll add a dedicated instruction for this.
-
Do we need a capability?
RESOLVED: Yes. We’ll add capability with extensions so that it’s simpler to move them into the core without needing complicated consumer logic.
-
Where can these instructions be executed?
DISCUSSION: GL_ARB_shader_group_vote says: "These functions may be called in conditionally executed code. In groups where some invocations do not execute the function call, the value returned by the function is not affected by any invocation not calling the function, even when <value> is well-defined for that invocation."
The existing SPIR-V OpGroup* instructions say: "All invocations of this module within Execution must reach this point of execution. This instruction is only guaranteed to work correctly if placed strictly within uniform control flow within Execution. This ensures that if any invocation executes it, all invocations will execute it. If placed elsewhere, an invocation may stall indefinitely."
RESOLVED: Due to the potentially differing semantics between the existing OpGroup* instructions and the instructions this extension wishes to support, we’ll add new dedicated instructions here.
-
Should the SubgroupVoteKHR capability be dependent on the Shader capability?
RESOLVED: No. There is no technical reason why it needs to be, and this enables it to be used in Kernels, if so desired and supported.
-
How do OpGroup{All,Any} differ from OpSubgroup{All,Any}KHR?
RESOLVED: The existing OpGroup instructions can only be used in uniform control flow, and take an execution scope which can either be workgroup or subgroup. The OpSubgroup*KHR instructions allow execution in dynamically non-uniform control flow, and only operate at the subgroup scope.
Revision History
Rev | Date | Author | Changes |
---|---|---|---|
1 |
2016-07-19 |
Daniel Koch |
Initial draft |
2 |
2016-08-09 |
Daniel Koch |
Add issue 2 and 3. Require Subgroup scope. Editorial changes. |
3 |
2016-08-16 |
Daniel Koch |
Add SubgroupVote capability. Add language allowing these to be used in conditionally executed code. Add more expository language about the functionality. Add Validation rules. |
4 |
2016-09-13 |
Daniel Koch |
Add suffix to capability and beautify. Move functional language to new section 2.21. |
5 |
2016-09-23 |
Daniel Koch |
Rename to KHR and assign enums. Use dedicated instructions instead of trying to leverage existing OpGroup instructions. Align language with SPV_KHR_shader_ballot. Various clarifications. |
6 |
2016-10-05 |
Daniel Koch |
Incorporated review feedback from dneto. |