2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-18 15:19:18 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-09-18 15:19:18 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-18 15:19:18 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-09-18 15:19:18 +00:00
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Image Instructions" section of
|
|
|
|
// the SPIR-V spec.
|
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-09-18 15:19:18 +00:00
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "test/test_fixture.h"
|
|
|
|
#include "test/unit_spirv.h"
|
2015-09-18 15:19:18 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-18 15:19:18 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using spvtest::MakeInstruction;
|
2015-11-11 21:36:42 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2015-09-18 15:19:18 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
|
|
|
|
// An example case for a mask value with operands.
|
|
|
|
struct ImageOperandsCase {
|
|
|
|
std::string image_operands;
|
|
|
|
// The expected mask, followed by its operands.
|
|
|
|
std::vector<uint32_t> expected_mask_and_operands;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test all kinds of image operands.
|
|
|
|
|
2015-10-13 16:46:13 +00:00
|
|
|
using ImageOperandsTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<ImageOperandsCase>>;
|
2015-09-18 15:19:18 +00:00
|
|
|
|
|
|
|
TEST_P(ImageOperandsTest, Sample) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
2016-02-15 19:20:01 +00:00
|
|
|
"%2 = OpImageFetch %1 %3 %4" + GetParam().image_operands + "\n";
|
2015-09-18 15:19:18 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2022-11-04 21:27:10 +00:00
|
|
|
Eq(MakeInstruction(spv::Op::OpImageFetch, {1, 2, 3, 4},
|
2015-10-01 15:24:11 +00:00
|
|
|
GetParam().expected_mask_and_operands)));
|
2015-09-18 15:19:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
#define MASK(NAME) uint32_t(spv::ImageOperandsMask::NAME)
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-09-18 15:19:18 +00:00
|
|
|
TextToBinaryImageOperandsAny, ImageOperandsTest,
|
|
|
|
::testing::ValuesIn(std::vector<ImageOperandsCase>{
|
|
|
|
// TODO(dneto): Rev32 adds many more values, and rearranges their
|
|
|
|
// values.
|
|
|
|
// Image operands are optional.
|
|
|
|
{"", {}},
|
|
|
|
// Test each kind, alone.
|
2016-02-15 19:20:01 +00:00
|
|
|
{" Bias %5", {MASK(Bias), 5}},
|
|
|
|
{" Lod %5", {MASK(Lod), 5}},
|
|
|
|
{" Grad %5 %6", {MASK(Grad), 5, 6}},
|
|
|
|
{" ConstOffset %5", {MASK(ConstOffset), 5}},
|
|
|
|
{" Offset %5", {MASK(Offset), 5}},
|
|
|
|
{" ConstOffsets %5", {MASK(ConstOffsets), 5}},
|
|
|
|
{" Sample %5", {MASK(Sample), 5}},
|
|
|
|
{" MinLod %5", {MASK(MinLod), 5}},
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-18 17:41:49 +00:00
|
|
|
#undef MASK
|
2022-11-04 21:27:10 +00:00
|
|
|
#define MASK(NAME) static_cast<uint32_t>(spv::ImageOperandsMask::NAME)
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-09-18 15:19:18 +00:00
|
|
|
TextToBinaryImageOperandsCombination, ImageOperandsTest,
|
|
|
|
::testing::ValuesIn(std::vector<ImageOperandsCase>{
|
|
|
|
// TODO(dneto): Rev32 adds many more values, and rearranges their
|
|
|
|
// values.
|
|
|
|
// Test adjacent pairs, so we can easily debug the values when it fails.
|
2016-02-15 19:20:01 +00:00
|
|
|
{" Bias|Lod %5 %6", {MASK(Bias) | MASK(Lod), 5, 6}},
|
|
|
|
{" Lod|Grad %5 %6 %7", {MASK(Lod) | MASK(Grad), 5, 6, 7}},
|
|
|
|
{" Grad|ConstOffset %5 %6 %7",
|
2015-09-22 19:50:33 +00:00
|
|
|
{MASK(Grad) | MASK(ConstOffset), 5, 6, 7}},
|
2017-11-27 15:16:41 +00:00
|
|
|
{" ConstOffset|Offset %5 %6", {MASK(ConstOffset) | MASK(Offset), 5, 6}},
|
2016-02-15 19:20:01 +00:00
|
|
|
{" Offset|ConstOffsets %5 %6",
|
2015-09-22 19:50:33 +00:00
|
|
|
{MASK(Offset) | MASK(ConstOffsets), 5, 6}},
|
2016-02-15 19:20:01 +00:00
|
|
|
{" ConstOffsets|Sample %5 %6",
|
2015-09-22 19:50:33 +00:00
|
|
|
{MASK(ConstOffsets) | MASK(Sample), 5, 6}},
|
2015-09-18 15:19:18 +00:00
|
|
|
// Test all masks together.
|
2016-02-15 19:20:01 +00:00
|
|
|
{" Bias|Lod|Grad|ConstOffset|Offset|ConstOffsets|Sample"
|
|
|
|
" %5 %6 %7 %8 %9 %10 %11 %12",
|
2015-09-18 15:19:18 +00:00
|
|
|
{MASK(Bias) | MASK(Lod) | MASK(Grad) | MASK(ConstOffset) |
|
|
|
|
MASK(Offset) | MASK(ConstOffsets) | MASK(Sample),
|
2015-09-22 19:50:33 +00:00
|
|
|
5, 6, 7, 8, 9, 10, 11, 12}},
|
2015-09-18 15:19:18 +00:00
|
|
|
// The same, but with mask value names reversed.
|
2016-02-15 19:20:01 +00:00
|
|
|
{" Sample|ConstOffsets|Offset|ConstOffset|Grad|Lod|Bias"
|
|
|
|
" %5 %6 %7 %8 %9 %10 %11 %12",
|
2015-09-18 15:19:18 +00:00
|
|
|
{MASK(Bias) | MASK(Lod) | MASK(Grad) | MASK(ConstOffset) |
|
|
|
|
MASK(Offset) | MASK(ConstOffsets) | MASK(Sample),
|
2019-01-29 23:56:52 +00:00
|
|
|
5, 6, 7, 8, 9, 10, 11, 12}}}));
|
2015-09-18 15:19:18 +00:00
|
|
|
#undef MASK
|
|
|
|
|
2015-10-13 18:47:22 +00:00
|
|
|
TEST_F(ImageOperandsTest, WrongOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%r = OpImageFetch %t %i %c xxyyzz"),
|
|
|
|
Eq("Invalid image operand 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-11-11 21:36:42 +00:00
|
|
|
// Test OpImage
|
|
|
|
|
|
|
|
using OpImageTest = TextToBinaryTest;
|
|
|
|
|
|
|
|
TEST_F(OpImageTest, Valid) {
|
|
|
|
const std::string input = "%2 = OpImage %1 %3\n";
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2022-11-04 21:27:10 +00:00
|
|
|
Eq(MakeInstruction(spv::Op::OpImage, {1, 2, 3})));
|
2015-11-11 21:36:42 +00:00
|
|
|
|
|
|
|
// Test the disassembler.
|
|
|
|
EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageTest, InvalidTypeOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage 42"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageTest, MissingSampledImageOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage %1"),
|
2022-03-28 14:46:39 +00:00
|
|
|
Eq("Expected operand for OpImage instruction, but found the end "
|
|
|
|
"of the stream."));
|
2015-11-11 21:36:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageTest, InvalidSampledImageOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage %1 1000"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageTest, TooManyOperands) {
|
|
|
|
// We should improve this message, to say what instruction we're trying to
|
|
|
|
// parse.
|
2017-11-27 15:16:41 +00:00
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 %4"), // an Id
|
2015-11-11 21:36:42 +00:00
|
|
|
Eq("Expected '=', found end of stream."));
|
|
|
|
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 99"), // a number
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '99'."));
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImage %1 %3 \"abc\""), // a string
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '\"abc\"'."));
|
|
|
|
}
|
|
|
|
|
2016-02-15 19:20:01 +00:00
|
|
|
// Test OpImageSparseRead
|
|
|
|
|
|
|
|
using OpImageSparseReadTest = TextToBinaryTest;
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, OnlyRequiredOperands) {
|
|
|
|
const std::string input = "%2 = OpImageSparseRead %1 %3 %4\n";
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2022-11-04 21:27:10 +00:00
|
|
|
Eq(MakeInstruction(spv::Op::OpImageSparseRead, {1, 2, 3, 4})));
|
2016-02-15 19:20:01 +00:00
|
|
|
// Test the disassembler.
|
|
|
|
EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test all kinds of image operands on OpImageSparseRead
|
|
|
|
|
|
|
|
using ImageSparseReadImageOperandsTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<ImageOperandsCase>>;
|
|
|
|
|
|
|
|
TEST_P(ImageSparseReadImageOperandsTest, Sample) {
|
|
|
|
const std::string input =
|
|
|
|
"%2 = OpImageSparseRead %1 %3 %4" + GetParam().image_operands + "\n";
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2022-11-04 21:27:10 +00:00
|
|
|
Eq(MakeInstruction(spv::Op::OpImageSparseRead, {1, 2, 3, 4},
|
2016-02-15 19:20:01 +00:00
|
|
|
GetParam().expected_mask_and_operands)));
|
|
|
|
// Test the disassembler.
|
|
|
|
EXPECT_THAT(EncodeAndDecodeSuccessfully(input), input);
|
|
|
|
}
|
|
|
|
|
2022-11-04 21:27:10 +00:00
|
|
|
#define MASK(NAME) uint32_t(spv::ImageOperandsMask::NAME)
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(ImageSparseReadImageOperandsAny,
|
|
|
|
ImageSparseReadImageOperandsTest,
|
|
|
|
::testing::ValuesIn(std::vector<ImageOperandsCase>{
|
|
|
|
// Image operands are optional.
|
|
|
|
{"", {}},
|
|
|
|
// Test each kind, alone.
|
|
|
|
{" Bias %5", {MASK(Bias), 5}},
|
|
|
|
{" Lod %5", {MASK(Lod), 5}},
|
|
|
|
{" Grad %5 %6", {MASK(Grad), 5, 6}},
|
|
|
|
{" ConstOffset %5", {MASK(ConstOffset), 5}},
|
|
|
|
{" Offset %5", {MASK(Offset), 5}},
|
|
|
|
{" ConstOffsets %5", {MASK(ConstOffsets), 5}},
|
|
|
|
{" Sample %5", {MASK(Sample), 5}},
|
|
|
|
{" MinLod %5", {MASK(MinLod), 5}},
|
|
|
|
}));
|
2016-02-15 19:20:01 +00:00
|
|
|
#undef MASK
|
2022-11-04 21:27:10 +00:00
|
|
|
#define MASK(NAME) static_cast<uint32_t>(spv::ImageOperandsMask::NAME)
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2016-02-15 19:20:01 +00:00
|
|
|
ImageSparseReadImageOperandsCombination, ImageSparseReadImageOperandsTest,
|
|
|
|
::testing::ValuesIn(std::vector<ImageOperandsCase>{
|
|
|
|
// values.
|
|
|
|
// Test adjacent pairs, so we can easily debug the values when it fails.
|
|
|
|
{" Bias|Lod %5 %6", {MASK(Bias) | MASK(Lod), 5, 6}},
|
|
|
|
{" Lod|Grad %5 %6 %7", {MASK(Lod) | MASK(Grad), 5, 6, 7}},
|
|
|
|
{" Grad|ConstOffset %5 %6 %7",
|
|
|
|
{MASK(Grad) | MASK(ConstOffset), 5, 6, 7}},
|
|
|
|
{" ConstOffset|Offset %5 %6", {MASK(ConstOffset) | MASK(Offset), 5, 6}},
|
|
|
|
{" Offset|ConstOffsets %5 %6",
|
|
|
|
{MASK(Offset) | MASK(ConstOffsets), 5, 6}},
|
|
|
|
{" ConstOffsets|Sample %5 %6",
|
|
|
|
{MASK(ConstOffsets) | MASK(Sample), 5, 6}},
|
|
|
|
// Test all masks together.
|
|
|
|
{" Bias|Lod|Grad|ConstOffset|Offset|ConstOffsets|Sample"
|
|
|
|
" %5 %6 %7 %8 %9 %10 %11 %12",
|
|
|
|
{MASK(Bias) | MASK(Lod) | MASK(Grad) | MASK(ConstOffset) |
|
|
|
|
MASK(Offset) | MASK(ConstOffsets) | MASK(Sample),
|
|
|
|
5, 6, 7, 8, 9, 10, 11, 12}},
|
|
|
|
// Don't try the masks reversed, since this is a round trip test,
|
|
|
|
// and the disassembler will sort them.
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2016-02-15 19:20:01 +00:00
|
|
|
#undef MASK
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, InvalidTypeOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImageSparseRead 42"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, MissingImageOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImageSparseRead %1"),
|
2022-03-28 14:46:39 +00:00
|
|
|
Eq("Expected operand for OpImageSparseRead instruction, but "
|
|
|
|
"found the end of the stream."));
|
2016-02-15 19:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, InvalidImageOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImageSparseRead %1 1000"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, MissingCoordinateOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImageSparseRead %1 %2"),
|
2022-03-28 14:46:39 +00:00
|
|
|
Eq("Expected operand for OpImageSparseRead instruction, but "
|
|
|
|
"found the end of the stream."));
|
2016-02-15 19:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpImageSparseReadTest, InvalidCoordinateOperand) {
|
|
|
|
EXPECT_THAT(CompileFailure("%2 = OpImageSparseRead %1 %2 1000"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
2015-09-24 21:10:35 +00:00
|
|
|
// TODO(dneto): OpSampledImage
|
|
|
|
// TODO(dneto): OpImageSampleImplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleExplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleDrefImplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleDrefExplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleProjImplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleProjExplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleProjDrefImplicitLod
|
|
|
|
// TODO(dneto): OpImageSampleProjDrefExplicitLod
|
|
|
|
// TODO(dneto): OpImageGather
|
|
|
|
// TODO(dneto): OpImageDrefGather
|
|
|
|
// TODO(dneto): OpImageRead
|
|
|
|
// TODO(dneto): OpImageWrite
|
|
|
|
// TODO(dneto): OpImageQueryFormat
|
|
|
|
// TODO(dneto): OpImageQueryOrder
|
|
|
|
// TODO(dneto): OpImageQuerySizeLod
|
|
|
|
// TODO(dneto): OpImageQuerySize
|
|
|
|
// TODO(dneto): OpImageQueryLod
|
|
|
|
// TODO(dneto): OpImageQueryLevels
|
|
|
|
// TODO(dneto): OpImageQuerySamples
|
|
|
|
// TODO(dneto): OpImageSparseSampleImplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleExplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleDrefImplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleDrefExplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleProjImplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleProjExplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleProjDrefImplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseSampleProjDrefExplicitLod
|
|
|
|
// TODO(dneto): OpImageSparseFetch
|
|
|
|
// TODO(dneto): OpImageSparseDrefGather
|
|
|
|
// TODO(dneto): OpImageSparseTexelsResident
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|