rhi: metal: Disable MTLBinaryArchive usage regardless of OS version

Ironically enough when the old macOS 13 problem is no longer occurring
(at least on an M1 Mini with 13.2.1), so the OS version based
differentiation could likely be removed, there are now reports about
problems with old Intel hardware and earlier OS versions.

Therefore, get rid of the OS version based logic, and rather add
a global flag that is enabled unconditionally for now, which
disables MTLBinaryArchive usage altogether.

How much we lose is not very clear anyway. The OS performs its
own persistent caching (most likely), hidden from applications.
Thus what we lose really is the fine grained control over the
data (e.g. specifying a custom storage file via
QQuickGraphicsConfiguration), with the possibility of pre-seeding
for the first run. As the performance of subsequent runs is less
likely to change in any significant way, this is seen as not
a big deal for Apple hardware in general so we might just live
with this. (and on macOS 13+ this was already crippled anyway
due to the OS version logic)

Fixes: QTBUG-114338
Task-number: QTBUG-108216
Change-Id: If7b908baea2093f6882674ebfbdc18e770d6503e
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit fa96e76ab124965f3112ae63298c69782b1bb311)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Laszlo Agocs 2023-07-12 10:36:15 +02:00 committed by Qt Cherry-pick Bot
parent d3d8a717fd
commit 095bfbd3e4

View File

@ -40,6 +40,14 @@ QT_BEGIN_NAMESPACE
#error ARC not supported #error ARC not supported
#endif #endif
// Even though the macOS 13 MTLBinaryArchive problem (QTBUG-106703) seems
// to be solved in later 13.x releases, we have reports from old Intel hardware
// and older macOS versions where this causes problems (QTBUG-114338).
// Thus we no longer do OS version based differentiation, but rather have a
// single toggle that is currently on, and so QRhi::(set)pipelineCache()
// does nothing with Metal.
#define QRHI_METAL_DISABLE_BINARY_ARCHIVE
/*! /*!
\class QRhiMetalInitParams \class QRhiMetalInitParams
\inmodule QtRhi \inmodule QtRhi
@ -151,7 +159,6 @@ struct QRhiMetalData
id<MTLDevice> dev = nil; id<MTLDevice> dev = nil;
id<MTLCommandQueue> cmdQueue = nil; id<MTLCommandQueue> cmdQueue = nil;
API_AVAILABLE(macosx(11.0), ios(14.0)) id<MTLBinaryArchive> binArch = nil; API_AVAILABLE(macosx(11.0), ios(14.0)) id<MTLBinaryArchive> binArch = nil;
bool binArchWasEmpty = false;
MTLRenderPassDescriptor *createDefaultRenderPass(bool hasDepthStencil, MTLRenderPassDescriptor *createDefaultRenderPass(bool hasDepthStencil,
const QColor &colorClearValue, const QColor &colorClearValue,
@ -489,6 +496,10 @@ bool QRhiMetal::probe(QRhiMetalInitParams *params)
bool QRhiMetalData::setupBinaryArchive(NSURL *sourceFileUrl) bool QRhiMetalData::setupBinaryArchive(NSURL *sourceFileUrl)
{ {
#ifdef QRHI_METAL_DISABLE_BINARY_ARCHIVE
return false;
#endif
if (@available(macOS 11.0, iOS 14.0, *)) { if (@available(macOS 11.0, iOS 14.0, *)) {
[binArch release]; [binArch release];
MTLBinaryArchiveDescriptor *binArchDesc = [MTLBinaryArchiveDescriptor new]; MTLBinaryArchiveDescriptor *binArchDesc = [MTLBinaryArchiveDescriptor new];
@ -501,7 +512,6 @@ bool QRhiMetalData::setupBinaryArchive(NSURL *sourceFileUrl)
qWarning("newBinaryArchiveWithDescriptor failed: %s", qPrintable(msg)); qWarning("newBinaryArchiveWithDescriptor failed: %s", qPrintable(msg));
return false; return false;
} }
binArchWasEmpty = sourceFileUrl == nil;
return true; return true;
} }
return false; return false;
@ -4812,33 +4822,10 @@ void QRhiMetalData::trySeedingRenderPipelineFromBinaryArchive(MTLRenderPipelineD
} }
} }
static bool canAddToBinaryArchive(QRhiMetalData *d)
{
if (@available(macOS 11.0, iOS 14.0, *)) {
if (!d->binArch)
return false;
// ### QTBUG-106703, QTBUG-108216, revisit after 13.0
if (!d->binArchWasEmpty && d->q->osMajor >= 13) {
static bool logPrinted = false;
if (!logPrinted) {
logPrinted = true;
qCDebug(QRHI_LOG_INFO, "Skipping adding more pipelines to MTLBinaryArchive on this OS version (%d.%d) due to known issues.",
d->q->osMajor, d->q->osMinor);
}
return false;
}
return true;
} else {
return false;
}
}
void QRhiMetalData::addRenderPipelineToBinaryArchive(MTLRenderPipelineDescriptor *rpDesc) void QRhiMetalData::addRenderPipelineToBinaryArchive(MTLRenderPipelineDescriptor *rpDesc)
{ {
if (@available(macOS 11.0, iOS 14.0, *)) { if (@available(macOS 11.0, iOS 14.0, *)) {
if (canAddToBinaryArchive(this)) { if (binArch) {
NSError *err = nil; NSError *err = nil;
if (![binArch addRenderPipelineFunctionsWithDescriptor: rpDesc error: &err]) { if (![binArch addRenderPipelineFunctionsWithDescriptor: rpDesc error: &err]) {
const QString msg = QString::fromNSString(err.localizedDescription); const QString msg = QString::fromNSString(err.localizedDescription);
@ -5818,7 +5805,7 @@ void QRhiMetalData::trySeedingComputePipelineFromBinaryArchive(MTLComputePipelin
void QRhiMetalData::addComputePipelineToBinaryArchive(MTLComputePipelineDescriptor *cpDesc) void QRhiMetalData::addComputePipelineToBinaryArchive(MTLComputePipelineDescriptor *cpDesc)
{ {
if (@available(macOS 11.0, iOS 14.0, *)) { if (@available(macOS 11.0, iOS 14.0, *)) {
if (canAddToBinaryArchive(this)) { if (binArch) {
NSError *err = nil; NSError *err = nil;
if (![binArch addComputePipelineFunctionsWithDescriptor: cpDesc error: &err]) { if (![binArch addComputePipelineFunctionsWithDescriptor: cpDesc error: &err]) {
const QString msg = QString::fromNSString(err.localizedDescription); const QString msg = QString::fromNSString(err.localizedDescription);