unique_ids_test.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (c) 2017 Google Inc.
  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 <string>
  15. #include <vector>
  16. #include "gmock/gmock.h"
  17. #include "test/link/linker_fixture.h"
  18. namespace spvtools {
  19. namespace {
  20. using UniqueIds = spvtest::LinkerTest;
  21. TEST_F(UniqueIds, UniquelyMerged) {
  22. std::vector<std::string> bodies(2);
  23. bodies[0] =
  24. // clang-format off
  25. "OpCapability Shader\n"
  26. "%1 = OpExtInstImport \"GLSL.std.450\"\n"
  27. "OpMemoryModel Logical GLSL450\n"
  28. "OpEntryPoint Vertex %main \"main\"\n"
  29. "OpSource ESSL 310\n"
  30. "OpName %main \"main\"\n"
  31. "OpName %f_ \"f(\"\n"
  32. "OpName %gv1 \"gv1\"\n"
  33. "OpName %gv2 \"gv2\"\n"
  34. "OpName %lv1 \"lv1\"\n"
  35. "OpName %lv2 \"lv2\"\n"
  36. "OpName %lv1_0 \"lv1\"\n"
  37. "%void = OpTypeVoid\n"
  38. "%10 = OpTypeFunction %void\n"
  39. "%float = OpTypeFloat 32\n"
  40. "%12 = OpTypeFunction %float\n"
  41. "%_ptr_Private_float = OpTypePointer Private %float\n"
  42. "%gv1 = OpVariable %_ptr_Private_float Private\n"
  43. "%float_10 = OpConstant %float 10\n"
  44. "%gv2 = OpVariable %_ptr_Private_float Private\n"
  45. "%float_100 = OpConstant %float 100\n"
  46. "%_ptr_Function_float = OpTypePointer Function %float\n"
  47. "%main = OpFunction %void None %10\n"
  48. "%17 = OpLabel\n"
  49. "%lv1_0 = OpVariable %_ptr_Function_float Function\n"
  50. "OpStore %gv1 %float_10\n"
  51. "OpStore %gv2 %float_100\n"
  52. "%18 = OpLoad %float %gv1\n"
  53. "%19 = OpLoad %float %gv2\n"
  54. "%20 = OpFSub %float %18 %19\n"
  55. "OpStore %lv1_0 %20\n"
  56. "OpReturn\n"
  57. "OpFunctionEnd\n"
  58. "%f_ = OpFunction %float None %12\n"
  59. "%21 = OpLabel\n"
  60. "%lv1 = OpVariable %_ptr_Function_float Function\n"
  61. "%lv2 = OpVariable %_ptr_Function_float Function\n"
  62. "%22 = OpLoad %float %gv1\n"
  63. "%23 = OpLoad %float %gv2\n"
  64. "%24 = OpFAdd %float %22 %23\n"
  65. "OpStore %lv1 %24\n"
  66. "%25 = OpLoad %float %gv1\n"
  67. "%26 = OpLoad %float %gv2\n"
  68. "%27 = OpFMul %float %25 %26\n"
  69. "OpStore %lv2 %27\n"
  70. "%28 = OpLoad %float %lv1\n"
  71. "%29 = OpLoad %float %lv2\n"
  72. "%30 = OpFDiv %float %28 %29\n"
  73. "OpReturnValue %30\n"
  74. "OpFunctionEnd\n";
  75. // clang-format on
  76. bodies[1] =
  77. // clang-format off
  78. "OpCapability Shader\n"
  79. "%1 = OpExtInstImport \"GLSL.std.450\"\n"
  80. "OpMemoryModel Logical GLSL450\n"
  81. "OpSource ESSL 310\n"
  82. "OpName %main \"main2\"\n"
  83. "OpName %f_ \"f(\"\n"
  84. "OpName %gv1 \"gv12\"\n"
  85. "OpName %gv2 \"gv22\"\n"
  86. "OpName %lv1 \"lv12\"\n"
  87. "OpName %lv2 \"lv22\"\n"
  88. "OpName %lv1_0 \"lv12\"\n"
  89. "%void = OpTypeVoid\n"
  90. "%10 = OpTypeFunction %void\n"
  91. "%float = OpTypeFloat 32\n"
  92. "%12 = OpTypeFunction %float\n"
  93. "%_ptr_Private_float = OpTypePointer Private %float\n"
  94. "%gv1 = OpVariable %_ptr_Private_float Private\n"
  95. "%float_10 = OpConstant %float 10\n"
  96. "%gv2 = OpVariable %_ptr_Private_float Private\n"
  97. "%float_100 = OpConstant %float 100\n"
  98. "%_ptr_Function_float = OpTypePointer Function %float\n"
  99. "%main = OpFunction %void None %10\n"
  100. "%17 = OpLabel\n"
  101. "%lv1_0 = OpVariable %_ptr_Function_float Function\n"
  102. "OpStore %gv1 %float_10\n"
  103. "OpStore %gv2 %float_100\n"
  104. "%18 = OpLoad %float %gv1\n"
  105. "%19 = OpLoad %float %gv2\n"
  106. "%20 = OpFSub %float %18 %19\n"
  107. "OpStore %lv1_0 %20\n"
  108. "OpReturn\n"
  109. "OpFunctionEnd\n"
  110. "%f_ = OpFunction %float None %12\n"
  111. "%21 = OpLabel\n"
  112. "%lv1 = OpVariable %_ptr_Function_float Function\n"
  113. "%lv2 = OpVariable %_ptr_Function_float Function\n"
  114. "%22 = OpLoad %float %gv1\n"
  115. "%23 = OpLoad %float %gv2\n"
  116. "%24 = OpFAdd %float %22 %23\n"
  117. "OpStore %lv1 %24\n"
  118. "%25 = OpLoad %float %gv1\n"
  119. "%26 = OpLoad %float %gv2\n"
  120. "%27 = OpFMul %float %25 %26\n"
  121. "OpStore %lv2 %27\n"
  122. "%28 = OpLoad %float %lv1\n"
  123. "%29 = OpLoad %float %lv2\n"
  124. "%30 = OpFDiv %float %28 %29\n"
  125. "OpReturnValue %30\n"
  126. "OpFunctionEnd\n";
  127. // clang-format on
  128. spvtest::Binary linked_binary;
  129. LinkerOptions options;
  130. options.SetVerifyIds(true);
  131. spv_result_t res = AssembleAndLink(bodies, &linked_binary, options);
  132. EXPECT_EQ(SPV_SUCCESS, res);
  133. }
  134. } // namespace
  135. } // namespace spvtools