Merge "rhi: metal: Remove most availability guards"
This commit is contained in:
commit
0bd705d91b
@ -211,8 +211,8 @@ struct QRhiMetalData
|
|||||||
};
|
};
|
||||||
QVarLengthArray<TextureReadback, 2> activeTextureReadbacks;
|
QVarLengthArray<TextureReadback, 2> activeTextureReadbacks;
|
||||||
|
|
||||||
API_AVAILABLE(macos(10.13), ios(11.0)) MTLCaptureManager *captureMgr;
|
MTLCaptureManager *captureMgr;
|
||||||
API_AVAILABLE(macos(10.13), ios(11.0)) id<MTLCaptureScope> captureScope = nil;
|
id<MTLCaptureScope> captureScope = nil;
|
||||||
|
|
||||||
static const int TEXBUF_ALIGN = 256; // probably not accurate
|
static const int TEXBUF_ALIGN = 256; // probably not accurate
|
||||||
|
|
||||||
@ -319,13 +319,7 @@ struct QMetalComputePipelineData
|
|||||||
|
|
||||||
struct QMetalSwapChainData
|
struct QMetalSwapChainData
|
||||||
{
|
{
|
||||||
// The iOS simulator's headers mark CAMetalLayer as iOS 13.0+ only.
|
|
||||||
// (for real device SDKs it is 8.0+)
|
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
API_AVAILABLE(ios(13.0)) CAMetalLayer *layer = nullptr;
|
|
||||||
#else
|
|
||||||
CAMetalLayer *layer = nullptr;
|
CAMetalLayer *layer = nullptr;
|
||||||
#endif
|
|
||||||
id<CAMetalDrawable> curDrawable = nil;
|
id<CAMetalDrawable> curDrawable = nil;
|
||||||
dispatch_semaphore_t sem[QMTL_FRAMES_IN_FLIGHT];
|
dispatch_semaphore_t sem[QMTL_FRAMES_IN_FLIGHT];
|
||||||
MTLRenderPassDescriptor *rp = nullptr;
|
MTLRenderPassDescriptor *rp = nullptr;
|
||||||
@ -409,15 +403,13 @@ bool QRhiMetal::create(QRhi::Flags flags)
|
|||||||
else
|
else
|
||||||
d->cmdQueue = [d->dev newCommandQueue];
|
d->cmdQueue = [d->dev newCommandQueue];
|
||||||
|
|
||||||
if (@available(macOS 10.13, iOS 11.0, *)) {
|
d->captureMgr = [MTLCaptureManager sharedCaptureManager];
|
||||||
d->captureMgr = [MTLCaptureManager sharedCaptureManager];
|
// Have a custom capture scope as well which then shows up in XCode as
|
||||||
// Have a custom capture scope as well which then shows up in XCode as
|
// an option when capturing, and becomes especially useful when having
|
||||||
// an option when capturing, and becomes especially useful when having
|
// multiple windows with multiple QRhis.
|
||||||
// multiple windows with multiple QRhis.
|
d->captureScope = [d->captureMgr newCaptureScopeWithCommandQueue: d->cmdQueue];
|
||||||
d->captureScope = [d->captureMgr newCaptureScopeWithCommandQueue: d->cmdQueue];
|
const QString label = QString::asprintf("Qt capture scope for QRhi %p", this);
|
||||||
const QString label = QString::asprintf("Qt capture scope for QRhi %p", this);
|
d->captureScope.label = label.toNSString();
|
||||||
d->captureScope.label = label.toNSString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
caps.maxTextureSize = 16384;
|
caps.maxTextureSize = 16384;
|
||||||
@ -457,10 +449,8 @@ void QRhiMetal::destroy()
|
|||||||
s.destroy();
|
s.destroy();
|
||||||
d->shaderCache.clear();
|
d->shaderCache.clear();
|
||||||
|
|
||||||
if (@available(macOS 10.13, iOS 11.0, *)) {
|
[d->captureScope release];
|
||||||
[d->captureScope release];
|
d->captureScope = nil;
|
||||||
d->captureScope = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
[d->cmdQueue release];
|
[d->cmdQueue release];
|
||||||
if (!importedCmdQueue)
|
if (!importedCmdQueue)
|
||||||
@ -1350,12 +1340,10 @@ void QRhiMetal::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)
|
|||||||
|
|
||||||
NSString *str = [NSString stringWithUTF8String: name.constData()];
|
NSString *str = [NSString stringWithUTF8String: name.constData()];
|
||||||
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
|
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
|
||||||
if (cbD->recordingPass != QMetalCommandBuffer::NoPass) {
|
if (cbD->recordingPass != QMetalCommandBuffer::NoPass)
|
||||||
[cbD->d->currentRenderPassEncoder pushDebugGroup: str];
|
[cbD->d->currentRenderPassEncoder pushDebugGroup: str];
|
||||||
} else {
|
else
|
||||||
if (@available(macOS 10.13, iOS 11.0, *))
|
[cbD->d->cb pushDebugGroup: str];
|
||||||
[cbD->d->cb pushDebugGroup: str];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QRhiMetal::debugMarkEnd(QRhiCommandBuffer *cb)
|
void QRhiMetal::debugMarkEnd(QRhiCommandBuffer *cb)
|
||||||
@ -1364,12 +1352,10 @@ void QRhiMetal::debugMarkEnd(QRhiCommandBuffer *cb)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
|
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
|
||||||
if (cbD->recordingPass != QMetalCommandBuffer::NoPass) {
|
if (cbD->recordingPass != QMetalCommandBuffer::NoPass)
|
||||||
[cbD->d->currentRenderPassEncoder popDebugGroup];
|
[cbD->d->currentRenderPassEncoder popDebugGroup];
|
||||||
} else {
|
else
|
||||||
if (@available(macOS 10.13, iOS 11.0, *))
|
[cbD->d->cb popDebugGroup];
|
||||||
[cbD->d->cb popDebugGroup];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QRhiMetal::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
|
void QRhiMetal::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
|
||||||
@ -1420,8 +1406,7 @@ QRhi::FrameOpResult QRhiMetal::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF
|
|||||||
if (swapChainD->ds)
|
if (swapChainD->ds)
|
||||||
swapChainD->ds->lastActiveFrameSlot = currentFrameSlot;
|
swapChainD->ds->lastActiveFrameSlot = currentFrameSlot;
|
||||||
|
|
||||||
if (@available(macOS 10.13, iOS 11.0, *))
|
[d->captureScope beginScope];
|
||||||
[d->captureScope beginScope];
|
|
||||||
|
|
||||||
// Do not let the command buffer mess with the refcount of objects. We do
|
// Do not let the command buffer mess with the refcount of objects. We do
|
||||||
// have a proper render loop and will manage lifetimes similarly to other
|
// have a proper render loop and will manage lifetimes similarly to other
|
||||||
@ -1478,8 +1463,7 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
|
|||||||
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
|
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
|
||||||
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount + 1));
|
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount + 1));
|
||||||
|
|
||||||
if (@available(macOS 10.13, iOS 11.0, *))
|
[d->captureScope endScope];
|
||||||
[d->captureScope endScope];
|
|
||||||
|
|
||||||
if (needsPresent)
|
if (needsPresent)
|
||||||
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT;
|
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT;
|
||||||
@ -1974,10 +1958,7 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb,
|
|||||||
QMetalSwapChain *swapChainD = QRHI_RES(QMetalSwapChain, currentSwapChain);
|
QMetalSwapChain *swapChainD = QRHI_RES(QMetalSwapChain, currentSwapChain);
|
||||||
if (!swapChainD->d->curDrawable) {
|
if (!swapChainD->d->curDrawable) {
|
||||||
QMacAutoReleasePool pool;
|
QMacAutoReleasePool pool;
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
swapChainD->d->curDrawable = [[swapChainD->d->layer nextDrawable] retain];
|
||||||
if (@available(ios 13.0, *))
|
|
||||||
#endif
|
|
||||||
swapChainD->d->curDrawable = [[swapChainD->d->layer nextDrawable] retain];
|
|
||||||
}
|
}
|
||||||
if (!swapChainD->d->curDrawable) {
|
if (!swapChainD->d->curDrawable) {
|
||||||
qWarning("No drawable");
|
qWarning("No drawable");
|
||||||
@ -3170,10 +3151,7 @@ static inline MTLVertexFormat toMetalAttributeFormat(QRhiVertexInputAttribute::F
|
|||||||
case QRhiVertexInputAttribute::UNormByte2:
|
case QRhiVertexInputAttribute::UNormByte2:
|
||||||
return MTLVertexFormatUChar2Normalized;
|
return MTLVertexFormatUChar2Normalized;
|
||||||
case QRhiVertexInputAttribute::UNormByte:
|
case QRhiVertexInputAttribute::UNormByte:
|
||||||
if (@available(macOS 10.13, iOS 11.0, *))
|
return MTLVertexFormatUCharNormalized;
|
||||||
return MTLVertexFormatUCharNormalized;
|
|
||||||
else
|
|
||||||
Q_UNREACHABLE();
|
|
||||||
case QRhiVertexInputAttribute::UInt4:
|
case QRhiVertexInputAttribute::UInt4:
|
||||||
return MTLVertexFormatUInt4;
|
return MTLVertexFormatUInt4;
|
||||||
case QRhiVertexInputAttribute::UInt3:
|
case QRhiVertexInputAttribute::UInt3:
|
||||||
@ -3795,10 +3773,6 @@ QMetalSwapChain::~QMetalSwapChain()
|
|||||||
|
|
||||||
void QMetalSwapChain::destroy()
|
void QMetalSwapChain::destroy()
|
||||||
{
|
{
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
if (@available(ios 13.0, *)) {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!d->layer)
|
if (!d->layer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -3830,10 +3804,6 @@ void QMetalSwapChain::destroy()
|
|||||||
QRHI_PROF_F(releaseSwapChain(this));
|
QRHI_PROF_F(releaseSwapChain(this));
|
||||||
|
|
||||||
rhiD->unregisterResource(this);
|
rhiD->unregisterResource(this);
|
||||||
|
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiCommandBuffer *QMetalSwapChain::currentFrameCommandBuffer()
|
QRhiCommandBuffer *QMetalSwapChain::currentFrameCommandBuffer()
|
||||||
@ -3846,9 +3816,6 @@ QRhiRenderTarget *QMetalSwapChain::currentFrameRenderTarget()
|
|||||||
return &rtWrapper;
|
return &rtWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
API_AVAILABLE(ios(13.0))
|
|
||||||
#endif
|
|
||||||
static inline CAMetalLayer *layerForWindow(QWindow *window)
|
static inline CAMetalLayer *layerForWindow(QWindow *window)
|
||||||
{
|
{
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
@ -3863,10 +3830,6 @@ static inline CAMetalLayer *layerForWindow(QWindow *window)
|
|||||||
|
|
||||||
QSize QMetalSwapChain::surfacePixelSize()
|
QSize QMetalSwapChain::surfacePixelSize()
|
||||||
{
|
{
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
if (@available(ios 13.0, *)) {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Q_ASSERT(m_window);
|
Q_ASSERT(m_window);
|
||||||
CAMetalLayer *layer = d->layer;
|
CAMetalLayer *layer = d->layer;
|
||||||
if (!layer)
|
if (!layer)
|
||||||
@ -3876,12 +3839,6 @@ QSize QMetalSwapChain::surfacePixelSize()
|
|||||||
layerSize.width *= layer.contentsScale;
|
layerSize.width *= layer.contentsScale;
|
||||||
layerSize.height *= layer.contentsScale;
|
layerSize.height *= layer.contentsScale;
|
||||||
return QSizeF::fromCGSize(layerSize).toSize();
|
return QSizeF::fromCGSize(layerSize).toSize();
|
||||||
|
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
} else {
|
|
||||||
return QSize();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor()
|
QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor()
|
||||||
@ -3917,10 +3874,6 @@ void QMetalSwapChain::chooseFormats()
|
|||||||
|
|
||||||
bool QMetalSwapChain::createOrResize()
|
bool QMetalSwapChain::createOrResize()
|
||||||
{
|
{
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
if (@available(ios 13.0, *)) {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Q_ASSERT(m_window);
|
Q_ASSERT(m_window);
|
||||||
|
|
||||||
const bool needsRegistration = !window || window != m_window;
|
const bool needsRegistration = !window || window != m_window;
|
||||||
@ -3951,10 +3904,8 @@ bool QMetalSwapChain::createOrResize()
|
|||||||
d->layer.framebufferOnly = NO;
|
d->layer.framebufferOnly = NO;
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
if (m_flags.testFlag(NoVSync)) {
|
if (m_flags.testFlag(NoVSync))
|
||||||
if (@available(macOS 10.13, *))
|
d->layer.displaySyncEnabled = NO;
|
||||||
d->layer.displaySyncEnabled = NO;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m_flags.testFlag(SurfaceHasPreMulAlpha)) {
|
if (m_flags.testFlag(SurfaceHasPreMulAlpha)) {
|
||||||
@ -4043,15 +3994,6 @@ bool QMetalSwapChain::createOrResize()
|
|||||||
rhiD->registerResource(this);
|
rhiD->registerResource(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#ifdef TARGET_IPHONE_SIMULATOR
|
|
||||||
} else {
|
|
||||||
// Won't ever get here in a normal app because MTLDevice creation would
|
|
||||||
// fail too. Print a warning, just in case.
|
|
||||||
qWarning("No CAMetalLayer support in this version of the iOS Simulator");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user