2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-10 17:23:11 +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-10 17:23:11 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-10 17:23:11 +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-10 17:23:11 +00:00
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Annotation" section of the
|
|
|
|
// SPIR-V spec.
|
|
|
|
|
|
|
|
#include <sstream>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <string>
|
2016-05-10 03:15:46 +00:00
|
|
|
#include <tuple>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <vector>
|
2015-09-10 17:23:11 +00:00
|
|
|
|
2016-05-10 03:15:46 +00:00
|
|
|
#include "gmock/gmock.h"
|
2019-08-08 14:53:19 +00:00
|
|
|
#include "source/util/string_utils.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "test/test_fixture.h"
|
|
|
|
#include "test/unit_spirv.h"
|
2015-09-10 17:23:11 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-10 17:23:11 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-10-01 20:58:17 +00:00
|
|
|
using spvtest::EnumCase;
|
2015-09-10 17:23:11 +00:00
|
|
|
using spvtest::MakeInstruction;
|
2019-08-08 14:53:19 +00:00
|
|
|
using utils::MakeVector;
|
2015-09-21 15:36:44 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2017-11-27 15:16:41 +00:00
|
|
|
using ::testing::Combine;
|
|
|
|
using ::testing::Eq;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::ValuesIn;
|
2015-09-10 17:23:11 +00:00
|
|
|
|
|
|
|
// Test OpDecorate
|
|
|
|
|
2018-08-01 18:58:12 +00:00
|
|
|
using OpDecorateSimpleTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<
|
|
|
|
std::tuple<spv_target_env, EnumCase<SpvDecoration>>>>;
|
2015-09-10 17:23:11 +00:00
|
|
|
|
|
|
|
TEST_P(OpDecorateSimpleTest, AnySimpleDecoration) {
|
|
|
|
// This string should assemble, but should not validate.
|
|
|
|
std::stringstream input;
|
2018-08-01 18:58:12 +00:00
|
|
|
input << "OpDecorate %1 " << std::get<1>(GetParam()).name();
|
|
|
|
for (auto operand : std::get<1>(GetParam()).operands())
|
|
|
|
input << " " << operand;
|
2015-11-30 19:39:31 +00:00
|
|
|
input << std::endl;
|
2018-08-01 18:58:12 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input.str(), std::get<0>(GetParam())),
|
2016-05-10 03:15:46 +00:00
|
|
|
Eq(MakeInstruction(SpvOpDecorate,
|
2018-08-01 18:58:12 +00:00
|
|
|
{1, uint32_t(std::get<1>(GetParam()).value())},
|
|
|
|
std::get<1>(GetParam()).operands())));
|
2015-11-30 19:39:31 +00:00
|
|
|
// Also check disassembly.
|
2016-05-10 03:15:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
EncodeAndDecodeSuccessfully(input.str(), SPV_BINARY_TO_TEXT_OPTION_NONE,
|
2018-08-01 18:58:12 +00:00
|
|
|
std::get<0>(GetParam())),
|
2016-05-10 03:15:46 +00:00
|
|
|
Eq(input.str()));
|
2015-09-10 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 16:27:18 +00:00
|
|
|
// Like above, but parameters to the decoration are IDs.
|
|
|
|
using OpDecorateSimpleIdTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<
|
|
|
|
std::tuple<spv_target_env, EnumCase<SpvDecoration>>>>;
|
|
|
|
|
|
|
|
TEST_P(OpDecorateSimpleIdTest, AnySimpleDecoration) {
|
|
|
|
// This string should assemble, but should not validate.
|
|
|
|
std::stringstream input;
|
|
|
|
input << "OpDecorateId %1 " << std::get<1>(GetParam()).name();
|
|
|
|
for (auto operand : std::get<1>(GetParam()).operands())
|
|
|
|
input << " %" << operand;
|
|
|
|
input << std::endl;
|
|
|
|
EXPECT_THAT(CompiledInstructions(input.str(), std::get<0>(GetParam())),
|
|
|
|
Eq(MakeInstruction(SpvOpDecorateId,
|
|
|
|
{1, uint32_t(std::get<1>(GetParam()).value())},
|
|
|
|
std::get<1>(GetParam()).operands())));
|
|
|
|
// Also check disassembly.
|
|
|
|
EXPECT_THAT(
|
|
|
|
EncodeAndDecodeSuccessfully(input.str(), SPV_BINARY_TO_TEXT_OPTION_NONE,
|
|
|
|
std::get<0>(GetParam())),
|
|
|
|
Eq(input.str()));
|
|
|
|
}
|
|
|
|
|
2015-10-28 17:40:52 +00:00
|
|
|
#define CASE(NAME) SpvDecoration##NAME, #NAME
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-09-28 15:37:57 +00:00
|
|
|
TextToBinaryDecorateSimple, OpDecorateSimpleTest,
|
2016-05-10 03:15:46 +00:00
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ValuesIn(std::vector<EnumCase<SpvDecoration>>{
|
|
|
|
// The operand literal values are arbitrarily chosen,
|
|
|
|
// but there are the right number of them.
|
|
|
|
{CASE(RelaxedPrecision), {}},
|
|
|
|
{CASE(SpecId), {100}},
|
|
|
|
{CASE(Block), {}},
|
|
|
|
{CASE(BufferBlock), {}},
|
|
|
|
{CASE(RowMajor), {}},
|
|
|
|
{CASE(ColMajor), {}},
|
|
|
|
{CASE(ArrayStride), {4}},
|
|
|
|
{CASE(MatrixStride), {16}},
|
|
|
|
{CASE(GLSLShared), {}},
|
|
|
|
{CASE(GLSLPacked), {}},
|
|
|
|
{CASE(CPacked), {}},
|
|
|
|
// Placeholder line for enum value 12
|
|
|
|
{CASE(NoPerspective), {}},
|
|
|
|
{CASE(Flat), {}},
|
|
|
|
{CASE(Patch), {}},
|
|
|
|
{CASE(Centroid), {}},
|
|
|
|
{CASE(Sample), {}},
|
|
|
|
{CASE(Invariant), {}},
|
|
|
|
{CASE(Restrict), {}},
|
|
|
|
{CASE(Aliased), {}},
|
|
|
|
{CASE(Volatile), {}},
|
|
|
|
{CASE(Constant), {}},
|
|
|
|
{CASE(Coherent), {}},
|
|
|
|
{CASE(NonWritable), {}},
|
|
|
|
{CASE(NonReadable), {}},
|
|
|
|
{CASE(Uniform), {}},
|
|
|
|
{CASE(SaturatedConversion), {}},
|
|
|
|
{CASE(Stream), {2}},
|
|
|
|
{CASE(Location), {6}},
|
|
|
|
{CASE(Component), {3}},
|
|
|
|
{CASE(Index), {14}},
|
|
|
|
{CASE(Binding), {19}},
|
|
|
|
{CASE(DescriptorSet), {7}},
|
|
|
|
{CASE(Offset), {12}},
|
|
|
|
{CASE(XfbBuffer), {1}},
|
|
|
|
{CASE(XfbStride), {8}},
|
|
|
|
{CASE(NoContraction), {}},
|
|
|
|
{CASE(InputAttachmentIndex), {102}},
|
|
|
|
{CASE(Alignment), {16}},
|
2019-01-29 23:56:52 +00:00
|
|
|
})));
|
2016-05-10 03:15:46 +00:00
|
|
|
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateSimpleV11, OpDecorateSimpleTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Values(EnumCase<SpvDecoration>{
|
|
|
|
CASE(MaxByteOffset), {128}})));
|
2019-05-07 16:27:18 +00:00
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateSimpleV14, OpDecorateSimpleTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_4),
|
|
|
|
ValuesIn(std::vector<EnumCase<SpvDecoration>>{
|
|
|
|
{CASE(Uniform), {}},
|
|
|
|
})));
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateSimpleIdV14,
|
|
|
|
OpDecorateSimpleIdTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_4),
|
|
|
|
ValuesIn(std::vector<EnumCase<SpvDecoration>>{
|
|
|
|
// In 1.4, UniformId decoration takes a
|
|
|
|
// scope Id.
|
|
|
|
{CASE(UniformId), {1}},
|
|
|
|
})));
|
2015-09-10 17:23:11 +00:00
|
|
|
#undef CASE
|
|
|
|
|
2015-10-13 19:35:49 +00:00
|
|
|
TEST_F(OpDecorateSimpleTest, WrongDecoration) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 xxyyzz"),
|
|
|
|
Eq("Invalid decoration 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-11-30 19:39:31 +00:00
|
|
|
TEST_F(OpDecorateSimpleTest, ExtraOperandsOnDecorationExpectingNone) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 RelaxedPrecision 99"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '99'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpDecorateSimpleTest, ExtraOperandsOnDecorationExpectingOne) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 SpecId 99 100"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '100'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpDecorateSimpleTest, ExtraOperandsOnDecorationExpectingTwo) {
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("OpDecorate %1 LinkageAttributes \"abc\" Import 42"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '42'."));
|
|
|
|
}
|
|
|
|
|
2015-09-10 17:23:11 +00:00
|
|
|
// A single test case for an enum decoration.
|
|
|
|
struct DecorateEnumCase {
|
|
|
|
// Place the enum value first, so it's easier to read the binary dumps when
|
|
|
|
// the test fails.
|
2015-09-18 15:50:54 +00:00
|
|
|
uint32_t value; // The value within the enum, e.g. Position
|
|
|
|
std::string name;
|
|
|
|
uint32_t enum_value; // Which enum, e.g. BuiltIn
|
|
|
|
std::string enum_name;
|
2015-09-10 17:23:11 +00:00
|
|
|
};
|
|
|
|
|
2015-10-13 16:46:13 +00:00
|
|
|
using OpDecorateEnumTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<DecorateEnumCase>>;
|
2015-09-10 17:23:11 +00:00
|
|
|
|
|
|
|
TEST_P(OpDecorateEnumTest, AnyEnumDecoration) {
|
|
|
|
// This string should assemble, but should not validate.
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input =
|
|
|
|
"OpDecorate %1 " + GetParam().enum_name + " " + GetParam().name;
|
2015-09-10 17:23:11 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpDecorate, {1, GetParam().enum_value,
|
2015-11-02 14:41:20 +00:00
|
|
|
GetParam().value})));
|
2015-09-10 17:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test OpDecorate BuiltIn.
|
|
|
|
// clang-format off
|
|
|
|
#define CASE(NAME) \
|
2015-10-28 17:40:52 +00:00
|
|
|
{ SpvBuiltIn##NAME, #NAME, SpvDecorationBuiltIn, "BuiltIn" }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateBuiltIn, OpDecorateEnumTest,
|
2015-09-10 17:23:11 +00:00
|
|
|
::testing::ValuesIn(std::vector<DecorateEnumCase>{
|
|
|
|
CASE(Position),
|
|
|
|
CASE(PointSize),
|
|
|
|
CASE(ClipDistance),
|
|
|
|
CASE(CullDistance),
|
|
|
|
CASE(VertexId),
|
|
|
|
CASE(InstanceId),
|
|
|
|
CASE(PrimitiveId),
|
|
|
|
CASE(InvocationId),
|
|
|
|
CASE(Layer),
|
|
|
|
CASE(ViewportIndex),
|
|
|
|
CASE(TessLevelOuter),
|
|
|
|
CASE(TessLevelInner),
|
|
|
|
CASE(TessCoord),
|
|
|
|
CASE(PatchVertices),
|
|
|
|
CASE(FragCoord),
|
|
|
|
CASE(PointCoord),
|
|
|
|
CASE(FrontFacing),
|
|
|
|
CASE(SampleId),
|
|
|
|
CASE(SamplePosition),
|
|
|
|
CASE(SampleMask),
|
2015-11-11 17:32:21 +00:00
|
|
|
// Value 21 intentionally missing.
|
2015-09-10 17:23:11 +00:00
|
|
|
CASE(FragDepth),
|
|
|
|
CASE(HelperInvocation),
|
|
|
|
CASE(NumWorkgroups),
|
|
|
|
CASE(WorkgroupSize),
|
|
|
|
CASE(WorkgroupId),
|
|
|
|
CASE(LocalInvocationId),
|
|
|
|
CASE(GlobalInvocationId),
|
|
|
|
CASE(LocalInvocationIndex),
|
|
|
|
CASE(WorkDim),
|
|
|
|
CASE(GlobalSize),
|
|
|
|
CASE(EnqueuedWorkgroupSize),
|
|
|
|
CASE(GlobalOffset),
|
|
|
|
CASE(GlobalLinearId),
|
2015-11-11 17:32:21 +00:00
|
|
|
// Value 35 intentionally missing.
|
2015-09-10 17:23:11 +00:00
|
|
|
CASE(SubgroupSize),
|
|
|
|
CASE(SubgroupMaxSize),
|
|
|
|
CASE(NumSubgroups),
|
|
|
|
CASE(NumEnqueuedSubgroups),
|
|
|
|
CASE(SubgroupId),
|
|
|
|
CASE(SubgroupLocalInvocationId),
|
2015-09-23 19:35:27 +00:00
|
|
|
CASE(VertexIndex),
|
|
|
|
CASE(InstanceIndex),
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-10 17:23:11 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-10-13 19:39:38 +00:00
|
|
|
TEST_F(OpDecorateEnumTest, WrongBuiltIn) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 BuiltIn xxyyzz"),
|
|
|
|
Eq("Invalid built-in 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-09-10 17:23:11 +00:00
|
|
|
// Test OpDecorate FuncParamAttr
|
|
|
|
// clang-format off
|
|
|
|
#define CASE(NAME) \
|
2015-10-28 17:40:52 +00:00
|
|
|
{ SpvFunctionParameterAttribute##NAME, #NAME, SpvDecorationFuncParamAttr, "FuncParamAttr" }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateFuncParamAttr, OpDecorateEnumTest,
|
2015-09-10 17:23:11 +00:00
|
|
|
::testing::ValuesIn(std::vector<DecorateEnumCase>{
|
|
|
|
CASE(Zext),
|
|
|
|
CASE(Sext),
|
|
|
|
CASE(ByVal),
|
|
|
|
CASE(Sret),
|
|
|
|
CASE(NoAlias),
|
|
|
|
CASE(NoCapture),
|
|
|
|
CASE(NoWrite),
|
|
|
|
CASE(NoReadWrite),
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-10 17:23:11 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-10-13 19:30:18 +00:00
|
|
|
TEST_F(OpDecorateEnumTest, WrongFuncParamAttr) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 FuncParamAttr xxyyzz"),
|
|
|
|
Eq("Invalid function parameter attribute 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-09-10 17:23:11 +00:00
|
|
|
// Test OpDecorate FPRoundingMode
|
|
|
|
// clang-format off
|
|
|
|
#define CASE(NAME) \
|
2015-10-28 17:40:52 +00:00
|
|
|
{ SpvFPRoundingMode##NAME, #NAME, SpvDecorationFPRoundingMode, "FPRoundingMode" }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateFPRoundingMode, OpDecorateEnumTest,
|
2015-09-10 17:23:11 +00:00
|
|
|
::testing::ValuesIn(std::vector<DecorateEnumCase>{
|
|
|
|
CASE(RTE),
|
|
|
|
CASE(RTZ),
|
|
|
|
CASE(RTP),
|
|
|
|
CASE(RTN),
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-10 17:23:11 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-10-13 19:15:54 +00:00
|
|
|
TEST_F(OpDecorateEnumTest, WrongFPRoundingMode) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 FPRoundingMode xxyyzz"),
|
|
|
|
Eq("Invalid floating-point rounding mode 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-09-10 17:23:11 +00:00
|
|
|
// Test OpDecorate FPFastMathMode.
|
|
|
|
// These can by named enums for the single-bit masks. However, we don't support
|
|
|
|
// symbolic combinations of the masks. Rather, they can use !<immediate>
|
|
|
|
// syntax, e.g. !0x3
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
#define CASE(ENUM,NAME) \
|
2015-10-28 17:40:52 +00:00
|
|
|
{ SpvFPFastMathMode##ENUM, #NAME, SpvDecorationFPFastMathMode, "FPFastMathMode" }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateFPFastMathMode, OpDecorateEnumTest,
|
2015-09-10 17:23:11 +00:00
|
|
|
::testing::ValuesIn(std::vector<DecorateEnumCase>{
|
|
|
|
CASE(MaskNone, None),
|
|
|
|
CASE(NotNaNMask, NotNaN),
|
|
|
|
CASE(NotInfMask, NotInf),
|
|
|
|
CASE(NSZMask, NSZ),
|
|
|
|
CASE(AllowRecipMask, AllowRecip),
|
|
|
|
CASE(FastMask, Fast),
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-10 17:23:11 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-10-13 19:02:03 +00:00
|
|
|
TEST_F(OpDecorateEnumTest, CombinedFPFastMathMask) {
|
2015-09-16 22:32:54 +00:00
|
|
|
// Sample a single combination. This ensures we've integrated
|
|
|
|
// the instruction parsing logic with spvTextParseMask.
|
2015-10-13 19:02:03 +00:00
|
|
|
const std::string input = "OpDecorate %1 FPFastMathMode NotNaN|NotInf|NSZ";
|
2015-10-28 17:40:52 +00:00
|
|
|
const uint32_t expected_enum = SpvDecorationFPFastMathMode;
|
|
|
|
const uint32_t expected_mask = SpvFPFastMathModeNotNaNMask |
|
|
|
|
SpvFPFastMathModeNotInfMask |
|
|
|
|
SpvFPFastMathModeNSZMask;
|
2015-09-16 22:32:54 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpDecorate, {1, expected_enum, expected_mask})));
|
2015-09-16 22:32:54 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 19:02:03 +00:00
|
|
|
TEST_F(OpDecorateEnumTest, WrongFPFastMathMode) {
|
2016-05-10 03:15:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("OpDecorate %1 FPFastMathMode NotNaN|xxyyzz"),
|
|
|
|
Eq("Invalid floating-point fast math mode operand 'NotNaN|xxyyzz'."));
|
2015-10-13 19:02:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 19:51:57 +00:00
|
|
|
// Test OpDecorate Linkage
|
|
|
|
|
|
|
|
// A single test case for a linkage
|
|
|
|
struct DecorateLinkageCase {
|
2015-09-18 15:50:54 +00:00
|
|
|
uint32_t linkage_type_value;
|
|
|
|
std::string linkage_type_name;
|
|
|
|
std::string external_name;
|
2015-09-10 19:51:57 +00:00
|
|
|
};
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using OpDecorateLinkageTest = spvtest::TextToBinaryTestBase<
|
2015-09-10 19:51:57 +00:00
|
|
|
::testing::TestWithParam<DecorateLinkageCase>>;
|
|
|
|
|
|
|
|
TEST_P(OpDecorateLinkageTest, AnyLinkageDecoration) {
|
|
|
|
// This string should assemble, but should not validate.
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpDecorate %1 LinkageAttributes \"" +
|
|
|
|
GetParam().external_name + "\" " +
|
|
|
|
GetParam().linkage_type_name;
|
2015-10-28 17:40:52 +00:00
|
|
|
std::vector<uint32_t> expected_operands{1, SpvDecorationLinkageAttributes};
|
2015-09-10 19:51:57 +00:00
|
|
|
std::vector<uint32_t> encoded_external_name =
|
|
|
|
MakeVector(GetParam().external_name);
|
|
|
|
expected_operands.insert(expected_operands.end(),
|
|
|
|
encoded_external_name.begin(),
|
|
|
|
encoded_external_name.end());
|
|
|
|
expected_operands.push_back(GetParam().linkage_type_value);
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpDecorate, expected_operands)));
|
2015-09-10 19:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clang-format off
|
2015-10-28 17:40:52 +00:00
|
|
|
#define CASE(ENUM) SpvLinkageType##ENUM, #ENUM
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TextToBinaryDecorateLinkage, OpDecorateLinkageTest,
|
2015-09-10 19:51:57 +00:00
|
|
|
::testing::ValuesIn(std::vector<DecorateLinkageCase>{
|
|
|
|
{ CASE(Import), "a" },
|
|
|
|
{ CASE(Export), "foo" },
|
|
|
|
{ CASE(Import), "some kind of long name with spaces etc." },
|
|
|
|
// TODO(dneto): utf-8, escaping, quoting cases.
|
2019-01-29 23:56:52 +00:00
|
|
|
}));
|
2015-09-10 19:51:57 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
2015-09-10 17:23:11 +00:00
|
|
|
|
2015-10-13 19:22:01 +00:00
|
|
|
TEST_F(OpDecorateLinkageTest, WrongType) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpDecorate %1 LinkageAttributes \"foo\" xxyyzz"),
|
|
|
|
Eq("Invalid linkage type 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
2015-09-28 18:09:29 +00:00
|
|
|
// Test OpGroupMemberDecorate
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateGoodOneTarget) {
|
|
|
|
EXPECT_THAT(CompiledInstructions("OpGroupMemberDecorate %group %id0 42"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpGroupMemberDecorate, {1, 2, 42})));
|
2015-09-28 18:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateGoodTwoTargets) {
|
2015-10-13 16:46:13 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("OpGroupMemberDecorate %group %id0 96 %id1 42"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpGroupMemberDecorate, {1, 2, 96, 3, 42})));
|
2015-09-28 18:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateMissingGroupId) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate"),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateInvalidGroupId) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate 16"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateInvalidTargetId) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group 12"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateMissingTargetMemberNumber) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group %id0"),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateInvalidTargetMemberNumber) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group %id0 %id1"),
|
2015-10-05 17:28:46 +00:00
|
|
|
Eq("Invalid unsigned integer literal: %id1"));
|
2015-09-28 18:09:29 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 18:40:10 +00:00
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateInvalidSecondTargetId) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group %id1 42 12"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateMissingSecondTargetMemberNumber) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group %id0 42 %id1"),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, GroupMemberDecorateInvalidSecondTargetMemberNumber) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpGroupMemberDecorate %group %id0 42 %id1 %id2"),
|
2015-10-05 17:28:46 +00:00
|
|
|
Eq("Invalid unsigned integer literal: %id2"));
|
2015-09-28 18:40:10 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 19:39:31 +00:00
|
|
|
// Test OpMemberDecorate
|
|
|
|
|
2018-08-01 18:58:12 +00:00
|
|
|
using OpMemberDecorateSimpleTest =
|
|
|
|
spvtest::TextToBinaryTestBase<::testing::TestWithParam<
|
|
|
|
std::tuple<spv_target_env, EnumCase<SpvDecoration>>>>;
|
2015-11-30 19:39:31 +00:00
|
|
|
|
|
|
|
TEST_P(OpMemberDecorateSimpleTest, AnySimpleDecoration) {
|
|
|
|
// This string should assemble, but should not validate.
|
|
|
|
std::stringstream input;
|
2018-08-01 18:58:12 +00:00
|
|
|
input << "OpMemberDecorate %1 42 " << std::get<1>(GetParam()).name();
|
|
|
|
for (auto operand : std::get<1>(GetParam()).operands())
|
|
|
|
input << " " << operand;
|
2015-11-30 19:39:31 +00:00
|
|
|
input << std::endl;
|
2018-08-01 18:58:12 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input.str(), std::get<0>(GetParam())),
|
|
|
|
Eq(MakeInstruction(SpvOpMemberDecorate,
|
|
|
|
{1, 42, uint32_t(std::get<1>(GetParam()).value())},
|
|
|
|
std::get<1>(GetParam()).operands())));
|
2015-11-30 19:39:31 +00:00
|
|
|
// Also check disassembly.
|
2016-05-10 03:15:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
EncodeAndDecodeSuccessfully(input.str(), SPV_BINARY_TO_TEXT_OPTION_NONE,
|
2018-08-01 18:58:12 +00:00
|
|
|
std::get<0>(GetParam())),
|
2016-05-10 03:15:46 +00:00
|
|
|
Eq(input.str()));
|
2015-11-30 19:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CASE(NAME) SpvDecoration##NAME, #NAME
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-11-30 19:39:31 +00:00
|
|
|
TextToBinaryDecorateSimple, OpMemberDecorateSimpleTest,
|
2016-05-10 03:15:46 +00:00
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ValuesIn(std::vector<EnumCase<SpvDecoration>>{
|
|
|
|
// The operand literal values are arbitrarily chosen,
|
|
|
|
// but there are the right number of them.
|
|
|
|
{CASE(RelaxedPrecision), {}},
|
|
|
|
{CASE(SpecId), {100}},
|
|
|
|
{CASE(Block), {}},
|
|
|
|
{CASE(BufferBlock), {}},
|
|
|
|
{CASE(RowMajor), {}},
|
|
|
|
{CASE(ColMajor), {}},
|
|
|
|
{CASE(ArrayStride), {4}},
|
|
|
|
{CASE(MatrixStride), {16}},
|
|
|
|
{CASE(GLSLShared), {}},
|
|
|
|
{CASE(GLSLPacked), {}},
|
|
|
|
{CASE(CPacked), {}},
|
|
|
|
// Placeholder line for enum value 12
|
|
|
|
{CASE(NoPerspective), {}},
|
|
|
|
{CASE(Flat), {}},
|
|
|
|
{CASE(Patch), {}},
|
|
|
|
{CASE(Centroid), {}},
|
|
|
|
{CASE(Sample), {}},
|
|
|
|
{CASE(Invariant), {}},
|
|
|
|
{CASE(Restrict), {}},
|
|
|
|
{CASE(Aliased), {}},
|
|
|
|
{CASE(Volatile), {}},
|
|
|
|
{CASE(Constant), {}},
|
|
|
|
{CASE(Coherent), {}},
|
|
|
|
{CASE(NonWritable), {}},
|
|
|
|
{CASE(NonReadable), {}},
|
|
|
|
{CASE(Uniform), {}},
|
|
|
|
{CASE(SaturatedConversion), {}},
|
|
|
|
{CASE(Stream), {2}},
|
|
|
|
{CASE(Location), {6}},
|
|
|
|
{CASE(Component), {3}},
|
|
|
|
{CASE(Index), {14}},
|
|
|
|
{CASE(Binding), {19}},
|
|
|
|
{CASE(DescriptorSet), {7}},
|
|
|
|
{CASE(Offset), {12}},
|
|
|
|
{CASE(XfbBuffer), {1}},
|
|
|
|
{CASE(XfbStride), {8}},
|
|
|
|
{CASE(NoContraction), {}},
|
|
|
|
{CASE(InputAttachmentIndex), {102}},
|
|
|
|
{CASE(Alignment), {16}},
|
2019-01-29 23:56:52 +00:00
|
|
|
})));
|
2016-05-10 03:15:46 +00:00
|
|
|
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2016-05-10 03:15:46 +00:00
|
|
|
TextToBinaryDecorateSimpleV11, OpMemberDecorateSimpleTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_1),
|
2019-01-29 23:56:52 +00:00
|
|
|
Values(EnumCase<SpvDecoration>{CASE(MaxByteOffset), {128}})));
|
2015-11-30 19:39:31 +00:00
|
|
|
#undef CASE
|
|
|
|
|
|
|
|
TEST_F(OpMemberDecorateSimpleTest, WrongDecoration) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemberDecorate %1 9 xxyyzz"),
|
|
|
|
Eq("Invalid decoration 'xxyyzz'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemberDecorateSimpleTest, ExtraOperandsOnDecorationExpectingNone) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemberDecorate %1 12 RelaxedPrecision 99"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '99'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemberDecorateSimpleTest, ExtraOperandsOnDecorationExpectingOne) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemberDecorate %1 0 SpecId 99 100"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '100'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemberDecorateSimpleTest, ExtraOperandsOnDecorationExpectingTwo) {
|
|
|
|
EXPECT_THAT(CompileFailure(
|
|
|
|
"OpMemberDecorate %1 1 LinkageAttributes \"abc\" Import 42"),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an "
|
|
|
|
"instruction, found '42'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(dneto): OpMemberDecorate cases for decorations with parameters which
|
|
|
|
// are: not just lists of literal numbers.
|
|
|
|
|
2015-09-10 17:23:11 +00:00
|
|
|
// TODO(dneto): OpDecorationGroup
|
|
|
|
// TODO(dneto): OpGroupDecorate
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|