modify_maximal_reconvergence_test.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // Copyright (c) 2024 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "assembly_builder.h"
  15. #include "pass_fixture.h"
  16. #include "pass_utils.h"
  17. namespace {
  18. using namespace spvtools;
  19. using ModifyMaximalReconvergenceTest = opt::PassTest<::testing::Test>;
  20. TEST_F(ModifyMaximalReconvergenceTest, AddNoEntryPoint) {
  21. const std::string text = R"(
  22. ; CHECK-NOT: OpExtension
  23. OpCapability Kernel
  24. OpCapability Linkage
  25. OpMemoryModel Logical OpenCL
  26. )";
  27. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  28. }
  29. TEST_F(ModifyMaximalReconvergenceTest, AddSingleEntryPoint) {
  30. const std::string text = R"(
  31. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  32. ; CHECK: OpExecutionMode %main MaximallyReconvergesKHR
  33. OpCapability Shader
  34. OpMemoryModel Logical GLSL450
  35. OpEntryPoint GLCompute %main "main"
  36. OpExecutionMode %main LocalSize 1 1 1
  37. OpName %main "main"
  38. %void = OpTypeVoid
  39. %void_fn = OpTypeFunction %void
  40. %main = OpFunction %void None %void_fn
  41. %entry = OpLabel
  42. OpReturn
  43. OpFunctionEnd
  44. )";
  45. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  46. }
  47. TEST_F(ModifyMaximalReconvergenceTest, AddExtensionExists) {
  48. const std::string text = R"(
  49. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  50. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  51. ; CHECK: OpExecutionMode %main MaximallyReconvergesKHR
  52. OpCapability Shader
  53. OpExtension "SPV_KHR_maximal_reconvergence"
  54. OpMemoryModel Logical GLSL450
  55. OpEntryPoint GLCompute %main "main"
  56. OpExecutionMode %main LocalSize 1 1 1
  57. OpName %main "main"
  58. %void = OpTypeVoid
  59. %void_fn = OpTypeFunction %void
  60. %main = OpFunction %void None %void_fn
  61. %entry = OpLabel
  62. OpReturn
  63. OpFunctionEnd
  64. )";
  65. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  66. }
  67. TEST_F(ModifyMaximalReconvergenceTest, AddExecutionModeExists) {
  68. const std::string text = R"(
  69. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  70. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  71. ; CHECK: OpExecutionMode %main LocalSize 1 1 1
  72. ; CHECK-NEXT: OpExecutionMode %main MaximallyReconvergesKHR
  73. ; CHECK-NOT: OpExecutionMode %main MaximallyReconvergesKHR
  74. OpCapability Shader
  75. OpExtension "SPV_KHR_maximal_reconvergence"
  76. OpMemoryModel Logical GLSL450
  77. OpEntryPoint GLCompute %main "main"
  78. OpExecutionMode %main LocalSize 1 1 1
  79. OpExecutionMode %main MaximallyReconvergesKHR
  80. OpName %main "main"
  81. %void = OpTypeVoid
  82. %void_fn = OpTypeFunction %void
  83. %main = OpFunction %void None %void_fn
  84. %entry = OpLabel
  85. OpReturn
  86. OpFunctionEnd
  87. )";
  88. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  89. }
  90. TEST_F(ModifyMaximalReconvergenceTest, AddTwoEntryPoints) {
  91. const std::string text = R"(
  92. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  93. ; CHECK: OpExecutionMode %comp MaximallyReconvergesKHR
  94. ; CHECK: OpExecutionMode %frag MaximallyReconvergesKHR
  95. OpCapability Shader
  96. OpMemoryModel Logical GLSL450
  97. OpEntryPoint GLCompute %comp "main"
  98. OpEntryPoint Fragment %frag "main"
  99. OpExecutionMode %comp LocalSize 1 1 1
  100. OpExecutionMode %frag OriginUpperLeft
  101. OpName %comp "comp"
  102. OpName %frag "frag"
  103. %void = OpTypeVoid
  104. %void_fn = OpTypeFunction %void
  105. %comp = OpFunction %void None %void_fn
  106. %entry1 = OpLabel
  107. OpReturn
  108. OpFunctionEnd
  109. %frag = OpFunction %void None %void_fn
  110. %entry2 = OpLabel
  111. OpReturn
  112. OpFunctionEnd
  113. )";
  114. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  115. }
  116. TEST_F(ModifyMaximalReconvergenceTest, AddTwoEntryPointsOneFunc) {
  117. const std::string text = R"(
  118. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  119. ; CHECK: OpExecutionMode %comp MaximallyReconvergesKHR
  120. ; CHECK-NOT: OpExecutionMode %comp MaximallyReconvergesKHR
  121. OpCapability Shader
  122. OpMemoryModel Logical GLSL450
  123. OpEntryPoint GLCompute %comp "main1"
  124. OpEntryPoint GLCompute %comp "main2"
  125. OpExecutionMode %comp LocalSize 1 1 1
  126. OpName %comp "comp"
  127. %void = OpTypeVoid
  128. %void_fn = OpTypeFunction %void
  129. %comp = OpFunction %void None %void_fn
  130. %entry1 = OpLabel
  131. OpReturn
  132. OpFunctionEnd
  133. )";
  134. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  135. }
  136. TEST_F(ModifyMaximalReconvergenceTest, AddTwoEntryPointsOneExecutionMode) {
  137. const std::string text = R"(
  138. ; CHECK: OpExtension "SPV_KHR_maximal_reconvergence"
  139. ; CHECK: OpExecutionMode %comp MaximallyReconvergesKHR
  140. ; CHECK-NOT: OpExecutionMode %comp MaximallyReconvergesKHR
  141. ; CHECK: OpExecutionMode %frag MaximallyReconvergesKHR
  142. ; CHECK-NOT: OpExecutionMode %comp MaximallyReconvergesKHR
  143. OpCapability Shader
  144. OpExtension "SPV_KHR_maximal_reconvergence"
  145. OpMemoryModel Logical GLSL450
  146. OpEntryPoint GLCompute %comp "main"
  147. OpEntryPoint Fragment %frag "main"
  148. OpExecutionMode %comp LocalSize 1 1 1
  149. OpExecutionMode %frag OriginUpperLeft
  150. OpExecutionMode %comp MaximallyReconvergesKHR
  151. OpName %comp "comp"
  152. OpName %frag "frag"
  153. %void = OpTypeVoid
  154. %void_fn = OpTypeFunction %void
  155. %comp = OpFunction %void None %void_fn
  156. %entry1 = OpLabel
  157. OpReturn
  158. OpFunctionEnd
  159. %frag = OpFunction %void None %void_fn
  160. %entry2 = OpLabel
  161. OpReturn
  162. OpFunctionEnd
  163. )";
  164. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, true);
  165. }
  166. TEST_F(ModifyMaximalReconvergenceTest, RemoveNoEntryPoint) {
  167. const std::string text = R"(OpCapability Kernel
  168. OpCapability Linkage
  169. OpMemoryModel Logical OpenCL
  170. )";
  171. SinglePassRunAndCheck<opt::ModifyMaximalReconvergence>(text, text, false,
  172. true, false);
  173. }
  174. TEST_F(ModifyMaximalReconvergenceTest, RemoveOnlyExtension) {
  175. const std::string text = R"(
  176. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  177. ; CHECK: OpExecutionMode %main LocalSize 1 1 1
  178. OpCapability Shader
  179. OpExtension "SPV_KHR_maximal_reconvergence"
  180. OpMemoryModel Logical GLSL450
  181. OpEntryPoint GLCompute %main "main"
  182. OpExecutionMode %main LocalSize 1 1 1
  183. OpName %main "main"
  184. %void = OpTypeVoid
  185. %void_fn = OpTypeFunction %void
  186. %main = OpFunction %void None %void_fn
  187. %entry = OpLabel
  188. OpReturn
  189. OpFunctionEnd
  190. )";
  191. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, false);
  192. }
  193. TEST_F(ModifyMaximalReconvergenceTest, RemoveSingleEntryPoint) {
  194. const std::string text = R"(
  195. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  196. ; CHECK: OpExecutionMode %main LocalSize 1 1 1
  197. ; CHECK-NOT: OpExecutionMode %main MaximallyReconvergesKHR
  198. OpCapability Shader
  199. OpExtension "SPV_KHR_maximal_reconvergence"
  200. OpMemoryModel Logical GLSL450
  201. OpEntryPoint GLCompute %main "main"
  202. OpExecutionMode %main LocalSize 1 1 1
  203. OpExecutionMode %main MaximallyReconvergesKHR
  204. OpName %main "main"
  205. %void = OpTypeVoid
  206. %void_fn = OpTypeFunction %void
  207. %main = OpFunction %void None %void_fn
  208. %entry = OpLabel
  209. OpReturn
  210. OpFunctionEnd
  211. )";
  212. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, false);
  213. }
  214. TEST_F(ModifyMaximalReconvergenceTest, RemoveTwoEntryPointsOneExecutionMode) {
  215. const std::string text = R"(
  216. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  217. ; CHECK: OpExecutionMode %comp LocalSize 1 1 1
  218. ; CHECK-NEXT: OpExecutionMode %frag OriginUpperLeft
  219. ; CHECK-NOT: OpExecutionMode %comp MaximallyReconvergesKHR
  220. OpCapability Shader
  221. OpExtension "SPV_KHR_maximal_reconvergence"
  222. OpMemoryModel Logical GLSL450
  223. OpEntryPoint GLCompute %comp "main"
  224. OpEntryPoint Fragment %frag "main"
  225. OpExecutionMode %comp LocalSize 1 1 1
  226. OpExecutionMode %comp MaximallyReconvergesKHR
  227. OpExecutionMode %frag OriginUpperLeft
  228. OpName %comp "comp"
  229. OpName %frag "frag"
  230. %void = OpTypeVoid
  231. %void_fn = OpTypeFunction %void
  232. %comp = OpFunction %void None %void_fn
  233. %entry1 = OpLabel
  234. OpReturn
  235. OpFunctionEnd
  236. %frag = OpFunction %void None %void_fn
  237. %entry2 = OpLabel
  238. OpReturn
  239. OpFunctionEnd
  240. )";
  241. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, false);
  242. }
  243. TEST_F(ModifyMaximalReconvergenceTest, RemoveTwoEntryPoints) {
  244. const std::string text = R"(
  245. ; CHECK-NOT: OpExtension "SPV_KHR_maximal_reconvergence"
  246. ; CHECK: OpExecutionMode %comp LocalSize 1 1 1
  247. ; CHECK-NEXT: OpExecutionMode %frag OriginUpperLeft
  248. ; CHECK-NOT: OpExecutionMode {{%\w}} MaximallyReconvergesKHR
  249. OpCapability Shader
  250. OpExtension "SPV_KHR_maximal_reconvergence"
  251. OpMemoryModel Logical GLSL450
  252. OpEntryPoint GLCompute %comp "main"
  253. OpEntryPoint Fragment %frag "main"
  254. OpExecutionMode %comp LocalSize 1 1 1
  255. OpExecutionMode %comp MaximallyReconvergesKHR
  256. OpExecutionMode %frag OriginUpperLeft
  257. OpExecutionMode %frag MaximallyReconvergesKHR
  258. OpName %comp "comp"
  259. OpName %frag "frag"
  260. %void = OpTypeVoid
  261. %void_fn = OpTypeFunction %void
  262. %comp = OpFunction %void None %void_fn
  263. %entry1 = OpLabel
  264. OpReturn
  265. OpFunctionEnd
  266. %frag = OpFunction %void None %void_fn
  267. %entry2 = OpLabel
  268. OpReturn
  269. OpFunctionEnd
  270. )";
  271. SinglePassRunAndMatch<opt::ModifyMaximalReconvergence>(text, true, false);
  272. }
  273. } // namespace