2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-09-23 14:07:17 +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-23 14:07:17 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-09-23 14:07:17 +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-23 14:07:17 +00:00
|
|
|
|
|
|
|
// Assembler tests for instructions in the "Barrier Instructions" section
|
|
|
|
// of the SPIR-V spec.
|
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <string>
|
2015-09-23 14:07:17 +00:00
|
|
|
|
2016-04-19 02:25:35 +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-23 14:07:17 +00:00
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
namespace spvtools {
|
2015-09-23 14:07:17 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using spvtest::MakeInstruction;
|
|
|
|
using spvtest::TextToBinaryTest;
|
2017-11-27 15:16:41 +00:00
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::Eq;
|
2015-09-23 14:07:17 +00:00
|
|
|
|
|
|
|
// Test OpMemoryBarrier
|
|
|
|
|
2015-09-25 17:56:09 +00:00
|
|
|
using OpMemoryBarrier = spvtest::TextToBinaryTest;
|
2015-09-23 14:07:17 +00:00
|
|
|
|
2015-09-28 20:00:42 +00:00
|
|
|
TEST_F(OpMemoryBarrier, Good) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpMemoryBarrier %1 %2\n";
|
2015-09-23 14:07:17 +00:00
|
|
|
EXPECT_THAT(CompiledInstructions(input),
|
2015-10-28 17:40:52 +00:00
|
|
|
Eq(MakeInstruction(SpvOpMemoryBarrier, {1, 2})));
|
2015-09-25 17:56:09 +00:00
|
|
|
EXPECT_THAT(EncodeAndDecodeSuccessfully(input), Eq(input));
|
2015-09-23 14:07:17 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 20:00:42 +00:00
|
|
|
TEST_F(OpMemoryBarrier, BadMissingScopeId) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpMemoryBarrier\n";
|
2015-09-28 20:00:42 +00:00
|
|
|
EXPECT_THAT(CompileFailure(input),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemoryBarrier, BadInvalidScopeId) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpMemoryBarrier 99\n";
|
2015-11-02 14:41:20 +00:00
|
|
|
EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
|
2015-09-28 20:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemoryBarrier, BadMissingMemorySemanticsId) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpMemoryBarrier %scope\n";
|
2015-09-28 20:00:42 +00:00
|
|
|
EXPECT_THAT(CompileFailure(input),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(OpMemoryBarrier, BadInvalidMemorySemanticsId) {
|
2015-10-13 16:46:13 +00:00
|
|
|
const std::string input = "OpMemoryBarrier %scope 14\n";
|
2015-11-02 14:41:20 +00:00
|
|
|
EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
|
2015-09-28 20:00:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 14:07:17 +00:00
|
|
|
// TODO(dneto): OpControlBarrier
|
2015-11-11 17:32:21 +00:00
|
|
|
// TODO(dneto): OpGroupAsyncCopy
|
|
|
|
// TODO(dneto): OpGroupWaitEvents
|
2015-09-23 14:07:17 +00:00
|
|
|
// TODO(dneto): OpGroupAll
|
|
|
|
// TODO(dneto): OpGroupAny
|
|
|
|
// TODO(dneto): OpGroupBroadcast
|
|
|
|
// TODO(dneto): OpGroupIAdd
|
|
|
|
// TODO(dneto): OpGroupFAdd
|
|
|
|
// TODO(dneto): OpGroupFMin
|
|
|
|
// TODO(dneto): OpGroupUMin
|
|
|
|
// TODO(dneto): OpGroupSMin
|
|
|
|
// TODO(dneto): OpGroupFMax
|
|
|
|
// TODO(dneto): OpGroupUMax
|
|
|
|
// TODO(dneto): OpGroupSMax
|
|
|
|
|
2016-04-19 02:25:35 +00:00
|
|
|
using NamedMemoryBarrierTest = spvtest::TextToBinaryTest;
|
|
|
|
|
2018-06-19 13:54:33 +00:00
|
|
|
// OpMemoryNamedBarrier is not in 1.0, but it is enabled by a capability.
|
|
|
|
// We should be able to assemble it. Validation checks are in another test
|
|
|
|
// file.
|
|
|
|
TEST_F(NamedMemoryBarrierTest, OpcodeAssemblesInV10) {
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("OpMemoryNamedBarrier %bar %scope %semantics",
|
|
|
|
SPV_ENV_UNIVERSAL_1_0),
|
|
|
|
ElementsAre(spvOpcodeMake(4, SpvOpMemoryNamedBarrier), _, _, _));
|
2016-04-19 02:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamedMemoryBarrierTest, ArgumentCount) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("OpMemoryNamedBarrier %bar", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("OpMemoryNamedBarrier %bar %scope", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("OpMemoryNamedBarrier %bar %scope %semantics",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ElementsAre(spvOpcodeMake(4, SpvOpMemoryNamedBarrier), _, _, _));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("OpMemoryNamedBarrier %bar %scope %semantics %extra",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected '=', found end of stream."));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamedMemoryBarrierTest, ArgumentTypes) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier 123 %scope %semantics",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
EXPECT_THAT(CompileFailure("OpMemoryNamedBarrier %bar %scope \"semantics\"",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected id to start with %."));
|
|
|
|
}
|
|
|
|
|
|
|
|
using TypeNamedBarrierTest = spvtest::TextToBinaryTest;
|
|
|
|
|
2018-06-19 13:54:33 +00:00
|
|
|
TEST_F(TypeNamedBarrierTest, OpcodeAssemblesInV10) {
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("%t = OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_0),
|
|
|
|
ElementsAre(spvOpcodeMake(2, SpvOpTypeNamedBarrier), _));
|
2016-04-19 02:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(TypeNamedBarrierTest, ArgumentCount) {
|
|
|
|
EXPECT_THAT(CompileFailure("OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected <result-id> at the beginning of an instruction, "
|
|
|
|
"found 'OpTypeNamedBarrier'."));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("%t = OpTypeNamedBarrier", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ElementsAre(spvOpcodeMake(2, SpvOpTypeNamedBarrier), _));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("%t = OpTypeNamedBarrier 1 2 3", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an instruction, "
|
|
|
|
"found '1'."));
|
|
|
|
}
|
|
|
|
|
|
|
|
using NamedBarrierInitializeTest = spvtest::TextToBinaryTest;
|
|
|
|
|
2018-06-19 13:54:33 +00:00
|
|
|
TEST_F(NamedBarrierInitializeTest, OpcodeAssemblesInV10) {
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("%bar = OpNamedBarrierInitialize %type %count",
|
|
|
|
SPV_ENV_UNIVERSAL_1_0),
|
|
|
|
ElementsAre(spvOpcodeMake(4, SpvOpNamedBarrierInitialize), _, _, _));
|
2016-04-19 02:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NamedBarrierInitializeTest, ArgumentCount) {
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("%bar = OpNamedBarrierInitialize", SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
EXPECT_THAT(CompileFailure("%bar = OpNamedBarrierInitialize %ype",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected operand, found end of stream."));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompiledInstructions("%bar = OpNamedBarrierInitialize %type %count",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
ElementsAre(spvOpcodeMake(4, SpvOpNamedBarrierInitialize), _, _, _));
|
|
|
|
EXPECT_THAT(
|
|
|
|
CompileFailure("%bar = OpNamedBarrierInitialize %type %count \"extra\"",
|
|
|
|
SPV_ENV_UNIVERSAL_1_1),
|
|
|
|
Eq("Expected <opcode> or <result-id> at the beginning of an instruction, "
|
|
|
|
"found '\"extra\"'."));
|
|
|
|
}
|
|
|
|
|
2018-07-11 13:24:49 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace spvtools
|