diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp | 434 |
1 files changed, 332 insertions, 102 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp b/src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp index 20961c44c1..9f18509438 100644 --- a/src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp +++ b/src/3rdparty/angle/src/compiler/translator/UniformHLSL.cpp @@ -4,7 +4,7 @@ // found in the LICENSE file. // // UniformHLSL.cpp: -// Methods for GLSL to HLSL translation for uniforms and interface blocks. +// Methods for GLSL to HLSL translation for uniforms and uniform blocks. // #include "compiler/translator/UniformHLSL.h" @@ -18,6 +18,9 @@ namespace sh { +namespace +{ + static const char *UniformRegisterPrefix(const TType &type) { if (IsSampler(type.getBasicType())) @@ -32,22 +35,23 @@ static const char *UniformRegisterPrefix(const TType &type) static TString InterfaceBlockFieldTypeString(const TField &field, TLayoutBlockStorage blockStorage) { - const TType &fieldType = *field.type(); + const TType &fieldType = *field.type(); const TLayoutMatrixPacking matrixPacking = fieldType.getLayoutQualifier().matrixPacking; ASSERT(matrixPacking != EmpUnspecified); - TStructure *structure = fieldType.getStruct(); + const TStructure *structure = fieldType.getStruct(); if (fieldType.isMatrix()) { // Use HLSL row-major packing for GLSL column-major matrices - const TString &matrixPackString = (matrixPacking == EmpRowMajor ? "column_major" : "row_major"); + const TString &matrixPackString = + (matrixPacking == EmpRowMajor ? "column_major" : "row_major"); return matrixPackString + " " + TypeString(fieldType); } else if (structure) { // Use HLSL row-major packing for GLSL column-major matrices return QualifiedStructNameString(*structure, matrixPacking == EmpColumnMajor, - blockStorage == EbsStd140); + blockStorage == EbsStd140); } else { @@ -60,23 +64,58 @@ static TString InterfaceBlockStructName(const TInterfaceBlock &interfaceBlock) return DecoratePrivate(interfaceBlock.name()) + "_type"; } -UniformHLSL::UniformHLSL(StructureHLSL *structureHLSL, ShShaderOutput outputType, const std::vector<Uniform> &uniforms) +void OutputSamplerIndexArrayInitializer(TInfoSinkBase &out, + const TType &type, + unsigned int startIndex) +{ + out << "{"; + TType elementType(type); + elementType.toArrayElementType(); + for (unsigned int i = 0u; i < type.getOutermostArraySize(); ++i) + { + if (i > 0u) + { + out << ", "; + } + if (elementType.isArray()) + { + OutputSamplerIndexArrayInitializer(out, elementType, + startIndex + i * elementType.getArraySizeProduct()); + } + else + { + out << (startIndex + i); + } + } + out << "}"; +} + +} // anonymous namespace + +UniformHLSL::UniformHLSL(sh::GLenum shaderType, + StructureHLSL *structureHLSL, + ShShaderOutput outputType, + const std::vector<Uniform> &uniforms) : mUniformRegister(0), - mInterfaceBlockRegister(0), - mSamplerRegister(0), + mUniformBlockRegister(0), + mTextureRegister(0), + mRWTextureRegister(0), + mSamplerCount(0), + mShaderType(shaderType), mStructureHLSL(structureHLSL), mOutputType(outputType), mUniforms(uniforms) -{} +{ +} void UniformHLSL::reserveUniformRegisters(unsigned int registerCount) { mUniformRegister = registerCount; } -void UniformHLSL::reserveInterfaceBlockRegisters(unsigned int registerCount) +void UniformHLSL::reserveUniformBlockRegisters(unsigned int registerCount) { - mInterfaceBlockRegister = registerCount; + mUniformBlockRegister = registerCount; } const Uniform *UniformHLSL::findUniformByName(const TString &name) const @@ -89,46 +128,78 @@ const Uniform *UniformHLSL::findUniformByName(const TString &name) const } } - UNREACHABLE(); - return NULL; + return nullptr; } -unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, - const TString &name, - unsigned int *registerCount) +unsigned int UniformHLSL::assignUniformRegister(const TType &type, + const TString &name, + unsigned int *outRegisterCount) { - unsigned int registerIndex = (IsSampler(type.getBasicType()) ? mSamplerRegister : mUniformRegister); - + unsigned int registerIndex; const Uniform *uniform = findUniformByName(name); ASSERT(uniform); + if (IsSampler(type.getBasicType()) || + (IsImage(type.getBasicType()) && type.getMemoryQualifier().readonly)) + { + registerIndex = mTextureRegister; + } + else if (IsImage(type.getBasicType())) + { + registerIndex = mRWTextureRegister; + } + else + { + registerIndex = mUniformRegister; + } + mUniformRegisterMap[uniform->name] = registerIndex; - ASSERT(registerCount); - *registerCount = HLSLVariableRegisterCount(*uniform, mOutputType); + unsigned int registerCount = HLSLVariableRegisterCount(*uniform, mOutputType); - if (gl::IsSamplerType(uniform->type)) + if (IsSampler(type.getBasicType()) || + (IsImage(type.getBasicType()) && type.getMemoryQualifier().readonly)) { - mSamplerRegister += *registerCount; + mTextureRegister += registerCount; + } + else if (IsImage(type.getBasicType())) + { + mRWTextureRegister += registerCount; } else { - mUniformRegister += *registerCount; + mUniformRegister += registerCount; + } + if (outRegisterCount) + { + *outRegisterCount = registerCount; } - return registerIndex; } -unsigned int UniformHLSL::declareUniformAndAssignRegister(const TType &type, const TString &name) +unsigned int UniformHLSL::assignSamplerInStructUniformRegister(const TType &type, + const TString &name, + unsigned int *outRegisterCount) { - unsigned int registerCount; - return declareUniformAndAssignRegister(type, name, ®isterCount); + // Sampler that is a field of a uniform structure. + ASSERT(IsSampler(type.getBasicType())); + unsigned int registerIndex = mTextureRegister; + mUniformRegisterMap[std::string(name.c_str())] = registerIndex; + unsigned int registerCount = type.isArray() ? type.getArraySizeProduct() : 1u; + mTextureRegister += registerCount; + if (outRegisterCount) + { + *outRegisterCount = registerCount; + } + return registerIndex; } -void UniformHLSL::outputHLSLSamplerUniformGroup(TInfoSinkBase &out, - const HLSLTextureSamplerGroup textureGroup, - const TVector<const TIntermSymbol *> &group, - unsigned int *groupTextureRegisterIndex) +void UniformHLSL::outputHLSLSamplerUniformGroup( + TInfoSinkBase &out, + const HLSLTextureGroup textureGroup, + const TVector<const TIntermSymbol *> &group, + const TMap<const TIntermSymbol *, TString> &samplerInStructSymbolsToAPINames, + unsigned int *groupTextureRegisterIndex) { if (group.empty()) { @@ -140,24 +211,33 @@ void UniformHLSL::outputHLSLSamplerUniformGroup(TInfoSinkBase &out, const TType &type = uniform->getType(); const TString &name = uniform->getSymbol(); unsigned int registerCount; - unsigned int samplerArrayIndex = - declareUniformAndAssignRegister(type, name, ®isterCount); + + // The uniform might be just a regular sampler or one extracted from a struct. + unsigned int samplerArrayIndex = 0u; + const Uniform *uniformByName = findUniformByName(name); + if (uniformByName) + { + samplerArrayIndex = assignUniformRegister(type, name, ®isterCount); + } + else + { + ASSERT(samplerInStructSymbolsToAPINames.find(uniform) != + samplerInStructSymbolsToAPINames.end()); + samplerArrayIndex = assignSamplerInStructUniformRegister( + type, samplerInStructSymbolsToAPINames.at(uniform), ®isterCount); + } groupRegisterCount += registerCount; + if (type.isArray()) { - out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type) - << " = {"; - for (int i = 0; i < type.getArraySize(); ++i) - { - if (i > 0) - out << ", "; - out << (samplerArrayIndex + i); - } - out << "};\n"; + out << "static const uint " << DecorateVariableIfNeeded(uniform->getName()) + << ArrayString(type) << " = "; + OutputSamplerIndexArrayInitializer(out, type, samplerArrayIndex); + out << ";\n"; } else { - out << "static const uint " << DecorateIfNeeded(uniform->getName()) << " = " + out << "static const uint " << DecorateVariableIfNeeded(uniform->getName()) << " = " << samplerArrayIndex << ";\n"; } } @@ -179,9 +259,88 @@ void UniformHLSL::outputHLSLSamplerUniformGroup(TInfoSinkBase &out, *groupTextureRegisterIndex += groupRegisterCount; } +void UniformHLSL::outputHLSL4_0_FL9_3Sampler(TInfoSinkBase &out, + const TType &type, + const TName &name, + const unsigned int registerIndex) +{ + out << "uniform " << SamplerString(type.getBasicType()) << " sampler_" + << DecorateVariableIfNeeded(name) << ArrayString(type) << " : register(s" + << str(registerIndex) << ");\n"; + out << "uniform " << TextureString(type.getBasicType()) << " texture_" + << DecorateVariableIfNeeded(name) << ArrayString(type) << " : register(t" + << str(registerIndex) << ");\n"; +} + +void UniformHLSL::outputHLSL4_1_FL11Texture(TInfoSinkBase &out, + const TType &type, + const TName &name, + const unsigned int registerIndex) +{ + // TODO(xinghua.cao@intel.com): if image2D variable is bound on one layer of Texture3D or + // Texture2DArray. Translate this variable to HLSL Texture3D object or HLSL Texture2DArray + // object, or create a temporary Texture2D to save content of the layer and bind the + // temporary Texture2D to image2D variable. + out << "uniform " + << TextureString(type.getBasicType(), type.getLayoutQualifier().imageInternalFormat) << " " + << DecorateVariableIfNeeded(name) << ArrayString(type) << " : register(t" + << str(registerIndex) << ");\n"; + return; +} + +void UniformHLSL::outputHLSL4_1_FL11RWTexture(TInfoSinkBase &out, + const TType &type, + const TName &name, + const unsigned int registerIndex) +{ + // TODO(xinghua.cao@intel.com): if image2D variable is bound on one layer of Texture3D or + // Texture2DArray. Translate this variable to HLSL RWTexture3D object or HLSL RWTexture2DArray + // object, or create a temporary Texture2D to save content of the layer and bind the + // temporary Texture2D to image2D variable. + if (mShaderType == GL_COMPUTE_SHADER) + { + out << "uniform " + << RWTextureString(type.getBasicType(), type.getLayoutQualifier().imageInternalFormat) + << " " << DecorateVariableIfNeeded(name) << ArrayString(type) << " : register(u" + << str(registerIndex) << ");\n"; + } + else + { + // TODO(xinghua.cao@intel.com): Support images in vertex shader and fragment shader, + // which are needed to sync binding value when linking program. + } + return; +} + +void UniformHLSL::outputUniform(TInfoSinkBase &out, + const TType &type, + const TName &name, + const unsigned int registerIndex) +{ + 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) + ")"; + + out << "uniform " << typeName << " "; + + out << DecorateVariableIfNeeded(name); + + out << ArrayString(type) << " : " << registerString << ";\n"; +} + void UniformHLSL::uniformsHeader(TInfoSinkBase &out, ShShaderOutput outputType, - const ReferencedSymbols &referencedUniforms) + const ReferencedSymbols &referencedUniforms, + TSymbolTable *symbolTable) { if (!referencedUniforms.empty()) { @@ -190,45 +349,69 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out, // In the case of HLSL 4, sampler uniforms need to be grouped by type before the code is // written. They are grouped based on the combination of the HLSL texture type and // HLSL sampler type, enumerated in HLSLTextureSamplerGroup. - TVector<TVector<const TIntermSymbol *>> groupedSamplerUniforms; - groupedSamplerUniforms.resize(HLSL_TEXTURE_MAX + 1); + TVector<TVector<const TIntermSymbol *>> groupedSamplerUniforms(HLSL_TEXTURE_MAX + 1); + TMap<const TIntermSymbol *, TString> samplerInStructSymbolsToAPINames; + TVector<const TIntermSymbol *> imageUniformsHLSL41Output; for (auto &uniformIt : referencedUniforms) { // Output regular uniforms. Group sampler uniforms by type. const TIntermSymbol &uniform = *uniformIt.second; - const TType &type = uniform.getType(); - const TString &name = uniform.getSymbol(); + const TType &type = uniform.getType(); + const TName &name = uniform.getName(); if (outputType == SH_HLSL_4_1_OUTPUT && IsSampler(type.getBasicType())) { - HLSLTextureSamplerGroup group = TextureGroup(type.getBasicType()); + HLSLTextureGroup group = TextureGroup(type.getBasicType()); groupedSamplerUniforms[group].push_back(&uniform); } else if (outputType == SH_HLSL_4_0_FL9_3_OUTPUT && IsSampler(type.getBasicType())) { - unsigned int registerIndex = declareUniformAndAssignRegister(type, name); - out << "uniform " << SamplerString(type.getBasicType()) << " sampler_" - << DecorateUniform(name, type) << ArrayString(type) << " : register(s" - << str(registerIndex) << ");\n"; - out << "uniform " << TextureString(type.getBasicType()) << " texture_" - << DecorateUniform(name, type) << ArrayString(type) << " : register(t" - << str(registerIndex) << ");\n"; + unsigned int registerIndex = assignUniformRegister(type, name.getString(), nullptr); + outputHLSL4_0_FL9_3Sampler(out, type, name, registerIndex); + } + else if (outputType == SH_HLSL_4_1_OUTPUT && IsImage(type.getBasicType())) + { + imageUniformsHLSL41Output.push_back(&uniform); } else { - unsigned int registerIndex = declareUniformAndAssignRegister(type, name); - 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) + ")"; - - out << "uniform " << typeName << " " << DecorateUniform(name, type) << ArrayString(type) - << " : " << registerString << ";\n"; + if (type.isStructureContainingSamplers()) + { + TVector<TIntermSymbol *> samplerSymbols; + TMap<TIntermSymbol *, TString> symbolsToAPINames; + type.createSamplerSymbols("angle_" + name.getString(), name.getString(), + &samplerSymbols, &symbolsToAPINames, symbolTable); + for (TIntermSymbol *sampler : samplerSymbols) + { + const TType &samplerType = sampler->getType(); + + // Will use angle_ prefix instead of regular prefix. + sampler->setInternal(true); + const TName &samplerName = sampler->getName(); + + if (outputType == SH_HLSL_4_1_OUTPUT) + { + HLSLTextureGroup group = TextureGroup(samplerType.getBasicType()); + groupedSamplerUniforms[group].push_back(sampler); + samplerInStructSymbolsToAPINames[sampler] = symbolsToAPINames[sampler]; + } + else if (outputType == SH_HLSL_4_0_FL9_3_OUTPUT) + { + unsigned int registerIndex = assignSamplerInStructUniformRegister( + samplerType, symbolsToAPINames[sampler], nullptr); + outputHLSL4_0_FL9_3Sampler(out, samplerType, samplerName, registerIndex); + } + else + { + ASSERT(outputType == SH_HLSL_3_0_OUTPUT); + unsigned int registerIndex = assignSamplerInStructUniformRegister( + samplerType, symbolsToAPINames[sampler], nullptr); + outputUniform(out, samplerType, samplerName, registerIndex); + } + } + } + unsigned int registerIndex = assignUniformRegister(type, name.getString(), nullptr); + outputUniform(out, type, name, registerIndex); } } @@ -239,70 +422,114 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out, ASSERT(HLSL_TEXTURE_MIN == HLSL_TEXTURE_2D); for (int groupId = HLSL_TEXTURE_MIN; groupId < HLSL_TEXTURE_MAX; ++groupId) { - outputHLSLSamplerUniformGroup(out, HLSLTextureSamplerGroup(groupId), - groupedSamplerUniforms[groupId], - &groupTextureRegisterIndex); + outputHLSLSamplerUniformGroup( + out, HLSLTextureGroup(groupId), groupedSamplerUniforms[groupId], + samplerInStructSymbolsToAPINames, &groupTextureRegisterIndex); + } + mSamplerCount = groupTextureRegisterIndex; + + for (const TIntermSymbol *image : imageUniformsHLSL41Output) + { + const TType &type = image->getType(); + const TName &name = image->getName(); + unsigned int registerIndex = assignUniformRegister(type, name.getString(), nullptr); + if (type.getMemoryQualifier().readonly) + { + outputHLSL4_1_FL11Texture(out, type, name, registerIndex); + } + else + { + outputHLSL4_1_FL11RWTexture(out, type, name, registerIndex); + } } } } -TString UniformHLSL::interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks) +void UniformHLSL::samplerMetadataUniforms(TInfoSinkBase &out, const char *reg) +{ + // If mSamplerCount is 0 the shader doesn't use any textures for samplers. + if (mSamplerCount > 0) + { + out << " struct SamplerMetadata\n" + " {\n" + " int baseLevel;\n" + " int internalFormatBits;\n" + " int wrapModes;\n" + " int padding;\n" + " };\n" + " SamplerMetadata samplerMetadata[" + << mSamplerCount << "] : packoffset(" << reg << ");\n"; + } +} + +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 TType &nodeType = interfaceBlockIt->second->getType(); const TInterfaceBlock &interfaceBlock = *nodeType.getInterfaceBlock(); - unsigned int arraySize = static_cast<unsigned int>(interfaceBlock.arraySize()); - unsigned int activeRegister = mInterfaceBlockRegister; + // 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; - mInterfaceBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister; - mInterfaceBlockRegister += std::max(1u, arraySize); + mUniformBlockRegisterMap[interfaceBlock.name().c_str()] = activeRegister; + mUniformBlockRegister += std::max(1u, interfaceBlockArraySize); // FIXME: interface block field names if (interfaceBlock.hasInstanceName()) { - interfaceBlocks += interfaceBlockStructString(interfaceBlock); + interfaceBlocks += uniformBlockStructString(interfaceBlock); } - if (arraySize > 0) + if (interfaceBlockArraySize > 0) { - for (unsigned int arrayIndex = 0; arrayIndex < arraySize; arrayIndex++) + for (unsigned int arrayIndex = 0; arrayIndex < interfaceBlockArraySize; arrayIndex++) { - interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex); + interfaceBlocks += + uniformBlockString(interfaceBlock, activeRegister + arrayIndex, arrayIndex); } } else { - interfaceBlocks += interfaceBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX); + interfaceBlocks += uniformBlockString(interfaceBlock, activeRegister, GL_INVALID_INDEX); } } - return (interfaceBlocks.empty() ? "" : ("// Interface Blocks\n\n" + interfaceBlocks)); + return (interfaceBlocks.empty() ? "" : ("// Uniform Blocks\n\n" + interfaceBlocks)); } -TString UniformHLSL::interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex) +TString UniformHLSL::uniformBlockString(const TInterfaceBlock &interfaceBlock, + unsigned int registerIndex, + unsigned int arrayIndex) { - const TString &arrayIndexString = (arrayIndex != GL_INVALID_INDEX ? Decorate(str(arrayIndex)) : ""); + const TString &arrayIndexString = + (arrayIndex != GL_INVALID_INDEX ? Decorate(str(arrayIndex)) : ""); const TString &blockName = interfaceBlock.name() + arrayIndexString; TString hlsl; - hlsl += "cbuffer " + blockName + " : register(b" + str(registerIndex) + ")\n" + hlsl += "cbuffer " + blockName + " : register(b" + str(registerIndex) + + ")\n" "{\n"; if (interfaceBlock.hasInstanceName()) { hlsl += " " + InterfaceBlockStructName(interfaceBlock) + " " + - interfaceBlockInstanceString(interfaceBlock, arrayIndex) + ";\n"; + uniformBlockInstanceString(interfaceBlock, arrayIndex) + ";\n"; } else { const TLayoutBlockStorage blockStorage = interfaceBlock.blockStorage(); - hlsl += interfaceBlockMembersString(interfaceBlock, blockStorage); + hlsl += uniformBlockMembersString(interfaceBlock, blockStorage); } hlsl += "};\n\n"; @@ -310,13 +537,14 @@ TString UniformHLSL::interfaceBlockString(const TInterfaceBlock &interfaceBlock, return hlsl; } -TString UniformHLSL::interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex) +TString UniformHLSL::uniformBlockInstanceString(const TInterfaceBlock &interfaceBlock, + unsigned int arrayIndex) { if (!interfaceBlock.hasInstanceName()) { return ""; } - else if (interfaceBlock.isArray()) + else if (arrayIndex != GL_INVALID_INDEX) { return DecoratePrivate(interfaceBlock.instanceName()) + "_" + str(arrayIndex); } @@ -326,7 +554,8 @@ TString UniformHLSL::interfaceBlockInstanceString(const TInterfaceBlock& interfa } } -TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfaceBlock, TLayoutBlockStorage blockStorage) +TString UniformHLSL::uniformBlockMembersString(const TInterfaceBlock &interfaceBlock, + TLayoutBlockStorage blockStorage) { TString hlsl; @@ -334,7 +563,7 @@ TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfac for (unsigned int typeIndex = 0; typeIndex < interfaceBlock.fields().size(); typeIndex++) { - const TField &field = *interfaceBlock.fields()[typeIndex]; + const TField &field = *interfaceBlock.fields()[typeIndex]; const TType &fieldType = *field.type(); if (blockStorage == EbsStd140) @@ -343,13 +572,15 @@ TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfac hlsl += padHelper.prePaddingString(fieldType); } - hlsl += " " + InterfaceBlockFieldTypeString(field, blockStorage) + - " " + Decorate(field.name()) + ArrayString(fieldType) + ";\n"; + hlsl += " " + InterfaceBlockFieldTypeString(field, blockStorage) + " " + + Decorate(field.name()) + ArrayString(fieldType) + ";\n"; - // must pad out after matrices and arrays, where HLSL usually allows itself room to pack stuff + // must pad out after matrices and arrays, where HLSL usually allows itself room to pack + // stuff if (blockStorage == EbsStd140) { - const bool useHLSLRowMajorPacking = (fieldType.getLayoutQualifier().matrixPacking == EmpColumnMajor); + const bool useHLSLRowMajorPacking = + (fieldType.getLayoutQualifier().matrixPacking == EmpColumnMajor); hlsl += padHelper.postPaddingString(fieldType, useHLSLRowMajorPacking); } } @@ -357,14 +588,13 @@ TString UniformHLSL::interfaceBlockMembersString(const TInterfaceBlock &interfac return hlsl; } -TString UniformHLSL::interfaceBlockStructString(const TInterfaceBlock &interfaceBlock) +TString UniformHLSL::uniformBlockStructString(const TInterfaceBlock &interfaceBlock) { const TLayoutBlockStorage blockStorage = interfaceBlock.blockStorage(); - return "struct " + InterfaceBlockStructName(interfaceBlock) + "\n" + return "struct " + InterfaceBlockStructName(interfaceBlock) + + "\n" "{\n" + - interfaceBlockMembersString(interfaceBlock, blockStorage) + - "};\n\n"; + uniformBlockMembersString(interfaceBlock, blockStorage) + "};\n\n"; } - } |