2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-14 18:28:33 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and/or associated documentation files (the
|
|
|
|
// "Materials"), to deal in the Materials without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Materials, and to
|
|
|
|
// permit persons to whom the Materials are furnished to do so, subject to
|
|
|
|
// the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Materials.
|
|
|
|
//
|
|
|
|
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
|
|
|
|
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
|
|
|
|
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
|
|
|
|
// https://www.khronos.org/registry/
|
|
|
|
//
|
|
|
|
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Control Flow" section of the
|
|
|
|
// SPIR-V spec.
|
|
|
|
|
2016-04-27 20:22:15 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-09-14 18:28:33 +00:00
|
|
|
#include "UnitSPIRV.h"
|
|
|
|
|
|
|
|
#include "TestFixture.h"
|
2016-04-27 20:22:15 +00:00
|
|
|
#include "gmock/gmock.h"
|
2015-09-14 18:28:33 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-27 20:22:15 +00:00
|
|
|
using ::testing::Combine;
|
|
|
|
using ::testing::Eq;
|
|
|
|
using ::testing::TestWithParam;
|
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::ValuesIn;
|
|
|
|
using spvtest::Concatenate;
|
2015-10-01 20:58:17 +00:00
|
|
|
using spvtest::EnumCase;
|
2015-09-14 18:28:33 +00:00
|
|
|
using spvtest::MakeInstruction;
|
2015-09-28 19:02:21 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2016-04-27 20:22:15 +00:00
|
|
|
using std::get;
|
|
|
|
using std::ostringstream;
|
|
|
|
using std::tuple;
|
2015-09-14 18:28:33 +00:00
|
|
|
|
|
|
|
// Test OpSelectionMerge
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using OpSelectionMergeTest = spvtest::TextToBinaryTestBase<
|
2016-04-27 20:22:15 +00:00
|
|
|
TestWithParam<EnumCase<SpvSelectionControlMask>>>;
|
2015-09-14 18:28:33 +00:00
|
|
|
|
|
|
|
TEST_P(OpSelectionMergeTest, AnySingleSelectionControlMask) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpSelectionMerge %1 " + GetParam().name();
|
2015-09-14 18:28:33 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSelectionMerge, {1, GetParam().value()})));
|
2015-09-14 18:28:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clang-format off
|
2015-10-28 17:40:52 +00:00
|
|
|
#define CASE(VALUE,NAME) { SpvSelectionControl##VALUE, NAME}
|
2015-09-14 18:28:33 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(TextToBinarySelectionMerge, OpSelectionMergeTest,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<EnumCase<SpvSelectionControlMask>>{
|
2015-09-14 18:28:33 +00:00
|
|
|
CASE(MaskNone, "None"),
|
|
|
|
CASE(FlattenMask, "Flatten"),
|
|
|
|
CASE(DontFlattenMask, "DontFlatten"),
|
2016-03-18 18:13:16 +00:00
|
|
|
}),);
|
2015-09-14 18:28:33 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
2015-09-16 22:32:54 +00:00
|
|
|
TEST_F(OpSelectionMergeTest, CombinedSelectionControlMask) {
|
|
|
|
const std::string input = "OpSelectionMerge %1 Flatten|DontFlatten";
|
|
|
|
const uint32_t expected_mask =
|
2015-10-28 17:40:52 +00:00
|
|
|
SpvSelectionControlFlattenMask | SpvSelectionControlDontFlattenMask;
|
2015-09-16 22:32:54 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSelectionMerge, {1, expected_mask})));
|
2015-09-16 22:32:54 +00:00
|
|
|
}
|
2015-09-14 18:28:33 +00:00
|
|
|
|
2015-10-13 19:49:53 +00:00
|
|
|
TEST_F(OpSelectionMergeTest, WrongSelectionControl) {
|
|
|
|
// Case sensitive: "flatten" != "Flatten" and thus wrong.
|
|
|
|
EXPECT_THAT(CompileFailure("OpSelectionMerge %1 flatten|DontFlatten"),
|
2015-11-24 23:37:24 +00:00
|
|
|
Eq("Invalid selection control operand 'flatten|DontFlatten'."));
|
2015-10-13 19:49:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 18:33:08 +00:00
|
|
|
// Test OpLoopMerge
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using OpLoopMergeTest = spvtest::TextToBinaryTestBase<
|
2016-04-27 20:22:15 +00:00
|
|
|
TestWithParam<tuple<spv_target_env, EnumCase<int>>>>;
|
2015-09-14 18:33:08 +00:00
|
|
|
|
|
|
|
TEST_P(OpLoopMergeTest, AnySingleLoopControlMask) {
|
2016-04-27 20:22:15 +00:00
|
|
|
const auto ctrl = get<1>(GetParam());
|
|
|
|
ostringstream input;
|
|
|
|
input << "OpLoopMerge %merge %continue " << ctrl.name();
|
|
|
|
for (auto num : ctrl.operands()) input << " " << num;
|
|
|
|
EXPECT_THAT(CompiledInstructions(input.str(), get<0>(GetParam())),
|
|
|
|
Eq(MakeInstruction(SpvOpLoopMerge, {1, 2, ctrl.value()},
|
|
|
|
ctrl.operands())));
|
2015-09-14 18:33:08 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 20:22:15 +00:00
|
|
|
#define CASE(VALUE, NAME) \
|
|
|
|
{ SpvLoopControl##VALUE, NAME }
|
|
|
|
#define CASE1(VALUE, NAME, PARM) \
|
|
|
|
{ \
|
|
|
|
SpvLoopControl##VALUE, NAME, { PARM } \
|
|
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryLoopMerge, OpLoopMergeTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ValuesIn(std::vector<EnumCase<int>>{
|
|
|
|
// clang-format off
|
|
|
|
CASE(MaskNone, "None"),
|
|
|
|
CASE(UnrollMask, "Unroll"),
|
|
|
|
CASE(DontUnrollMask, "DontUnroll"),
|
|
|
|
// clang-format on
|
|
|
|
})), );
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryLoopMergeV11, OpLoopMergeTest,
|
|
|
|
Combine(Values(SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ValuesIn(std::vector<EnumCase<int>>{
|
|
|
|
// clang-format off
|
|
|
|
CASE(DependencyInfiniteMask, "DependencyInfinite"),
|
|
|
|
CASE1(DependencyLengthMask, "DependencyLength", 234),
|
|
|
|
{SpvLoopControlUnrollMask|SpvLoopControlDependencyLengthMask,
|
|
|
|
"DependencyLength|Unroll", {33}},
|
|
|
|
// clang-format on
|
|
|
|
})), );
|
2015-09-14 18:33:08 +00:00
|
|
|
#undef CASE
|
2016-04-27 20:22:15 +00:00
|
|
|
#undef CASE1
|
2015-09-14 18:33:08 +00:00
|
|
|
|
2015-09-16 22:32:54 +00:00
|
|
|
TEST_F(OpLoopMergeTest, CombinedLoopControlMask) {
|
2015-09-24 19:45:59 +00:00
|
|
|
const std::string input = "OpLoopMerge %merge %continue Unroll|DontUnroll";
|
2015-09-16 22:32:54 +00:00
|
|
|
const uint32_t expected_mask =
|
2015-10-28 17:40:52 +00:00
|
|
|
SpvLoopControlUnrollMask | SpvLoopControlDontUnrollMask;
|
2015-09-16 22:32:54 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpLoopMerge, {1, 2, expected_mask})));
|
2015-09-16 22:32:54 +00:00
|
|
|
}
|
2015-10-13 19:53:46 +00:00
|
|
|
|
|
|
|
TEST_F(OpLoopMergeTest, WrongLoopControl) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpLoopMerge %m %c none"),
|
2015-11-24 23:37:24 +00:00
|
|
|
Eq("Invalid loop control operand 'none'."));
|
2015-10-13 19:53:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 19:02:21 +00:00
|
|
|
// Test OpSwitch
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchGoodZeroTargets) {
|
|
|
|
EXPECT_THAT(CompiledInstructions("OpSwitch %selector %default"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpSwitch, {1, 2})));
|
2015-09-28 19:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchGoodOneTarget) {
|
2015-09-29 15:28:34 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions("%1 = OpTypeInt 32 0\n"
|
|
|
|
"%2 = OpConstant %1 52\n"
|
|
|
|
"OpSwitch %2 %default 12 %target0"),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(Concatenate({MakeInstruction(SpvOpTypeInt, {1, 32, 0}),
|
|
|
|
MakeInstruction(SpvOpConstant, {1, 2, 52}),
|
|
|
|
MakeInstruction(SpvOpSwitch, {2, 3, 12, 4})})));
|
2015-09-28 19:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchGoodTwoTargets) {
|
2015-09-29 15:28:34 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("%1 = OpTypeInt 32 0\n"
|
|
|
|
"%2 = OpConstant %1 52\n"
|
|
|
|
"OpSwitch %2 %default 12 %target0 42 %target1"),
|
|
|
|
Eq(Concatenate({
|
2015-10-28 17:40:52 +00:00
|
|
|
MakeInstruction(SpvOpTypeInt, {1, 32, 0}),
|
|
|
|
MakeInstruction(SpvOpConstant, {1, 2, 52}),
|
|
|
|
MakeInstruction(SpvOpSwitch, {2, 3, 12, 4, 42, 5}),
|
2015-09-29 15:28:34 +00:00
|
|
|
})));
|
2015-09-28 19:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchBadMissingSelector) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpSwitch"),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchBadInvalidSelector) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpSwitch 12"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchBadMissingDefault) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpSwitch %selector"),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchBadInvalidDefault) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpSwitch %selector 12"),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
2015-11-05 22:45:09 +00:00
|
|
|
TEST_F(TextToBinaryTest, SwitchBadInvalidLiteral) {
|
2015-09-28 19:02:21 +00:00
|
|
|
// The assembler recognizes "OpSwitch %selector %default" as a complete
|
2015-11-05 22:45:09 +00:00
|
|
|
// instruction. Then it tries to parse "%abc" as the start of a new
|
|
|
|
// instruction, but can't since it hits the end of stream.
|
2015-10-05 17:28:46 +00:00
|
|
|
const auto input = R"(%i32 = OpTypeInt 32 0
|
|
|
|
%selector = OpConstant %i32 42
|
|
|
|
OpSwitch %selector %default %abc)";
|
|
|
|
EXPECT_THAT(CompileFailure(input), Eq("Expected '=', found end of stream."));
|
2015-09-28 19:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TextToBinaryTest, SwitchBadMissingTarget) {
|
2015-09-29 15:28:34 +00:00
|
|
|
EXPECT_THAT(CompileFailure("%1 = OpTypeInt 32 0\n"
|
|
|
|
"%2 = OpConstant %1 52\n"
|
|
|
|
"OpSwitch %2 %default 12"),
|
2015-09-28 19:02:21 +00:00
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
2015-10-05 17:28:46 +00:00
|
|
|
// A test case for an OpSwitch.
|
|
|
|
// It is also parameterized to test encodings OpConstant
|
|
|
|
// integer literals. This can capture both single and multi-word
|
|
|
|
// integer literal tests.
|
2015-10-13 16:46:13 +00:00
|
|
|
struct SwitchTestCase {
|
2015-09-29 15:28:34 +00:00
|
|
|
std::string constant_type_args;
|
2015-10-05 17:28:46 +00:00
|
|
|
std::string constant_value_arg;
|
|
|
|
std::string case_value_arg;
|
2015-09-29 15:28:34 +00:00
|
|
|
std::vector<uint32_t> expected_instructions;
|
|
|
|
};
|
|
|
|
|
2015-10-13 16:46:13 +00:00
|
|
|
using OpSwitchValidTest =
|
2016-04-27 20:22:15 +00:00
|
|
|
spvtest::TextToBinaryTestBase<TestWithParam<SwitchTestCase>>;
|
2015-09-29 15:28:34 +00:00
|
|
|
|
2015-10-05 17:28:46 +00:00
|
|
|
// Tests the encoding of OpConstant literal values, and also
|
|
|
|
// the literal integer cases in an OpSwitch. This can
|
|
|
|
// test both single and multi-word integer literal encodings.
|
2015-10-13 16:46:13 +00:00
|
|
|
TEST_P(OpSwitchValidTest, ValidTypes) {
|
|
|
|
const std::string input = "%1 = OpTypeInt " + GetParam().constant_type_args +
|
|
|
|
"\n"
|
2015-10-05 17:28:46 +00:00
|
|
|
"%2 = OpConstant %1 " +
|
|
|
|
GetParam().constant_value_arg +
|
|
|
|
"\n"
|
|
|
|
"OpSwitch %2 %default " +
|
|
|
|
GetParam().case_value_arg + " %4\n";
|
2015-09-29 15:28:34 +00:00
|
|
|
std::vector<uint32_t> instructions;
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
|
|
|
Eq(GetParam().expected_instructions));
|
|
|
|
}
|
2015-10-05 17:28:46 +00:00
|
|
|
|
|
|
|
// Constructs a SwitchTestCase from the given integer_width, signedness,
|
|
|
|
// constant value string, and expected encoded constant.
|
|
|
|
SwitchTestCase MakeSwitchTestCase(uint32_t integer_width,
|
|
|
|
uint32_t integer_signedness,
|
|
|
|
std::string constant_str,
|
|
|
|
std::vector<uint32_t> encoded_constant,
|
|
|
|
std::string case_value_str,
|
|
|
|
std::vector<uint32_t> encoded_case_value) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << integer_width << " " << integer_signedness;
|
|
|
|
return SwitchTestCase{
|
|
|
|
ss.str(),
|
|
|
|
constant_str,
|
|
|
|
case_value_str,
|
|
|
|
{Concatenate(
|
2015-10-28 17:40:52 +00:00
|
|
|
{MakeInstruction(SpvOpTypeInt,
|
2015-10-05 17:28:46 +00:00
|
|
|
{1, integer_width, integer_signedness}),
|
2015-10-28 17:40:52 +00:00
|
|
|
MakeInstruction(SpvOpConstant,
|
2015-10-05 17:28:46 +00:00
|
|
|
Concatenate({{1, 2}, encoded_constant})),
|
2015-10-28 17:40:52 +00:00
|
|
|
MakeInstruction(SpvOpSwitch,
|
2015-10-05 17:28:46 +00:00
|
|
|
Concatenate({{2, 3}, encoded_case_value, {4}}))})}};
|
|
|
|
}
|
|
|
|
|
2015-09-29 15:28:34 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2015-10-05 17:28:46 +00:00
|
|
|
TextToBinaryOpSwitchValid1Word, OpSwitchValidTest,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<SwitchTestCase>({
|
2015-10-05 17:28:46 +00:00
|
|
|
MakeSwitchTestCase(32, 0, "42", {42}, "100", {100}),
|
|
|
|
MakeSwitchTestCase(32, 1, "-1", {0xffffffff}, "100", {100}),
|
|
|
|
// SPIR-V 1.0 Rev 1 clarified that for an integer narrower than 32-bits,
|
|
|
|
// its bits will appear in the lower order bits of the 32-bit word, and
|
|
|
|
// a signed integer is sign-extended.
|
|
|
|
MakeSwitchTestCase(7, 0, "127", {127}, "100", {100}),
|
|
|
|
MakeSwitchTestCase(14, 0, "99", {99}, "100", {100}),
|
|
|
|
MakeSwitchTestCase(16, 0, "65535", {65535}, "100", {100}),
|
|
|
|
MakeSwitchTestCase(16, 1, "101", {101}, "100", {100}),
|
|
|
|
// Demonstrate sign extension
|
|
|
|
MakeSwitchTestCase(16, 1, "-2", {0xfffffffe}, "100", {100}),
|
|
|
|
// Hex cases
|
|
|
|
MakeSwitchTestCase(16, 1, "0x7ffe", {0x7ffe}, "0x1234", {0x1234}),
|
|
|
|
MakeSwitchTestCase(16, 1, "0x8000", {0xffff8000}, "0x8100",
|
|
|
|
{0xffff8100}),
|
|
|
|
MakeSwitchTestCase(16, 0, "0x8000", {0x00008000}, "0x8100", {0x8100}),
|
2016-04-27 20:22:15 +00:00
|
|
|
})), );
|
2015-10-05 17:28:46 +00:00
|
|
|
|
|
|
|
// NB: The words LOW ORDER bits show up first.
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryOpSwitchValid2Words, OpSwitchValidTest,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<SwitchTestCase>({
|
2015-10-05 17:28:46 +00:00
|
|
|
MakeSwitchTestCase(33, 0, "101", {101, 0}, "500", {500, 0}),
|
|
|
|
MakeSwitchTestCase(48, 1, "-1", {0xffffffff, 0xffffffff}, "900",
|
|
|
|
{900, 0}),
|
|
|
|
MakeSwitchTestCase(64, 1, "-2", {0xfffffffe, 0xffffffff}, "-5",
|
|
|
|
{0xfffffffb, uint32_t(-1)}),
|
|
|
|
// Hex cases
|
|
|
|
MakeSwitchTestCase(48, 1, "0x7fffffffffff", {0xffffffff, 0x00007fff},
|
|
|
|
"100", {100, 0}),
|
|
|
|
MakeSwitchTestCase(48, 1, "0x800000000000", {0x00000000, 0xffff8000},
|
|
|
|
"0x800000000000", {0x00000000, 0xffff8000}),
|
|
|
|
MakeSwitchTestCase(48, 0, "0x800000000000", {0x00000000, 0x00008000},
|
|
|
|
"0x800000000000", {0x00000000, 0x00008000}),
|
|
|
|
MakeSwitchTestCase(63, 0, "0x500000000", {0, 5}, "12", {12, 0}),
|
2015-10-15 19:20:45 +00:00
|
|
|
MakeSwitchTestCase(64, 0, "0x600000000", {0, 6}, "12", {12, 0}),
|
|
|
|
MakeSwitchTestCase(64, 1, "0x700000123", {0x123, 7}, "12", {12, 0}),
|
2016-04-27 20:22:15 +00:00
|
|
|
})), );
|
2015-09-29 15:28:34 +00:00
|
|
|
|
2015-10-14 18:40:24 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2015-11-10 20:43:12 +00:00
|
|
|
OpSwitchRoundTripUnsignedIntegers, RoundTripTest,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<std::string>({
|
2015-10-14 18:40:24 +00:00
|
|
|
// Unsigned 16-bit.
|
|
|
|
"%1 = OpTypeInt 16 0\n%2 = OpConstant %1 65535\nOpSwitch %2 %3\n",
|
|
|
|
// Unsigned 32-bit, three non-default cases.
|
|
|
|
"%1 = OpTypeInt 32 0\n%2 = OpConstant %1 123456\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 102 %5 1000000 %6\n",
|
|
|
|
// Unsigned 48-bit, three non-default cases.
|
|
|
|
"%1 = OpTypeInt 48 0\n%2 = OpConstant %1 5000000000\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 102 %5 6000000000 %6\n",
|
|
|
|
// Unsigned 64-bit, three non-default cases.
|
|
|
|
"%1 = OpTypeInt 64 0\n%2 = OpConstant %1 9223372036854775807\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 102 %5 9000000000000000000 %6\n",
|
2016-04-27 20:22:15 +00:00
|
|
|
})), );
|
2015-10-14 18:40:24 +00:00
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2015-11-10 20:43:12 +00:00
|
|
|
OpSwitchRoundTripSignedIntegers, RoundTripTest,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<std::string>{
|
2015-10-14 18:40:24 +00:00
|
|
|
// Signed 16-bit, with two non-default cases
|
|
|
|
"%1 = OpTypeInt 16 1\n%2 = OpConstant %1 32767\n"
|
|
|
|
"OpSwitch %2 %3 99 %4 -102 %5\n",
|
|
|
|
"%1 = OpTypeInt 16 1\n%2 = OpConstant %1 -32768\n"
|
|
|
|
"OpSwitch %2 %3 99 %4 -102 %5\n",
|
|
|
|
// Signed 32-bit, two non-default cases.
|
|
|
|
"%1 = OpTypeInt 32 1\n%2 = OpConstant %1 -123456\n"
|
2015-11-10 20:43:12 +00:00
|
|
|
"OpSwitch %2 %3 100 %4 -123456 %5\n",
|
2015-10-14 18:40:24 +00:00
|
|
|
"%1 = OpTypeInt 32 1\n%2 = OpConstant %1 123456\n"
|
2015-11-10 20:43:12 +00:00
|
|
|
"OpSwitch %2 %3 100 %4 123456 %5\n",
|
2015-10-14 18:40:24 +00:00
|
|
|
// Signed 48-bit, three non-default cases.
|
|
|
|
"%1 = OpTypeInt 48 1\n%2 = OpConstant %1 5000000000\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 -7000000000 %5 6000000000 %6\n",
|
|
|
|
"%1 = OpTypeInt 48 1\n%2 = OpConstant %1 -5000000000\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 -7000000000 %5 6000000000 %6\n",
|
|
|
|
// Signed 64-bit, three non-default cases.
|
|
|
|
"%1 = OpTypeInt 64 1\n%2 = OpConstant %1 9223372036854775807\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 7000000000 %5 -1000000000000000000 %6\n",
|
|
|
|
"%1 = OpTypeInt 64 1\n%2 = OpConstant %1 -9223372036854775808\n"
|
|
|
|
"OpSwitch %2 %3 100 %4 7000000000 %5 -1000000000000000000 %6\n",
|
2016-04-27 20:22:15 +00:00
|
|
|
}), );
|
2015-10-14 18:40:24 +00:00
|
|
|
|
2015-10-13 16:46:13 +00:00
|
|
|
using OpSwitchInvalidTypeTestCase =
|
2016-04-27 20:22:15 +00:00
|
|
|
spvtest::TextToBinaryTestBase<TestWithParam<std::string>>;
|
2015-09-29 15:28:34 +00:00
|
|
|
|
2015-10-13 16:46:13 +00:00
|
|
|
TEST_P(OpSwitchInvalidTypeTestCase, InvalidTypes) {
|
|
|
|
const std::string input =
|
|
|
|
"%1 = " + GetParam() +
|
|
|
|
"\n"
|
|
|
|
"%3 = OpCopyObject %1 %2\n" // We only care the type of the expression
|
2015-09-29 15:28:34 +00:00
|
|
|
"%4 = OpSwitch %3 %default 32 %c\n";
|
|
|
|
EXPECT_THAT(CompileFailure(input),
|
2015-10-22 17:24:41 +00:00
|
|
|
Eq("The selector operand for OpSwitch must be the result of an "
|
|
|
|
"instruction that generates an integer scalar"));
|
2015-09-29 15:28:34 +00:00
|
|
|
}
|
2015-10-22 17:24:41 +00:00
|
|
|
|
2015-09-29 15:28:34 +00:00
|
|
|
// clang-format off
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryOpSwitchInvalidTests, OpSwitchInvalidTypeTestCase,
|
2016-04-27 20:22:15 +00:00
|
|
|
ValuesIn(std::vector<std::string>{
|
2015-09-29 15:28:34 +00:00
|
|
|
{"OpTypeVoid",
|
|
|
|
"OpTypeBool",
|
|
|
|
"OpTypeFloat 32",
|
|
|
|
"OpTypeVector %a 32",
|
|
|
|
"OpTypeMatrix %a 32",
|
|
|
|
"OpTypeImage %a 1D 0 0 0 0 Unknown",
|
|
|
|
"OpTypeSampler",
|
|
|
|
"OpTypeSampledImage %a",
|
|
|
|
"OpTypeArray %a %b",
|
|
|
|
"OpTypeRuntimeArray %a",
|
|
|
|
"OpTypeStruct %a",
|
|
|
|
"OpTypeOpaque \"Foo\"",
|
|
|
|
"OpTypePointer UniformConstant %a",
|
|
|
|
"OpTypeFunction %a %b",
|
|
|
|
"OpTypeEvent",
|
|
|
|
"OpTypeDeviceEvent",
|
|
|
|
"OpTypeReserveId",
|
|
|
|
"OpTypeQueue",
|
|
|
|
"OpTypePipe ReadOnly",
|
|
|
|
"OpTypeForwardPointer %a UniformConstant",
|
|
|
|
// At least one thing that isn't a type at all
|
|
|
|
"OpNot %a %b"
|
|
|
|
},
|
2016-03-18 18:13:16 +00:00
|
|
|
}),);
|
2015-09-29 15:28:34 +00:00
|
|
|
// clang-format on
|
2015-09-28 19:02:21 +00:00
|
|
|
|
2015-09-14 18:28:33 +00:00
|
|
|
// TODO(dneto): OpPhi
|
|
|
|
// TODO(dneto): OpLoopMerge
|
|
|
|
// TODO(dneto): OpLabel
|
|
|
|
// TODO(dneto): OpBranch
|
|
|
|
// TODO(dneto): OpSwitch
|
|
|
|
// TODO(dneto): OpKill
|
|
|
|
// TODO(dneto): OpReturn
|
|
|
|
// TODO(dneto): OpReturnValue
|
|
|
|
// TODO(dneto): OpUnreachable
|
|
|
|
// TODO(dneto): OpLifetimeStart
|
|
|
|
// TODO(dneto): OpLifetimeStop
|
|
|
|
|
|
|
|
} // anonymous namespace
|