Consolidate the register counting functions to a single location in the HLSL layout encoder source.
This new method explicitly depends on HLSL packing rules, instead of a GL idiom.
TRAC #23748
Signed-off-by: Geoff Lang
Signed-off-by: Nicolas Capens
diff --git a/src/compiler/HLSLLayoutEncoder.cpp b/src/compiler/HLSLLayoutEncoder.cpp
index d93ceea..97124ba 100644
--- a/src/compiler/HLSLLayoutEncoder.cpp
+++ b/src/compiler/HLSLLayoutEncoder.cpp
@@ -84,4 +84,32 @@
}
}
+template <class ShaderVarType>
+unsigned int HLSLRegisterCount(const ShaderVarType &variable)
+{
+ if (variable.isStruct())
+ {
+ unsigned int totalCount = 0;
+ for (size_t fieldIndex = 0; fieldIndex < variable.fields.size(); fieldIndex++)
+ {
+ totalCount += HLSLVariableRegisterCount(variable.fields[fieldIndex]);
+ }
+ return totalCount * variable.elementCount();
+ }
+ else
+ {
+ return gl::VariableRowCount(variable.type) * variable.elementCount();
+ }
+}
+
+unsigned int HLSLVariableRegisterCount(const Varying &variable)
+{
+ return HLSLRegisterCount(variable);
+}
+
+unsigned int HLSLVariableRegisterCount(const Uniform &variable)
+{
+ return HLSLRegisterCount(variable);
+}
+
}