From 954862c62232b8860f7caa0ff340433818530b71 Mon Sep 17 00:00:00 2001 From: Evan Tang Date: Thu, 5 Dec 2024 10:58:44 -0600 Subject: [PATCH] Work around 10.15 AMD driver's broken blit encoder timestamp sampling --- MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm | 3 +++ MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm index 25021c667..f79cf62df 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm @@ -1012,6 +1012,9 @@ } } else if (mvkIsAnyFlagEnabled(samplingPoints, MVK_COUNTER_SAMPLING_AT_BLIT)) { [getMTLBlitEncoder(kMVKCommandUseRecordGPUCounterSample) sampleCountersInBuffer: mvkQryPool->getMTLCounterBuffer() atSampleIndex: sampleIndex withBarrier: YES]; + } else if (mvkIsAnyFlagEnabled(samplingPoints, MVK_COUNTER_SAMPLING_AT_DISPATCH)) { + // Workaround for broken 10.15 AMD driver which crashes if you try to record to an empty blit encoder + [getMTLComputeEncoder(kMVKCommandUseRecordGPUCounterSample) sampleCountersInBuffer: mvkQryPool->getMTLCounterBuffer() atSampleIndex: sampleIndex withBarrier: YES]; } } diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 15d8caaf3..c8ec8ebe7 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -2492,8 +2492,12 @@ #if MVK_MACOS // On macOS, if we couldn't query supported sample points (on macOS 11), // but the platform can support immediate-mode sample points, indicate that here. - if (!_metalFeatures.counterSamplingPoints && mvkOSVersionIsAtLeast(10.15) && !supportsMTLGPUFamily(Apple1)) { \ - _metalFeatures.counterSamplingPoints = MVK_COUNTER_SAMPLING_AT_DRAW | MVK_COUNTER_SAMPLING_AT_DISPATCH | MVK_COUNTER_SAMPLING_AT_BLIT; \ + if (!_metalFeatures.counterSamplingPoints && mvkOSVersionIsAtLeast(10.15) && !supportsMTLGPUFamily(Apple1)) { + _metalFeatures.counterSamplingPoints = MVK_COUNTER_SAMPLING_AT_DRAW | MVK_COUNTER_SAMPLING_AT_DISPATCH | MVK_COUNTER_SAMPLING_AT_BLIT; + } + // The macOS 10.15 AMD Metal driver crashes if you attempt to sample on an empty blit encoder + if ((_metalFeatures.counterSamplingPoints & MVK_COUNTER_SAMPLING_AT_BLIT) && _properties.vendorID == kAMDVendorId && !mvkOSVersionIsAtLeast(11)) { + _metalFeatures.counterSamplingPoints &= ~MVK_COUNTER_SAMPLING_AT_BLIT; } #endif