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 utilities functions that create Metal shaders, convert from angle enums
8
// to Metal enums and so on.
11
#ifndef LIBANGLE_RENDERER_METAL_MTL_UTILS_H_
12
#define LIBANGLE_RENDERER_METAL_MTL_UTILS_H_
14
#import <Metal/Metal.h>
17
#include "common/PackedEnums.h"
18
#include "libANGLE/Context.h"
19
#include "libANGLE/Texture.h"
20
#include "libANGLE/renderer/metal/mtl_format_utils.h"
21
#include "libANGLE/renderer/metal/mtl_resources.h"
22
#include "libANGLE/renderer/metal/mtl_state_cache.h"
29
NS_ASSUME_NONNULL_BEGIN
31
angle::Result InitializeTextureContents(const gl::Context *context,
32
const TextureRef &texture,
33
const Format &textureObjFormat,
34
const gl::ImageIndex &index);
36
MTLViewport GetViewport(const gl::Rectangle &rect, double znear = 0, double zfar = 1);
37
MTLViewport GetViewportFlipY(const gl::Rectangle &rect,
38
NSUInteger screenHeight,
41
MTLViewport GetViewport(const gl::Rectangle &rect,
42
NSUInteger screenHeight,
46
MTLScissorRect GetScissorRect(const gl::Rectangle &rect,
47
NSUInteger screenHeight = 0,
50
AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(id<MTLDevice> metalDevice,
51
const std::string &source,
52
AutoObjCPtr<NSError *> *error);
54
AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(id<MTLDevice> metalDevice,
57
AutoObjCPtr<NSError *> *error);
59
AutoObjCPtr<id<MTLLibrary>> CreateShaderLibraryFromBinary(id<MTLDevice> metalDevice,
60
const uint8_t *binarySource,
61
size_t binarySourceLen,
62
AutoObjCPtr<NSError *> *error);
64
// Need to define invalid enum value since Metal doesn't define it
65
constexpr MTLTextureType MTLTextureTypeInvalid = static_cast<MTLTextureType>(NSUIntegerMax);
66
static_assert(sizeof(MTLTextureType) == sizeof(NSUInteger),
67
"MTLTextureType is supposed to be based on NSUInteger");
69
constexpr MTLPrimitiveType MTLPrimitiveTypeInvalid = static_cast<MTLPrimitiveType>(NSUIntegerMax);
70
static_assert(sizeof(MTLPrimitiveType) == sizeof(NSUInteger),
71
"MTLPrimitiveType is supposed to be based on NSUInteger");
73
constexpr MTLIndexType MTLIndexTypeInvalid = static_cast<MTLIndexType>(NSUIntegerMax);
74
static_assert(sizeof(MTLIndexType) == sizeof(NSUInteger),
75
"MTLIndexType is supposed to be based on NSUInteger");
77
MTLTextureType GetTextureType(gl::TextureType glType);
79
MTLSamplerMinMagFilter GetFilter(GLenum filter);
80
MTLSamplerMipFilter GetMipmapFilter(GLenum filter);
81
MTLSamplerAddressMode GetSamplerAddressMode(GLenum wrap);
83
MTLBlendFactor GetBlendFactor(GLenum factor);
84
MTLBlendOperation GetBlendOp(GLenum op);
86
MTLCompareFunction GetCompareFunc(GLenum func);
87
MTLStencilOperation GetStencilOp(GLenum op);
89
MTLWinding GetFontfaceWinding(GLenum frontFaceMode, bool invert);
91
PrimitiveTopologyClass GetPrimitiveTopologyClass(gl::PrimitiveMode mode);
92
MTLPrimitiveType GetPrimitiveType(gl::PrimitiveMode mode);
93
MTLIndexType GetIndexType(gl::DrawElementsType type);
95
// Useful to set clear color for texture originally having no alpha in GL, but backend's format
97
MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask colorMask);
103
#endif /* LIBANGLE_RENDERER_METAL_MTL_UTILS_H_ */