Skip to content

Commit

Permalink
Add macOS availability checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent a63c047 commit 20d22fd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
17 changes: 11 additions & 6 deletions impeller/renderer/backend/metal/device_buffer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@
return nullptr;
}

auto texture = [buffer_ newTextureWithDescriptor:ToMTLTextureDescriptor(desc)
offset:offset
bytesPerRow:desc.GetBytesPerRow()];
if (!texture) {
if (@available(macOS 10.13, *)) {
auto texture =
[buffer_ newTextureWithDescriptor:ToMTLTextureDescriptor(desc)
offset:offset
bytesPerRow:desc.GetBytesPerRow()];
if (!texture) {
return nullptr;
}

return std::make_shared<TextureMTL>(desc, texture);
} else {
return nullptr;
}

return std::make_shared<TextureMTL>(desc, texture);
}

[[nodiscard]] bool DeviceBufferMTL::CopyHostBuffer(const uint8_t* source,
Expand Down
36 changes: 30 additions & 6 deletions impeller/renderer/backend/metal/vertex_descriptor_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
if (input.bit_width == 8 * sizeof(float) / 2) {
switch (input.vec_size) {
case 1:
return MTLVertexFormatHalf;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatHalf;
} else {
return MTLVertexFormatInvalid;
}
case 2:
return MTLVertexFormatHalf2;
case 3:
Expand All @@ -56,15 +60,23 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
}
case ShaderType::kBoolean: {
if (input.bit_width == 8 * sizeof(bool) && input.vec_size == 1) {
return MTLVertexFormatChar;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatChar;
} else {
return MTLVertexFormatInvalid;
}
}
return MTLVertexFormatInvalid;
}
case ShaderType::kSignedByte: {
if (input.bit_width == 8 * sizeof(char)) {
switch (input.vec_size) {
case 1:
return MTLVertexFormatChar;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatChar;
} else {
return MTLVertexFormatInvalid;
}
case 2:
return MTLVertexFormatChar2;
case 3:
Expand All @@ -79,7 +91,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
if (input.bit_width == 8 * sizeof(char)) {
switch (input.vec_size) {
case 1:
return MTLVertexFormatUChar;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatUChar;
} else {
return MTLVertexFormatInvalid;
}
case 2:
return MTLVertexFormatUChar2;
case 3:
Expand All @@ -94,7 +110,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
if (input.bit_width == 8 * sizeof(short)) {
switch (input.vec_size) {
case 1:
return MTLVertexFormatShort;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatShort;
} else {
return MTLVertexFormatInvalid;
}
case 2:
return MTLVertexFormatShort2;
case 3:
Expand All @@ -109,7 +129,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
if (input.bit_width == 8 * sizeof(ushort)) {
switch (input.vec_size) {
case 1:
return MTLVertexFormatUShort;
if (@available(macOS 10.13, *)) {
return MTLVertexFormatUShort;
} else {
return MTLVertexFormatInvalid;
}
case 2:
return MTLVertexFormatUShort2;
case 3:
Expand Down

0 comments on commit 20d22fd

Please sign in to comment.