diff options
Diffstat (limited to 'src/gui/rhi/qrhimetal.mm')
-rw-r--r-- | src/gui/rhi/qrhimetal.mm | 251 |
1 files changed, 186 insertions, 65 deletions
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 2ae90bdb0e..2c78517f74 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -402,12 +402,16 @@ bool QRhiMetal::create(QRhi::Flags flags) #if defined(Q_OS_MACOS) caps.maxTextureSize = 16384; caps.baseVertexAndInstance = true; + if (@available(macOS 10.15, *)) + caps.isAppleGPU = [d->dev supportsFamily:MTLGPUFamilyApple7]; + caps.maxThreadGroupSize = 1024; #elif defined(Q_OS_TVOS) if ([d->dev supportsFeatureSet: MTLFeatureSet(30003)]) // MTLFeatureSet_tvOS_GPUFamily2_v1 caps.maxTextureSize = 16384; else caps.maxTextureSize = 8192; caps.baseVertexAndInstance = false; + caps.isAppleGPU = true; #elif defined(Q_OS_IOS) // welcome to feature set hell if ([d->dev supportsFeatureSet: MTLFeatureSet(16)] // MTLFeatureSet_iOS_GPUFamily5_v1 @@ -425,6 +429,11 @@ bool QRhiMetal::create(QRhi::Flags flags) caps.maxTextureSize = 4096; caps.baseVertexAndInstance = false; } + caps.isAppleGPU = true; + if (@available(iOS 13, *)) { + if ([d->dev supportsFamily:MTLGPUFamilyApple4]) + caps.maxThreadGroupSize = 1024; + } #endif caps.supportedSampleCounts = { 1 }; @@ -524,16 +533,32 @@ bool QRhiMetal::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture { Q_UNUSED(flags); + bool supportsFamilyMac2 = false; // needed for BC* formats + bool supportsFamilyApple3 = false; + #ifdef Q_OS_MACOS - if (format >= QRhiTexture::ETC2_RGB8 && format <= QRhiTexture::ETC2_RGBA8) - return false; - if (format >= QRhiTexture::ASTC_4x4 && format <= QRhiTexture::ASTC_12x12) - return false; + supportsFamilyMac2 = true; + if (caps.isAppleGPU) + supportsFamilyApple3 = true; #else - if (format >= QRhiTexture::BC1 && format <= QRhiTexture::BC7) - return false; + supportsFamilyApple3 = true; #endif + // BC5 is not available for any Apple hardare + if (format == QRhiTexture::BC5) + return false; + + if (!supportsFamilyApple3) { + if (format >= QRhiTexture::ETC2_RGB8 && format <= QRhiTexture::ETC2_RGBA8) + return false; + if (format >= QRhiTexture::ASTC_4x4 && format <= QRhiTexture::ASTC_12x12) + return false; + } + + if (!supportsFamilyMac2) + if (format >= QRhiTexture::BC1 && format <= QRhiTexture::BC7) + return false; + return true; } @@ -638,11 +663,7 @@ int QRhiMetal::resourceLimit(QRhi::ResourceLimit limit) const case QRhi::MaxThreadGroupY: Q_FALLTHROUGH(); case QRhi::MaxThreadGroupZ: -#if defined(Q_OS_MACOS) - return 1024; -#else - return 512; -#endif + return caps.maxThreadGroupSize; case QRhi::TextureArraySizeMax: return 2048; case QRhi::MaxUniformBufferRange: @@ -799,7 +820,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD } res[SUPPORTED_STAGES]; enum { VERTEX = 0, FRAGMENT = 1, COMPUTE = 2 }; - for (const QRhiShaderResourceBinding &binding : qAsConst(srbD->sortedBindings)) { + for (const QRhiShaderResourceBinding &binding : std::as_const(srbD->sortedBindings)) { const QRhiShaderResourceBinding::Data *b = binding.data(); switch (b->type) { case QRhiShaderResourceBinding::UniformBuffer: @@ -941,7 +962,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD return a.nativeBinding < b.nativeBinding; }); - for (const Stage::Buffer &buf : qAsConst(res[stage].buffers)) { + for (const Stage::Buffer &buf : std::as_const(res[stage].buffers)) { res[stage].bufferBatches.feed(buf.nativeBinding, buf.mtlbuf); res[stage].bufferOffsetBatches.feed(buf.nativeBinding, buf.offset); } @@ -985,10 +1006,10 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD return a.nativeBinding < b.nativeBinding; }); - for (const Stage::Texture &t : qAsConst(res[stage].textures)) + for (const Stage::Texture &t : std::as_const(res[stage].textures)) res[stage].textureBatches.feed(t.nativeBinding, t.mtltex); - for (const Stage::Sampler &s : qAsConst(res[stage].samplers)) + for (const Stage::Sampler &s : std::as_const(res[stage].samplers)) res[stage].samplerBatches.feed(s.nativeBinding, s.mtlsampler); res[stage].textureBatches.finish(); @@ -1284,7 +1305,7 @@ void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) // x,y is top-left in MTLViewportRect but bottom-left in QRhiViewport float x, y, w, h; - if (!qrhi_toTopLeftRenderTargetRect(outputSize, viewport.viewport(), &x, &y, &w, &h)) + if (!qrhi_toTopLeftRenderTargetRect<UnBounded>(outputSize, viewport.viewport(), &x, &y, &w, &h)) return; MTLViewport vp; @@ -1299,6 +1320,7 @@ void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport) if (!QRHI_RES(QMetalGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) { MTLScissorRect s; + qrhi_toTopLeftRenderTargetRect<Bounded>(outputSize, viewport.viewport(), &x, &y, &w, &h); s.x = NSUInteger(x); s.y = NSUInteger(y); s.width = NSUInteger(w); @@ -1316,7 +1338,7 @@ void QRhiMetal::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor) // x,y is top-left in MTLScissorRect but bottom-left in QRhiScissor int x, y, w, h; - if (!qrhi_toTopLeftRenderTargetRect(outputSize, scissor.scissor(), &x, &y, &w, &h)) + if (!qrhi_toTopLeftRenderTargetRect<Bounded>(outputSize, scissor.scissor(), &x, &y, &w, &h)) return; MTLScissorRect s; @@ -1457,7 +1479,7 @@ QRhi::FrameOpResult QRhiMetal::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF // commands+present to complete, while for others just for the commands // (for this same frame slot) but not sure how to do that in a sane way so // wait for full cb completion for now. - for (QMetalSwapChain *sc : qAsConst(swapchains)) { + for (QMetalSwapChain *sc : std::as_const(swapchains)) { dispatch_semaphore_t sem = sc->d->sem[swapChainD->currentFrameSlot]; dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); if (sc != swapChainD) @@ -1550,15 +1572,13 @@ QRhi::FrameOpResult QRhiMetal::beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi: Q_UNUSED(flags); currentFrameSlot = (currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT; - if (swapchains.count() > 1) { - for (QMetalSwapChain *sc : qAsConst(swapchains)) { - // wait+signal is the general pattern to ensure the commands for a - // given frame slot have completed (if sem is 1, we go 0 then 1; if - // sem is 0 we go -1, block, completion increments to 0, then us to 1) - dispatch_semaphore_t sem = sc->d->sem[currentFrameSlot]; - dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); - dispatch_semaphore_signal(sem); - } + for (QMetalSwapChain *sc : std::as_const(swapchains)) { + // wait+signal is the general pattern to ensure the commands for a + // given frame slot have completed (if sem is 1, we go 0 then 1; if + // sem is 0 we go -1, block, completion increments to 0, then us to 1) + dispatch_semaphore_t sem = sc->d->sem[currentFrameSlot]; + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + dispatch_semaphore_signal(sem); } d->ofr.active = true; @@ -1605,7 +1625,7 @@ QRhi::FrameOpResult QRhiMetal::finish() } } - for (QMetalSwapChain *sc : qAsConst(swapchains)) { + for (QMetalSwapChain *sc : std::as_const(swapchains)) { for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i) { if (currentSwapChain && sc == currentSwapChain && i == currentFrameSlot) { // no wait as this is the thing we're going to be commit below and @@ -1853,7 +1873,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate qsizetype stagingSize = 0; for (int layer = 0, maxLayer = u.subresDesc.count(); layer < maxLayer; ++layer) { for (int level = 0; level < QRhi::MAX_MIP_LEVELS; ++level) { - for (const QRhiTextureSubresourceUploadDescription &subresDesc : qAsConst(u.subresDesc[layer][level])) + for (const QRhiTextureSubresourceUploadDescription &subresDesc : std::as_const(u.subresDesc[layer][level])) stagingSize += subresUploadByteSize(subresDesc); } } @@ -1867,7 +1887,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate qsizetype curOfs = 0; for (int layer = 0, maxLayer = u.subresDesc.count(); layer < maxLayer; ++layer) { for (int level = 0; level < QRhi::MAX_MIP_LEVELS; ++level) { - for (const QRhiTextureSubresourceUploadDescription &subresDesc : qAsConst(u.subresDesc[layer][level])) + for (const QRhiTextureSubresourceUploadDescription &subresDesc : std::as_const(u.subresDesc[layer][level])) enqueueSubresUpload(utexD, mp, blitEnc, layer, level, subresDesc, &curOfs); } } @@ -1980,7 +2000,7 @@ void QRhiMetal::executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot) void *p = [bufD->d->buf[slot] contents]; int changeBegin = -1; int changeEnd = -1; - for (const QMetalBufferData::BufferUpdate &u : qAsConst(bufD->d->pendingUpdates[slot])) { + for (const QMetalBufferData::BufferUpdate &u : std::as_const(bufD->d->pendingUpdates[slot])) { memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size())); if (changeBegin == -1 || u.offset < changeBegin) changeBegin = u.offset; @@ -2319,8 +2339,10 @@ bool QMetalBuffer::create() d->managed = false; MTLResourceOptions opts = MTLResourceStorageModeShared; + + QRHI_RES_RHI(QRhiMetal); #ifdef Q_OS_MACOS - if (m_type != Dynamic) { + if (!rhiD->caps.isAppleGPU && m_type != Dynamic) { opts = MTLResourceStorageModeManaged; d->managed = true; } @@ -2332,7 +2354,6 @@ bool QMetalBuffer::create() // same buffer is still in flight. d->slotted = !m_usage.testFlag(QRhiBuffer::StorageBuffer); // except for SSBOs written in the shader - QRHI_RES_RHI(QRhiMetal); for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i) { if (i == 0 || d->slotted) { d->buf[i] = [rhiD->d->dev newBufferWithLength: roundedSize options: opts]; @@ -2395,11 +2416,12 @@ void QMetalBuffer::endFullDynamicBufferUpdateForCurrentFrame() #endif } -static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QRhiTexture::Flags flags, const QRhiMetalData *d) +static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QRhiTexture::Flags flags, const QRhiMetal *d) { #ifndef Q_OS_MACOS Q_UNUSED(d); #endif + const bool srgb = flags.testFlag(QRhiTexture::sRGB); switch (format) { case QRhiTexture::RGBA8: @@ -2441,9 +2463,9 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR case QRhiTexture::D16: return MTLPixelFormatDepth16Unorm; case QRhiTexture::D24: - return [d->dev isDepth24Stencil8PixelFormatSupported] ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float; + return [d->d->dev isDepth24Stencil8PixelFormatSupported] ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float; case QRhiTexture::D24S8: - return [d->dev isDepth24Stencil8PixelFormatSupported] ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float_Stencil8; + return [d->d->dev isDepth24Stencil8PixelFormatSupported] ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float_Stencil8; #else case QRhiTexture::D16: return MTLPixelFormatDepth32Float; @@ -2466,7 +2488,7 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR return MTLPixelFormatBC4_RUnorm; case QRhiTexture::BC5: qWarning("QRhiMetal does not support BC5"); - return MTLPixelFormatRGBA8Unorm; + return MTLPixelFormatInvalid; case QRhiTexture::BC6H: return MTLPixelFormatBC6H_RGBUfloat; case QRhiTexture::BC7: @@ -2480,7 +2502,7 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR case QRhiTexture::BC6H: case QRhiTexture::BC7: qWarning("QRhiMetal: BCx compression not supported on this platform"); - return MTLPixelFormatRGBA8Unorm; + return MTLPixelFormatInvalid; #endif #ifndef Q_OS_MACOS @@ -2521,32 +2543,129 @@ static inline MTLPixelFormat toMetalTextureFormat(QRhiTexture::Format format, QR return srgb ? MTLPixelFormatASTC_12x12_sRGB : MTLPixelFormatASTC_12x12_LDR; #else case QRhiTexture::ETC2_RGB8: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatETC2_RGB8_sRGB : MTLPixelFormatETC2_RGB8; + } + qWarning("QRhiMetal: ETC2 compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ETC2_RGB8A1: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatETC2_RGB8A1_sRGB : MTLPixelFormatETC2_RGB8A1; + } + qWarning("QRhiMetal: ETC2 compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ETC2_RGBA8: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatEAC_RGBA8_sRGB : MTLPixelFormatEAC_RGBA8; + } qWarning("QRhiMetal: ETC2 compression not supported on this platform"); - return MTLPixelFormatRGBA8Unorm; - + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_4x4: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_4x4_sRGB : MTLPixelFormatASTC_4x4_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_5x4: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_5x4_sRGB : MTLPixelFormatASTC_5x4_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_5x5: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_5x5_sRGB : MTLPixelFormatASTC_5x5_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_6x5: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_6x5_sRGB : MTLPixelFormatASTC_6x5_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_6x6: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_6x6_sRGB : MTLPixelFormatASTC_6x6_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_8x5: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_8x5_sRGB : MTLPixelFormatASTC_8x5_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_8x6: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_8x6_sRGB : MTLPixelFormatASTC_8x6_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_8x8: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_8x8_sRGB : MTLPixelFormatASTC_8x8_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_10x5: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_10x5_sRGB : MTLPixelFormatASTC_10x5_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_10x6: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_10x6_sRGB : MTLPixelFormatASTC_10x6_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_10x8: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_10x8_sRGB : MTLPixelFormatASTC_10x8_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_10x10: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_10x10_sRGB : MTLPixelFormatASTC_10x10_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_12x10: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_12x10_sRGB : MTLPixelFormatASTC_12x10_LDR; + } + qWarning("QRhiMetal: ASTC compression not supported on this platform"); + return MTLPixelFormatInvalid; case QRhiTexture::ASTC_12x12: + if (d->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) + return srgb ? MTLPixelFormatASTC_12x12_sRGB : MTLPixelFormatASTC_12x12_LDR; + } qWarning("QRhiMetal: ASTC compression not supported on this platform"); - return MTLPixelFormatRGBA8Unorm; + return MTLPixelFormatInvalid; #endif default: Q_UNREACHABLE(); - return MTLPixelFormatRGBA8Unorm; + return MTLPixelFormatInvalid; } } @@ -2606,9 +2725,18 @@ bool QMetalRenderBuffer::create() switch (m_type) { case DepthStencil: #ifdef Q_OS_MACOS - desc.storageMode = MTLStorageModePrivate; - d->format = rhiD->d->dev.depth24Stencil8PixelFormatSupported - ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float_Stencil8; + if (rhiD->caps.isAppleGPU) { + if (@available(macOS 11.0, *)) { + desc.storageMode = MTLStorageModeMemoryless; + d->format = MTLPixelFormatDepth32Float_Stencil8; + } else { + Q_UNREACHABLE(); + } + } else { + desc.storageMode = MTLStorageModePrivate; + d->format = rhiD->d->dev.depth24Stencil8PixelFormatSupported + ? MTLPixelFormatDepth24Unorm_Stencil8 : MTLPixelFormatDepth32Float_Stencil8; + } #else desc.storageMode = MTLStorageModeMemoryless; d->format = MTLPixelFormatDepth32Float_Stencil8; @@ -2618,7 +2746,7 @@ bool QMetalRenderBuffer::create() case Color: desc.storageMode = MTLStorageModePrivate; if (m_backingFormatHint != QRhiTexture::UnknownFormat) - d->format = toMetalTextureFormat(m_backingFormatHint, {}, rhiD->d); + d->format = toMetalTextureFormat(m_backingFormatHint, {}, rhiD); else d->format = MTLPixelFormatRGBA8Unorm; desc.pixelFormat = d->format; @@ -2707,7 +2835,7 @@ bool QMetalTexture::prepareCreate(QSize *adjustedSize) const bool hasMipMaps = m_flags.testFlag(MipMapped); QRHI_RES_RHI(QRhiMetal); - d->format = toMetalTextureFormat(m_format, m_flags, rhiD->d); + d->format = toMetalTextureFormat(m_format, m_flags, rhiD); mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1; samples = rhiD->effectiveSampleCount(m_sampleCount); if (samples > 1) { @@ -3594,10 +3722,7 @@ id<MTLLibrary> QRhiMetalData::createMetalLib(const QShader &shader, QShader::Var id<MTLFunction> QRhiMetalData::createMSLShaderFunction(id<MTLLibrary> lib, const QByteArray &entryPoint) { - NSString *name = [NSString stringWithUTF8String: entryPoint.constData()]; - id<MTLFunction> f = [lib newFunctionWithName: name]; - [name release]; - return f; + return [lib newFunctionWithName:[NSString stringWithUTF8String:entryPoint.constData()]]; } bool QMetalGraphicsPipeline::create() @@ -3642,7 +3767,7 @@ bool QMetalGraphicsPipeline::create() // descriptor for each buffer combination as this depends on the actual // buffers not just the resource binding layout) so leave it at the default - for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) { + for (const QRhiShaderStage &shaderStage : std::as_const(m_shaderStages)) { auto cacheIt = rhiD->d->shaderCache.constFind(shaderStage); if (cacheIt != rhiD->d->shaderCache.constEnd()) { switch (shaderStage.type()) { @@ -3741,7 +3866,7 @@ bool QMetalGraphicsPipeline::create() // validation blows up otherwise. MTLPixelFormat fmt = MTLPixelFormat(rpD->dsFormat); rpDesc.depthAttachmentPixelFormat = fmt; -#ifdef Q_OS_MACOS +#if defined(Q_OS_MACOS) if (fmt != MTLPixelFormatDepth16Unorm && fmt != MTLPixelFormatDepth32Float) #else if (fmt != MTLPixelFormatDepth32Float) @@ -4040,8 +4165,7 @@ QSize QMetalSwapChain::surfacePixelSize() bool QMetalSwapChain::isFormatSupported(Format f) { #ifdef Q_OS_MACOS - if (@available(macOS 10.12, /*iOS 10.0,*/ *)) - return f == SDR || f == HDRExtendedSrgbLinear; + return f == SDR || f == HDRExtendedSrgbLinear; #endif return f == SDR; } @@ -4075,11 +4199,9 @@ void QMetalSwapChain::chooseFormats() samples = rhiD->effectiveSampleCount(m_sampleCount); // pick a format that is allowed for CAMetalLayer.pixelFormat if (m_format == HDRExtendedSrgbLinear) { - if (@available(macOS 10.12, /*iOS 10.0,*/ *)) { - d->colorFormat = MTLPixelFormatRGBA16Float; - d->rhiColorFormat = QRhiTexture::RGBA16F; - return; - } + d->colorFormat = MTLPixelFormatRGBA16Float; + d->rhiColorFormat = QRhiTexture::RGBA16F; + return; } d->colorFormat = m_flags.testFlag(sRGB) ? MTLPixelFormatBGRA8Unorm_sRGB : MTLPixelFormatBGRA8Unorm; d->rhiColorFormat = QRhiTexture::BGRA8; @@ -4113,11 +4235,10 @@ bool QMetalSwapChain::createOrResize() if (d->colorFormat != d->layer.pixelFormat) d->layer.pixelFormat = d->colorFormat; #ifdef Q_OS_MACOS - if (@available(macOS 10.12, /*iOS 10.0,*/ *)) { // Can't enable this on iOS until wantsExtendedDynamicRangeContent is available - if (m_format == HDRExtendedSrgbLinear) { - d->layer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB); - d->layer.wantsExtendedDynamicRangeContent = YES; - } + // Can't enable this on iOS until wantsExtendedDynamicRangeContent is available + if (m_format == HDRExtendedSrgbLinear) { + d->layer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB); + d->layer.wantsExtendedDynamicRangeContent = YES; } #endif |