1 // 2 // Copyright 2020 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 // DriverUniform.h: Add code to support driver uniforms 7 // 8 9 #ifndef COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_ 10 #define COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_ 11 12 #include "common/angleutils.h" 13 #include "compiler/translator/Types.h" 14 15 namespace sh 16 { 17 18 class TCompiler; 19 class TIntermBlock; 20 class TIntermNode; 21 class TSymbolTable; 22 class TIntermTyped; 23 class TIntermSwizzle; 24 class TIntermBinary; 25 26 enum class DriverUniformMode 27 { 28 // Define the driver uniforms as an interface block. Used by the 29 // Vulkan and Metal/SPIR-V backends. 30 InterfaceBlock, 31 32 // Define the driver uniforms as a structure. Used by the 33 // direct-to-MSL Metal backend. 34 Structure 35 }; 36 37 class DriverUniform 38 { 39 public: DriverUniform(DriverUniformMode mode)40 DriverUniform(DriverUniformMode mode) 41 : mMode(mode), mDriverUniforms(nullptr), mEmulatedDepthRangeType(nullptr) 42 {} 43 virtual ~DriverUniform() = default; 44 45 bool addComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable); 46 bool addGraphicsDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable); 47 48 TIntermTyped *getViewportRef() const; 49 TIntermTyped *getAbcBufferOffsets() const; 50 TIntermTyped *getXfbVerticesPerInstance() const; 51 TIntermTyped *getXfbBufferOffsets() const; 52 TIntermTyped *getClipDistancesEnabled() const; 53 TIntermTyped *getDepthRangeRef() const; 54 TIntermTyped *getDepthRangeReservedFieldRef() const; 55 TIntermTyped *getNumSamplesRef() const; 56 TIntermTyped *getAdvancedBlendEquationRef() const; 57 getFlipXYRef()58 virtual TIntermTyped *getFlipXYRef() const { return nullptr; } getNegFlipXYRef()59 virtual TIntermTyped *getNegFlipXYRef() const { return nullptr; } getPreRotationMatrixRef()60 virtual TIntermTyped *getPreRotationMatrixRef() const { return nullptr; } getFragRotationMatrixRef()61 virtual TIntermTyped *getFragRotationMatrixRef() const { return nullptr; } getHalfRenderAreaRef()62 virtual TIntermTyped *getHalfRenderAreaRef() const { return nullptr; } getNegFlipYRef()63 virtual TIntermTyped *getNegFlipYRef() const { return nullptr; } getDitherRef()64 virtual TIntermTyped *getDitherRef() const { return nullptr; } 65 getDriverUniformsVariable()66 const TVariable *getDriverUniformsVariable() const { return mDriverUniforms; } 67 68 protected: 69 TIntermTyped *createDriverUniformRef(const char *fieldName) const; 70 virtual TFieldList *createUniformFields(TSymbolTable *symbolTable); 71 TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable); 72 73 const DriverUniformMode mMode; 74 const TVariable *mDriverUniforms; 75 TType *mEmulatedDepthRangeType; 76 }; 77 78 class DriverUniformExtended : public DriverUniform 79 { 80 public: DriverUniformExtended(DriverUniformMode mode)81 DriverUniformExtended(DriverUniformMode mode) : DriverUniform(mode) {} ~DriverUniformExtended()82 virtual ~DriverUniformExtended() override {} 83 84 TIntermTyped *getFlipXYRef() const override; 85 TIntermTyped *getNegFlipXYRef() const override; 86 TIntermTyped *getPreRotationMatrixRef() const override; 87 TIntermTyped *getFragRotationMatrixRef() const override; 88 TIntermTyped *getHalfRenderAreaRef() const override; 89 TIntermTyped *getNegFlipYRef() const override; 90 TIntermTyped *getDitherRef() const override; 91 92 protected: 93 virtual TFieldList *createUniformFields(TSymbolTable *symbolTable) override; 94 }; 95 96 } // namespace sh 97 98 #endif // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_ 99