2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-14 19:08:48 +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-14 19:08:48 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-14 19:08:48 +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-14 19:08:48 +00:00
|
|
|
|
|
|
|
// 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", {}},
|
2016-03-18 18:13:16 +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-11-18 14:22:10 +00:00
|
|
|
EXPECT_THAT(expected_mask, Eq(3u));
|
2015-09-17 21:06:10 +00:00
|
|
|
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),
|
2015-11-11 17:32:21 +00:00
|
|
|
CASE(Workgroup),
|
|
|
|
CASE(CrossWorkgroup),
|
|
|
|
CASE(Private),
|
2015-09-21 21:16:45 +00:00
|
|
|
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),
|
2016-03-18 18:13:16 +00:00
|
|
|
}),);
|
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
|