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 <sstream>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-09-14 19:08:48 +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-14 19:08:48 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-14 19:08:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-09-21 21:16:45 +00:00
|
|
|
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", {}},
|
2019-01-29 23:56:52 +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, {} }
|
2019-01-29 23:56:52 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
2015-09-21 21:16:45 +00:00
|
|
|
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),
|
2019-01-29 23:56:52 +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
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|