1 // 2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // UniformHLSL.h: 7 // Methods for GLSL to HLSL translation for uniforms and interface blocks. 8 // 9 10 #ifndef TRANSLATOR_UNIFORMHLSL_H_ 11 #define TRANSLATOR_UNIFORMHLSL_H_ 12 13 #include "compiler/translator/Types.h" 14 15 namespace sh 16 { 17 class StructureHLSL; 18 19 class UniformHLSL 20 { 21 public: 22 UniformHLSL(StructureHLSL *structureHLSL, TranslatorHLSL *translator); 23 24 void reserveUniformRegisters(unsigned int registerCount); 25 void reserveInterfaceBlockRegisters(unsigned int registerCount); 26 TString uniformsHeader(ShShaderOutput outputType, const ReferencedSymbols &referencedUniforms); 27 TString interfaceBlocksHeader(const ReferencedSymbols &referencedInterfaceBlocks); 28 29 // Used for direct index references 30 static TString interfaceBlockInstanceString(const TInterfaceBlock& interfaceBlock, unsigned int arrayIndex); 31 32 const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const 33 { 34 return mInterfaceBlockRegisterMap; 35 } 36 const std::map<std::string, unsigned int> &getUniformRegisterMap() const 37 { 38 return mUniformRegisterMap; 39 } 40 41 private: 42 TString interfaceBlockString(const TInterfaceBlock &interfaceBlock, unsigned int registerIndex, unsigned int arrayIndex); 43 TString interfaceBlockMembersString(const TInterfaceBlock &interfaceBlock, TLayoutBlockStorage blockStorage); 44 TString interfaceBlockStructString(const TInterfaceBlock &interfaceBlock); 45 const Uniform *findUniformByName(const TString &name) const; 46 47 // Returns the uniform's register index 48 unsigned int declareUniformAndAssignRegister(const TType &type, const TString &name); 49 50 unsigned int mUniformRegister; 51 unsigned int mInterfaceBlockRegister; 52 unsigned int mSamplerRegister; 53 StructureHLSL *mStructureHLSL; 54 ShShaderOutput mOutputType; 55 56 const std::vector<Uniform> &mUniforms; 57 std::map<std::string, unsigned int> mInterfaceBlockRegisterMap; 58 std::map<std::string, unsigned int> mUniformRegisterMap; 59 }; 60 61 } 62 63 #endif // TRANSLATOR_UNIFORMHLSL_H_ 64