Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 0960c8d

Browse files
committed
Availability guard for Metal
1 parent b6bdd7d commit 0960c8d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

impeller/renderer/backend/metal/formats_mtl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
5252
return PixelFormat::kUnknown;
5353
}
5454

55+
/// Safe accessor for MTLPixelFormatDepth24Unorm_Stencil8.
56+
/// Returns PixelFormat::kUnknown if MTLPixelFormatDepth24Unorm_Stencil8 isn't
57+
/// supported.
58+
MTLPixelFormat SafeMTLPixelFormatDepth24Unorm_Stencil8();
59+
5560
/// Safe accessor for MTLPixelFormatBGR10_XR_sRGB.
5661
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR_sRGB isn't
5762
/// supported.
@@ -90,7 +95,7 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
9095
case PixelFormat::kS8UInt:
9196
return MTLPixelFormatStencil8;
9297
case PixelFormat::kD24UnormS8Uint:
93-
return MTLPixelFormatDepth24Unorm_Stencil8;
98+
return SafeMTLPixelFormatDepth24Unorm_Stencil8();
9499
case PixelFormat::kD32FloatS8UInt:
95100
return MTLPixelFormatDepth32Float_Stencil8;
96101
case PixelFormat::kB10G10R10XRSRGB:

impeller/renderer/backend/metal/formats_mtl.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include "impeller/renderer/backend/metal/formats_mtl.h"
6+
#include <Metal/Metal.h>
67

78
#include <memory>
89

@@ -109,6 +110,13 @@
109110
return mtl_desc;
110111
}
111112

113+
MTLPixelFormat SafeMTLPixelFormatDepth24Unorm_Stencil8() {
114+
if (@available(macOS 10.11, *)) {
115+
return MTLPixelFormatDepth24Unorm_Stencil8;
116+
}
117+
return MTLPixelFormatInvalid;
118+
}
119+
112120
MTLPixelFormat SafeMTLPixelFormatBGR10_XR_sRGB() {
113121
if (@available(iOS 11, macOS 11.0, *)) {
114122
return MTLPixelFormatBGR10_XR_sRGB;

0 commit comments

Comments
 (0)