xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/ShaderD3D.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 #include <memory>
16 
17 namespace angle
18 {
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 // Workarounds attached to each shader. Do not need to expose information about these workarounds so
34 // a simple bool struct suffices.
35 struct CompilerWorkaroundsD3D
36 {
37     bool skipOptimization = false;
38 
39     bool useMaxOptimization = false;
40 
41     // IEEE strictness needs to be enabled for NANs to work.
42     bool enableIEEEStrictness = false;
43 };
44 
45 enum class FragDepthUsage
46 {
47     Unused,
48     Any,
49     Greater,
50     Less
51 };
52 
53 struct CompiledShaderStateD3D : angle::NonCopyable
54 {
55     CompiledShaderStateD3D();
56     ~CompiledShaderStateD3D();
57 
58     bool hasUniform(const std::string &name) const;
59 
60     // Query regular uniforms with their name. Query sampler fields of structs with field selection
61     // using dot (.) operator.
62     unsigned int getUniformRegister(const std::string &uniformName) const;
63 
64     unsigned int getUniformBlockRegister(const std::string &blockName) const;
65     bool shouldUniformBlockUseStructuredBuffer(const std::string &blockName) const;
66     unsigned int getShaderStorageBlockRegister(const std::string &blockName) const;
67     bool useImage2DFunction(const std::string &functionName) const;
68     const std::set<std::string> &getSlowCompilingUniformBlockSet() const;
appendDebugInfoCompiledShaderStateD3D69     void appendDebugInfo(const std::string &info) { debugInfo += info; }
70 
71     void generateWorkarounds(CompilerWorkaroundsD3D *workarounds) const;
72 
73     ShShaderOutput compilerOutputType;
74 
75     bool usesMultipleRenderTargets;
76     bool usesFragColor;
77     bool usesFragData;
78     bool usesSecondaryColor;
79     bool usesFragCoord;
80     bool usesFrontFacing;
81     bool usesHelperInvocation;
82     bool usesPointSize;
83     bool usesPointCoord;
84     bool usesDepthRange;
85     bool usesSampleID;
86     bool usesSamplePosition;
87     bool usesSampleMaskIn;
88     bool usesSampleMask;
89     bool hasMultiviewEnabled;
90     bool usesVertexID;
91     bool usesViewID;
92     bool usesDiscardRewriting;
93     bool usesNestedBreak;
94     bool requiresIEEEStrictCompiling;
95     FragDepthUsage fragDepthUsage;
96     uint8_t clipDistanceSize;
97     uint8_t cullDistanceSize;
98 
99     std::string debugInfo;
100     std::map<std::string, unsigned int> uniformRegisterMap;
101     std::map<std::string, unsigned int> uniformBlockRegisterMap;
102     std::map<std::string, bool> uniformBlockUseStructuredBufferMap;
103     std::set<std::string> slowCompilingUniformBlockSet;
104     std::map<std::string, unsigned int> shaderStorageBlockRegisterMap;
105     unsigned int readonlyImage2DRegisterIndex;
106     unsigned int image2DRegisterIndex;
107     std::set<std::string> usedImage2DFunctionNames;
108 };
109 using SharedCompiledShaderStateD3D = std::shared_ptr<CompiledShaderStateD3D>;
110 
111 class ShaderD3D : public ShaderImpl
112 {
113   public:
114     ShaderD3D(const gl::ShaderState &state, RendererD3D *renderer);
115     ~ShaderD3D() override;
116 
117     std::shared_ptr<ShaderTranslateTask> compile(const gl::Context *context,
118                                                  ShCompileOptions *options) override;
119     std::shared_ptr<ShaderTranslateTask> load(const gl::Context *context,
120                                               gl::BinaryInputStream *stream) override;
121 
122     std::string getDebugInfo() const override;
123 
getCompiledState()124     const SharedCompiledShaderStateD3D &getCompiledState() const { return mCompiledState; }
125 
126   private:
127     RendererD3D *mRenderer;
128 
129     SharedCompiledShaderStateD3D mCompiledState;
130 };
131 }  // namespace rx
132 
133 #endif  // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
134