Commit 9638b948 by Chris Forbes

Add complex type walker for literal indexes

This will be used by OpCompositeInsert and OpCompositeExtract. All indices are known at compile time, and are specified as literals rather than ids of constants, (as in Op*AccessChain) Bug: b/126475423 Change-Id: Ic29e2f988fb6b9bdab4b722b368e51db929c8bd3 Reviewed-on: https://swiftshader-review.googlesource.com/c/25213Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent b97a9572
...@@ -600,6 +600,47 @@ namespace sw ...@@ -600,6 +600,47 @@ namespace sw
return dynamicOffset + Int4(constantOffset); return dynamicOffset + Int4(constantOffset);
} }
uint32_t SpirvShader::WalkLiteralAccessChain(TypeID typeId, uint32_t numIndexes, uint32_t const *indexes) const
{
uint32_t constantOffset = 0;
for (auto i = 0u; i < numIndexes; i++)
{
auto & type = getType(typeId);
switch (type.definition.opcode())
{
case spv::OpTypeStruct:
{
int memberIndex = indexes[i];
int offsetIntoStruct = 0;
for (auto j = 0; j < memberIndex; j++) {
auto memberType = type.definition.word(2u + j);
offsetIntoStruct += getType(memberType).sizeInComponents;
}
constantOffset += offsetIntoStruct;
typeId = type.definition.word(2u + memberIndex);
break;
}
case spv::OpTypeVector:
case spv::OpTypeMatrix:
case spv::OpTypeArray:
{
auto elementType = type.definition.word(2);
auto stride = getType(elementType).sizeInComponents;
constantOffset += stride * indexes[i];
typeId = elementType;
break;
}
default:
UNIMPLEMENTED("Unexpected type in WalkLiteralAccessChain");
}
}
return constantOffset;
}
void SpirvShader::Decorations::Apply(spv::Decoration decoration, uint32_t arg) void SpirvShader::Decorations::Apply(spv::Decoration decoration, uint32_t arg)
{ {
switch (decoration) switch (decoration)
......
...@@ -349,6 +349,7 @@ namespace sw ...@@ -349,6 +349,7 @@ namespace sw
void ProcessInterfaceVariable(Object &object); void ProcessInterfaceVariable(Object &object);
Int4 WalkAccessChain(ObjectID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const; Int4 WalkAccessChain(ObjectID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const;
uint32_t WalkLiteralAccessChain(TypeID id, uint32_t numIndexes, uint32_t const *indexes) const;
}; };
class SpirvRoutine class SpirvRoutine
......
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