unsigned int UniformHLSL::assignUniformRegister(const TType &type, const TString &name, unsigned int *outRegisterCount) { unsigned int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister); const Uniform *uniform = findUniformByName(name); ASSERT(uniform); mUniformRegisterMap[uniform->name] = registerIndex; unsigned int registerCount = HLSLVariableRegisterCount(*uniform, mOutputType); if (gl::IsSamplerType(uniform->type)) { mSamplerRegister += registerCount; } else { mUniformRegister += registerCount; } if (outRegisterCount) { *outRegisterCount = registerCount; } return registerIndex; }
unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType) { HLSLBlockEncoder encoder(HLSLBlockEncoder::GetStrategyFor(outputType)); HLSLVariableRegisterCount(variable, &encoder); const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister); return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes); }
unsigned int HLSLVariableRegisterCount(const Varying &variable) { HLSLBlockEncoder encoder(NULL, HLSLBlockEncoder::ENCODE_PACKED); HLSLVariableRegisterCount(variable, &encoder); const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister); return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes); }
unsigned int HLSLVariableRegisterCount(const Uniform &variable, ShShaderOutput outputType) { HLSLBlockEncoder encoder(NULL, outputType == SH_HLSL9_OUTPUT ? HLSLBlockEncoder::ENCODE_LOOSE : HLSLBlockEncoder::ENCODE_PACKED); HLSLVariableRegisterCount(variable, &encoder); const size_t registerBytes = (encoder.BytesPerComponent * encoder.ComponentsPerRegister); return static_cast<unsigned int>(rx::roundUp<size_t>(encoder.getBlockSize(), registerBytes) / registerBytes); }
int UniformHLSL::declareUniformAndAssignRegister(const TType &type, const TString &name) { int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister); declareUniformToList(type, name, registerIndex, &mActiveUniforms); unsigned int registerCount = HLSLVariableRegisterCount(mActiveUniforms.back(), mOutputType); if (IsSampler(type.getBasicType())) { mSamplerRegister += registerCount; } else { mUniformRegister += registerCount; } return registerIndex; }
void HLSLVariableRegisterCount(const ShaderVarType &variable, HLSLBlockEncoder *encoder) { if (variable.isStruct()) { for (size_t arrayElement = 0; arrayElement < variable.elementCount(); arrayElement++) { encoder->enterAggregateType(); for (size_t fieldIndex = 0; fieldIndex < variable.fields.size(); fieldIndex++) { HLSLVariableRegisterCount(variable.fields[fieldIndex], encoder); } encoder->exitAggregateType(); } } else { // We operate only on varyings and uniforms, which do not have matrix layout qualifiers encoder->encodeType(variable.type, variable.arraySize, false); } }
void HLSLVariableGetRegisterInfo(unsigned int baseRegisterIndex, gl::Uniform *variable, HLSLBlockEncoder *encoder, const std::vector<gl::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); } }