Hash :
d7aa0130
Author :
Date :
2021-04-26T16:56:15
Upstream Apple's direct-to-Metal backend: compile translator. This change is meant to merge the translator changes from Apple's direct-to-Metal backend. Taken from Kyle Piddington's CL: https://chromium-review.googlesource.com/c/angle/angle/+/2857366/ The goal of this CL is to merge the translator code in a state that compiles, but not to switch the Metal backend over to use this translator backend yet. Bug: angleproject:5505 Change-Id: I68a6354604498cd5fd1eb96c13fc56f3b38f2bd0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2897536 Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
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
//
// 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.
//
#ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_
#define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_
#include "common/angleutils.h"
#include "compiler/translator/Types.h"
namespace sh
{
constexpr const auto kDefaultLayoutBlockStorage = TLayoutBlockStorage::EbsShared;
constexpr const auto kDefaultLayoutMatrixPacking = TLayoutMatrixPacking::EmpColumnMajor;
constexpr const auto kDefaultStructAlignmentSize = 16;
// Returns `oldStorage` if `type` has unspecified block storage.
// Otherwise returns block storage of `type`.
TLayoutBlockStorage Overlay(TLayoutBlockStorage oldStorage, const TType &type);
// Returns `oldPacking` if `type` has unspecified matrix packing.
// Otherwise returns matrix packing of `type`.
TLayoutMatrixPacking Overlay(TLayoutMatrixPacking oldPacking, const TType &type);
// Returns whether or not it is permissable for the block storage to use a packed representation.
bool CanBePacked(TLayoutBlockStorage storage);
// Returns whether or not it is permissable for the layout qualifier to use a packed representation.
bool CanBePacked(TLayoutQualifier layoutQualifier);
// Returns whether or not it is permissable for the type to use a packed representation.
bool CanBePacked(const TType &type);
// Sets the block storage for a type.
void SetBlockStorage(TType &type, TLayoutBlockStorage storage);
// Contains `sizeof` and `alignof` information.
struct Layout
{
size_t sizeOf;
size_t alignOf;
static Layout Identity() { return {0, 1}; }
static Layout Invalid() { return {0, 0}; }
static Layout Both(size_t n) { return {n, n}; }
void requireAlignment(size_t align, bool pad);
bool operator==(const Layout &other) const;
void operator+=(const Layout &other);
void operator*=(size_t scale);
Layout operator+(const Layout &other) const;
Layout operator*(size_t scale) const;
};
struct MetalLayoutOfConfig
{
bool disablePacking = false;
bool maskArray = false;
bool treatSamplersAsTextureEnv = false;
bool assumeStructsAreTailPadded = false; // Pad to multiple of 16
};
// Returns the layout of a type if it were to be represented in a Metal program.
// This deliberately ignores the TLayoutBlockStorage and TLayoutMatrixPacking of any type.
ANGLE_NO_DISCARD Layout MetalLayoutOf(const TType &type, MetalLayoutOfConfig config = {});
// Returns the layout of a type if it were to be represented in a GLSL program.
ANGLE_NO_DISCARD Layout
GlslLayoutOf(const TType &type,
TLayoutBlockStorage storage = TLayoutBlockStorage::EbsUnspecified,
TLayoutMatrixPacking matrixPacking = TLayoutMatrixPacking::EmpUnspecified,
bool maskArray = false);
// Returns the layout of a structure if it were to be represented in a GLSL program.
ANGLE_NO_DISCARD Layout GlslStructLayoutOf(TField const *const *begin,
TField const *const *end,
TLayoutBlockStorage storage,
TLayoutMatrixPacking matrixPacking,
bool maskArray = false);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_LAYOUT_H_