TString UniformHLSL::uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms) { TString uniforms; for (ReferencedSymbols::const_iterator uniformIt = referencedUniforms.begin(); uniformIt != referencedUniforms.end(); uniformIt++) { const TIntermSymbol &uniform = *uniformIt->second; const TType &type = uniform.getType(); const TString &name = uniform.getSymbol(); int registerIndex = declareUniformAndAssignRegister(type, name); if (outputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) // Also declare the texture { uniforms += "uniform " + SamplerString(type) + " sampler_" + DecorateUniform(name, type) + ArrayString(type) + " : register(s" + str(registerIndex) + ");\n"; uniforms += "uniform " + TextureString(type) + " texture_" + DecorateUniform(name, type) + ArrayString(type) + " : register(t" + str(registerIndex) + ");\n"; } else { const TStructure *structure = type.getStruct(); const TString &typeName = (structure ? QualifiedStructNameString(*structure, false, false) : TypeString(type)); const TString ®isterString = TString("register(") + UniformRegisterPrefix(type) + str(registerIndex) + ")"; uniforms += "uniform " + typeName + " " + DecorateUniform(name, type) + ArrayString(type) + " : " + registerString + ";\n"; } } return (uniforms.empty() ? "" : ("// Uniforms\n\n" + uniforms)); }
TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks) { TString interfaceBlocks; for (ReferencedSymbols::const_iterator interfaceBlockIt = referencedInterfaceBlocks.begin(); interfaceBlockIt != referencedInterfaceBlocks.end(); interfaceBlockIt++) { const TType &nodeType = interfaceBlockIt->second->getType(); const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock(); const TFieldList &fieldList = interfaceBlock.fields(); unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize()); InterfaceBlock activeBlock(interfaceBlock.name().c_str(), arraySize, mInterfaceBlockRegister); for (unsigned int typeIndex = 0; typeIndex < fieldList.size(); typeIndex++) { const TField &field = *fieldList[typeIndex]; const TString &fullFieldName = InterfaceBlockFieldName(interfaceBlock, field); bool isRowMajor = (field.type()->getLayoutQualifier().matrixPacking == EmpRowMajor); GetInterfaceBlockFieldTraverser traverser(&activeBlock.fields, isRowMajor); traverser.traverse(*field.type(), fullFieldName); } mInterfaceBlockRegisterMap[activeBlock.name] = mInterfaceBlockRegister; mInterfaceBlockRegister += std::max(1u, arraySize); BlockLayoutType blockLayoutType = GetBlockLayoutType(interfaceBlock.blockStorage()); SetBlockLayout(&activeBlock, blockLayoutType); if (interfaceBlock.matrixPacking() == EmpRowMajor) { activeBlock.isRowMajorLayout = true; } mActiveInterfaceBlocks.push_back(activeBlock); if (interfaceBlock.hasInstanceName()) { interfaceBlocks += interfaceBlockStructString(interfaceBlock); } if (arraySize > 0) { for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex + arrayIndex, arrayIndex); } } else { interfaceBlocks += interfaceBlockString(interfaceBlock, activeBlock.registerIndex, GL_INVALID_INDEX); } } return (interfaceBlocks.empty() ? "" : ("// Interface Blocks\n\n" + interfaceBlocks)); }
TString UniformHLSL::uniformBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks) { TString interfaceBlocks; for (ReferencedSymbols::const_iterator interfaceBlockIt = referencedInterfaceBlocks.begin(); interfaceBlockIt != referencedInterfaceBlocks.end(); interfaceBlockIt++) { const TType &nodeType = interfaceBlockIt->second->getType(); const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock(); // nodeType.isInterfaceBlock() == false means the node is a field of a uniform block which // doesn't have instance name, so this block cannot be an array. unsigned int interfaceBlockArraySize = 0u; if (nodeType.isInterfaceBlock() && nodeType.isArray()) { interfaceBlockArraySize = nodeType.getOutermostArraySize(); } unsigned int activeRegister = mUniformBlockRegister; mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister; mUniformBlockRegister += std::max(1u, interfaceBlockArraySize); // FIXME: interface block field names if (interfaceBlock.hasInstanceName()) { interfaceBlocks += uniformBlockStructString(interfaceBlock); } if (interfaceBlockArraySize > 0) { for (unsigned int arrayIndex = 0; arrayIndex < interfaceBlockArraySize; arrayIndex++) { interfaceBlocks += uniformBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex); } } else { interfaceBlocks += uniformBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX); } } return (interfaceBlocks.empty() ? "" : ("// Uniform Blocks\n\n" + interfaceBlocks)); }
TString UniformHLSL::uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms) { TString uniforms; for (ReferencedSymbols::const_iterator uniformIt = referencedUniforms.begin(); uniformIt != referencedUniforms.end(); uniformIt++) { const TIntermSymbol &uniform = *uniformIt->second; const TType &type = uniform.getType(); const TString &name = uniform.getSymbol(); unsigned int registerIndex = declareUniformAndAssignRegister(type, name); if (outputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) // Also declare the texture { uniforms += "uniform " + SamplerString(type) + " sampler_" + DecorateUniform(name, type) + ArrayString(type) + " : register(s" + str(registerIndex) + ");\n"; uniforms += "uniform " + TextureString(type) + " texture_" + DecorateUniform(name, type) + ArrayString(type) + " : register(t" + str(registerIndex) + ");\n"; } else { const TStructure *structure = type.getStruct(); // If this is a nameless struct, we need to use its full definition, rather than its (empty) name. // TypeString() will invoke defineNameless in this case; qualifier prefixes are unnecessary for // nameless structs in ES, as nameless structs cannot be used anywhere that layout qualifiers are // permitted. const TString &typeName = ((structure && !structure->name().empty()) ? QualifiedStructNameString(*structure, false, false) : TypeString(type)); const TString ®isterString = TString("register(") + UniformRegisterPrefix(type) + str(registerIndex) + ")"; uniforms += "uniform " + typeName + " " + DecorateUniform(name, type) + ArrayString(type) + " : " + registerString + ";\n"; } } return (uniforms.empty() ? "" : ("// Uniforms\n\n" + uniforms)); }
TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks) { TString interfaceBlocks; for (ReferencedSymbols::const_iterator interfaceBlockIt = referencedInterfaceBlocks.begin(); interfaceBlockIt != referencedInterfaceBlocks.end(); interfaceBlockIt++) { const TType &nodeType = interfaceBlockIt->second->getType(); const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock(); unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize()); unsigned int activeRegister = mInterfaceBlockRegister; mInterfaceBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister; mInterfaceBlockRegister += std::max(1u, arraySize); // FIXME: interface block field names if (interfaceBlock.hasInstanceName()) { interfaceBlocks += interfaceBlockStructString(interfaceBlock); } if (arraySize > 0) { for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) { interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex); } } else { interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX); } } return (interfaceBlocks.empty() ? "" : ("// Interface Blocks\n\n" + interfaceBlocks)); }