tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DriverUniform.h (3705B)


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