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(
34       CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
35       Eq(MakeInstruction(SpvOpImageSparseSampleProjImplicitLod, {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(SpvOpImageSparseSampleProjExplicitLod,
43                                  {1, 2, 3, 4, SpvImageOperandsLodMask, 5})));
44 }
45 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjDrefImplicitLod)46 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefImplicitLod) {
47   std::string input =
48       "%2 = OpImageSparseSampleProjDrefImplicitLod %1 %3 %4 %5\n";
49   EXPECT_THAT(CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
50               Eq(MakeInstruction(SpvOpImageSparseSampleProjDrefImplicitLod,
51                                  {1, 2, 3, 4, 5})));
52 }
53 
TEST_F(ReservedSamplingInstTest,OpImageSparseSampleProjDrefExplicitLod)54 TEST_F(ReservedSamplingInstTest, OpImageSparseSampleProjDrefExplicitLod) {
55   std::string input =
56       "%2 = OpImageSparseSampleProjDrefExplicitLod %1 %3 %4 %5 Lod %6\n";
57   EXPECT_THAT(CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_0),
58               Eq(MakeInstruction(SpvOpImageSparseSampleProjDrefExplicitLod,
59                                  {1, 2, 3, 4, 5, SpvImageOperandsLodMask, 6})));
60 }
61 
62 }  // namespace
63 }  // namespace spvtools
64