Hash :
9ff58e26
Author :
Date :
2020-09-27T15:27:12
Metal: Implement sampler object & shadow compare mode Note: GL_TEXTURE_COMPARE_MODE=GL_NONE is not supported on shadow sampler for now. Bug: angleproject:2634 Change-Id: I470bad6322e78ef1408e4334e1e778821df7cbf1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2433332 Commit-Queue: Le Hoang Quyen <le.hoang.q@gmail.com> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: 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 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
//
// Copyright 2019 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.
//
// mtl_format_utils.h:
// Declares Format conversion utilities classes that convert from angle formats
// to respective MTLPixelFormat and MTLVertexFormat.
//
#ifndef LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_
#define LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_
#import <Metal/Metal.h>
#include <unordered_map>
#include "common/angleutils.h"
#include "libANGLE/Caps.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/copyvertex.h"
#include "libANGLE/renderer/renderer_utils.h"
namespace rx
{
class DisplayMtl;
namespace mtl
{
struct FormatBase
{
inline bool operator==(const FormatBase &rhs) const
{
return intendedFormatId == rhs.intendedFormatId && actualFormatId == rhs.actualFormatId;
}
inline bool operator!=(const FormatBase &rhs) const { return !((*this) == rhs); }
const angle::Format &actualAngleFormat() const;
const angle::Format &intendedAngleFormat() const;
angle::FormatID actualFormatId = angle::FormatID::NONE;
angle::FormatID intendedFormatId = angle::FormatID::NONE;
};
struct FormatCaps
{
bool isRenderable() const { return colorRenderable || depthRenderable; }
bool filterable = false;
bool writable = false;
bool colorRenderable = false;
bool depthRenderable = false;
bool blendable = false;
bool multisample = false; // can be used as MSAA target
bool resolve = false; // Can be used as resolve target
};
// Pixel format
struct Format : public FormatBase
{
Format() = default;
const gl::InternalFormat &intendedInternalFormat() const;
const gl::InternalFormat &actualInternalFormat() const;
bool valid() const { return metalFormat != MTLPixelFormatInvalid; }
bool hasDepthAndStencilBits() const
{
return actualAngleFormat().depthBits && actualAngleFormat().stencilBits;
}
bool hasDepthOrStencilBits() const
{
return actualAngleFormat().depthBits || actualAngleFormat().stencilBits;
}
bool isPVRTC() const;
const FormatCaps &getCaps() const { return *caps; }
// Need conversion between source format and this format?
bool needConversion(angle::FormatID srcFormatId) const;
MTLPixelFormat metalFormat = MTLPixelFormatInvalid;
LoadFunctionMap textureLoadFunctions = nullptr;
InitializeTextureDataFunction initFunction = nullptr;
const FormatCaps *caps = nullptr;
bool swizzled = false;
std::array<GLenum, 4> swizzle;
private:
void init(const DisplayMtl *display, angle::FormatID intendedFormatId);
friend class FormatTable;
};
// Vertex format
struct VertexFormat : public FormatBase
{
VertexFormat() = default;
MTLVertexFormat metalFormat = MTLVertexFormatInvalid;
VertexCopyFunction vertexLoadFunction = nullptr;
uint32_t defaultAlpha = 0;
// Intended and actual format have same GL type, and possibly only differ in number of
// components?
bool actualSameGLType = true;
private:
void init(angle::FormatID angleFormatId, bool tightlyPacked = false);
friend class FormatTable;
};
class FormatTable final : angle::NonCopyable
{
public:
FormatTable() = default;
~FormatTable() = default;
angle::Result initialize(const DisplayMtl *display);
void generateTextureCaps(const DisplayMtl *display,
gl::TextureCapsMap *capsMapOut,
std::vector<GLenum> *compressedFormatsOut);
const Format &getPixelFormat(angle::FormatID angleFormatId) const;
const FormatCaps &getNativeFormatCaps(MTLPixelFormat mtlFormat) const;
// tightlyPacked means this format will be used in a tightly packed vertex buffer.
// In that case, it's easier to just convert everything to float to ensure
// Metal alignment requirements between 2 elements inside the buffer will be met regardless
// of how many components each element has.
const VertexFormat &getVertexFormat(angle::FormatID angleFormatId, bool tightlyPacked) const;
uint32_t getMaxSamples() const { return mMaxSamples; }
private:
void initNativeFormatCapsAutogen(const DisplayMtl *display);
void initNativeFormatCaps(const DisplayMtl *display);
void setFormatCaps(MTLPixelFormat formatId,
bool filterable,
bool writable,
bool blendable,
bool multisample,
bool resolve,
bool colorRenderable);
void setFormatCaps(MTLPixelFormat formatId,
bool filterable,
bool writable,
bool blendable,
bool multisample,
bool resolve,
bool colorRenderable,
bool depthRenderable);
void setCompressedFormatCaps(MTLPixelFormat formatId, bool filterable);
std::array<Format, angle::kNumANGLEFormats> mPixelFormatTable;
std::unordered_map<MTLPixelFormat, FormatCaps> mNativePixelFormatCapsTable;
// One for tightly packed buffers, one for general cases.
std::array<VertexFormat, angle::kNumANGLEFormats> mVertexFormatTables[2];
uint32_t mMaxSamples;
};
} // namespace mtl
} // namespace rx
#endif /* LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_ */