diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 8aa83438..df50cc2d 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -22,6 +22,7 @@ Released TBD - Support base vertex instance support in shader conversion. - Fix alignment between outputs and inputs between shader stages when using nested structures. - Fix issue where the depth component of a stencil-only renderpass attachment was incorrectly attempting to be stored. +- Fix deletion of GPU counter `MTLFence` while it is being used by `MTLCommandBuffer`. - `MoltenVKShaderConverter` tool defaults to the highest MSL version supported on runtime OS. - Update *glslang* version, to use `python3` in *glslang* scripts, to replace missing `python` on *macOS 12.3*. - Update to latest SPIRV-Cross: diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h index 80f433e7..7a38e67f 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h +++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h @@ -29,7 +29,6 @@ #include class MVKCommandPool; -class MVKQueue; class MVKQueueCommandBufferSubmission; class MVKCommandEncoder; class MVKCommandEncodingPool; @@ -492,8 +491,6 @@ public: MVKCommandEncoder(MVKCommandBuffer* cmdBuffer); - ~MVKCommandEncoder() override; - protected: void addActivatedQueries(MVKQueryPool* pQueryPool, uint32_t query, uint32_t queryCount); void finishQueries(); diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm index 9d4a5f70..ac7124b2 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm @@ -830,7 +830,14 @@ void MVKCommandEncoder::encodeTimestampStageCounterSamples() {} #endif id MVKCommandEncoder::getStageCountersMTLFence() { - if ( !_stageCountersMTLFence ) { _stageCountersMTLFence = [getMTLDevice() newFence]; } //retained + if ( !_stageCountersMTLFence ) { + // Create MTLFence as local ref and pass to completion handler + // block to release once MTLCommandBuffer no longer needs it. + id mtlFence = [getMTLDevice() newFence]; + [_mtlCmdBuffer addCompletedHandler: ^(id mcb) { [mtlFence release]; }]; + + _stageCountersMTLFence = mtlFence; // retained + } return _stageCountersMTLFence; } @@ -899,10 +906,6 @@ MVKCommandEncoder::MVKCommandEncoder(MVKCommandBuffer* cmdBuffer) : MVKBaseDevic _stageCountersMTLFence = nil; } -MVKCommandEncoder::~MVKCommandEncoder() { - [_stageCountersMTLFence release]; -} - #pragma mark - #pragma mark Support functions