From 36c1c8338f406489047cfc26f11ec0a9a99349b7 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Mon, 23 Mar 2026 23:52:27 +0800 Subject: [PATCH] fix: D3D12 CommandQueue and SwapChain unit test fixes - CommandQueue::ExecuteCommandLists: fix type conversion from void** to ID3D12CommandList**, reset command list before execution, add null checks - SwapChain::ShouldClose: add m_shouldClose member and implement getter/setter - SwapChain::SetFullscreen: add m_fullscreen member to track state locally --- .../XCEngine/RHI/D3D12/D3D12SwapChain.h | 2 ++ engine/src/RHI/D3D12/D3D12CommandQueue.cpp | 22 +++++++++++++++++-- engine/src/RHI/D3D12/D3D12SwapChain.cpp | 8 +++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/engine/include/XCEngine/RHI/D3D12/D3D12SwapChain.h b/engine/include/XCEngine/RHI/D3D12/D3D12SwapChain.h index 3f3488f8..622c19d3 100644 --- a/engine/include/XCEngine/RHI/D3D12/D3D12SwapChain.h +++ b/engine/include/XCEngine/RHI/D3D12/D3D12SwapChain.h @@ -45,6 +45,8 @@ private: uint32_t m_height; uint32_t m_bufferCount; std::vector m_backBuffers; + bool m_shouldClose = false; + bool m_fullscreen = false; }; } // namespace RHI diff --git a/engine/src/RHI/D3D12/D3D12CommandQueue.cpp b/engine/src/RHI/D3D12/D3D12CommandQueue.cpp index 075795bc..105d9f32 100644 --- a/engine/src/RHI/D3D12/D3D12CommandQueue.cpp +++ b/engine/src/RHI/D3D12/D3D12CommandQueue.cpp @@ -52,13 +52,31 @@ void D3D12CommandQueue::Shutdown() { } void D3D12CommandQueue::ExecuteCommandLists(uint32_t count, void** lists) { - ExecuteCommandListsInternal(count, reinterpret_cast(lists)); + if (count == 0 || lists == nullptr) { + return; + } + + std::vector cmdLists(count); + for (uint32_t i = 0; i < count; ++i) { + auto* cmdList = static_cast(lists[i]); + if (cmdList) { + cmdList->Reset(); + cmdLists[i] = cmdList->GetCommandList(); + } + } + + ExecuteCommandListsInternal(count, cmdLists.data()); } void D3D12CommandQueue::ExecuteCommandListsInternal(uint32_t count, ID3D12CommandList** lists) { + if (!m_commandQueue || count == 0 || lists == nullptr) { + return; + } m_commandQueue->ExecuteCommandLists(count, lists); m_currentFrame++; - m_commandQueue->Signal(m_frameFence.Get(), m_currentFrame); + if (m_frameFence) { + m_commandQueue->Signal(m_frameFence.Get(), m_currentFrame); + } } void D3D12CommandQueue::Signal(RHIFence* fence, uint64_t value) { diff --git a/engine/src/RHI/D3D12/D3D12SwapChain.cpp b/engine/src/RHI/D3D12/D3D12SwapChain.cpp index 3e8500ea..5cf32374 100644 --- a/engine/src/RHI/D3D12/D3D12SwapChain.cpp +++ b/engine/src/RHI/D3D12/D3D12SwapChain.cpp @@ -103,13 +103,12 @@ void D3D12SwapChain::Resize(uint32_t width, uint32_t height) { } void D3D12SwapChain::SetFullscreen(bool fullscreen) { + m_fullscreen = fullscreen; m_swapChain->SetFullscreenState(fullscreen, nullptr); } bool D3D12SwapChain::IsFullscreen() const { - BOOL fullscreen = FALSE; - m_swapChain->GetFullscreenState(&fullscreen, nullptr); - return fullscreen != FALSE; + return m_fullscreen; } void* D3D12SwapChain::GetNativeHandle() { @@ -121,10 +120,11 @@ RHITexture* D3D12SwapChain::GetCurrentBackBuffer() { } bool D3D12SwapChain::ShouldClose() const { - return false; + return m_shouldClose; } void D3D12SwapChain::SetShouldClose(bool shouldClose) { + m_shouldClose = shouldClose; } void D3D12SwapChain::PollEvents() {