Merge pull request #1645 from billhollings/counterset-crash-on-intel-iris
Work around MTLCounterSet crash on additional Intel Iris Plus Graphics drivers
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index f432400..1b81ed6 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -24,6 +24,7 @@
- Reducing redundant state changes to improve command encoding performance.
- Update minimum Xcode deployment targets to macOS 10.13, iOS 11, and tvOS 11,
to avoid Xcode build warnings in Xcode 14.
+- Work around MTLCounterSet crash on additional Intel Iris Plus Graphics drivers.
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
index 7de4a79..f7bc5ac 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
@@ -393,6 +393,7 @@
void initExternalMemoryProperties();
void initExtensions();
void initCounterSets();
+ bool needsCounterSetRetained();
MVKArrayRef<MVKQueueFamily*> getQueueFamilies();
void initPipelineCacheUUID();
uint32_t getHighestGPUCapability();
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
index b773d0a..1195cb9 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
@@ -2856,12 +2856,7 @@
if (_metalFeatures.counterSamplingPoints) {
NSArray<id<MTLCounterSet>>* counterSets = _mtlDevice.counterSets;
- // Workaround for a bug in Intel Iris Plus Graphics driver where the counterSets
- // array is not properly retained internally, and becomes a zombie when counterSets
- // is called more than once, which occurs when an app creates more than one VkInstance.
- // This workaround will cause a very small memory leak on systems that do not have this
- // bug, so we apply the workaround only when absolutely needed for specific devices.
- if (_properties.vendorID == kIntelVendorId && _properties.deviceID == 0x8a53) { [counterSets retain]; }
+ if (needsCounterSetRetained()) { [counterSets retain]; }
for (id<MTLCounterSet> cs in counterSets){
NSString* csName = cs.name;
@@ -2880,6 +2875,27 @@
}
}
+// Workaround for a bug in Intel Iris Plus Graphics driver where the counterSets array is
+// not properly retained internally, and becomes a zombie when counterSets is called more
+// than once, which occurs when an app creates more than one VkInstance. This workaround
+// will cause a very small memory leak on systems that do not have this bug, so we apply
+// the workaround only when absolutely needed for specific devices. The list of deviceIDs
+// is sourced from the list of Intel Iris Plus Graphics Gen11 tier G7 devices found here:
+// https://en.wikipedia.org/wiki/List_of_Intel_graphics_processing_units#Gen11
+bool MVKPhysicalDevice::needsCounterSetRetained() {
+
+ if (_properties.vendorID != kIntelVendorId) { return false; }
+
+ switch (_properties.deviceID) {
+ case 0x8a51:
+ case 0x8a52:
+ case 0x8a53:
+ return true;
+ default:
+ return false;
+ }
+}
+
void MVKPhysicalDevice::logGPUInfo() {
string devTypeStr;
switch (_properties.deviceType) {