1Name 2 3 EXT_shader_group_vote 4 5Name Strings 6 7 GL_EXT_shader_group_vote 8 9Contact 10 11 Tobias Hector, Imagination Technologies (tobias.hector 'at' imgtec.com) 12 13Contributors 14 15 Contributors to the original ARB_shader_group_vote specification 16 Daniel Koch, NVIDIA 17 18Status 19 20 Complete 21 22Version 23 24 Last Modified Date: December 10, 2018 25 Revision: 3 26 27Number 28 29 OpenGL ES Extension #254 30 31Dependencies 32 33 This extension is written against the OpenGL ES Shading Language 34 Specification, Version 3.00.4. 35 36 OpenGL ES 3.0 is required. 37 38Overview 39 40 This extension provides new built-in functions to compute the composite of 41 a set of boolean conditions across a group of shader invocations. These 42 composite results may be used to execute shaders more efficiently on a 43 single-instruction multiple-data (SIMD) processor. The set of shader 44 invocations across which boolean conditions are evaluated is 45 implementation-dependent, and this extension provides no guarantee over 46 how individual shader invocations are assigned to such sets. In 47 particular, the set of shader invocations has no necessary relationship 48 with the compute shader workgroup -- a pair of shader invocations 49 in a single compute shader workgroup may end up in different sets used by 50 these built-ins. 51 52 Compute shaders operate on an explicitly specified group of threads (a 53 workgroup), but many implementations of OpenGL ES 3.0 will even group 54 non-compute shader invocations and execute them in a SIMD fashion. When 55 executing code like 56 57 if (condition) { 58 result = do_fast_path(); 59 } else { 60 result = do_general_path(); 61 } 62 63 where <condition> diverges between invocations, a SIMD implementation 64 might first call do_fast_path() for the invocations where <condition> is 65 true and leave the other invocations dormant. Once do_fast_path() 66 returns, it might call do_general_path() for invocations where <condition> 67 is false and leave the other invocations dormant. In this case, the 68 shader executes *both* the fast and the general path and might be better 69 off just using the general path for all invocations. 70 71 This extension provides the ability to avoid divergent execution by 72 evaluting a condition across an entire SIMD invocation group using code 73 like: 74 75 if (allInvocationsEXT(condition)) { 76 result = do_fast_path(); 77 } else { 78 result = do_general_path(); 79 } 80 81 The built-in function allInvocationsEXT() will return the same value for 82 all invocations in the group, so the group will either execute 83 do_fast_path() or do_general_path(), but never both. For example, shader 84 code might want to evaluate a complex function iteratively by starting 85 with an approximation of the result and then refining the approximation. 86 Some input values may require a small number of iterations to generate an 87 accurate result (do_fast_path) while others require a larger number 88 (do_general_path). In another example, shader code might want to evaluate 89 a complex function (do_general_path) that can be greatly simplified when 90 assuming a specific value for one of its inputs (do_fast_path). 91 92New Procedures and Functions 93 94 None. 95 96New Tokens 97 98 None. 99 100New Shading Language Functions 101 102 bool anyInvocationEXT(bool value); 103 bool allInvocationsEXT(bool value); 104 bool allInvocationsEqualEXT(bool value); 105 106Modifications to the OpenGL Shading Language Specification 107 108 Including the following line in a shader can be used to control the 109 language features described in this extension: 110 111 #extension GL_EXT_shader_group_vote : <behavior> 112 113 where <behavior> is as specified in section 3.4. 114 115 New preprocessor #defines are added to the OpenGL ES Shading Language: 116 117 #define GL_EXT_shader_group_vote 1 118 119 Modify Chapter 8, Built-in Functions 120 121 (insert a new section at the end of the chapter) 122 123 Section 8.10, Shader Invocation Group Functions 124 125 Implementations of the OpenGL ES Shading Language may optionally group 126 multiple shader invocations for a single shader stage into a single SIMD 127 invocation group, where invocations are assigned to groups in an 128 undefined, implementation-dependent manner. Shader algorithms on such 129 implementations may benefit from being able to evaluate a composite of 130 boolean values over all active invocations in a group. 131 132 Syntax: 133 134 bool anyInvocationEXT(bool value); 135 bool allInvocationsEXT(bool value); 136 bool allInvocationsEqualEXT(bool value); 137 138 The function anyInvocationEXT() returns true if and only if <value> is 139 true for at least one active invocation in the group. 140 141 The function allInvocationsEXT() returns true if and only if <value> is 142 true for all active invocations in the group. 143 144 The function allInvocationsEqualEXT() returns true if <value> is the same 145 for all active invocations in the group. 146 147 For all of these functions, the same value is returned to all active 148 invocations in the group. 149 150 These functions may be called in conditionally executed code. In groups 151 where some invocations do not execute the function call, the value 152 returned by the function is not affected by any invocation not calling the 153 function, even when <value> is well-defined for that invocation. 154 155 Since these functions depend on the values of <value> in an undefined 156 group of invocations, the value returned by these functions is largely 157 undefined. However, anyInvocationEXT() is guaranteed to return true if 158 <value> is true, and allInvocationsEXT() is guaranteed to return false if 159 <value> is false. 160 161 Since implementations are not required to combine invocations into groups, 162 simply returning <value> for anyInvocationEXT() and allInvocationsEXT() 163 and returning true for allInvocationsEqualEXT() is a legal implementation 164 of these functions. 165 166 For fragment shaders, invocations in a SIMD invocation group may include 167 invocations corresponding to pixels that are covered by a primitive being 168 rasterized, as well as invocations corresponding to neighboring pixels not 169 covered by the primitive. The invocations for these neighboring "helper" 170 pixels may be created so that differencing can be used to evaluate 171 derivative functions like dFdx() and dFdx() (section 8.9) and implicit 172 derivatives used by texture() and related functions (section 8.8). The 173 value of <value> for such "helper" pixels may affect the value returned by 174 anyInvocationEXT(), allInvocationsEXT(), and allInvocationsEqualEXT(). 175 176Errors 177 178 None. 179 180New State 181 182 None. 183 184New Implementation Dependent State 185 186 None. 187 188Issues 189 190 Note: The EXT_shader_group_vote specification is based on the OpenGL 191 extension ARB_shader_group_vote as updated in OpenGL 4.x. Resolved issues 192 from ARB_shader_group_vote have been removed, but some remain applicable to 193 this extension. ARB_shader_group_vote can be found in the OpenGL Registry. 194 195Revision History 196 197 Revision 3, December 10, 2018 (Jon Leech) 198 - Use 'workgroup' consistently throughout (Bug 11723, internal API 199 issue 87). 200 Revision 2, October 21, 2015 201 - Promoted to EXT 202 Revision 1, October 23, 2014 203 - Initial revision. 204