Add utility function to count input components
This cl adds a new utility function to count
the number of components used by an input.
Bug: b/171415086
Change-Id: I348959ccd8945d2f336384cf7d905d3140231e4e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51736
Commit-Queue: Alexis Hétu <sugoi@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 41beb88..d7a3069 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -899,6 +899,25 @@
}
}
+uint32_t SpirvShader::GetNumInputComponents(int32_t location) const
+{
+ ASSERT(location >= 0);
+
+ // Verify how many component(s) per input
+ // 1 to 4, for float, vec2, vec3, vec4.
+ // Note that matrices are divided over multiple inputs
+ uint32_t num_components_per_input = 0;
+ for(; num_components_per_input < 4; ++num_components_per_input)
+ {
+ if(inputs[(location << 2) | num_components_per_input].Type == ATTRIBTYPE_UNUSED)
+ {
+ break;
+ }
+ }
+
+ return num_components_per_input;
+}
+
void SpirvShader::ProcessExecutionMode(InsnIterator insn)
{
Function::ID function = insn.word(1);
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 93a01f4..84db5fd 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -1229,6 +1229,8 @@
void EvalSpecConstantUnaryOp(InsnIterator insn);
void EvalSpecConstantBinaryOp(InsnIterator insn);
+ uint32_t GetNumInputComponents(int32_t location) const;
+
// Helper for implementing OpStore, which doesn't take an InsnIterator so it
// can also store independent operands.
void Store(Object::ID pointerId, const Operand &value, bool atomic, std::memory_order memoryOrder, EmitState *state) const;