ShaderD3D.h (4472B)
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, RendererD3D *renderer); 48 ~ShaderD3D() override; 49 50 std::shared_ptr<WaitableCompileEvent> compile(const gl::Context *context, 51 gl::ShCompilerInstance *compilerInstance, 52 ShCompileOptions *options) override; 53 54 std::string getDebugInfo() const override; 55 56 // D3D-specific methods 57 void uncompile(); 58 59 bool hasUniform(const std::string &name) const; 60 61 // Query regular uniforms with their name. Query sampler fields of structs with field selection 62 // using dot (.) operator. 63 unsigned int getUniformRegister(const std::string &uniformName) const; 64 65 unsigned int getUniformBlockRegister(const std::string &blockName) const; 66 bool shouldUniformBlockUseStructuredBuffer(const std::string &blockName) const; 67 unsigned int getShaderStorageBlockRegister(const std::string &blockName) const; 68 unsigned int getReadonlyImage2DRegisterIndex() const { return mReadonlyImage2DRegisterIndex; } 69 unsigned int getImage2DRegisterIndex() const { return mImage2DRegisterIndex; } 70 bool useImage2DFunction(const std::string &functionName) const; 71 const std::set<std::string> &getSlowCompilingUniformBlockSet() const; 72 void appendDebugInfo(const std::string &info) const { mDebugInfo += info; } 73 74 void generateWorkarounds(CompilerWorkaroundsD3D *workarounds) const; 75 76 bool usesMultipleRenderTargets() const { return mUsesMultipleRenderTargets; } 77 bool usesFragColor() const { return mUsesFragColor; } 78 bool usesFragData() const { return mUsesFragData; } 79 bool usesSecondaryColor() const { return mUsesSecondaryColor; } 80 bool usesFragCoord() const { return mUsesFragCoord; } 81 bool usesFrontFacing() const { return mUsesFrontFacing; } 82 bool usesHelperInvocation() const { return mUsesHelperInvocation; } 83 bool usesPointSize() const { return mUsesPointSize; } 84 bool usesPointCoord() const { return mUsesPointCoord; } 85 bool usesDepthRange() const { return mUsesDepthRange; } 86 bool usesFragDepth() const { return mUsesFragDepth; } 87 bool usesVertexID() const { return mUsesVertexID; } 88 bool usesViewID() const { return mUsesViewID; } 89 bool hasANGLEMultiviewEnabled() const { return mHasANGLEMultiviewEnabled; } 90 91 ShShaderOutput getCompilerOutputType() const; 92 93 private: 94 bool mUsesMultipleRenderTargets; 95 bool mUsesFragColor; 96 bool mUsesFragData; 97 bool mUsesSecondaryColor; 98 bool mUsesFragCoord; 99 bool mUsesFrontFacing; 100 bool mUsesHelperInvocation; 101 bool mUsesPointSize; 102 bool mUsesPointCoord; 103 bool mUsesDepthRange; 104 bool mUsesFragDepth; 105 bool mHasANGLEMultiviewEnabled; 106 bool mUsesVertexID; 107 bool mUsesViewID; 108 bool mUsesDiscardRewriting; 109 bool mUsesNestedBreak; 110 bool mRequiresIEEEStrictCompiling; 111 112 RendererD3D *mRenderer; 113 ShShaderOutput mCompilerOutputType; 114 mutable std::string mDebugInfo; 115 std::map<std::string, unsigned int> mUniformRegisterMap; 116 std::map<std::string, unsigned int> mUniformBlockRegisterMap; 117 std::map<std::string, bool> mUniformBlockUseStructuredBufferMap; 118 std::set<std::string> mSlowCompilingUniformBlockSet; 119 std::map<std::string, unsigned int> mShaderStorageBlockRegisterMap; 120 unsigned int mReadonlyImage2DRegisterIndex; 121 unsigned int mImage2DRegisterIndex; 122 std::set<std::string> mUsedImage2DFunctionNames; 123 }; 124 } // namespace rx 125 126 #endif // LIBANGLE_RENDERER_D3D_SHADERD3D_H_