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 enum class DriverUniformFlip 38 { 39 // Flip uniforms for fragment shaders 40 Fragment, 41 // Flip uniforms for pre-rasterization stages. These differ from the fragment values by whether 42 // the viewport needs to be flipped, and whether negative viewports are supported. 43 PreFragment, 44 }; 45 46 class DriverUniform 47 { 48 public: DriverUniform(DriverUniformMode mode)49 DriverUniform(DriverUniformMode mode) 50 : mMode(mode), mDriverUniforms(nullptr), mEmulatedDepthRangeType(nullptr) 51 {} 52 virtual ~DriverUniform() = default; 53 54 bool addComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable); 55 bool addGraphicsDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable); 56 57 TIntermTyped *getAcbBufferOffsets() const; 58 TIntermTyped *getDepthRange() const; 59 TIntermTyped *getViewportZScale() const; 60 TIntermTyped *getHalfRenderArea() const; 61 TIntermTyped *getFlipXY(TSymbolTable *symbolTable, DriverUniformFlip stage) const; 62 // Returns vec2(flip.x, -flip.y) 63 TIntermTyped *getNegFlipXY(TSymbolTable *symbolTable, DriverUniformFlip stage) const; 64 TIntermTyped *getDither() const; 65 TIntermTyped *getSwapXY() const; 66 TIntermTyped *getAdvancedBlendEquation() const; 67 TIntermTyped *getNumSamples() const; 68 TIntermTyped *getClipDistancesEnabled() const; 69 TIntermTyped *getTransformDepth() const; 70 TIntermTyped *getAlphaToCoverage() const; 71 getViewport()72 virtual TIntermTyped *getViewport() const { return nullptr; } getXfbBufferOffsets()73 virtual TIntermTyped *getXfbBufferOffsets() const { return nullptr; } getXfbVerticesPerInstance()74 virtual TIntermTyped *getXfbVerticesPerInstance() const { return nullptr; } 75 getDriverUniformsVariable()76 const TVariable *getDriverUniformsVariable() const { return mDriverUniforms; } 77 78 protected: 79 TIntermTyped *createDriverUniformRef(const char *fieldName) const; 80 virtual TFieldList *createUniformFields(TSymbolTable *symbolTable); 81 const TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable); 82 83 const DriverUniformMode mMode; 84 const TVariable *mDriverUniforms; 85 TType *mEmulatedDepthRangeType; 86 }; 87 88 class DriverUniformExtended : public DriverUniform 89 { 90 public: DriverUniformExtended(DriverUniformMode mode)91 DriverUniformExtended(DriverUniformMode mode) : DriverUniform(mode) {} ~DriverUniformExtended()92 ~DriverUniformExtended() override {} 93 94 TIntermTyped *getXfbBufferOffsets() const override; 95 TIntermTyped *getXfbVerticesPerInstance() const override; 96 97 protected: 98 TFieldList *createUniformFields(TSymbolTable *symbolTable) override; 99 }; 100 101 // Returns either (1,0) or (0,1) based on whether X and Y should remain as-is or swapped 102 // respectively. dot((x,y), multiplier) will yield x, and dot((x,y), multiplier.yx) will yield y in 103 // the possibly-swapped coordinates. 104 // 105 // Each component is separately returned by a function 106 TIntermTyped *MakeSwapXMultiplier(TIntermTyped *swapped); 107 TIntermTyped *MakeSwapYMultiplier(TIntermTyped *swapped); 108 109 } // namespace sh 110 111 #endif // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_ 112