move latency waitable to end of present

This commit is contained in:
jacob 2025-07-10 15:06:31 -05:00
parent 63a8dc7595
commit b270737bec

View File

@ -42,10 +42,7 @@
#define DX12_ALLOW_TEARING 1 #define DX12_ALLOW_TEARING 1
#define DX12_WAIT_FRAME_LATENCY 1 #define DX12_WAIT_FRAME_LATENCY 1
#define DX12_SWAPCHAIN_FLAGS ((DX12_ALLOW_TEARING * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) | (DX12_WAIT_FRAME_LATENCY * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)) #define DX12_SWAPCHAIN_FLAGS ((DX12_ALLOW_TEARING * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) | (DX12_WAIT_FRAME_LATENCY * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
#define DX12_SWAPCHAIN_BUFFER_COUNT (4)
#define DX12_SWAPCHAIN_BUFFER_COUNT (2)
#define DX12_SWAPCHAIN_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM)
//#define DX12_SWAPCHAIN_RTV_FORMAT (DXGI_FORMAT_R8G8B8A8_UNORM_SRGB)
/* Arbitrary limits */ /* Arbitrary limits */
#define DX12_NUM_CBV_SRV_UAV_DESCRIPTORS (1024 * 64) #define DX12_NUM_CBV_SRV_UAV_DESCRIPTORS (1024 * 64)
@ -2611,7 +2608,7 @@ INTERNAL struct swapchain_buffer *update_swapchain(struct swapchain *swapchain,
IDXGISwapChain1 *swapchain1 = 0; IDXGISwapChain1 *swapchain1 = 0;
{ {
DXGI_SWAP_CHAIN_DESC1 desc = ZI; DXGI_SWAP_CHAIN_DESC1 desc = ZI;
desc.Format = DX12_SWAPCHAIN_FORMAT; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.Width = resolution.x; desc.Width = resolution.x;
desc.Height = resolution.y; desc.Height = resolution.y;
desc.SampleDesc.Count = 1; desc.SampleDesc.Count = 1;
@ -2771,11 +2768,11 @@ INTERNAL void present_blit(struct swapchain_buffer *dst, struct dx12_resource *s
pipeline_scope_end(pipeline_scope); pipeline_scope_end(pipeline_scope);
} }
void gp_present(struct sys_window *window, struct v2i32 backresolution, struct gp_resource *texture, struct xform texture_xf, i32 vsync) void gp_present(struct sys_window *window, struct v2i32 backbuffer_resolution, struct gp_resource *texture, struct xform texture_xf, i32 vsync)
{ {
__prof; __prof;
struct swapchain *swapchain = &G.swapchain; struct swapchain *swapchain = &G.swapchain;
struct swapchain_buffer *swapchain_buffer = update_swapchain(swapchain, window, backresolution); struct swapchain_buffer *swapchain_buffer = update_swapchain(swapchain, window, backbuffer_resolution);
struct dx12_resource *texture_resource = (struct dx12_resource *)texture; struct dx12_resource *texture_resource = (struct dx12_resource *)texture;
/* Blit */ /* Blit */
@ -2786,14 +2783,7 @@ void gp_present(struct sys_window *window, struct v2i32 backresolution, struct g
present_flags |= (DXGI_PRESENT_ALLOW_TEARING * DX12_ALLOW_TEARING); present_flags |= (DXGI_PRESENT_ALLOW_TEARING * DX12_ALLOW_TEARING);
} }
/* Wait */
if (swapchain->waitable) {
__profn("Present wait");
WaitForSingleObjectEx(swapchain->waitable, 1000, 1);
}
/* Present */ /* Present */
/* FIXME: Resource barrier */
{ {
__profn("Present"); __profn("Present");
HRESULT hr = IDXGISwapChain3_Present(swapchain->swapchain, vsync, present_flags); HRESULT hr = IDXGISwapChain3_Present(swapchain->swapchain, vsync, present_flags);
@ -2822,6 +2812,13 @@ void gp_present(struct sys_window *window, struct v2i32 backresolution, struct g
} }
} }
#endif #endif
/* Wait on swapchain */
/* TODO: Move this to system layer */
if (swapchain->waitable) {
__profn("Present wait");
WaitForSingleObjectEx(swapchain->waitable, 1000, 1);
}
} }
/* ========================== * /* ========================== *