From d929cbea9243588c4ea8e2071d4a5786d57e98b2 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Mon, 11 Nov 2024 19:24:09 -0800 Subject: [PATCH] Metal: unbind descriptor sets upon destruction --- filament/backend/src/metal/MetalDriver.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index 8e49c90dd7d4..10b242ec7d1e 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -872,6 +872,15 @@ void MetalDriver::destroyDescriptorSet(Handle dsh) { DEBUG_LOG("destroyDescriptorSet(dsh = %d)\n", dsh.getId()); + + // Unbind this descriptor set. + auto* descriptorSet = handle_cast(dsh); + for (size_t i = 0; i < MAX_DESCRIPTOR_SET_COUNT; i++) { + if (UTILS_UNLIKELY(mContext->currentDescriptorSets[i] == descriptorSet)) { + mContext->currentDescriptorSets[i] = nullptr; + } + } + if (dsh) { executeAfterCurrentCommandBufferCompletes( [this, dsh]() mutable { destruct_handle(dsh); });