refactor: encapsulate frame fence synchronization in CommandQueue
- Add WaitForPreviousFrame() and GetCurrentFrame() to RHICommandQueue interface - D3D12CommandQueue now manages frame fence internally - ExecuteCommandLists automatically signals fence after command execution - OpenGLCommandQueue provides stub implementations for interface compliance - Minimal test now uses CommandQueue::WaitForPreviousFrame() instead of manual fence
This commit is contained in:
@@ -42,7 +42,6 @@ D3D12CommandQueue gCommandQueue;
|
||||
D3D12SwapChain gSwapChain;
|
||||
D3D12CommandAllocator gCommandAllocator;
|
||||
D3D12CommandList gCommandList;
|
||||
D3D12Fence gFence;
|
||||
|
||||
// Render targets
|
||||
D3D12Texture gColorRTs[2];
|
||||
@@ -55,7 +54,6 @@ D3D12DepthStencilView gDSV;
|
||||
UINT gRTVDescriptorSize = 0;
|
||||
UINT gDSVDescriptorSize = 0;
|
||||
int gCurrentRTIndex = 0;
|
||||
UINT64 gFenceValue = 0;
|
||||
|
||||
// Window
|
||||
HWND gHWND = nullptr;
|
||||
@@ -162,9 +160,6 @@ bool InitD3D12() {
|
||||
gCommandAllocator.Initialize(device, CommandQueueType::Direct);
|
||||
gCommandList.Initialize(device, CommandQueueType::Direct, gCommandAllocator.GetCommandAllocator());
|
||||
|
||||
// Create fence
|
||||
gFence.Initialize(device, 0);
|
||||
|
||||
Log("[INFO] D3D12 initialized successfully");
|
||||
return true;
|
||||
}
|
||||
@@ -179,8 +174,6 @@ void ExecuteCommandList() {
|
||||
gCommandList.Close();
|
||||
void* commandLists[] = { gCommandList.GetCommandList() };
|
||||
gCommandQueue.ExecuteCommandLists(1, commandLists);
|
||||
gFenceValue += 1;
|
||||
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
|
||||
}
|
||||
|
||||
// Begin rendering
|
||||
@@ -277,7 +270,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
} else {
|
||||
// Wait for previous frame to complete before resetting
|
||||
if (frameCount > 0) {
|
||||
gFence.Wait(gFenceValue);
|
||||
gCommandQueue.WaitForPreviousFrame();
|
||||
}
|
||||
|
||||
// Reset command list for this frame
|
||||
@@ -324,7 +317,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
// Shutdown
|
||||
gCommandList.Shutdown();
|
||||
gCommandAllocator.Shutdown();
|
||||
gFence.Shutdown();
|
||||
gSwapChain.Shutdown();
|
||||
gDevice.Shutdown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user