• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016-2024 The Khronos Group Inc.
2//
3// SPDX-License-Identifier: CC-BY-4.0
4
5include::{generated}/meta/{refprefix}VK_EXT_shader_subgroup_vote.adoc[]
6
7=== Other Extension Metadata
8
9*Last Modified Date*::
10    2016-11-28
11*IP Status*::
12    No known IP claims.
13*Interactions and External Dependencies*::
14  - This extension provides API support for
15    {GLregistry}/ARB/ARB_shader_group_vote.txt[`GL_ARB_shader_group_vote`]
16*Contributors*::
17  - Neil Henning, Codeplay
18  - Daniel Koch, NVIDIA Corporation
19
20=== Description
21
22This extension adds support for the following SPIR-V extension in Vulkan:
23
24  * `SPV_KHR_subgroup_vote`
25
26This extension provides new SPIR-V instructions:
27
28  * code:OpSubgroupAllKHR,
29  * code:OpSubgroupAnyKHR, and
30  * code:OpSubgroupAllEqualKHR.
31
32to compute the composite of a set of boolean conditions across a group of
33shader invocations that are running concurrently (a _subgroup_).
34These composite results may be used to execute shaders more efficiently on a
35slink:VkPhysicalDevice.
36
37When using GLSL source-based shader languages, the following shader
38functions from GL_ARB_shader_group_vote can map to these SPIR-V
39instructions:
40
41  * code:anyInvocationARB() -> code:OpSubgroupAnyKHR,
42  * code:allInvocationsARB() -> code:OpSubgroupAllKHR, and
43  * code:allInvocationsEqualARB() -> code:OpSubgroupAllEqualKHR.
44
45The subgroup across which the boolean conditions are evaluated is
46implementation-dependent, and this extension provides no guarantee over how
47individual shader invocations are assigned to subgroups.
48In particular, a subgroup has no necessary relationship with the compute
49shader _local workgroup_ -- any pair of shader invocations in a compute
50local workgroup may execute in different subgroups as used by these
51instructions.
52
53Compute shaders operate on an explicitly specified group of threads (a local
54workgroup), but many implementations will also group non-compute shader
55invocations and execute them concurrently.
56When executing code like
57
58[source,c++]
59----
60if (condition) {
61  result = do_fast_path();
62} else {
63  result = do_general_path();
64}
65----
66
67where code:condition diverges between invocations, an implementation might
68first execute code:do_fast_path() for the invocations where code:condition
69is true and leave the other invocations dormant.
70Once code:do_fast_path() returns, it might call code:do_general_path() for
71invocations where code:condition is code:false and leave the other
72invocations dormant.
73In this case, the shader executes *both* the fast and the general path and
74might be better off just using the general path for all invocations.
75
76This extension provides the ability to avoid divergent execution by
77evaluating a condition across an entire subgroup using code like:
78
79[source,c++]
80----
81if (allInvocationsARB(condition)) {
82  result = do_fast_path();
83} else {
84  result = do_general_path();
85}
86----
87
88The built-in function code:allInvocationsARB() will return the same value
89for all invocations in the group, so the group will either execute
90code:do_fast_path() or code:do_general_path(), but never both.
91For example, shader code might want to evaluate a complex function
92iteratively by starting with an approximation of the result and then
93refining the approximation.
94Some input values may require a small number of iterations to generate an
95accurate result (code:do_fast_path) while others require a larger number
96(code:do_general_path).
97In another example, shader code might want to evaluate a complex function
98(code:do_general_path) that can be greatly simplified when assuming a
99specific value for one of its inputs (code:do_fast_path).
100
101=== Deprecated by Vulkan 1.1
102
103All functionality in this extension is superseded by the core Vulkan 1.1
104<<VkPhysicalDeviceSubgroupProperties, subgroup operations>>.
105
106include::{generated}/interfaces/VK_EXT_shader_subgroup_vote.adoc[]
107
108=== New SPIR-V Capabilities
109
110  * <<spirvenv-capabilities-table-SubgroupVoteKHR, code:SubgroupVoteKHR>>
111
112=== Version History
113
114  * Revision 1, 2016-11-28 (Daniel Koch)
115  ** Initial draft
116