• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     TIntermBinary *getViewportRef() const;
49     TIntermBinary *getAbcBufferOffsets() const;
50     TIntermBinary *getXfbActiveUnpaused() const;
51     TIntermBinary *getXfbVerticesPerInstance() const;
52     TIntermBinary *getXfbBufferOffsets() const;
53     TIntermBinary *getClipDistancesEnabled() const;
54     TIntermBinary *getDepthRangeRef() const;
55     TIntermBinary *getDepthRangeReservedFieldRef() const;
56     TIntermBinary *getNumSamplesRef() const;
57 
getFlipXYRef()58     virtual TIntermBinary *getFlipXYRef() const { return nullptr; }
getNegFlipXYRef()59     virtual TIntermBinary *getNegFlipXYRef() const { return nullptr; }
getPreRotationMatrixRef()60     virtual TIntermBinary *getPreRotationMatrixRef() const { return nullptr; }
getFragRotationMatrixRef()61     virtual TIntermBinary *getFragRotationMatrixRef() const { return nullptr; }
getHalfRenderAreaRef()62     virtual TIntermBinary *getHalfRenderAreaRef() const { return nullptr; }
getNegFlipYRef()63     virtual TIntermSwizzle *getNegFlipYRef() const { return nullptr; }
getEmulatedInstanceId()64     virtual TIntermBinary *getEmulatedInstanceId() const { return nullptr; }
getCoverageMask()65     virtual TIntermBinary *getCoverageMask() const { return nullptr; }
66 
getDriverUniformsVariable()67     const TVariable *getDriverUniformsVariable() const { return mDriverUniforms; }
68 
69   protected:
70     TIntermBinary *createDriverUniformRef(const char *fieldName) const;
71     virtual TFieldList *createUniformFields(TSymbolTable *symbolTable);
72     TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable);
73 
74     const DriverUniformMode mMode;
75     const TVariable *mDriverUniforms;
76     TType *mEmulatedDepthRangeType;
77 };
78 
79 class DriverUniformExtended : public DriverUniform
80 {
81   public:
DriverUniformExtended(DriverUniformMode mode)82     DriverUniformExtended(DriverUniformMode mode) : DriverUniform(mode) {}
~DriverUniformExtended()83     virtual ~DriverUniformExtended() override {}
84 
85     TIntermBinary *getFlipXYRef() const override;
86     TIntermBinary *getNegFlipXYRef() const override;
87     TIntermBinary *getPreRotationMatrixRef() const override;
88     TIntermBinary *getFragRotationMatrixRef() const override;
89     TIntermBinary *getHalfRenderAreaRef() const override;
90     TIntermSwizzle *getNegFlipYRef() const override;
91     TIntermBinary *getEmulatedInstanceId() const override;
92     TIntermBinary *getCoverageMask() const override;
93 
94   protected:
95     virtual TFieldList *createUniformFields(TSymbolTable *symbolTable) override;
96 };
97 
98 }  // namespace sh
99 
100 #endif  // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
101