Name Strings
SPV_KHR_shader_ballot
Contact
See Issues list in the Khronos SPIRVHeaders repository: https://github.com/KhronosGroup/SPIRVHeaders
Contributors

Neil Henning, Codeplay

Kerch Holt, NVIDIA

John Kessenich, Google

Daniel Koch, NVIDIA

David Neto, Google

Daniel Rakos, AMD

Rex Xu, AMD
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: 20160712

Ratified by the Khronos Board: 20160902
Version
Last Modified Date 
20161018 
Revision 
11 
Dependencies
This extension is written against the SPIRV Specification, Version 1.1 Revision 1.
This extension requires SPIRV 1.0.
Overview
This extension provides new builtin variable decorations and instructions to support the OpenGL GL_ARB_shader_ballot extension in SPIRV.
Unlike GL_ARB_shader_ballot the SPIRV extension does not depend on GL_ARB_shader_gpu_int64 because the types representing subgroup IDs are held in a 4 component vector of integers.
Extension Name
To use this extension within a SPIRV module, OpExtension "SPV_KHR_shader_ballot", must be present in the module:
OpExtension "SPV_KHR_shader_ballot"
New Capabilities
This extension introduces a new capability.
SubgroupBallotKHR
New Builtins
Builtin variables provide a bitmask for invocations.
SubgroupEqMaskKHR SubgroupGeMaskKHR SubgroupGtMaskKHR SubgroupLeMaskKHR SubgroupLtMaskKHR
New Instructions
Instructions added under SubgroupBallotKHR capability.
OpSubgroupBallotKHR OpSubgroupFirstInvocationKHR OpSubgroupReadInvocationKHR
Token Number Assignments
SubgroupEqMaskKHR 
4416 
SubgroupGeMaskKHR 
4417 
SubgroupGtMaskKHR 
4418 
SubgroupLeMaskKHR 
4419 
SubgroupLtMaskKHR 
4420 
OpSubgroupBallotKHR 
4421 
OpSubgroupFirstInvocationKHR 
4422 
SubgroupBallotKHR 
4423 
OpSubgroupReadInvocationKHR 
4432 
Modifications to the SPIRV Specification, Version 1.1
 (Modify Section 3.21, BuiltIn)

 (add the following new builtins to the table)

BuiltIn Required Capability 4416
SubgroupEqMaskKHR
Provides a 4 component 32 bit integer vector bitmask for all invocations with one bit per invocation starting with the least significant bit in the first vector component continuing to the last bit (less than SubgroupSize) in the last required vector component where SubgroupLocalInvocationId is equal to the bit index.SubgroupBallotKHR
4417
SubgroupGeMaskKHR
Provides a 4 component 32 bit integer vector bitmask for all invocations with one bit per invocation starting with the least significant bit in the first vector component continuing to the last bit (less than SubgroupSize) in the last required vector component where SubgroupLocalInvocationId is greater than or equal to the bit index.SubgroupBallotKHR
4418
SubgroupGtMaskKHR
Provides a 4 component 32 bit integer vector bitmask for all invocations with one bit per invocation starting with the least significant bit in the first vector component continuing to the last bit (less than SubgroupSize) in the last required vector component where SubgroupLocalInvocationId is greater than the bit index.SubgroupBallotKHR
4419
SubgroupLeMaskKHR
Provides a 4 component 32 bit integer vector bitmask for all invocations with one bit per invocation starting with the least significant bit in the first vector component continuing to the last bit (less than SubgroupSize) in the last required vector component where SubgroupLocalInvocationId is less than or equal to the bit index.SubgroupBallotKHR
4420
SubgroupLtMaskKHR
Provides a 4 component 32 bit integer vector bitmask for all invocations with one bit per invocation starting with the least significant bit in the first vector component continuing to the last bit (less than SubgroupSize) in the last required vector component where SubgroupLocalInvocationId is less than the bit index.SubgroupBallotKHR
(Add the SubgroupBallotKHR capability to SubgroupSize.)
(Add the SubgroupBallotKHR capability to SubgroupLocalInvocationId.)
 (Modify Section 3.31, Capability, adding a row to the Capability table)

Capability Depends On 4423
SubgroupBallotKHR
 (Modify Section 3.32.21, Group Instructions, adding to the end of the list of instructions)

Validation Rules
None.
Issues

The subgroup mask is specified as a 64 bit integer type which may artificially limit the number of subgroups.
RESOLVED: Result type and masks now changed to 4 component vector of 32 bit integers.

Should these instructions have a scope of Subgroup instead of limiting them to a set of subgroups?
RESOLVED: The scope is Subgroup (SPIRV WG 6/28/2016)

The functionality for readInvocationARB is presumed to be supported through the OpGroupBroadcast with Subgroup scope.
RESOLVED: The use of OpGroupBroadcast is sufficient (SPIRV WG 6/28/2016) RERESOLVED: OpGroupBroadcast has a different semantic than what is precisely desired. readInvocationARB may appear in dynamically nonuniform control flow paths and doesn’t have a scope. Concluded that a new instruction is required. (SPIRV WG 10/18/2016)

The GL_ARB_shader_ballot extension calls out explicitly a dependency on the int64 bit type. Does this dependency need to be called out?
RESOLVED: Result type and mask type changed to 4 component vector and thus removes dependency on GL_ARB_shader_gpu_int64.

GL_ARB_shader_ballot allows calls to ballotARB in control flow so the semantics of subgroup may be different than the current SPIRV definition of subgroup.
RESOLVED: (Paraphrasing David Neto) A "lockstep" concept of execution is replaced by use of the concept of "dynamic instance" (already in the SPIRV spec), and subgroups. This doesn’t force B=D in the following example. It does not define pairwise reconvergence of invocations in the absence of completely uniform control flow.
void foo() { const bool odd = gl_VertexID & 1; const bool odd2 = gl_VertexID & 2; uint64_t A = 0; uint64_t B = 0; uint64_t C = 0; uint64_t D = 0; uint64_t E = 0; A = ballotARB(true) if (odd) { B = ballotARB(true); if (odd2) { C = ballotARB(true); } D = ballotARB(true); } E = ballotARB(true); }
Revision History
Rev  Date  Author  Changes 

1 
20160510 
Kerch Holt 
Initial revision 
2 
20160517 
Kerch Holt 
Changes as per SPIRV WG May 17th 
3 
20160524 
Kerch Holt 
Change result type and mask type to 4 component int 32 vector 
4 
20160608 
Kerch Holt 
Change names to include "KHR" and update to include suggestions from reviews and SPIRV WG. 
5 
20160628 
Kerch Holt 
Filled in the remaining "UNRESOLVED" text as per SPIRV WG. Added token number assignments 
6 
20160802 
Kerch Holt 
Added wording to cover case of bit values for inactive invocations. 
7 
20160902 
Kerch Holt 
Added token number for ShaderBallot capability. 
8 
20160906 
David Neto 
Rename SubgroupBallot capability to SubgroupBallotKHR 
9 
20160913 
Kerch Holt 
Changed status to "ratified" with date 
10 
20160920 
Daniel Koch 
Improve formatting, use ISO dates, remove extension number 
11 
20161018 
Kerch Holt 
Add instruction for readInvocationARB (as per Oct 18th SPIRV meeting) 