val_explicit_reserved_test.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // Validation tests for illegal instructions
  15. #include <string>
  16. #include "gmock/gmock.h"
  17. #include "test/unit_spirv.h"
  18. #include "test/val/val_fixtures.h"
  19. namespace spvtools {
  20. namespace val {
  21. namespace {
  22. using ::testing::Eq;
  23. using ::testing::HasSubstr;
  24. using ReservedSamplingInstTest = spvtest::ValidateBase<std::string>;
  25. // Generate a shader for use with validation tests for sparse sampling
  26. // instructions.
  27. std::string ShaderAssembly(const std::string& instruction_under_test) {
  28. std::ostringstream os;
  29. os << R"( OpCapability Shader
  30. OpCapability SparseResidency
  31. OpMemoryModel Logical GLSL450
  32. OpEntryPoint Fragment %1 "main"
  33. OpExecutionMode %1 OriginUpperLeft
  34. OpSource GLSL 450
  35. OpDecorate %2 DescriptorSet 0
  36. OpDecorate %2 Binding 0
  37. %void = OpTypeVoid
  38. %4 = OpTypeFunction %void
  39. %float = OpTypeFloat 32
  40. %v4float = OpTypeVector %float 4
  41. %float_0 = OpConstant %float 0
  42. %8 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
  43. %9 = OpTypeImage %float 2D 0 0 0 1 Unknown
  44. %10 = OpTypeSampledImage %9
  45. %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
  46. %2 = OpVariable %_ptr_UniformConstant_10 UniformConstant
  47. %v2float = OpTypeVector %float 2
  48. %13 = OpConstantComposite %v2float %float_0 %float_0
  49. %int = OpTypeInt 32 1
  50. %_struct_15 = OpTypeStruct %int %v4float
  51. %1 = OpFunction %void None %4
  52. %16 = OpLabel
  53. %17 = OpLoad %10 %2
  54. )" << instruction_under_test
  55. << R"(
  56. OpReturn
  57. OpFunctionEnd
  58. )";
  59. return os.str();
  60. }
  61. TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjImplicitLod) {
  62. const std::string input = ShaderAssembly(
  63. "%result = OpImageSparseSampleProjImplicitLod %_struct_15 %17 %13");
  64. CompileSuccessfully(input);
  65. EXPECT_THAT(ValidateInstructions(), Eq(SPV_ERROR_INVALID_BINARY));
  66. EXPECT_THAT(
  67. getDiagnosticString(),
  68. HasSubstr("Invalid Opcode name 'OpImageSparseSampleProjImplicitLod'"));
  69. }
  70. TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjExplicitLod) {
  71. const std::string input = ShaderAssembly(
  72. "%result = OpImageSparseSampleProjExplicitLod %_struct_15 %17 %13 Lod "
  73. "%float_0\n");
  74. CompileSuccessfully(input);
  75. EXPECT_THAT(ValidateInstructions(), Eq(SPV_ERROR_INVALID_BINARY));
  76. EXPECT_THAT(
  77. getDiagnosticString(),
  78. HasSubstr("Invalid Opcode name 'OpImageSparseSampleProjExplicitLod'"));
  79. }
  80. TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefImplicitLod) {
  81. const std::string input = ShaderAssembly(
  82. "%result = OpImageSparseSampleProjDrefImplicitLod %_struct_15 %17 %13 "
  83. "%float_0\n");
  84. CompileSuccessfully(input);
  85. EXPECT_THAT(ValidateInstructions(), Eq(SPV_ERROR_INVALID_BINARY));
  86. EXPECT_THAT(
  87. getDiagnosticString(),
  88. HasSubstr(
  89. "Invalid Opcode name 'OpImageSparseSampleProjDrefImplicitLod'"));
  90. }
  91. TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefExplicitLod) {
  92. const std::string input = ShaderAssembly(
  93. "%result = OpImageSparseSampleProjDrefExplicitLod %_struct_15 %17 %13 "
  94. "%float_0 Lod "
  95. "%float_0\n");
  96. CompileSuccessfully(input);
  97. EXPECT_THAT(ValidateInstructions(), Eq(SPV_ERROR_INVALID_BINARY));
  98. EXPECT_THAT(
  99. getDiagnosticString(),
  100. HasSubstr(
  101. "Invalid Opcode name 'OpImageSparseSampleProjDrefExplicitLod'"));
  102. }
  103. } // namespace
  104. } // namespace val
  105. } // namespace spvtools