Add macOS availability checks.

This commit is contained in:
Chinmay Garde 2021-12-06 13:49:18 -08:00 committed by Dan Field
parent 72e4d8c955
commit 82e7078ca8
2 changed files with 41 additions and 12 deletions

View File

@ -34,14 +34,19 @@ std::shared_ptr<Texture> DeviceBufferMTL::MakeTexture(TextureDescriptor desc,
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,

View File

@ -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:
@ -56,7 +60,11 @@ 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;
}
@ -64,7 +72,11 @@ static MTLVertexFormat ReadStageInputFormat(const ShaderStageIOSlot& input) {
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:
@ -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:
@ -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:
@ -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: