mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 03:30:06 +00:00
opt: add Int64 capability to trim pass (#5398)
Adds support for Int64 capability trimming.
This commit is contained in:
parent
3cc7e1c4c3
commit
1121c23198
@ -40,6 +40,7 @@ constexpr uint32_t kOpTypePointerStorageClassIndex = 0;
|
||||
constexpr uint32_t kTypeArrayTypeIndex = 0;
|
||||
constexpr uint32_t kOpTypeScalarBitWidthIndex = 0;
|
||||
constexpr uint32_t kTypePointerTypeIdInIdx = 1;
|
||||
constexpr uint32_t kOpTypeIntSizeIndex = 0;
|
||||
|
||||
// DFS visit of the type defined by `instruction`.
|
||||
// If `condition` is true, children of the current node are visited.
|
||||
@ -255,13 +256,24 @@ static std::optional<spv::Capability> Handler_OpTypePointer_StorageUniform16(
|
||||
: std::nullopt;
|
||||
}
|
||||
|
||||
static std::optional<spv::Capability> Handler_OpTypeInt_Int64(
|
||||
const Instruction* instruction) {
|
||||
assert(instruction->opcode() == spv::Op::OpTypeInt &&
|
||||
"This handler only support OpTypeInt opcodes.");
|
||||
|
||||
const uint32_t size =
|
||||
instruction->GetSingleWordInOperand(kOpTypeIntSizeIndex);
|
||||
return size == 64 ? std::optional(spv::Capability::Int64) : std::nullopt;
|
||||
}
|
||||
|
||||
// Opcode of interest to determine capabilities requirements.
|
||||
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 4> kOpcodeHandlers{{
|
||||
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 5> kOpcodeHandlers{{
|
||||
// clang-format off
|
||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageInputOutput16},
|
||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StoragePushConstant16},
|
||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniformBufferBlock16},
|
||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniform16}
|
||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniform16},
|
||||
{spv::Op::OpTypeInt, Handler_OpTypeInt_Int64 },
|
||||
// clang-format on
|
||||
}};
|
||||
|
||||
|
@ -78,6 +78,7 @@ class TrimCapabilitiesPass : public Pass {
|
||||
spv::Capability::FragmentShaderSampleInterlockEXT,
|
||||
spv::Capability::FragmentShaderShadingRateInterlockEXT,
|
||||
spv::Capability::Groups,
|
||||
spv::Capability::Int64,
|
||||
spv::Capability::Linkage,
|
||||
spv::Capability::MinLod,
|
||||
spv::Capability::Shader,
|
||||
|
@ -1591,6 +1591,45 @@ TEST_F(TrimCapabilitiesPassTest,
|
||||
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
|
||||
}
|
||||
|
||||
TEST_F(TrimCapabilitiesPassTest, Int64_RemovedWhenUnused) {
|
||||
const std::string kTest = R"(
|
||||
OpCapability Int64
|
||||
; CHECK-NOT: OpCapability Int64
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %1 "main"
|
||||
%void = OpTypeVoid
|
||||
%3 = OpTypeFunction %void
|
||||
%1 = OpFunction %void None %3
|
||||
%6 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd;
|
||||
)";
|
||||
const auto result =
|
||||
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
|
||||
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
|
||||
}
|
||||
|
||||
TEST_F(TrimCapabilitiesPassTest, Int64_RemainsWhenUsed) {
|
||||
const std::string kTest = R"(
|
||||
OpCapability Int64
|
||||
; CHECK: OpCapability Int64
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %1 "main"
|
||||
%void = OpTypeVoid
|
||||
%int = OpTypeInt 64 0
|
||||
%3 = OpTypeFunction %void
|
||||
%1 = OpFunction %void None %3
|
||||
%6 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd;
|
||||
)";
|
||||
const auto result =
|
||||
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
|
||||
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
Loading…
Reference in New Issue
Block a user