Commit 28f70c3a by Jamie Madill

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/207256Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org>
parent bf9cce2e
......@@ -288,52 +288,6 @@ size_t HLSLInterfaceBlockDataSize(const sh::InterfaceBlock &interfaceBlock)
}
}
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)
{
......
......@@ -104,10 +104,6 @@ class HLSLBlockEncoder : public BlockLayoutEncoder
// 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);
......
......@@ -63,28 +63,18 @@ struct ShaderVariable
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
......
......@@ -123,12 +123,13 @@ unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, con
{
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 @@ unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, con
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;
......
......@@ -48,7 +48,6 @@ class UniformHLSL
// 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;
......
......@@ -39,13 +39,12 @@ template <typename VarT>
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;
......
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