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;
appendDebugInfo(const std::string & info)62     void appendDebugInfo(const std::string &info) const { mDebugInfo += info; }
63 
64     void generateWorkarounds(angle::CompilerWorkaroundsD3D *workarounds) const;
65 
usesMultipleRenderTargets()66     bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; }
usesFragColor()67     bool usesFragColor() const { return mUsesFragColor; }
usesFragData()68     bool usesFragData() const { return mUsesFragData; }
usesSecondaryColor()69     bool usesSecondaryColor() const { return mUsesSecondaryColor; }
usesFragCoord()70     bool usesFragCoord() const { return mUsesFragCoord; }
usesFrontFacing()71     bool usesFrontFacing() const { return mUsesFrontFacing; }
usesHelperInvocation()72     bool usesHelperInvocation() const { return mUsesHelperInvocation; }
usesPointSize()73     bool usesPointSize() const { return mUsesPointSize; }
usesPointCoord()74     bool usesPointCoord() const { return mUsesPointCoord; }
usesDepthRange()75     bool usesDepthRange() const { return mUsesDepthRange; }
usesFragDepth()76     bool usesFragDepth() const { return mUsesFragDepth; }
usesVertexID()77     bool usesVertexID() const { return mUsesVertexID; }
usesViewID()78     bool usesViewID() const { return mUsesViewID; }
hasANGLEMultiviewEnabled()79     bool hasANGLEMultiviewEnabled() const { return mHasANGLEMultiviewEnabled; }
80 
81     ShShaderOutput getCompilerOutputType() const;
82 
83   private:
84     bool mUsesMultipleRenderTargets;
85     bool mUsesFragColor;
86     bool mUsesFragData;
87     bool mUsesSecondaryColor;
88     bool mUsesFragCoord;
89     bool mUsesFrontFacing;
90     bool mUsesHelperInvocation;
91     bool mUsesPointSize;
92     bool mUsesPointCoord;
93     bool mUsesDepthRange;
94     bool mUsesFragDepth;
95     bool mHasANGLEMultiviewEnabled;
96     bool mUsesVertexID;
97     bool mUsesViewID;
98     bool mUsesDiscardRewriting;
99     bool mUsesNestedBreak;
100     bool mRequiresIEEEStrictCompiling;
101 
102     ShShaderOutput mCompilerOutputType;
103     mutable std::string mDebugInfo;
104     std::map<std::string, unsigned int> mUniformRegisterMap;
105     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
106     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
107     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
108     unsigned int mReadonlyImage2DRegisterIndex;
109     unsigned int mImage2DRegisterIndex;
110     std::set<std::string> mUsedImage2DFunctionNames;
111     ShCompileOptions mAdditionalOptions;
112 };
113 }  // namespace rx
114 
115 #endif  // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
116