Hash :
cac1e824
Author :
Date :
2025-04-29T18:27:36
WGSL: Output driver uniform and UBO structs This is the WGSL half of the change to implement driver uniforms. Driver uniforms are implemented as a UBO and reuse the default set of driver uniforms. User-provided UBOs don't yet have variables outputted for them. This requires moving MSL's ReduceInterfaceBlocks to the tree_ops dir in order to change interface block definitions into struct definitions. Bug: angleproject:389145696 Change-Id: I27f3837b3d115f2ffac66cc545f3b60ca9f01cb6 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6477564 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DriverUniform.h: Add code to support driver uniforms
//
#ifndef COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
#define COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_
#include "common/angleutils.h"
#include "compiler/translator/Types.h"
namespace sh
{
class TCompiler;
class TIntermBlock;
class TIntermNode;
class TSymbolTable;
class TIntermTyped;
class TIntermSwizzle;
class TIntermBinary;
enum class DriverUniformMode
{
// Define the driver uniforms as an interface block. Used by the
// Vulkan and Metal/SPIR-V backends.
InterfaceBlock,
// Define the driver uniforms as a structure. Used by the
// direct-to-MSL Metal backend.
Structure
};
enum class DriverUniformFlip
{
// Flip uniforms for fragment shaders
Fragment,
// Flip uniforms for pre-rasterization stages. These differ from the fragment values by whether
// the viewport needs to be flipped, and whether negative viewports are supported.
PreFragment,
};
constexpr ImmutableString kEmulatedDepthRangeParams = ImmutableString("ANGLEDepthRangeParams");
constexpr ImmutableString kDriverUniformsBlockName = ImmutableString("ANGLEUniformBlock");
constexpr ImmutableString kDriverUniformsVarName = ImmutableString("ANGLEUniforms");
class DriverUniform
{
public:
DriverUniform(DriverUniformMode mode)
: mMode(mode), mDriverUniforms(nullptr), mEmulatedDepthRangeType(nullptr)
{}
virtual ~DriverUniform() = default;
bool addComputeDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable);
bool addGraphicsDriverUniformsToShader(TIntermBlock *root, TSymbolTable *symbolTable);
TIntermTyped *getAcbBufferOffsets() const;
TIntermTyped *getDepthRange() const;
TIntermTyped *getViewportZScale() const;
TIntermTyped *getHalfRenderArea() const;
TIntermTyped *getFlipXY(TSymbolTable *symbolTable, DriverUniformFlip stage) const;
// Returns vec2(flip.x, -flip.y)
TIntermTyped *getNegFlipXY(TSymbolTable *symbolTable, DriverUniformFlip stage) const;
TIntermTyped *getDither() const;
TIntermTyped *getSwapXY() const;
TIntermTyped *getAdvancedBlendEquation() const;
TIntermTyped *getNumSamples() const;
TIntermTyped *getClipDistancesEnabled() const;
TIntermTyped *getTransformDepth() const;
TIntermTyped *getAlphaToCoverage() const;
TIntermTyped *getLayeredFramebuffer() const;
virtual TIntermTyped *getViewport() const { return nullptr; }
virtual TIntermTyped *getXfbBufferOffsets() const { return nullptr; }
virtual TIntermTyped *getXfbVerticesPerInstance() const { return nullptr; }
const TVariable *getDriverUniformsVariable() const { return mDriverUniforms; }
protected:
TIntermTyped *createDriverUniformRef(const char *fieldName) const;
virtual TFieldList *createUniformFields(TSymbolTable *symbolTable);
const TType *createEmulatedDepthRangeType(TSymbolTable *symbolTable);
const DriverUniformMode mMode;
const TVariable *mDriverUniforms;
TType *mEmulatedDepthRangeType;
};
class DriverUniformExtended : public DriverUniform
{
public:
DriverUniformExtended(DriverUniformMode mode) : DriverUniform(mode) {}
~DriverUniformExtended() override {}
TIntermTyped *getXfbBufferOffsets() const override;
TIntermTyped *getXfbVerticesPerInstance() const override;
protected:
TFieldList *createUniformFields(TSymbolTable *symbolTable) override;
};
// Returns either (1,0) or (0,1) based on whether X and Y should remain as-is or swapped
// respectively. dot((x,y), multiplier) will yield x, and dot((x,y), multiplier.yx) will yield y in
// the possibly-swapped coordinates.
//
// Each component is separately returned by a function
TIntermTyped *MakeSwapXMultiplier(TIntermTyped *swapped);
TIntermTyped *MakeSwapYMultiplier(TIntermTyped *swapped);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEUTIL_DRIVERUNIFORM_H_