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 
15 // Validation tests for illegal instructions
16 
17 #include <string>
18 
19 #include "gmock/gmock.h"
20 #include "test/test_fixture.h"
21 #include "test/unit_spirv.h"
22 
23 namespace spvtools {
24 namespace {
25 
26 using ::spvtest::MakeInstruction;
27 using ::testing::Eq;
28 
29 using ReservedSamplingInstTest = RoundTripTest;
30 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjImplicitLod)31 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjImplicitLod) {
32   std::string input = "%2 = OpImageSparseSampleProjImplicitLod %1 %3 %4\n";
33   EXPECT_THAT(CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
34               Eq(MakeInstruction(spv::Op::OpImageSparseSampleProjImplicitLod,
35                                  {1, 2, 3, 4})));
36 }
37 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjExplicitLod)38 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjExplicitLod) {
39   std::string input =
40       "%2 = OpImageSparseSampleProjExplicitLod %1 %3 %4 Lod %5\n";
41   EXPECT_THAT(CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
42               Eq(MakeInstruction(
43                   spv::Op::OpImageSparseSampleProjExplicitLod,
44                   {1, 2, 3, 4, (uint32_t)spv::ImageOperandsMask::Lod, 5})));
45 }
46 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjDrefImplicitLod)47 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefImplicitLod) {
48   std::string input =
49       "%2 = OpImageSparseSampleProjDrefImplicitLod %1 %3 %4 %5\n";
50   EXPECT_THAT(
51       CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
52       Eq(MakeInstruction(spv::Op::OpImageSparseSampleProjDrefImplicitLod,
53                          {1, 2, 3, 4, 5})));
54 }
55 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjDrefExplicitLod)56 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefExplicitLod) {
57   std::string input =
58       "%2 = OpImageSparseSampleProjDrefExplicitLod %1 %3 %4 %5 Lod %6\n";
59   EXPECT_THAT(CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
60               Eq(MakeInstruction(
61                   spv::Op::OpImageSparseSampleProjDrefExplicitLod,
62                   {1, 2, 3, 4, 5, (uint32_t)spv::ImageOperandsMask::Lod, 6})));
63 }
64 
65 }  // namespace
66 }  // namespace spvtools
67