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/25213
Tested-by: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 97fc5d8..0f335ce 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -600,6 +600,47 @@
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)
{
switch (decoration)