Support SPV_KHR_subgroup_uniform_control_flow (#4318)

* Support SPV_KHR_subgroup_uniform_control_flow

Covers:
- assembler
- disassembler
- validator
- optimizer (add to whitelists)

* fix copyright

Co-authored-by: David Neto <dneto@google.com>
This commit is contained in:
alan-baker 2021-06-15 10:07:42 -04:00 коммит произвёл GitHub
Родитель ecdd9a3e6b
Коммит 4d22f58a81
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 132 добавлений и 0 удалений

Просмотреть файл

@ -997,6 +997,7 @@ void AggressiveDCEPass::InitExtensions() {
"SPV_KHR_terminate_invocation",
"SPV_KHR_shader_clock",
"SPV_KHR_vulkan_memory_model",
"SPV_KHR_subgroup_uniform_control_flow",
});
}

Просмотреть файл

@ -418,6 +418,7 @@ void LocalAccessChainConvertPass::InitExtensions() {
"SPV_KHR_ray_query",
"SPV_EXT_fragment_invocation_density",
"SPV_KHR_terminate_invocation",
"SPV_KHR_subgroup_uniform_control_flow",
});
}

Просмотреть файл

@ -270,6 +270,7 @@ void LocalSingleBlockLoadStoreElimPass::InitExtensions() {
"SPV_EXT_fragment_invocation_density",
"SPV_EXT_physical_storage_buffer",
"SPV_KHR_terminate_invocation",
"SPV_KHR_subgroup_uniform_control_flow",
});
}

Просмотреть файл

@ -123,6 +123,7 @@ void LocalSingleStoreElimPass::InitExtensionAllowList() {
"SPV_EXT_fragment_invocation_density",
"SPV_EXT_physical_storage_buffer",
"SPV_KHR_terminate_invocation",
"SPV_KHR_subgroup_uniform_control_flow",
});
}
bool LocalSingleStoreElimPass::ProcessVariable(Instruction* var_inst) {

Просмотреть файл

@ -935,6 +935,22 @@ INSTANTIATE_TEST_SUITE_P(
MakeVector("SPV_KHR_expect_assume"))},
{"OpAssumeTrueKHR %1\n",
MakeInstruction(SpvOpAssumeTrueKHR, {1})}})));
// SPV_KHR_subgroup_uniform_control_flow
INSTANTIATE_TEST_SUITE_P(
SPV_KHR_subgroup_uniform_control_flow, ExtensionRoundTripTest,
Combine(Values(SPV_ENV_UNIVERSAL_1_0, SPV_ENV_UNIVERSAL_1_3,
SPV_ENV_VULKAN_1_0, SPV_ENV_VULKAN_1_1, SPV_ENV_VULKAN_1_2),
ValuesIn(std::vector<AssemblyCase>{
{"OpExtension \"SPV_KHR_subgroup_uniform_control_flow\"\n",
MakeInstruction(
SpvOpExtension,
MakeVector("SPV_KHR_subgroup_uniform_control_flow"))},
{"OpExecutionMode %1 SubgroupUniformControlFlowKHR\n",
MakeInstruction(
SpvOpExecutionMode,
{1, SpvExecutionModeSubgroupUniformControlFlowKHR})},
})));
} // namespace
} // namespace spvtools

Просмотреть файл

@ -189,6 +189,7 @@ INSTANTIATE_TEST_SUITE_P(
{CASE(OutputTriangleStrip), {}},
{CASE(VecTypeHint), {96}},
{CASE(ContractionOff), {}},
{CASE(SubgroupUniformControlFlowKHR), {}},
})));
INSTANTIATE_TEST_SUITE_P(

Просмотреть файл

@ -40,6 +40,7 @@ add_spvtools_unittest(TARGET val_abcde
val_extensions_test.cpp
val_extension_spv_khr_expect_assume.cpp
val_extension_spv_khr_linkonce_odr.cpp
val_extension_spv_khr_subgroup_uniform_control_flow.cpp
val_extension_spv_khr_terminate_invocation.cpp
val_ext_inst_test.cpp
${VAL_TEST_COMMON_SRCS}

Просмотреть файл

@ -0,0 +1,110 @@
// Copyright (c) 2021 Google Inc.
//
// 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
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// 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.
// Tests for OpExtension validator rules.
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "source/enum_string_mapping.h"
#include "source/extensions.h"
#include "source/spirv_target_env.h"
#include "test/test_fixture.h"
#include "test/unit_spirv.h"
#include "test/val/val_fixtures.h"
namespace spvtools {
namespace val {
namespace {
using ::testing::HasSubstr;
using ::testing::Values;
using ::testing::ValuesIn;
using ValidateSpvKHRSubgroupUniformControlFlow = spvtest::ValidateBase<bool>;
TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, Valid) {
const std::string str = R"(
OpCapability Shader
OpExtension "SPV_KHR_subgroup_uniform_control_flow"
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpExecutionMode %main SubgroupUniformControlFlowKHR
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
}
TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, RequiresExtension) {
const std::string str = R"(
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpExecutionMode %main SubgroupUniformControlFlowKHR
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("2nd operand of ExecutionMode: operand "
"SubgroupUniformControlFlowKHR(4421) "
"requires one of these extensions: "
"SPV_KHR_subgroup_uniform_control_flow"));
}
TEST_F(ValidateSpvKHRSubgroupUniformControlFlow, RequiresShaderCapability) {
const std::string str = R"(
OpCapability Kernel
OpCapability Addresses
OpExtension "SPV_KHR_subgroup_uniform_control_flow"
OpMemoryModel Physical32 OpenCL
OpEntryPoint Kernel %main "main"
OpExecutionMode %main SubgroupUniformControlFlowKHR
%void = OpTypeVoid
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
OpReturn
OpFunctionEnd
)";
CompileSuccessfully(str.c_str());
EXPECT_NE(SPV_SUCCESS, ValidateInstructions());
EXPECT_THAT(getDiagnosticString(),
HasSubstr("Operand 2 of ExecutionMode requires one of these "
"capabilities: Shader"));
}
} // namespace
} // namespace val
} // namespace spvtools