text_to_binary.subgroup_dispatch_test.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (c) 2016 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. // Assembler tests for instructions in the "Barrier Instructions" section
  15. // of the SPIR-V spec.
  16. #include "test/unit_spirv.h"
  17. #include "gmock/gmock.h"
  18. #include "test/test_fixture.h"
  19. namespace spvtools {
  20. namespace {
  21. using ::spvtest::MakeInstruction;
  22. using ::testing::Eq;
  23. using OpGetKernelLocalSizeForSubgroupCountTest = spvtest::TextToBinaryTest;
  24. // We should be able to assemble it. Validation checks are in another test
  25. // file.
  26. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, OpcodeAssemblesInV10) {
  27. EXPECT_THAT(
  28. CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  29. "%sgcount %invoke %param %param_size %param_align",
  30. SPV_ENV_UNIVERSAL_1_0),
  31. Eq(MakeInstruction(spv::Op::OpGetKernelLocalSizeForSubgroupCount,
  32. {1, 2, 3, 4, 5, 6, 7})));
  33. }
  34. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentCount) {
  35. EXPECT_THAT(CompileFailure("OpGetKernelLocalSizeForSubgroupCount",
  36. SPV_ENV_UNIVERSAL_1_1),
  37. Eq("Expected <result-id> at the beginning of an instruction, "
  38. "found 'OpGetKernelLocalSizeForSubgroupCount'."));
  39. EXPECT_THAT(CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount",
  40. SPV_ENV_UNIVERSAL_1_1),
  41. Eq("Expected operand for OpGetKernelLocalSizeForSubgroupCount "
  42. "instruction, but found the end of the stream."));
  43. EXPECT_THAT(
  44. CompileFailure("%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6",
  45. SPV_ENV_UNIVERSAL_1_1),
  46. Eq("Expected operand for OpGetKernelLocalSizeForSubgroupCount "
  47. "instruction, but found the end of the stream."));
  48. EXPECT_THAT(
  49. CompiledInstructions("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  50. "%sgcount %invoke %param %param_size %param_align",
  51. SPV_ENV_UNIVERSAL_1_1),
  52. Eq(MakeInstruction(spv::Op::OpGetKernelLocalSizeForSubgroupCount,
  53. {1, 2, 3, 4, 5, 6, 7})));
  54. EXPECT_THAT(
  55. CompileFailure("%res = OpGetKernelLocalSizeForSubgroupCount %type "
  56. "%sgcount %invoke %param %param_size %param_align %extra",
  57. SPV_ENV_UNIVERSAL_1_1),
  58. Eq("Expected '=', found end of stream."));
  59. }
  60. TEST_F(OpGetKernelLocalSizeForSubgroupCountTest, ArgumentTypes) {
  61. EXPECT_THAT(CompileFailure(
  62. "%1 = OpGetKernelLocalSizeForSubgroupCount 2 %3 %4 %5 %6 %7",
  63. SPV_ENV_UNIVERSAL_1_1),
  64. Eq("Expected id to start with %."));
  65. EXPECT_THAT(
  66. CompileFailure(
  67. "%1 = OpGetKernelLocalSizeForSubgroupCount %2 %3 %4 %5 %6 \"abc\"",
  68. SPV_ENV_UNIVERSAL_1_1),
  69. Eq("Expected id to start with %."));
  70. }
  71. using OpGetKernelMaxNumSubgroupsTest = spvtest::TextToBinaryTest;
  72. TEST_F(OpGetKernelMaxNumSubgroupsTest, OpcodeAssemblesInV10) {
  73. EXPECT_THAT(CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
  74. "%invoke %param %param_size %param_align",
  75. SPV_ENV_UNIVERSAL_1_0),
  76. Eq(MakeInstruction(spv::Op::OpGetKernelMaxNumSubgroups,
  77. {1, 2, 3, 4, 5, 6})));
  78. }
  79. TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentCount) {
  80. EXPECT_THAT(
  81. CompileFailure("OpGetKernelMaxNumSubgroups", SPV_ENV_UNIVERSAL_1_1),
  82. Eq("Expected <result-id> at the beginning of an instruction, found "
  83. "'OpGetKernelMaxNumSubgroups'."));
  84. EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups",
  85. SPV_ENV_UNIVERSAL_1_1),
  86. Eq("Expected operand for OpGetKernelMaxNumSubgroups instruction, "
  87. "but found the end of the stream."));
  88. EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5",
  89. SPV_ENV_UNIVERSAL_1_1),
  90. Eq("Expected operand for OpGetKernelMaxNumSubgroups instruction, "
  91. "but found the end of the stream."));
  92. EXPECT_THAT(CompiledInstructions("%res = OpGetKernelMaxNumSubgroups %type "
  93. "%invoke %param %param_size %param_align",
  94. SPV_ENV_UNIVERSAL_1_1),
  95. Eq(MakeInstruction(spv::Op::OpGetKernelMaxNumSubgroups,
  96. {1, 2, 3, 4, 5, 6})));
  97. EXPECT_THAT(CompileFailure("%res = OpGetKernelMaxNumSubgroups %type %invoke "
  98. "%param %param_size %param_align %extra",
  99. SPV_ENV_UNIVERSAL_1_1),
  100. Eq("Expected '=', found end of stream."));
  101. }
  102. TEST_F(OpGetKernelMaxNumSubgroupsTest, ArgumentTypes) {
  103. EXPECT_THAT(CompileFailure("%1 = OpGetKernelMaxNumSubgroups 2 %3 %4 %5 %6",
  104. SPV_ENV_UNIVERSAL_1_1),
  105. Eq("Expected id to start with %."));
  106. EXPECT_THAT(
  107. CompileFailure("%1 = OpGetKernelMaxNumSubgroups %2 %3 %4 %5 \"abc\"",
  108. SPV_ENV_UNIVERSAL_1_1),
  109. Eq("Expected id to start with %."));
  110. }
  111. } // namespace
  112. } // namespace spvtools