• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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 // ResourcesHLSL.h:
7 //   Methods for GLSL to HLSL translation for uniforms and interface blocks.
8 //
9 
10 #ifndef COMPILER_TRANSLATOR_RESOURCESHLSL_H_
11 #define COMPILER_TRANSLATOR_RESOURCESHLSL_H_
12 
13 #include "compiler/translator/OutputHLSL.h"
14 #include "compiler/translator/UtilsHLSL.h"
15 
16 namespace sh
17 {
18 class ImmutableString;
19 class StructureHLSL;
20 class TSymbolTable;
21 
22 class ResourcesHLSL : angle::NonCopyable
23 {
24   public:
25     ResourcesHLSL(StructureHLSL *structureHLSL,
26                   ShShaderOutput outputType,
27                   const std::vector<ShaderVariable> &uniforms,
28                   unsigned int firstUniformRegister);
29 
30     void reserveUniformRegisters(unsigned int registerCount);
31     void reserveUniformBlockRegisters(unsigned int registerCount);
32     void uniformsHeader(TInfoSinkBase &out,
33                         ShShaderOutput outputType,
34                         const ReferencedVariables &referencedUniforms,
35                         TSymbolTable *symbolTable);
36 
37     // Must be called after uniformsHeader
38     void samplerMetadataUniforms(TInfoSinkBase &out, unsigned int regIndex);
getSamplerCount()39     unsigned int getSamplerCount() const { return mSamplerCount; }
40     void imageMetadataUniforms(TInfoSinkBase &out, unsigned int regIndex);
41     TString uniformBlocksHeader(
42         const ReferencedInterfaceBlocks &referencedInterfaceBlocks,
43         const std::map<int, const TInterfaceBlock *> &uniformBlockOptimizedMap);
44     void allocateShaderStorageBlockRegisters(
45         const ReferencedInterfaceBlocks &referencedInterfaceBlocks);
46     TString shaderStorageBlocksHeader(const ReferencedInterfaceBlocks &referencedInterfaceBlocks);
47 
48     // Used for direct index references
49     static TString InterfaceBlockInstanceString(const ImmutableString &instanceName,
50                                                 unsigned int arrayIndex);
51 
getShaderStorageBlockRegisterMap()52     const std::map<std::string, unsigned int> &getShaderStorageBlockRegisterMap() const
53     {
54         return mShaderStorageBlockRegisterMap;
55     }
56 
getUniformBlockRegisterMap()57     const std::map<std::string, unsigned int> &getUniformBlockRegisterMap() const
58     {
59         return mUniformBlockRegisterMap;
60     }
61 
getUniformBlockUseStructuredBufferMap()62     const std::map<std::string, bool> &getUniformBlockUseStructuredBufferMap() const
63     {
64         return mUniformBlockUseStructuredBufferMap;
65     }
66 
getUniformRegisterMap()67     const std::map<std::string, unsigned int> &getUniformRegisterMap() const
68     {
69         return mUniformRegisterMap;
70     }
71 
getReadonlyImage2DRegisterIndex()72     unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; }
getImage2DRegisterIndex()73     unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; }
74 
75   private:
76     TString uniformBlockString(const TInterfaceBlock &interfaceBlock,
77                                const TVariable *instanceVariable,
78                                unsigned int registerIndex,
79                                unsigned int arrayIndex);
80     TString uniformBlockWithOneLargeArrayMemberString(const TInterfaceBlock &interfaceBlock,
81                                                       const TVariable *instanceVariable,
82                                                       unsigned int registerIndex,
83                                                       unsigned int arrayIndex);
84 
85     TString shaderStorageBlockString(const TInterfaceBlock &interfaceBlock,
86                                      const TVariable *instanceVariable,
87                                      unsigned int registerIndex,
88                                      unsigned int arrayIndex);
89     TString uniformBlockMembersString(const TInterfaceBlock &interfaceBlock,
90                                       TLayoutBlockStorage blockStorage);
91     TString uniformBlockStructString(const TInterfaceBlock &interfaceBlock);
92     const ShaderVariable *findUniformByName(const ImmutableString &name) const;
93 
94     void outputHLSL4_0_FL9_3Sampler(TInfoSinkBase &out,
95                                     const TType &type,
96                                     const TVariable &variable,
97                                     const unsigned int registerIndex);
98     void outputUniform(TInfoSinkBase &out,
99                        const TType &type,
100                        const TVariable &variable,
101                        const unsigned int registerIndex);
102     void outputAtomicCounterBuffer(TInfoSinkBase &out,
103                                    const int binding,
104                                    const unsigned int registerIndex);
105 
106     // Returns the uniform's register index
107     unsigned int assignUniformRegister(const TType &type,
108                                        const ImmutableString &name,
109                                        unsigned int *outRegisterCount);
110     unsigned int assignSamplerInStructUniformRegister(const TType &type,
111                                                       const TString &name,
112                                                       unsigned int *outRegisterCount);
113 
114     void outputHLSLSamplerUniformGroup(
115         TInfoSinkBase &out,
116         const HLSLTextureGroup textureGroup,
117         const TVector<const TVariable *> &group,
118         const TMap<const TVariable *, TString> &samplerInStructSymbolsToAPINames,
119         unsigned int *groupTextureRegisterIndex);
120 
121     void outputHLSLImageUniformIndices(TInfoSinkBase &out,
122                                        const TVector<const TVariable *> &group,
123                                        unsigned int imageArrayIndex,
124                                        unsigned int *groupRegisterCount);
125     void outputHLSLReadonlyImageUniformGroup(TInfoSinkBase &out,
126                                              const HLSLTextureGroup textureGroup,
127                                              const TVector<const TVariable *> &group,
128                                              unsigned int *groupTextureRegisterIndex);
129     void outputHLSLImageUniformGroup(TInfoSinkBase &out,
130                                      const HLSLRWTextureGroup textureGroup,
131                                      const TVector<const TVariable *> &group,
132                                      unsigned int *groupTextureRegisterIndex);
133 
134     unsigned int mUniformRegister;
135     unsigned int mUniformBlockRegister;
136     unsigned int mSRVRegister;
137     unsigned int mUAVRegister;
138     unsigned int mSamplerCount;
139     unsigned int mReadonlyImageCount;
140     unsigned int mImageCount;
141     StructureHLSL *mStructureHLSL;
142     ShShaderOutput mOutputType;
143 
144     const std::vector<ShaderVariable> &mUniforms;
145     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
146     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
147     std::map<std::string, unsigned int> mUniformRegisterMap;
148     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
149     unsigned int mReadonlyImage2DRegisterIndex;
150     unsigned int mImage2DRegisterIndex;
151 };
152 }  // namespace sh
153 
154 #endif  // COMPILER_TRANSLATOR_RESOURCESHLSL_H_
155