• 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 enum class FragDepthUsage
45 {
46     Unused,
47     Any,
48     Greater,
49     Less
50 };
51 
52 class ShaderD3D : public ShaderImpl
53 {
54   public:
55     ShaderD3D(const gl::ShaderState &state, RendererD3D *renderer);
56     ~ShaderD3D() override;
57 
58     std::shared_ptr<WaitableCompileEvent> compile(const gl::Context *context,
59                                                   gl::ShCompilerInstance *compilerInstance,
60                                                   ShCompileOptions *options) override;
61 
62     std::string getDebugInfo() const override;
63 
64     // D3D-specific methods
65     void uncompile();
66 
67     bool hasUniform(const std::string &name) const;
68 
69     // Query regular uniforms with their name. Query sampler fields of structs with field selection
70     // using dot (.) operator.
71     unsigned int getUniformRegister(const std::string &uniformName) const;
72 
73     unsigned int getUniformBlockRegister(const std::string &blockName) const;
74     bool shouldUniformBlockUseStructuredBuffer(const std::string &blockName) const;
75     unsigned int getShaderStorageBlockRegister(const std::string &blockName) const;
getReadonlyImage2DRegisterIndex()76     unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; }
getImage2DRegisterIndex()77     unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; }
78     bool useImage2DFunction(const std::string &functionName) const;
79     const std::set<std::string> &getSlowCompilingUniformBlockSet() const;
appendDebugInfo(const std::string & info)80     void appendDebugInfo(const std::string &info) const { mDebugInfo += info; }
81 
82     void generateWorkarounds(CompilerWorkaroundsD3D *workarounds) const;
83 
usesMultipleRenderTargets()84     bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; }
usesFragColor()85     bool usesFragColor() const { return mUsesFragColor; }
usesFragData()86     bool usesFragData() const { return mUsesFragData; }
usesSecondaryColor()87     bool usesSecondaryColor() const { return mUsesSecondaryColor; }
usesFragCoord()88     bool usesFragCoord() const { return mUsesFragCoord; }
usesFrontFacing()89     bool usesFrontFacing() const { return mUsesFrontFacing; }
usesHelperInvocation()90     bool usesHelperInvocation() const { return mUsesHelperInvocation; }
usesPointSize()91     bool usesPointSize() const { return mUsesPointSize; }
usesPointCoord()92     bool usesPointCoord() const { return mUsesPointCoord; }
usesDepthRange()93     bool usesDepthRange() const { return mUsesDepthRange; }
usesVertexID()94     bool usesVertexID() const { return mUsesVertexID; }
usesViewID()95     bool usesViewID() const { return mUsesViewID; }
usesSampleID()96     bool usesSampleID() const { return mUsesSampleID; }
usesSamplePosition()97     bool usesSamplePosition() const { return mUsesSamplePosition; }
usesSampleMaskIn()98     bool usesSampleMaskIn() const { return mUsesSampleMaskIn; }
usesSampleMask()99     bool usesSampleMask() const { return mUsesSampleMask; }
hasMultiviewEnabled()100     bool hasMultiviewEnabled() const { return mHasMultiviewEnabled; }
getFragDepthUsage()101     FragDepthUsage getFragDepthUsage() const { return mFragDepthUsage; }
getClipDistanceArraySize()102     uint8_t getClipDistanceArraySize() const { return mClipDistanceSize; }
getCullDistanceArraySize()103     uint8_t getCullDistanceArraySize() const { return mCullDistanceSize; }
104 
105     ShShaderOutput getCompilerOutputType() const;
106 
107   private:
108     bool mUsesMultipleRenderTargets;
109     bool mUsesFragColor;
110     bool mUsesFragData;
111     bool mUsesSecondaryColor;
112     bool mUsesFragCoord;
113     bool mUsesFrontFacing;
114     bool mUsesHelperInvocation;
115     bool mUsesPointSize;
116     bool mUsesPointCoord;
117     bool mUsesDepthRange;
118     bool mUsesSampleID;
119     bool mUsesSamplePosition;
120     bool mUsesSampleMaskIn;
121     bool mUsesSampleMask;
122     bool mHasMultiviewEnabled;
123     bool mUsesVertexID;
124     bool mUsesViewID;
125     bool mUsesDiscardRewriting;
126     bool mUsesNestedBreak;
127     bool mRequiresIEEEStrictCompiling;
128     FragDepthUsage mFragDepthUsage;
129     uint8_t mClipDistanceSize;
130     uint8_t mCullDistanceSize;
131 
132     RendererD3D *mRenderer;
133     ShShaderOutput mCompilerOutputType;
134     mutable std::string mDebugInfo;
135     std::map<std::string, unsigned int> mUniformRegisterMap;
136     std::map<std::string, unsigned int> mUniformBlockRegisterMap;
137     std::map<std::string, bool> mUniformBlockUseStructuredBufferMap;
138     std::set<std::string> mSlowCompilingUniformBlockSet;
139     std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap;
140     unsigned int mReadonlyImage2DRegisterIndex;
141     unsigned int mImage2DRegisterIndex;
142     std::set<std::string> mUsedImage2DFunctionNames;
143 };
144 }  // namespace rx
145 
146 #endif  // LIBANGLE_RENDERER_D3D_SHADERD3D_H_
147