2
// Copyright 2019 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.
7
// Declares Format conversion utilities classes that convert from angle formats
8
// to respective MTLPixelFormat and MTLVertexFormat.
11
#ifndef LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_
12
#define LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_
14
#import <Metal/Metal.h>
16
#include "common/angleutils.h"
17
#include "libANGLE/Caps.h"
18
#include "libANGLE/formatutils.h"
19
#include "libANGLE/renderer/copyvertex.h"
30
inline bool operator==(const FormatBase &rhs) const
32
return intendedFormatId == rhs.intendedFormatId && actualFormatId == rhs.actualFormatId;
35
inline bool operator!=(const FormatBase &rhs) const { return !((*this) == rhs); }
37
const angle::Format &actualAngleFormat() const;
38
const angle::Format &intendedAngleFormat() const;
40
angle::FormatID actualFormatId = angle::FormatID::NONE;
41
angle::FormatID intendedFormatId = angle::FormatID::NONE;
45
struct Format : public FormatBase
49
const gl::InternalFormat &intendedInternalFormat() const;
51
bool valid() const { return metalFormat != MTLPixelFormatInvalid; }
53
static bool FormatRenderable(MTLPixelFormat format);
54
static bool FormatCPUReadable(MTLPixelFormat format);
56
MTLPixelFormat metalFormat = MTLPixelFormatInvalid;
59
void init(const DisplayMtl *display, angle::FormatID intendedFormatId);
61
friend class FormatTable;
65
struct VertexFormat : public FormatBase
67
VertexFormat() = default;
69
MTLVertexFormat metalFormat = MTLVertexFormatInvalid;
71
VertexCopyFunction vertexLoadFunction = nullptr;
74
void init(angle::FormatID angleFormatId, bool tightlyPacked = false);
76
friend class FormatTable;
79
class FormatTable final : angle::NonCopyable
82
FormatTable() = default;
83
~FormatTable() = default;
85
angle::Result initialize(const DisplayMtl *display);
87
void generateTextureCaps(const DisplayMtl *display,
88
gl::TextureCapsMap *capsMapOut,
89
std::vector<GLenum> *compressedFormatsOut) const;
91
const Format &getPixelFormat(angle::FormatID angleFormatId) const;
93
// tightlyPacked means this format will be used in a tightly packed vertex buffer.
94
// In that case, it's easier to just convert everything to float to ensure
95
// Metal alignment requirements between 2 elements inside the buffer will be met regardless
96
// of how many components each element has.
97
const VertexFormat &getVertexFormat(angle::FormatID angleFormatId, bool tightlyPacked) const;
100
std::array<Format, angle::kNumANGLEFormats> mPixelFormatTable;
101
// One for tightly packed buffers, one for general cases.
102
std::array<VertexFormat, angle::kNumANGLEFormats> mVertexFormatTables[2];
108
#endif /* LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_ */