1 //
2 // Copyright 2002 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 
7 #ifndef COMPILER_TRANSLATOR_TRANSLATORHLSL_H_
8 #define COMPILER_TRANSLATOR_TRANSLATORHLSL_H_
9 
10 #include "compiler/translator/Compiler.h"
11 
12 namespace sh
13 {
14 
15 class TranslatorHLSL : public TCompiler
16 {
17   public:
18     TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
getAsTranslatorHLSL()19     TranslatorHLSL *getAsTranslatorHLSL() override { return this; }
20 
21     bool hasShaderStorageBlock(const std::string &interfaceBlockName) const;
22     unsigned int getShaderStorageBlockRegister(const std::string &interfaceBlockName) const;
23 
24     bool hasUniformBlock(const std::string &interfaceBlockName) const;
25     unsigned int getUniformBlockRegister(const std::string &interfaceBlockName) const;
26     bool shouldUniformBlockUseStructuredBuffer(const std::string &uniformBlockName) const;
27     const std::set<std::string> *getSlowCompilingUniformBlockSet() const;
28 
29     const std::map<std::string, unsigned int> *getUniformRegisterMap() const;
30     unsigned int getReadonlyImage2DRegisterIndex() const;
31     unsigned int getImage2DRegisterIndex() const;
32     const std::set<std::string> *getUsedImage2DFunctionNames() const;
33 
34   protected:
35     ANGLE_NO_DISCARD bool translate(TIntermBlock *root,
36                                     ShCompileOptions compileOptions,
37                                     PerformanceDiagnostics *perfDiagnostics) override;
38     bool shouldFlattenPragmaStdglInvariantAll() override;
39 
40     // collectVariables needs to be run always so registers can be assigned.
shouldCollectVariables(ShCompileOptions compileOptions)41     bool shouldCollectVariables(ShCompileOptions compileOptions) override { return true; }
42 
43     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
44     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
45     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
46     std::map<std::string, unsigned int> mUniformRegisterMap;
47     unsigned int mReadonlyImage2DRegisterIndex;
48     unsigned int mImage2DRegisterIndex;
49     std::set<std::string> mUsedImage2DFunctionNames;
50     std::map<int, const TInterfaceBlock *> mUniformBlockOptimizedMap;
51     std::set<std::string> mSlowCompilingUniformBlockSet;
52 };
53 
54 }  // namespace sh
55 
56 #endif  // COMPILER_TRANSLATOR_TRANSLATORHLSL_H_
57