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 TIntermTyped *getLayeredFramebuffer() const; 72 getViewport()73 virtual TIntermTyped *getViewport() const { return nullptr; } getXfbBufferOffsets()74 virtual TIntermTyped *getXfbBufferOffsets() const { return nullptr; } getXfbVerticesPerInstance()75 virtual TIntermTyped *getXfbVerticesPerInstance() const { return nullptr; } 76 getDriverUniformsVariable()77 const TVariable *getDriverUniformsVariable() const { return mDriverUniforms; } 78 79 protected: 80 TIntermTyped *createDriverUniformRef(const char *fieldName) const; 81 virtual TFieldList *createUniformFields(TSymbolTable *symbolTable); 82 const TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable); 83 84 const DriverUniformMode mMode; 85 const TVariable *mDriverUniforms; 86 TType *mEmulatedDepthRangeType; 87 }; 88 89 class DriverUniformExtended : public DriverUniform 90 { 91 public: DriverUniformExtended(DriverUniformMode mode)92 DriverUniformExtended(DriverUniformMode mode) : DriverUniform(mode) {} ~DriverUniformExtended()93 ~DriverUniformExtended() override {} 94 95 TIntermTyped *getXfbBufferOffsets() const override; 96 TIntermTyped *getXfbVerticesPerInstance() const override; 97 98 protected: 99 TFieldList *createUniformFields(TSymbolTable *symbolTable) override; 100 }; 101 102 // Returns either (1,0) or (0,1) based on whether X and Y should remain as-is or swapped 103 // respectively. dot((x,y), multiplier) will yield x, and dot((x,y), multiplier.yx) will yield y in 104 // the possibly-swapped coordinates. 105 // 106 // Each component is separately returned by a function 107 TIntermTyped *MakeSwapXMultiplier(TIntermTyped *swapped); 108 TIntermTyped *MakeSwapYMultiplier(TIntermTyped *swapped); 109 110 } // namespace sh 111 112 #endif // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_ 113