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