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