2015-09-14 19:08:48 +00:00
|
|
|
// Copyright (c) 2015 The Khronos Group Inc.
|
|
|
|
//
|
|
|
|
// 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 "Memory Instructions" section of
|
|
|
|
// the SPIR-V spec.
|
|
|
|
|
|
|
|
#include "UnitSPIRV.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "TestFixture.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-10-01 20:58:17 +00:00
|
|
|
using spvtest::EnumCase;
|
2015-09-14 19:08:48 +00:00
|
|
|
using spvtest::MakeInstruction;
|
2015-09-21 15:36:44 +00:00
|
|
|
using spvtest::TextToBinaryTest;
|
2015-09-14 19:08:48 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
|
|
|
|
// Test assembly of Memory Access masks
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using MemoryAccessTest = spvtest::TextToBinaryTestBase<
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::TestWithParam<EnumCase<SpvMemoryAccessMask>>>;
|
2015-09-14 19:08:48 +00:00
|
|
|
|
|
|
|
TEST_P(MemoryAccessTest, AnySingleMemoryAccessMask) {
|
|
|
|
std::stringstream input;
|
2015-09-21 21:16:45 +00:00
|
|
|
input << "OpStore %ptr %value " << GetParam().name();
|
|
|
|
for (auto operand : GetParam().operands()) input << " " << operand;
|
2015-09-14 19:08:48 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input.str()),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpStore, {1, 2, GetParam().value()},
|
2015-10-01 15:24:11 +00:00
|
|
|
GetParam().operands())));
|
2015-09-14 19:08:48 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 21:16:45 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryMemoryAccessTest, MemoryAccessTest,
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::ValuesIn(std::vector<EnumCase<SpvMemoryAccessMask>>{
|
|
|
|
{SpvMemoryAccessMaskNone, "None", {}},
|
|
|
|
{SpvMemoryAccessVolatileMask, "Volatile", {}},
|
|
|
|
{SpvMemoryAccessAlignedMask, "Aligned", {16}},
|
|
|
|
{SpvMemoryAccessNontemporalMask, "Nontemporal", {}},
|
2015-09-21 21:16:45 +00:00
|
|
|
}));
|
2015-09-14 19:08:48 +00:00
|
|
|
|
2015-09-17 21:06:10 +00:00
|
|
|
TEST_F(TextToBinaryTest, CombinedMemoryAccessMask) {
|
|
|
|
const std::string input = "OpStore %ptr %value Volatile|Aligned 16";
|
|
|
|
const uint32_t expected_mask =
|
2015-10-28 17:40:52 +00:00
|
|
|
SpvMemoryAccessVolatileMask | SpvMemoryAccessAlignedMask;
|
2015-09-17 21:06:10 +00:00
|
|
|
EXPECT_THAT(expected_mask, Eq(3));
|
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpStore, {1, 2, expected_mask, 16})));
|
2015-09-17 21:06:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 20:41:38 +00:00
|
|
|
// Test Storage Class enum values
|
|
|
|
|
2015-09-21 15:36:44 +00:00
|
|
|
using StorageClassTest = spvtest::TextToBinaryTestBase<
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::TestWithParam<EnumCase<SpvStorageClass>>>;
|
2015-09-15 20:41:38 +00:00
|
|
|
|
|
|
|
TEST_P(StorageClassTest, AnyStorageClass) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "%1 = OpVariable %2 " + GetParam().name();
|
2015-09-15 20:41:38 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpVariable, {1, 2, GetParam().value()})));
|
2015-09-15 20:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clang-format off
|
2015-10-28 17:40:52 +00:00
|
|
|
#define CASE(NAME) { SpvStorageClass##NAME, #NAME, {} }
|
2015-09-21 21:16:45 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TextToBinaryStorageClassTest, StorageClassTest,
|
2015-10-28 17:40:52 +00:00
|
|
|
::testing::ValuesIn(std::vector<EnumCase<SpvStorageClass>>{
|
2015-09-21 21:16:45 +00:00
|
|
|
CASE(UniformConstant),
|
|
|
|
CASE(Input),
|
|
|
|
CASE(Uniform),
|
|
|
|
CASE(Output),
|
|
|
|
CASE(WorkgroupLocal),
|
|
|
|
CASE(WorkgroupGlobal),
|
|
|
|
CASE(PrivateGlobal),
|
|
|
|
CASE(Function),
|
|
|
|
CASE(Generic),
|
2015-09-23 14:19:57 +00:00
|
|
|
CASE(PushConstant),
|
2015-09-21 21:16:45 +00:00
|
|
|
CASE(AtomicCounter),
|
|
|
|
CASE(Image),
|
|
|
|
}));
|
2015-09-15 20:41:38 +00:00
|
|
|
#undef CASE
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
// TODO(dneto): OpVariable with initializers
|
2015-09-14 19:08:48 +00:00
|
|
|
// TODO(dneto): OpImageTexelPointer
|
|
|
|
// TODO(dneto): OpLoad
|
|
|
|
// TODO(dneto): OpStore
|
|
|
|
// TODO(dneto): OpCopyMemory
|
|
|
|
// TODO(dneto): OpCopyMemorySized
|
|
|
|
// TODO(dneto): OpAccessChain
|
|
|
|
// TODO(dneto): OpInBoundsAccessChain
|
|
|
|
// TODO(dneto): OpPtrAccessChain
|
|
|
|
// TODO(dneto): OpArrayLength
|
|
|
|
// TODO(dneto): OpGenercPtrMemSemantics
|
|
|
|
|
|
|
|
} // anonymous namespace
|