PageRenderTime 299ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/bgfx/3rdparty/spirv-tools/test/tools/opt/flags.py

https://gitlab.com/JFT/Irrlicht_extended
Python | 379 lines | 362 code | 4 blank | 13 comment | 0 complexity | 9421b4be9d4c71e070259384b3518c8b MD5 | raw file
  1. # Copyright (c) 2018 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. import placeholder
  15. import expect
  16. import re
  17. from spirv_test_framework import inside_spirv_testsuite
  18. def empty_main_assembly():
  19. return """
  20. OpCapability Shader
  21. OpMemoryModel Logical GLSL450
  22. OpEntryPoint Vertex %4 "main"
  23. OpName %4 "main"
  24. %2 = OpTypeVoid
  25. %3 = OpTypeFunction %2
  26. %4 = OpFunction %2 None %3
  27. %5 = OpLabel
  28. OpReturn
  29. OpFunctionEnd"""
  30. @inside_spirv_testsuite('SpirvOptBase')
  31. class TestAssemblyFileAsOnlyParameter(expect.ValidObjectFile1_4):
  32. """Tests that spirv-opt accepts a SPIR-V object file."""
  33. shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
  34. output = placeholder.TempFileName('output.spv')
  35. spirv_args = [shader, '-o', output]
  36. expected_object_filenames = (output)
  37. @inside_spirv_testsuite('SpirvOptFlags')
  38. class TestHelpFlag(expect.ReturnCodeIsZero, expect.StdoutMatch):
  39. """Test the --help flag."""
  40. spirv_args = ['--help']
  41. expected_stdout = re.compile(r'.*The SPIR-V binary is read from <input>')
  42. @inside_spirv_testsuite('SpirvOptFlags')
  43. class TestValidPassFlags(expect.ValidObjectFile1_4,
  44. expect.ExecutedListOfPasses):
  45. """Tests that spirv-opt accepts all valid optimization flags."""
  46. flags = [
  47. '--wrap-opkill', '--ccp', '--cfg-cleanup', '--combine-access-chains', '--compact-ids',
  48. '--convert-local-access-chains', '--copy-propagate-arrays',
  49. '--eliminate-dead-branches',
  50. '--eliminate-dead-code-aggressive', '--eliminate-dead-const',
  51. '--eliminate-dead-functions', '--eliminate-dead-inserts',
  52. '--eliminate-dead-variables', '--eliminate-insert-extract',
  53. '--eliminate-local-multi-store', '--eliminate-local-single-block',
  54. '--eliminate-local-single-store', '--flatten-decorations',
  55. '--fold-spec-const-op-composite', '--freeze-spec-const',
  56. '--if-conversion', '--inline-entry-points-exhaustive', '--loop-fission',
  57. '20', '--loop-fusion', '5', '--loop-unroll', '--loop-unroll-partial', '3',
  58. '--loop-peeling', '--merge-blocks', '--merge-return', '--loop-unswitch',
  59. '--private-to-local', '--reduce-load-size', '--redundancy-elimination',
  60. '--remove-duplicates', '--replace-invalid-opcode', '--ssa-rewrite',
  61. '--scalar-replacement', '--scalar-replacement=42', '--strength-reduction',
  62. '--strip-debug', '--strip-reflect', '--vector-dce', '--workaround-1209',
  63. '--unify-const'
  64. ]
  65. expected_passes = [
  66. 'wrap-opkill',
  67. 'ccp',
  68. 'cfg-cleanup',
  69. 'combine-access-chains',
  70. 'compact-ids',
  71. 'convert-local-access-chains',
  72. 'copy-propagate-arrays',
  73. 'eliminate-dead-branches',
  74. 'eliminate-dead-code-aggressive',
  75. 'eliminate-dead-const',
  76. 'eliminate-dead-functions',
  77. 'eliminate-dead-inserts',
  78. 'eliminate-dead-variables',
  79. # --eliminate-insert-extract runs the simplify-instructions pass.
  80. 'simplify-instructions',
  81. 'eliminate-local-multi-store',
  82. 'eliminate-local-single-block',
  83. 'eliminate-local-single-store',
  84. 'flatten-decorations',
  85. 'fold-spec-const-op-composite',
  86. 'freeze-spec-const',
  87. 'if-conversion',
  88. 'inline-entry-points-exhaustive',
  89. 'loop-fission',
  90. 'loop-fusion',
  91. 'loop-unroll',
  92. 'loop-unroll',
  93. 'loop-peeling',
  94. 'merge-blocks',
  95. 'merge-return',
  96. 'loop-unswitch',
  97. 'private-to-local',
  98. 'reduce-load-size',
  99. 'redundancy-elimination',
  100. 'remove-duplicates',
  101. 'replace-invalid-opcode',
  102. 'ssa-rewrite',
  103. 'scalar-replacement=100',
  104. 'scalar-replacement=42',
  105. 'strength-reduction',
  106. 'strip-debug',
  107. 'strip-reflect',
  108. 'vector-dce',
  109. 'workaround-1209',
  110. 'unify-const'
  111. ]
  112. shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
  113. output = placeholder.TempFileName('output.spv')
  114. spirv_args = [shader, '-o', output, '--print-all'] + flags
  115. expected_object_filenames = (output)
  116. @inside_spirv_testsuite('SpirvOptFlags')
  117. class TestPerformanceOptimizationPasses(expect.ValidObjectFile1_4,
  118. expect.ExecutedListOfPasses):
  119. """Tests that spirv-opt schedules all the passes triggered by -O."""
  120. flags = ['-O']
  121. expected_passes = [
  122. 'wrap-opkill',
  123. 'eliminate-dead-branches',
  124. 'merge-return',
  125. 'inline-entry-points-exhaustive',
  126. 'eliminate-dead-code-aggressive',
  127. 'private-to-local',
  128. 'eliminate-local-single-block',
  129. 'eliminate-local-single-store',
  130. 'eliminate-dead-code-aggressive',
  131. 'scalar-replacement=100',
  132. 'convert-local-access-chains',
  133. 'eliminate-local-single-block',
  134. 'eliminate-local-single-store',
  135. 'eliminate-dead-code-aggressive',
  136. 'eliminate-local-multi-store',
  137. 'eliminate-dead-code-aggressive',
  138. 'ccp',
  139. 'eliminate-dead-code-aggressive',
  140. 'redundancy-elimination',
  141. 'combine-access-chains',
  142. 'simplify-instructions',
  143. 'vector-dce',
  144. 'eliminate-dead-inserts',
  145. 'eliminate-dead-branches',
  146. 'simplify-instructions',
  147. 'if-conversion',
  148. 'copy-propagate-arrays',
  149. 'reduce-load-size',
  150. 'eliminate-dead-code-aggressive',
  151. 'merge-blocks',
  152. 'redundancy-elimination',
  153. 'eliminate-dead-branches',
  154. 'merge-blocks',
  155. 'simplify-instructions',
  156. ]
  157. shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
  158. output = placeholder.TempFileName('output.spv')
  159. spirv_args = [shader, '-o', output, '--print-all'] + flags
  160. expected_object_filenames = (output)
  161. @inside_spirv_testsuite('SpirvOptFlags')
  162. class TestSizeOptimizationPasses(expect.ValidObjectFile1_4,
  163. expect.ExecutedListOfPasses):
  164. """Tests that spirv-opt schedules all the passes triggered by -Os."""
  165. flags = ['-Os']
  166. expected_passes = [
  167. 'wrap-opkill',
  168. 'eliminate-dead-branches',
  169. 'merge-return',
  170. 'inline-entry-points-exhaustive',
  171. 'eliminate-dead-code-aggressive',
  172. 'private-to-local',
  173. 'scalar-replacement=100',
  174. 'convert-local-access-chains',
  175. 'eliminate-local-single-block',
  176. 'eliminate-local-single-store',
  177. 'eliminate-dead-code-aggressive',
  178. 'simplify-instructions',
  179. 'eliminate-dead-inserts',
  180. 'eliminate-local-multi-store',
  181. 'eliminate-dead-code-aggressive',
  182. 'ccp',
  183. 'eliminate-dead-code-aggressive',
  184. 'eliminate-dead-branches',
  185. 'if-conversion',
  186. 'eliminate-dead-code-aggressive',
  187. 'merge-blocks',
  188. 'simplify-instructions',
  189. 'eliminate-dead-inserts',
  190. 'redundancy-elimination',
  191. 'cfg-cleanup',
  192. 'eliminate-dead-code-aggressive',
  193. ]
  194. shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
  195. output = placeholder.TempFileName('output.spv')
  196. spirv_args = [shader, '-o', output, '--print-all'] + flags
  197. expected_object_filenames = (output)
  198. @inside_spirv_testsuite('SpirvOptFlags')
  199. class TestLegalizationPasses(expect.ValidObjectFile1_4,
  200. expect.ExecutedListOfPasses):
  201. """Tests that spirv-opt schedules all the passes triggered by --legalize-hlsl.
  202. """
  203. flags = ['--legalize-hlsl']
  204. expected_passes = [
  205. 'wrap-opkill',
  206. 'eliminate-dead-branches',
  207. 'merge-return',
  208. 'inline-entry-points-exhaustive',
  209. 'eliminate-dead-functions',
  210. 'private-to-local',
  211. 'fix-storage-class',
  212. 'eliminate-local-single-block',
  213. 'eliminate-local-single-store',
  214. 'eliminate-dead-code-aggressive',
  215. 'scalar-replacement=0',
  216. 'eliminate-local-single-block',
  217. 'eliminate-local-single-store',
  218. 'eliminate-dead-code-aggressive',
  219. 'eliminate-local-multi-store',
  220. 'eliminate-dead-code-aggressive',
  221. 'ccp',
  222. 'loop-unroll',
  223. 'eliminate-dead-branches',
  224. 'simplify-instructions',
  225. 'eliminate-dead-code-aggressive',
  226. 'copy-propagate-arrays',
  227. 'vector-dce',
  228. 'eliminate-dead-inserts',
  229. 'reduce-load-size',
  230. 'eliminate-dead-code-aggressive',
  231. ]
  232. shader = placeholder.FileSPIRVShader(empty_main_assembly(), '.spvasm')
  233. output = placeholder.TempFileName('output.spv')
  234. spirv_args = [shader, '-o', output, '--print-all'] + flags
  235. expected_object_filenames = (output)
  236. @inside_spirv_testsuite('SpirvOptFlags')
  237. class TestScalarReplacementArgsNegative(expect.ErrorMessageSubstr):
  238. """Tests invalid arguments to --scalar-replacement."""
  239. spirv_args = ['--scalar-replacement=-10']
  240. expected_error_substr = 'must have no arguments or a non-negative integer argument'
  241. @inside_spirv_testsuite('SpirvOptFlags')
  242. class TestScalarReplacementArgsInvalidNumber(expect.ErrorMessageSubstr):
  243. """Tests invalid arguments to --scalar-replacement."""
  244. spirv_args = ['--scalar-replacement=a10f']
  245. expected_error_substr = 'must have no arguments or a non-negative integer argument'
  246. @inside_spirv_testsuite('SpirvOptFlags')
  247. class TestLoopFissionArgsNegative(expect.ErrorMessageSubstr):
  248. """Tests invalid arguments to --loop-fission."""
  249. spirv_args = ['--loop-fission=-10']
  250. expected_error_substr = 'must have a positive integer argument'
  251. @inside_spirv_testsuite('SpirvOptFlags')
  252. class TestLoopFissionArgsInvalidNumber(expect.ErrorMessageSubstr):
  253. """Tests invalid arguments to --loop-fission."""
  254. spirv_args = ['--loop-fission=a10f']
  255. expected_error_substr = 'must have a positive integer argument'
  256. @inside_spirv_testsuite('SpirvOptFlags')
  257. class TestLoopFusionArgsNegative(expect.ErrorMessageSubstr):
  258. """Tests invalid arguments to --loop-fusion."""
  259. spirv_args = ['--loop-fusion=-10']
  260. expected_error_substr = 'must have a positive integer argument'
  261. @inside_spirv_testsuite('SpirvOptFlags')
  262. class TestLoopFusionArgsInvalidNumber(expect.ErrorMessageSubstr):
  263. """Tests invalid arguments to --loop-fusion."""
  264. spirv_args = ['--loop-fusion=a10f']
  265. expected_error_substr = 'must have a positive integer argument'
  266. @inside_spirv_testsuite('SpirvOptFlags')
  267. class TestLoopUnrollPartialArgsNegative(expect.ErrorMessageSubstr):
  268. """Tests invalid arguments to --loop-unroll-partial."""
  269. spirv_args = ['--loop-unroll-partial=-10']
  270. expected_error_substr = 'must have a positive integer argument'
  271. @inside_spirv_testsuite('SpirvOptFlags')
  272. class TestLoopUnrollPartialArgsInvalidNumber(expect.ErrorMessageSubstr):
  273. """Tests invalid arguments to --loop-unroll-partial."""
  274. spirv_args = ['--loop-unroll-partial=a10f']
  275. expected_error_substr = 'must have a positive integer argument'
  276. @inside_spirv_testsuite('SpirvOptFlags')
  277. class TestLoopPeelingThresholdArgsNegative(expect.ErrorMessageSubstr):
  278. """Tests invalid arguments to --loop-peeling-threshold."""
  279. spirv_args = ['--loop-peeling-threshold=-10']
  280. expected_error_substr = 'must have a positive integer argument'
  281. @inside_spirv_testsuite('SpirvOptFlags')
  282. class TestLoopPeelingThresholdArgsInvalidNumber(expect.ErrorMessageSubstr):
  283. """Tests invalid arguments to --loop-peeling-threshold."""
  284. spirv_args = ['--loop-peeling-threshold=a10f']
  285. expected_error_substr = 'must have a positive integer argument'
  286. @inside_spirv_testsuite('SpirvOptFlags')
  287. class TestWebGPUToVulkanThenVulkanToWebGPUIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  288. """Tests Vulkan->WebGPU flag cannot be used after WebGPU->Vulkan flag."""
  289. spirv_args = ['--webgpu-to-vulkan', '--vulkan-to-webgpu']
  290. expected_error_substr = 'Cannot use both'
  291. @inside_spirv_testsuite('SpirvOptFlags')
  292. class TestVulkanToWebGPUThenWebGPUToVulkanIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  293. """Tests WebGPU->Vulkan flag cannot be used after Vulkan->WebGPU flag."""
  294. spirv_args = ['--vulkan-to-webgpu', '--webgpu-to-vulkan']
  295. expected_error_substr = 'Cannot use both'
  296. @inside_spirv_testsuite('SpirvOptFlags')
  297. class TestTargetEnvThenVulkanToWebGPUIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  298. """Tests Vulkan->WebGPU flag cannot be used after target env flag."""
  299. spirv_args = ['--target-env=opengl4.0', '--vulkan-to-webgpu']
  300. expected_error_substr = 'defines the target environment'
  301. @inside_spirv_testsuite('SpirvOptFlags')
  302. class TestVulkanToWebGPUThenTargetEnvIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  303. """Tests target env flag cannot be used after Vulkan->WebGPU flag."""
  304. spirv_args = ['--vulkan-to-webgpu', '--target-env=opengl4.0']
  305. expected_error_substr = 'defines the target environment'
  306. @inside_spirv_testsuite('SpirvOptFlags')
  307. class TestTargetEnvThenWebGPUToVulkanIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  308. """Tests WebGPU->Vulkan flag cannot be used after target env flag."""
  309. spirv_args = ['--target-env=opengl4.0', '--webgpu-to-vulkan']
  310. expected_error_substr = 'defines the target environment'
  311. @inside_spirv_testsuite('SpirvOptFlags')
  312. class TestWebGPUToVulkanThenTargetEnvIsInvalid(expect.ReturnCodeIsNonZero, expect.ErrorMessageSubstr):
  313. """Tests target env flag cannot be used after WebGPU->Vulkan flag."""
  314. spirv_args = ['--webgpu-to-vulkan', '--target-env=opengl4.0']
  315. expected_error_substr = 'defines the target environment'