Skip to content

Commit 20d22fd

Browse files
chinmaygardednfield
authored andcommitted
Add macOS availability checks.
1 parent a63c047 commit 20d22fd

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

impeller/renderer/backend/metal/device_buffer_mtl.mm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@
3434
return nullptr;
3535
}
3636

37-
auto texture = [buffer_ newTextureWithDescriptor:ToMTLTextureDescriptor(desc)
38-
offset:offset
39-
bytesPerRow:desc.GetBytesPerRow()];
40-
if (!texture) {
37+
if (@available(macOS 10.13, *)) {
38+
auto texture =
39+
[buffer_ newTextureWithDescriptor:ToMTLTextureDescriptor(desc)
40+
offset:offset
41+
bytesPerRow:desc.GetBytesPerRow()];
42+
if (!texture) {
43+
return nullptr;
44+
}
45+
46+
return std::make_shared<TextureMTL>(desc, texture);
47+
} else {
4148
return nullptr;
4249
}
43-
44-
return std::make_shared<TextureMTL>(desc, texture);
4550
}
4651

4752
[[nodiscard]] bool DeviceBufferMTL::CopyHostBuffer(const uint8_t* source,

impeller/renderer/backend/metal/vertex_descriptor_mtl.mm

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
3939
if (input.bit_width == 8 * sizeof(float) / 2) {
4040
switch (input.vec_size) {
4141
case 1:
42-
return MTLVertexFormatHalf;
42+
if (@available(macOS 10.13, *)) {
43+
return MTLVertexFormatHalf;
44+
} else {
45+
return MTLVertexFormatInvalid;
46+
}
4347
case 2:
4448
return MTLVertexFormatHalf2;
4549
case 3:
@@ -56,15 +60,23 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
5660
}
5761
case ShaderType::kBoolean: {
5862
if (input.bit_width == 8 * sizeof(bool) && input.vec_size == 1) {
59-
return MTLVertexFormatChar;
63+
if (@available(macOS 10.13, *)) {
64+
return MTLVertexFormatChar;
65+
} else {
66+
return MTLVertexFormatInvalid;
67+
}
6068
}
6169
return MTLVertexFormatInvalid;
6270
}
6371
case ShaderType::kSignedByte: {
6472
if (input.bit_width == 8 * sizeof(char)) {
6573
switch (input.vec_size) {
6674
case 1:
67-
return MTLVertexFormatChar;
75+
if (@available(macOS 10.13, *)) {
76+
return MTLVertexFormatChar;
77+
} else {
78+
return MTLVertexFormatInvalid;
79+
}
6880
case 2:
6981
return MTLVertexFormatChar2;
7082
case 3:
@@ -79,7 +91,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
7991
if (input.bit_width == 8 * sizeof(char)) {
8092
switch (input.vec_size) {
8193
case 1:
82-
return MTLVertexFormatUChar;
94+
if (@available(macOS 10.13, *)) {
95+
return MTLVertexFormatUChar;
96+
} else {
97+
return MTLVertexFormatInvalid;
98+
}
8399
case 2:
84100
return MTLVertexFormatUChar2;
85101
case 3:
@@ -94,7 +110,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
94110
if (input.bit_width == 8 * sizeof(short)) {
95111
switch (input.vec_size) {
96112
case 1:
97-
return MTLVertexFormatShort;
113+
if (@available(macOS 10.13, *)) {
114+
return MTLVertexFormatShort;
115+
} else {
116+
return MTLVertexFormatInvalid;
117+
}
98118
case 2:
99119
return MTLVertexFormatShort2;
100120
case 3:
@@ -109,7 +129,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
109129
if (input.bit_width == 8 * sizeof(ushort)) {
110130
switch (input.vec_size) {
111131
case 1:
112-
return MTLVertexFormatUShort;
132+
if (@available(macOS 10.13, *)) {
133+
return MTLVertexFormatUShort;
134+
} else {
135+
return MTLVertexFormatInvalid;
136+
}
113137
case 2:
114138
return MTLVertexFormatUShort2;
115139
case 3:

0 commit comments

Comments
 (0)