Commit 49d664dd by Chris Forbes

Split out decoration application helpers to avoid some iterator noise

Bug: b/124388146 Change-Id: I17531e47fc6fc4b296f893f94beb75f471847fd3 Reviewed-on: https://swiftshader-review.googlesource.com/c/24789Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 0f59a2cb
...@@ -416,11 +416,7 @@ namespace sw ...@@ -416,11 +416,7 @@ namespace sw
// This covers the rules in Vulkan 1.1 spec, 14.1.4 Location Assignment. // This covers the rules in Vulkan 1.1 spec, 14.1.4 Location Assignment.
auto const it = decorations.find(id); ApplyDecorationsForId(&d, id);
if (it != decorations.end())
{
d.Apply(it->second);
}
auto const &obj = getType(id); auto const &obj = getType(id);
switch (obj.definition.opcode()) switch (obj.definition.opcode())
...@@ -452,15 +448,10 @@ namespace sw ...@@ -452,15 +448,10 @@ namespace sw
return d.Location + 1; return d.Location + 1;
case spv::OpTypeStruct: case spv::OpTypeStruct:
{ {
auto const memberDecorationsIt = memberDecorations.find(id);
// iterate over members, which may themselves have Location/Component decorations // iterate over members, which may themselves have Location/Component decorations
for (auto i = 0u; i < obj.definition.wordCount() - 2; i++) for (auto i = 0u; i < obj.definition.wordCount() - 2; i++)
{ {
// Apply any member decorations for this member to the carried state. ApplyDecorationsForIdMember(&d, id, i);
if (memberDecorationsIt != memberDecorations.end() && i < memberDecorationsIt->second.size())
{
d.Apply(memberDecorationsIt->second[i]);
}
d.Location = PopulateInterfaceInner(iface, obj.definition.word(i + 2), d); d.Location = PopulateInterfaceInner(iface, obj.definition.word(i + 2), d);
d.Component = 0; // Implicit locations always have component=0 d.Component = 0; // Implicit locations always have component=0
} }
...@@ -485,12 +476,7 @@ namespace sw ...@@ -485,12 +476,7 @@ namespace sw
{ {
// Walk a variable definition and populate the interface from it. // Walk a variable definition and populate the interface from it.
Decorations d{}; Decorations d{};
ApplyDecorationsForId(&d, id);
auto const it = decorations.find(id);
if (it != decorations.end())
{
d.Apply(it->second);
}
auto def = getObject(id).definition; auto def = getObject(id).definition;
assert(def.opcode() == spv::OpVariable); assert(def.opcode() == spv::OpVariable);
...@@ -562,6 +548,22 @@ namespace sw ...@@ -562,6 +548,22 @@ namespace sw
BufferBlock |= src.BufferBlock; BufferBlock |= src.BufferBlock;
} }
void SpirvShader::ApplyDecorationsForId(Decorations *d, uint32_t id) const
{
auto it = decorations.find(id);
if (it != decorations.end())
d->Apply(it->second);
}
void SpirvShader::ApplyDecorationsForIdMember(Decorations *d, uint32_t id, uint32_t member) const
{
auto it = memberDecorations.find(id);
if (it != memberDecorations.end() && member < it->second.size())
{
d->Apply(it->second[member]);
}
}
uint32_t SpirvShader::GetConstantInt(uint32_t id) uint32_t SpirvShader::GetConstantInt(uint32_t id)
{ {
// Slightly hackish access to constants very early in translation. // Slightly hackish access to constants very early in translation.
......
...@@ -257,6 +257,8 @@ namespace sw ...@@ -257,6 +257,8 @@ namespace sw
void ProcessExecutionMode(InsnIterator it); void ProcessExecutionMode(InsnIterator it);
uint32_t ComputeTypeSize(InsnIterator insn); uint32_t ComputeTypeSize(InsnIterator insn);
void ApplyDecorationsForId(Decorations *d, uint32_t id) const;
void ApplyDecorationsForIdMember(Decorations *d, uint32_t id, uint32_t member) const;
void PopulateInterfaceSlot(std::vector<InterfaceComponent> *iface, Decorations const &d, AttribType type); void PopulateInterfaceSlot(std::vector<InterfaceComponent> *iface, Decorations const &d, AttribType type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment