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 
7 // ShaderD3D.h: Defines the rx::ShaderD3D class which implements rx::ShaderImpl.
8 
9 #ifndef LIBANGLE_RENDERER_D3D_SHADERD3D_H_
10 #define LIBANGLE_RENDERER_D3D_SHADERD3D_H_
11 
12 #include "libANGLE/renderer/ShaderImpl.h"
13 
14 #include <map>
15 
16 namespace angle
17 {
18 struct CompilerWorkaroundsD3D;
19 struct FeaturesD3D;
20 }  // namespace angle
21 
22 namespace gl
23 {
24 struct Extensions;
25 }
26 
27 namespace rx
28 {
29 class DynamicHLSL;
30 class RendererD3D;
31 struct D3DUniform;
32 
33 class ShaderD3D : public ShaderImpl
34 {
35   public:
36     ShaderD3D(const gl::ShaderState &state,
37               const angle::FeaturesD3D &features,
38               const gl::Extensions &extensions);
39     ~ShaderD3D() override;
40 
41     std::shared_ptr<WaitableCompileEvent> compile(const gl::Context *context,
42                                                   gl::ShCompilerInstance *compilerInstance,
43                                                   ShCompileOptions options) override;
44 
45     std::string getDebugInfo() const override;
46 
47     // D3D-specific methods
48     void uncompile();
49 
50     bool hasUniform(const std::string &name) const;
51 
52     // Query regular uniforms with their name. Query sampler fields of structs with field selection
53     // using dot (.) operator.
54     unsigned int getUniformRegister(const std::string &uniformName) const;
55 
56     unsigned int getUniformBlockRegister(const std::string &blockName) const;
57     bool shouldUniformBlockUseStructuredBuffer(const std::string &blockName) const;
58     unsigned int getShaderStorageBlockRegister(const std::string &blockName) const;
getReadonlyImage2DRegisterIndex()59     unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; }
getImage2DRegisterIndex()60     unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; }
61     bool useImage2DFunction(const std::string &functionName) const;
62     const std::set<std::string> &getSlowCompilingUniformBlockSet() const;
appendDebugInfo(const std::string & info)63     void appendDebugInfo(const std::string &info) const { mDebugInfo += info; }
64 
65     void generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds) const;
66 
usesMultipleRenderTargets()67     bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; }
usesFragColor()68     bool usesFragColor() const { return mUsesFragColor; }
usesFragData()69     bool usesFragData() const { return mUsesFragData; }
usesSecondaryColor()70     bool usesSecondaryColor() const { return mUsesSecondaryColor; }
usesFragCoord()71     bool usesFragCoord() const { return mUsesFragCoord; }
usesFrontFacing()72     bool usesFrontFacing() const { return mUsesFrontFacing; }
usesHelperInvocation()73     bool usesHelperInvocation() const { return mUsesHelperInvocation; }
usesPointSize()74     bool usesPointSize() const { return mUsesPointSize; }
usesPointCoord()75     bool usesPointCoord() const { return mUsesPointCoord; }
usesDepthRange()76     bool usesDepthRange() const { return mUsesDepthRange; }
usesFragDepth()77     bool usesFragDepth() const { return mUsesFragDepth; }
usesVertexID()78     bool usesVertexID() const { return mUsesVertexID; }
usesViewID()79     bool usesViewID() const { return mUsesViewID; }
hasANGLEMultiviewEnabled()80     bool hasANGLEMultiviewEnabled() const { return mHasANGLEMultiviewEnabled; }
81 
82     ShShaderOutput getCompilerOutputType() const;
83 
84   private:
85     bool mUsesMultipleRenderTargets;
86     bool mUsesFragColor;
87     bool mUsesFragData;
88     bool mUsesSecondaryColor;
89     bool mUsesFragCoord;
90     bool mUsesFrontFacing;
91     bool mUsesHelperInvocation;
92     bool mUsesPointSize;
93     bool mUsesPointCoord;
94     bool mUsesDepthRange;
95     bool mUsesFragDepth;
96     bool mHasANGLEMultiviewEnabled;
97     bool mUsesVertexID;
98     bool mUsesViewID;
99     bool mUsesDiscardRewriting;
100     bool mUsesNestedBreak;
101     bool mRequiresIEEEStrictCompiling;
102 
103     ShShaderOutput mCompilerOutputType;
104     mutable std::string mDebugInfo;
105     std::map<std::string, unsigned int> mUniformRegisterMap;
106     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
107     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
108     std::set<std::string> mSlowCompilingUniformBlockSet;
109     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
110     unsigned int mReadonlyImage2DRegisterIndex;
111     unsigned int mImage2DRegisterIndex;
112     std::set<std::string> mUsedImage2DFunctionNames;
113     ShCompileOptions mAdditionalOptions;
114 };
115 }  // namespace rx
116 
117 #endif  // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
118