spec_constant_op_autogen.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // GENERATED FILE - DO NOT EDIT.
  2. // Generated by generate_tests.py
  3. //
  4. // Copyright (c) 2022 Google LLC.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. #include "../diff_test_utils.h"
  18. #include "gtest/gtest.h"
  19. namespace spvtools {
  20. namespace diff {
  21. namespace {
  22. // Tests OpSpecConstantOp matching.
  23. constexpr char kSrc[] = R"( OpCapability Shader
  24. OpMemoryModel Logical GLSL450
  25. OpEntryPoint GLCompute %1 "main"
  26. OpExecutionMode %1 LocalSize 1 1 1
  27. %2 = OpTypeVoid
  28. %3 = OpTypeFunction %2
  29. %4 = OpTypeInt 32 0
  30. %5 = OpTypeVector %4 3
  31. %6 = OpConstant %4 1
  32. %7 = OpSpecConstantComposite %5 %6 %6 %6
  33. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  34. %9 = OpSpecConstantOp %4 CompositeExtract %7 1
  35. %10 = OpSpecConstantOp %4 CompositeExtract %7 0
  36. %1 = OpFunction %2 None %3
  37. %11 = OpLabel
  38. OpReturn
  39. OpFunctionEnd)";
  40. constexpr char kDst[] = R"( OpCapability Shader
  41. OpMemoryModel Logical GLSL450
  42. OpEntryPoint GLCompute %1 "main"
  43. OpExecutionMode %1 LocalSize 1 1 1
  44. %2 = OpTypeVoid
  45. %3 = OpTypeFunction %2
  46. %4 = OpTypeInt 32 0
  47. %5 = OpTypeVector %4 3
  48. %6 = OpConstant %4 1
  49. %7 = OpSpecConstantComposite %5 %6 %6 %6
  50. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  51. %9 = OpSpecConstantOp %4 CompositeExtract %7 3
  52. %10 = OpSpecConstantOp %4 IMul %8 %8
  53. %1 = OpFunction %2 None %3
  54. %11 = OpLabel
  55. OpReturn
  56. OpFunctionEnd
  57. )";
  58. TEST(DiffTest, SpecConstantOp) {
  59. constexpr char kDiff[] = R"( ; SPIR-V
  60. ; Version: 1.6
  61. ; Generator: Khronos SPIR-V Tools Assembler; 0
  62. -; Bound: 12
  63. +; Bound: 14
  64. ; Schema: 0
  65. OpCapability Shader
  66. OpMemoryModel Logical GLSL450
  67. OpEntryPoint GLCompute %1 "main"
  68. OpExecutionMode %1 LocalSize 1 1 1
  69. %2 = OpTypeVoid
  70. %3 = OpTypeFunction %2
  71. %4 = OpTypeInt 32 0
  72. %5 = OpTypeVector %4 3
  73. %6 = OpConstant %4 1
  74. %7 = OpSpecConstantComposite %5 %6 %6 %6
  75. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  76. -%9 = OpSpecConstantOp %4 CompositeExtract %7 1
  77. -%10 = OpSpecConstantOp %4 CompositeExtract %7 0
  78. +%12 = OpSpecConstantOp %4 CompositeExtract %7 3
  79. +%13 = OpSpecConstantOp %4 IMul %8 %8
  80. %1 = OpFunction %2 None %3
  81. %11 = OpLabel
  82. OpReturn
  83. OpFunctionEnd
  84. )";
  85. Options options;
  86. DoStringDiffTest(kSrc, kDst, kDiff, options);
  87. }
  88. TEST(DiffTest, SpecConstantOpNoDebug) {
  89. constexpr char kSrcNoDebug[] = R"( OpCapability Shader
  90. OpMemoryModel Logical GLSL450
  91. OpEntryPoint GLCompute %1 "main"
  92. OpExecutionMode %1 LocalSize 1 1 1
  93. %2 = OpTypeVoid
  94. %3 = OpTypeFunction %2
  95. %4 = OpTypeInt 32 0
  96. %5 = OpTypeVector %4 3
  97. %6 = OpConstant %4 1
  98. %7 = OpSpecConstantComposite %5 %6 %6 %6
  99. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  100. %9 = OpSpecConstantOp %4 CompositeExtract %7 1
  101. %10 = OpSpecConstantOp %4 CompositeExtract %7 0
  102. %1 = OpFunction %2 None %3
  103. %11 = OpLabel
  104. OpReturn
  105. OpFunctionEnd)";
  106. constexpr char kDstNoDebug[] = R"( OpCapability Shader
  107. OpMemoryModel Logical GLSL450
  108. OpEntryPoint GLCompute %1 "main"
  109. OpExecutionMode %1 LocalSize 1 1 1
  110. %2 = OpTypeVoid
  111. %3 = OpTypeFunction %2
  112. %4 = OpTypeInt 32 0
  113. %5 = OpTypeVector %4 3
  114. %6 = OpConstant %4 1
  115. %7 = OpSpecConstantComposite %5 %6 %6 %6
  116. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  117. %9 = OpSpecConstantOp %4 CompositeExtract %7 3
  118. %10 = OpSpecConstantOp %4 IMul %8 %8
  119. %1 = OpFunction %2 None %3
  120. %11 = OpLabel
  121. OpReturn
  122. OpFunctionEnd
  123. )";
  124. constexpr char kDiff[] = R"( ; SPIR-V
  125. ; Version: 1.6
  126. ; Generator: Khronos SPIR-V Tools Assembler; 0
  127. -; Bound: 12
  128. +; Bound: 14
  129. ; Schema: 0
  130. OpCapability Shader
  131. OpMemoryModel Logical GLSL450
  132. OpEntryPoint GLCompute %1 "main"
  133. OpExecutionMode %1 LocalSize 1 1 1
  134. %2 = OpTypeVoid
  135. %3 = OpTypeFunction %2
  136. %4 = OpTypeInt 32 0
  137. %5 = OpTypeVector %4 3
  138. %6 = OpConstant %4 1
  139. %7 = OpSpecConstantComposite %5 %6 %6 %6
  140. %8 = OpSpecConstantOp %4 CompositeExtract %7 2
  141. -%9 = OpSpecConstantOp %4 CompositeExtract %7 1
  142. -%10 = OpSpecConstantOp %4 CompositeExtract %7 0
  143. +%12 = OpSpecConstantOp %4 CompositeExtract %7 3
  144. +%13 = OpSpecConstantOp %4 IMul %8 %8
  145. %1 = OpFunction %2 None %3
  146. %11 = OpLabel
  147. OpReturn
  148. OpFunctionEnd
  149. )";
  150. Options options;
  151. DoStringDiffTest(kSrcNoDebug, kDstNoDebug, kDiff, options);
  152. }
  153. } // namespace
  154. } // namespace diff
  155. } // namespace spvtools