mirror of
https://github.com/KhronosGroup/SPIRV-Tools
synced 2024-11-22 19:50:05 +00:00
opt: add StorageUniformBufferBlock16 to trim pass (#5367)
Add StorageUniformBufferBlock16 to the list of enabled capabilities.
This commit is contained in:
parent
ebda56e352
commit
4788ff1578
@ -461,7 +461,7 @@ std::vector<T> DecorationManager::InternalGetDecorationsFor(
|
|||||||
|
|
||||||
bool DecorationManager::WhileEachDecoration(
|
bool DecorationManager::WhileEachDecoration(
|
||||||
uint32_t id, uint32_t decoration,
|
uint32_t id, uint32_t decoration,
|
||||||
std::function<bool(const Instruction&)> f) {
|
std::function<bool(const Instruction&)> f) const {
|
||||||
for (const Instruction* inst : GetDecorationsFor(id, true)) {
|
for (const Instruction* inst : GetDecorationsFor(id, true)) {
|
||||||
switch (inst->opcode()) {
|
switch (inst->opcode()) {
|
||||||
case spv::Op::OpMemberDecorate:
|
case spv::Op::OpMemberDecorate:
|
||||||
@ -485,14 +485,19 @@ bool DecorationManager::WhileEachDecoration(
|
|||||||
|
|
||||||
void DecorationManager::ForEachDecoration(
|
void DecorationManager::ForEachDecoration(
|
||||||
uint32_t id, uint32_t decoration,
|
uint32_t id, uint32_t decoration,
|
||||||
std::function<void(const Instruction&)> f) {
|
std::function<void(const Instruction&)> f) const {
|
||||||
WhileEachDecoration(id, decoration, [&f](const Instruction& inst) {
|
WhileEachDecoration(id, decoration, [&f](const Instruction& inst) {
|
||||||
f(inst);
|
f(inst);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DecorationManager::HasDecoration(uint32_t id, uint32_t decoration) {
|
bool DecorationManager::HasDecoration(uint32_t id,
|
||||||
|
spv::Decoration decoration) const {
|
||||||
|
return HasDecoration(id, static_cast<uint32_t>(decoration));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DecorationManager::HasDecoration(uint32_t id, uint32_t decoration) const {
|
||||||
bool has_decoration = false;
|
bool has_decoration = false;
|
||||||
ForEachDecoration(id, decoration, [&has_decoration](const Instruction&) {
|
ForEachDecoration(id, decoration, [&has_decoration](const Instruction&) {
|
||||||
has_decoration = true;
|
has_decoration = true;
|
||||||
|
@ -92,20 +92,21 @@ class DecorationManager {
|
|||||||
|
|
||||||
// Returns whether a decoration instruction for |id| with decoration
|
// Returns whether a decoration instruction for |id| with decoration
|
||||||
// |decoration| exists or not.
|
// |decoration| exists or not.
|
||||||
bool HasDecoration(uint32_t id, uint32_t decoration);
|
bool HasDecoration(uint32_t id, uint32_t decoration) const;
|
||||||
|
bool HasDecoration(uint32_t id, spv::Decoration decoration) const;
|
||||||
|
|
||||||
// |f| is run on each decoration instruction for |id| with decoration
|
// |f| is run on each decoration instruction for |id| with decoration
|
||||||
// |decoration|. Processed are all decorations which target |id| either
|
// |decoration|. Processed are all decorations which target |id| either
|
||||||
// directly or indirectly by Decoration Groups.
|
// directly or indirectly by Decoration Groups.
|
||||||
void ForEachDecoration(uint32_t id, uint32_t decoration,
|
void ForEachDecoration(uint32_t id, uint32_t decoration,
|
||||||
std::function<void(const Instruction&)> f);
|
std::function<void(const Instruction&)> f) const;
|
||||||
|
|
||||||
// |f| is run on each decoration instruction for |id| with decoration
|
// |f| is run on each decoration instruction for |id| with decoration
|
||||||
// |decoration|. Processes all decoration which target |id| either directly or
|
// |decoration|. Processes all decoration which target |id| either directly or
|
||||||
// indirectly through decoration groups. If |f| returns false, iteration is
|
// indirectly through decoration groups. If |f| returns false, iteration is
|
||||||
// terminated and this function returns false.
|
// terminated and this function returns false.
|
||||||
bool WhileEachDecoration(uint32_t id, uint32_t decoration,
|
bool WhileEachDecoration(uint32_t id, uint32_t decoration,
|
||||||
std::function<bool(const Instruction&)> f);
|
std::function<bool(const Instruction&)> f) const;
|
||||||
|
|
||||||
// |f| is run on each decoration instruction for |id| with decoration
|
// |f| is run on each decoration instruction for |id| with decoration
|
||||||
// |decoration|. Processes all decoration which target |id| either directly or
|
// |decoration|. Processes all decoration which target |id| either directly or
|
||||||
|
@ -173,11 +173,46 @@ Handler_OpTypePointer_StoragePushConstant16(const Instruction* instruction) {
|
|||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::optional<spv::Capability>
|
||||||
|
Handler_OpTypePointer_StorageUniformBufferBlock16(
|
||||||
|
const Instruction* instruction) {
|
||||||
|
assert(instruction->opcode() == spv::Op::OpTypePointer &&
|
||||||
|
"This handler only support OpTypePointer opcodes.");
|
||||||
|
|
||||||
|
// This capability is only required if the variable has a Uniform storage
|
||||||
|
// class.
|
||||||
|
spv::StorageClass storage_class = spv::StorageClass(
|
||||||
|
instruction->GetSingleWordInOperand(kOpTypePointerStorageClassIndex));
|
||||||
|
if (storage_class != spv::StorageClass::Uniform) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Has16BitCapability(instruction->context()->get_feature_mgr())) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* decoration_mgr = instruction->context()->get_decoration_mgr();
|
||||||
|
const bool matchesCondition =
|
||||||
|
AnyTypeOf(instruction, [decoration_mgr](const Instruction* item) {
|
||||||
|
if (!decoration_mgr->HasDecoration(item->result_id(),
|
||||||
|
spv::Decoration::BufferBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return AnyTypeOf(item, is16bitType);
|
||||||
|
});
|
||||||
|
|
||||||
|
return matchesCondition
|
||||||
|
? std::optional(spv::Capability::StorageUniformBufferBlock16)
|
||||||
|
: std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
// Opcode of interest to determine capabilities requirements.
|
// Opcode of interest to determine capabilities requirements.
|
||||||
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 2> kOpcodeHandlers{{
|
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 3> kOpcodeHandlers{{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageInputOutput16},
|
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageInputOutput16},
|
||||||
{spv::Op::OpTypePointer, Handler_OpTypePointer_StoragePushConstant16},
|
{spv::Op::OpTypePointer, Handler_OpTypePointer_StoragePushConstant16},
|
||||||
|
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniformBufferBlock16},
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
@ -80,7 +80,8 @@ class TrimCapabilitiesPass : public Pass {
|
|||||||
spv::Capability::Shader,
|
spv::Capability::Shader,
|
||||||
spv::Capability::ShaderClockKHR,
|
spv::Capability::ShaderClockKHR,
|
||||||
spv::Capability::StorageInputOutput16,
|
spv::Capability::StorageInputOutput16,
|
||||||
spv::Capability::StoragePushConstant16
|
spv::Capability::StoragePushConstant16,
|
||||||
|
spv::Capability::StorageUniformBufferBlock16
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1134,7 +1134,7 @@ TEST_F(TrimCapabilitiesPassTest, StoragePushConstant16_RemovedSimplePointer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrimCapabilitiesPassTest,
|
TEST_F(TrimCapabilitiesPassTest,
|
||||||
DISABLED_StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_0) {
|
StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_0) {
|
||||||
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
||||||
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
||||||
spv::Capability::StorageBuffer16BitAccess);
|
spv::Capability::StorageBuffer16BitAccess);
|
||||||
@ -1169,7 +1169,7 @@ TEST_F(TrimCapabilitiesPassTest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrimCapabilitiesPassTest,
|
TEST_F(TrimCapabilitiesPassTest,
|
||||||
DISABLED_StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_1) {
|
StorageUniformBufferBlock16_RemainsSimplePointer_Vulkan1_1) {
|
||||||
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
||||||
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
||||||
spv::Capability::StorageBuffer16BitAccess);
|
spv::Capability::StorageBuffer16BitAccess);
|
||||||
@ -1204,7 +1204,7 @@ TEST_F(TrimCapabilitiesPassTest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrimCapabilitiesPassTest,
|
TEST_F(TrimCapabilitiesPassTest,
|
||||||
DISABLED_StorageUniformBufferBlock16_RemovedSimplePointer) {
|
StorageUniformBufferBlock16_RemovedSimplePointer) {
|
||||||
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/5354
|
||||||
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
static_assert(spv::Capability::StorageUniformBufferBlock16 ==
|
||||||
spv::Capability::StorageBuffer16BitAccess);
|
spv::Capability::StorageBuffer16BitAccess);
|
||||||
|
Loading…
Reference in New Issue
Block a user