fix: replace Sleep with proper fence synchronization in minimal test

This commit is contained in:
2026-03-20 02:49:19 +08:00
parent e01dcfe6ed
commit b7d66a09de

View File

@@ -180,6 +180,7 @@ void ExecuteCommandList() {
void* commandLists[] = { gCommandList.GetCommandList() }; void* commandLists[] = { gCommandList.GetCommandList() };
gCommandQueue.ExecuteCommandLists(1, commandLists); gCommandQueue.ExecuteCommandLists(1, commandLists);
gFenceValue += 1; gFenceValue += 1;
gCommandQueue.Signal(gFence.GetFence(), gFenceValue);
} }
// Begin rendering // Begin rendering
@@ -274,6 +275,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} else { } else {
// Wait for previous frame to complete before resetting
if (frameCount > 0) {
gFence.Wait(gFenceValue);
}
// Reset command list for this frame // Reset command list for this frame
gCommandAllocator.Reset(); gCommandAllocator.Reset();
gCommandList.Reset(); gCommandList.Reset();
@@ -312,9 +318,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// Present // Present
gSwapChain.Present(0, 0); gSwapChain.Present(0, 0);
// Add small delay to prevent GPU overload
Sleep(10);
} }
} }