From 4ff504b52de0dd295a45aa146cce108517359bd8 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 5 Jul 2022 13:59:35 +0200 Subject: [PATCH] vkd3d: Match native runtime better in command allocator reset. Even when misusing the API, S_OK is still returned on native runtimes. Keep the error log, and add an error report to command allocator release if there are still pending submissions. Signed-off-by: Hans-Kristian Arntzen --- libs/vkd3d/command.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 83777f14..473451e9 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -1700,6 +1700,7 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo struct d3d12_command_allocator *allocator = impl_from_ID3D12CommandAllocator(iface); ULONG refcount = InterlockedDecrement(&allocator->refcount); unsigned int i, j; + LONG pending; TRACE("%p decreasing refcount to %u.\n", allocator, refcount); @@ -1710,6 +1711,13 @@ static ULONG STDMETHODCALLTYPE d3d12_command_allocator_Release(ID3D12CommandAllo vkd3d_private_store_destroy(&allocator->private_store); + if ((pending = vkd3d_atomic_uint32_load_explicit(&allocator->outstanding_submissions_count, vkd3d_memory_order_acquire)) != 0) + { + /* Nothing we can do about this other than report the error. Might find some game bugs! */ + ERR("Attempting to free command allocator, but there are still %u pending submissions!\n", + (unsigned int)allocator->outstanding_submissions_count); + } + if (allocator->current_command_list) d3d12_command_list_allocator_destroyed(allocator->current_command_list); @@ -1856,11 +1864,12 @@ static HRESULT STDMETHODCALLTYPE d3d12_command_allocator_Reset(ID3D12CommandAllo * however, this is enough to workaround SotTR which resets the command list right * after calling ID3D12CommandQueue::ExecuteCommandLists(). * Only happens once or twice on bootup and doesn't cause memory leaks over time - * since the command pool is eventually reset. - * Game does not seem to care if E_FAIL is returned, which is the correct thing to do here. */ + * since the command pool is eventually reset. */ + + /* Runtime appears to detect this case, but does not return E_FAIL for whatever reason anymore. */ ERR("There are still %u pending command lists awaiting execution from command allocator iface %p!\n", (unsigned int)pending, iface); - return E_FAIL; + return S_OK; } device = allocator->device;