Commit dfc0f3b7 by Ben Clayton Committed by Ben Clayton

SpirvShader: Move emit() instructions to their own functions

These are only going to grow. Bug: b/126126820 Change-Id: I03a2b214e9968c31dabc4814b505c1f8c22349ae Reviewed-on: https://swiftshader-review.googlesource.com/c/25552 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent d4e4c66b
...@@ -836,6 +836,45 @@ namespace sw ...@@ -836,6 +836,45 @@ namespace sw
break; break;
case spv::OpVariable: case spv::OpVariable:
EmitVariable(insn, routine);
break;
case spv::OpLoad:
EmitLoad(insn, routine);
break;
case spv::OpStore:
EmitStore(insn, routine);
break;
case spv::OpAccessChain:
EmitAccessChain(insn, routine);
break;
case spv::OpCompositeConstruct:
EmitCompositeConstruct(insn, routine);
break;
case spv::OpCompositeInsert:
EmitCompositeInsert(insn, routine);
break;
case spv::OpCompositeExtract:
EmitCompositeExtract(insn, routine);
break;
case spv::OpVectorShuffle:
EmitVectorShuffle(insn, routine);
break;
default:
printf("emit: ignoring opcode %s\n", OpcodeName(insn.opcode()).c_str());
break;
}
}
}
void SpirvShader::EmitVariable(InsnIterator insn, SpirvRoutine *routine) const
{ {
ObjectID resultId = insn.word(2); ObjectID resultId = insn.word(2);
auto &object = getObject(resultId); auto &object = getObject(resultId);
...@@ -850,9 +889,9 @@ namespace sw ...@@ -850,9 +889,9 @@ namespace sw
dst[offset++] = routine->inputs[scalarSlot]; dst[offset++] = routine->inputs[scalarSlot];
}); });
} }
break;
} }
case spv::OpLoad:
void SpirvShader::EmitLoad(InsnIterator insn, SpirvRoutine *routine) const
{ {
ObjectID objectId = insn.word(2); ObjectID objectId = insn.word(2);
ObjectID pointerId = insn.word(3); ObjectID pointerId = insn.word(3);
...@@ -898,9 +937,9 @@ namespace sw ...@@ -898,9 +937,9 @@ namespace sw
dst.emplace(i, ptrBase[i]); dst.emplace(i, ptrBase[i]);
} }
} }
break;
} }
case spv::OpAccessChain:
void SpirvShader::EmitAccessChain(InsnIterator insn, SpirvRoutine *routine) const
{ {
TypeID typeId = insn.word(1); TypeID typeId = insn.word(1);
ObjectID objectId = insn.word(2); ObjectID objectId = insn.word(2);
...@@ -920,9 +959,9 @@ namespace sw ...@@ -920,9 +959,9 @@ namespace sw
} }
auto &dst = routine->createIntermediate(objectId, type.sizeInComponents); auto &dst = routine->createIntermediate(objectId, type.sizeInComponents);
dst.emplace(0, As<SIMD::Float>(WalkAccessChain(baseId, insn.wordCount() - 4, insn.wordPointer(4), routine))); dst.emplace(0, As<SIMD::Float>(WalkAccessChain(baseId, insn.wordCount() - 4, insn.wordPointer(4), routine)));
break;
} }
case spv::OpStore:
void SpirvShader::EmitStore(InsnIterator insn, SpirvRoutine *routine) const
{ {
ObjectID pointerId = insn.word(1); ObjectID pointerId = insn.word(1);
ObjectID objectId = insn.word(2); ObjectID objectId = insn.word(2);
...@@ -994,9 +1033,9 @@ namespace sw ...@@ -994,9 +1033,9 @@ namespace sw
} }
} }
} }
break;
} }
case spv::OpCompositeConstruct:
void SpirvShader::EmitCompositeConstruct(InsnIterator insn, SpirvRoutine *routine) const
{ {
auto &type = getType(insn.word(1)); auto &type = getType(insn.word(1));
auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents); auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
...@@ -1012,9 +1051,9 @@ namespace sw ...@@ -1012,9 +1051,9 @@ namespace sw
for (auto j = 0u; j < srcObjectTy.sizeInComponents; j++) for (auto j = 0u; j < srcObjectTy.sizeInComponents; j++)
dst.emplace(offset++, srcObjectAccess[j]); dst.emplace(offset++, srcObjectAccess[j]);
} }
break;
} }
case spv::OpCompositeInsert:
void SpirvShader::EmitCompositeInsert(InsnIterator insn, SpirvRoutine *routine) const
{ {
TypeID resultTypeId = insn.word(1); TypeID resultTypeId = insn.word(1);
auto &type = getType(resultTypeId); auto &type = getType(resultTypeId);
...@@ -1028,16 +1067,22 @@ namespace sw ...@@ -1028,16 +1067,22 @@ namespace sw
// old components before // old components before
for (auto i = 0u; i < firstNewComponent; i++) for (auto i = 0u; i < firstNewComponent; i++)
{
dst.emplace(i, srcObjectAccess[i]); dst.emplace(i, srcObjectAccess[i]);
}
// new part // new part
for (auto i = 0u; i < newPartObjectTy.sizeInComponents; i++) for (auto i = 0u; i < newPartObjectTy.sizeInComponents; i++)
{
dst.emplace(firstNewComponent + i, newPartObjectAccess[i]); dst.emplace(firstNewComponent + i, newPartObjectAccess[i]);
}
// old components after // old components after
for (auto i = firstNewComponent + newPartObjectTy.sizeInComponents; i < type.sizeInComponents; i++) for (auto i = firstNewComponent + newPartObjectTy.sizeInComponents; i < type.sizeInComponents; i++)
{
dst.emplace(i, srcObjectAccess[i]); dst.emplace(i, srcObjectAccess[i]);
break;
} }
case spv::OpCompositeExtract: }
void SpirvShader::EmitCompositeExtract(InsnIterator insn, SpirvRoutine *routine) const
{ {
auto &type = getType(insn.word(1)); auto &type = getType(insn.word(1));
auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents); auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
...@@ -1047,10 +1092,12 @@ namespace sw ...@@ -1047,10 +1092,12 @@ namespace sw
GenericValue compositeObjectAccess(this, routine, insn.word(3)); GenericValue compositeObjectAccess(this, routine, insn.word(3));
for (auto i = 0u; i < type.sizeInComponents; i++) for (auto i = 0u; i < type.sizeInComponents; i++)
{
dst.emplace(i, compositeObjectAccess[firstComponent + i]); dst.emplace(i, compositeObjectAccess[firstComponent + i]);
break;
} }
case spv::OpVectorShuffle: }
void SpirvShader::EmitVectorShuffle(InsnIterator insn, SpirvRoutine *routine) const
{ {
auto &type = getType(insn.word(1)); auto &type = getType(insn.word(1));
auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents); auto &dst = routine->createIntermediate(insn.word(2), type.sizeInComponents);
...@@ -1076,13 +1123,6 @@ namespace sw ...@@ -1076,13 +1123,6 @@ namespace sw
dst.emplace(i, secondHalfAccess[selector - type.sizeInComponents]); dst.emplace(i, secondHalfAccess[selector - type.sizeInComponents]);
} }
} }
break;
}
default:
printf("emit: ignoring opcode %s\n", OpcodeName(insn.opcode()).c_str());
break;
}
}
} }
void SpirvShader::emitEpilog(SpirvRoutine *routine) const void SpirvShader::emitEpilog(SpirvRoutine *routine) const
......
...@@ -381,6 +381,16 @@ namespace sw ...@@ -381,6 +381,16 @@ namespace sw
SIMD::Int WalkAccessChain(ObjectID id, uint32_t numIndexes, uint32_t const *indexIds, SpirvRoutine *routine) const; SIMD::Int 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; uint32_t WalkLiteralAccessChain(TypeID id, uint32_t numIndexes, uint32_t const *indexes) const;
// Emit pass instructions:
void EmitVariable(InsnIterator insn, SpirvRoutine *routine) const;
void EmitLoad(InsnIterator insn, SpirvRoutine *routine) const;
void EmitStore(InsnIterator insn, SpirvRoutine *routine) const;
void EmitAccessChain(InsnIterator insn, SpirvRoutine *routine) const;
void EmitCompositeConstruct(InsnIterator insn, SpirvRoutine *routine) const;
void EmitCompositeInsert(InsnIterator insn, SpirvRoutine *routine) const;
void EmitCompositeExtract(InsnIterator insn, SpirvRoutine *routine) const;
void EmitVectorShuffle(InsnIterator insn, SpirvRoutine *routine) const;
// OpcodeName returns the name of the opcode op. // OpcodeName returns the name of the opcode op.
// If NDEBUG is defined, then OpcodeName will only return the numerical code. // If NDEBUG is defined, then OpcodeName will only return the numerical code.
static std::string OpcodeName(spv::Op op); static std::string OpcodeName(spv::Op op);
......
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