• 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 
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 FeaturesD3D;
19 }  // namespace angle
20 
21 namespace gl
22 {
23 struct Extensions;
24 }
25 
26 namespace rx
27 {
28 class DynamicHLSL;
29 class RendererD3D;
30 struct D3DUniform;
31 
32 // Workarounds attached to each shader. Do not need to expose information about these workarounds so
33 // a simple bool struct suffices.
34 struct CompilerWorkaroundsD3D
35 {
36     bool skipOptimization = false;
37 
38     bool useMaxOptimization = false;
39 
40     // IEEE strictness needs to be enabled for NANs to work.
41     bool enableIEEEStrictness = false;
42 };
43 
44 class ShaderD3D : public ShaderImpl
45 {
46   public:
47     ShaderD3D(const gl::ShaderState &state,
48               const angle::FeaturesD3D &features,
49               const gl::Extensions &extensions);
50     ~ShaderD3D() override;
51 
52     std::shared_ptr<WaitableCompileEvent> compile(const gl::Context *context,
53                                                   gl::ShCompilerInstance *compilerInstance,
54                                                   ShCompileOptions options) override;
55 
56     std::string getDebugInfo() const override;
57 
58     // D3D-specific methods
59     void uncompile();
60 
61     bool hasUniform(const std::string &name) const;
62 
63     // Query regular uniforms with their name. Query sampler fields of structs with field selection
64     // using dot (.) operator.
65     unsigned int getUniformRegister(const std::string &uniformName) const;
66 
67     unsigned int getUniformBlockRegister(const std::string &blockName) const;
68     bool shouldUniformBlockUseStructuredBuffer(const std::string &blockName) const;
69     unsigned int getShaderStorageBlockRegister(const std::string &blockName) const;
getReadonlyImage2DRegisterIndex()70     unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; }
getImage2DRegisterIndex()71     unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; }
72     bool useImage2DFunction(const std::string &functionName) const;
73     const std::set<std::string> &getSlowCompilingUniformBlockSet() const;
appendDebugInfo(const std::string & info)74     void appendDebugInfo(const std::string &info) const { mDebugInfo += info; }
75 
76     void generateWorkarounds(CompilerWorkaroundsD3D *workarounds) const;
77 
usesMultipleRenderTargets()78     bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; }
usesFragColor()79     bool usesFragColor() const { return mUsesFragColor; }
usesFragData()80     bool usesFragData() const { return mUsesFragData; }
usesSecondaryColor()81     bool usesSecondaryColor() const { return mUsesSecondaryColor; }
usesFragCoord()82     bool usesFragCoord() const { return mUsesFragCoord; }
usesFrontFacing()83     bool usesFrontFacing() const { return mUsesFrontFacing; }
usesHelperInvocation()84     bool usesHelperInvocation() const { return mUsesHelperInvocation; }
usesPointSize()85     bool usesPointSize() const { return mUsesPointSize; }
usesPointCoord()86     bool usesPointCoord() const { return mUsesPointCoord; }
usesDepthRange()87     bool usesDepthRange() const { return mUsesDepthRange; }
usesFragDepth()88     bool usesFragDepth() const { return mUsesFragDepth; }
usesVertexID()89     bool usesVertexID() const { return mUsesVertexID; }
usesViewID()90     bool usesViewID() const { return mUsesViewID; }
hasANGLEMultiviewEnabled()91     bool hasANGLEMultiviewEnabled() const { return mHasANGLEMultiviewEnabled; }
92 
93     ShShaderOutput getCompilerOutputType() const;
94 
95   private:
96     bool mUsesMultipleRenderTargets;
97     bool mUsesFragColor;
98     bool mUsesFragData;
99     bool mUsesSecondaryColor;
100     bool mUsesFragCoord;
101     bool mUsesFrontFacing;
102     bool mUsesHelperInvocation;
103     bool mUsesPointSize;
104     bool mUsesPointCoord;
105     bool mUsesDepthRange;
106     bool mUsesFragDepth;
107     bool mHasANGLEMultiviewEnabled;
108     bool mUsesVertexID;
109     bool mUsesViewID;
110     bool mUsesDiscardRewriting;
111     bool mUsesNestedBreak;
112     bool mRequiresIEEEStrictCompiling;
113 
114     ShShaderOutput mCompilerOutputType;
115     mutable std::string mDebugInfo;
116     std::map<std::string, unsigned int> mUniformRegisterMap;
117     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
118     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
119     std::set<std::string> mSlowCompilingUniformBlockSet;
120     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
121     unsigned int mReadonlyImage2DRegisterIndex;
122     unsigned int mImage2DRegisterIndex;
123     std::set<std::string> mUsedImage2DFunctionNames;
124     ShCompileOptions mAdditionalOptions;
125 };
126 }  // namespace rx
127 
128 #endif  // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
129