Remove sh::Uniform::registerIndex and elementIndex.
With the previous cleanups, these fields aren't needed any longer.
We can also clean up some unused methods and simplify existing code.
BUG=angle:466
Change-Id: I96df8d152324bda5e6868b5eccdf52bdc09155e9
Reviewed-on: https://chromium-review.googlesource.com/207256
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/common/blocklayout.cpp b/src/common/blocklayout.cpp
index 0bdfa1e..d48894c 100644
--- a/src/common/blocklayout.cpp
+++ b/src/common/blocklayout.cpp
@@ -288,52 +288,6 @@
}
}
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable, HLSLBlockEncoder *encoder,
- const std::vector<BlockMemberInfo> &blockInfo, ShShaderOutput outputType)
-{
- // because this method computes offsets (element indexes) instead of any total sizes,
- // we can ignore the array size of the variable
-
- if (variable->isStruct())
- {
- encoder->enterAggregateType();
-
- variable->registerIndex = baseRegisterIndex;
-
- for (size_t fieldIndex = 0; fieldIndex < variable->fields.size(); fieldIndex++)
- {
- HLSLVariableGetRegisterInfo(baseRegisterIndex, &variable->fields[fieldIndex], encoder, blockInfo, outputType);
- }
-
- // Since the above loop only encodes one element of an array, ensure we don't lose track of the
- // current register offset
- if (variable->isArray())
- {
- unsigned int structRegisterCount = (HLSLVariableRegisterCount(*variable, outputType) / variable->arraySize);
- encoder->skipRegisters(structRegisterCount * (variable->arraySize - 1));
- }
-
- encoder->exitAggregateType();
- }
- else
- {
- encoder->encodeType(variable->type, variable->arraySize, false);
-
- const size_t registerBytes = (encoder->BytesPerComponent * encoder->ComponentsPerRegister);
- variable->registerIndex = baseRegisterIndex + (blockInfo.back().offset / registerBytes);
- variable->elementIndex = (blockInfo.back().offset % registerBytes) / sizeof(float);
- }
-}
-
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable, ShShaderOutput outputType)
-{
- std::vector<BlockMemberInfo> blockInfo;
- HLSLBlockEncoder encoder(&blockInfo,
- outputType == SH_HLSL9_OUTPUT ? HLSLBlockEncoder::ENCODE_LOOSE
- : HLSLBlockEncoder::ENCODE_PACKED);
- HLSLVariableGetRegisterInfo(baseRegisterIndex, variable, &encoder, blockInfo, outputType);
-}
-
template <class ShaderVarType>
void HLSLVariableRegisterCount(const ShaderVarType &variable, HLSLBlockEncoder *encoder)
{
diff --git a/src/common/blocklayout.h b/src/common/blocklayout.h
index 2df6db9..5dae343 100644
--- a/src/common/blocklayout.h
+++ b/src/common/blocklayout.h
@@ -104,10 +104,6 @@
// This method returns the data size of an interface block in HLSL, according to its layout.
size_t HLSLInterfaceBlockDataSize(const sh::InterfaceBlock &interfaceBlock);
-// This method assigns values to the variable's "registerIndex" and "elementIndex" fields.
-// "elementIndex" is only used for structures.
-void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, Uniform *variable, ShShaderOutput outputType);
-
// This method returns the number of used registers for a ShaderVariable. It is dependent on the HLSLBlockEncoder
// class to count the number of used registers in a struct (which are individually packed according to the same rules).
unsigned int HLSLVariableRegisterCount(const Varying &variable);
diff --git a/src/common/shadervars.h b/src/common/shadervars.h
index 2c51135..635f66d 100644
--- a/src/common/shadervars.h
+++ b/src/common/shadervars.h
@@ -63,28 +63,18 @@
bool staticUse;
};
-// Uniform registers (and element indices) are assigned when outputting shader code
struct Uniform : public ShaderVariable
{
Uniform()
- : registerIndex(-1),
- elementIndex(-1)
{}
- Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn,
- unsigned int registerIndexIn, unsigned int elementIndexIn)
- : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn),
- registerIndex(registerIndexIn),
- elementIndex(elementIndexIn)
+ Uniform(GLenum typeIn, GLenum precisionIn, const char *nameIn, unsigned int arraySizeIn)
+ : ShaderVariable(typeIn, precisionIn, nameIn, arraySizeIn)
{}
bool isStruct() const { return !fields.empty(); }
std::vector<Uniform> fields;
-
- // HLSL-specific members
- unsigned int registerIndex;
- unsigned int elementIndex; // Offset within a register, for struct members
};
struct Attribute : public ShaderVariable
diff --git a/src/compiler/translator/UniformHLSL.cpp b/src/compiler/translator/UniformHLSL.cpp
index 7d09c96..ecc8516 100644
--- a/src/compiler/translator/UniformHLSL.cpp
+++ b/src/compiler/translator/UniformHLSL.cpp
@@ -123,12 +123,13 @@
{
unsigned int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister);
- declareUniformToList(type, name, registerIndex, &mActiveUniforms);
+ GetVariableTraverser<Uniform> traverser(&mActiveUniforms);
+ traverser.traverse(type, name);
const sh::Uniform &activeUniform = mActiveUniforms.back();
- unsigned int registerCount = HLSLVariableRegisterCount(activeUniform, mOutputType);
mUniformRegisterMap[activeUniform.name] = registerIndex;
+ unsigned int registerCount = HLSLVariableRegisterCount(activeUniform, mOutputType);
if (IsSampler(type.getBasicType()))
{
mSamplerRegister += registerCount;
@@ -141,43 +142,6 @@
return registerIndex;
}
-class DeclareUniformsTraverser : public GetVariableTraverser<Uniform>
-{
- public:
- DeclareUniformsTraverser(std::vector<Uniform> *output,
- unsigned int registerIndex,
- ShShaderOutput outputType)
- : GetVariableTraverser(output),
- mRegisterIndex(registerIndex),
- mOutputType(outputType)
- {}
-
- private:
- virtual void visitVariable(Uniform *uniform)
- {
- if (!uniform->isStruct())
- {
- uniform->registerIndex = mRegisterIndex;
- uniform->elementIndex = 0;
- }
- else
- {
- // Assign register offset information.
- // This will override the offsets in any nested structures.
- HLSLVariableGetRegisterInfo(mRegisterIndex, uniform, mOutputType);
- }
- }
-
- unsigned int mRegisterIndex;
- ShShaderOutput mOutputType;
-};
-
-void UniformHLSL::declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<Uniform> *output)
-{
- DeclareUniformsTraverser traverser(output, registerIndex, mOutputType);
- traverser.traverse(type, name);
-}
-
TString UniformHLSL::uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms)
{
TString uniforms;
diff --git a/src/compiler/translator/UniformHLSL.h b/src/compiler/translator/UniformHLSL.h
index d21a599..835b1ef 100644
--- a/src/compiler/translator/UniformHLSL.h
+++ b/src/compiler/translator/UniformHLSL.h
@@ -48,7 +48,6 @@
// Returns the uniform's register index
unsigned int declareUniformAndAssignRegister(const TType &type, const TString &name);
- void declareUniformToList(const TType &type, const TString &name, int registerIndex, std::vector<Uniform> *output);
unsigned int mUniformRegister;
unsigned int mInterfaceBlockRegister;
diff --git a/src/compiler/translator/util.h b/src/compiler/translator/util.h
index b9f02f8..5c214dd 100644
--- a/src/compiler/translator/util.h
+++ b/src/compiler/translator/util.h
@@ -39,13 +39,12 @@
class GetVariableTraverser
{
public:
+ GetVariableTraverser(std::vector<VarT> *output);
void traverse(const TType &type, const TString &name);
protected:
- GetVariableTraverser(std::vector<VarT> *output);
-
- // Must be overloaded
- virtual void visitVariable(VarT *newVar) = 0;
+ // May be overloaded
+ virtual void visitVariable(VarT *newVar) {}
private:
std::stack<std::vector<VarT> *> mOutputStack;