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