keep backbuffer at monitor size

This commit is contained in:
jacob 2025-10-27 01:30:51 -05:00
parent e730ad7b5e
commit 054fe159f5
6 changed files with 49 additions and 17 deletions

View File

@ -351,10 +351,12 @@ Struct(GPU_Scissor)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Memory info types //~ Memory info types
Struct(GPU_MemoryInfo) Struct(GPU_MemoryStats)
{ {
u64 local_used; u64 budget;
u64 non_local_used; u64 committed;
u64 reserved;
u64 available_to_reserve;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -468,10 +470,11 @@ void GPU_CopyBytesToFootprint(void *dst, void *src, GPU_Resource *footprint_refe
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Memory info operations //~ @hookdecl Memory info operations
GPU_MemoryInfo GPU_QueryMemoryInfo(void); GPU_MemoryStats GPU_QueryDedicatedMemoryStats(void);
GPU_MemoryStats GPU_QuerySharedMemoryStats(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Swapchain operations //~ @hookdecl Swapchain available_to_reserve
GPU_Swapchain *GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size); GPU_Swapchain *GPU_AcquireSwapchain(WND_Handle window, GPU_Format format, Vec2I32 size);
void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain); void GPU_ReleaseSwapchain(GPU_Swapchain *swapchain);

View File

@ -169,7 +169,7 @@ void GPU_D12_InitDevice(void)
/* Create device */ /* Create device */
{ {
__profn("Create device"); __profn("Create device");
IDXGIAdapter1 *adapter = 0; IDXGIAdapter3 *adapter = 0;
ID3D12Device *device = 0; ID3D12Device *device = 0;
String error = Lit("Could not initialize GPU device."); String error = Lit("Could not initialize GPU device.");
String first_gpu_name = ZI; String first_gpu_name = ZI;
@ -178,12 +178,12 @@ void GPU_D12_InitDevice(void)
for (;;) for (;;)
{ {
{ {
hr = IDXGIFactory6_EnumAdapterByGpuPreference(g->factory, adapter_index, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, &IID_IDXGIAdapter1, (void **)&adapter); hr = IDXGIFactory6_EnumAdapterByGpuPreference(g->factory, adapter_index, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, &IID_IDXGIAdapter3, (void **)&adapter);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
DXGI_ADAPTER_DESC1 desc; DXGI_ADAPTER_DESC1 desc;
IDXGIAdapter1_GetDesc1(adapter, &desc); IDXGIAdapter3_GetDesc1(adapter, &desc);
if (first_gpu_name.len == 0) if (first_gpu_name.len == 0)
{ {
first_gpu_name = StringFromWstrNoLimit(scratch.arena, desc.Description); first_gpu_name = StringFromWstrNoLimit(scratch.arena, desc.Description);
@ -197,7 +197,7 @@ void GPU_D12_InitDevice(void)
} }
skip = 0; skip = 0;
ID3D12Device_Release(device); ID3D12Device_Release(device);
IDXGIAdapter1_Release(adapter); IDXGIAdapter3_Release(adapter);
adapter = 0; adapter = 0;
device = 0; device = 0;
++adapter_index; ++adapter_index;
@ -1810,10 +1810,36 @@ void GPU_CopyBytesToFootprint(void *dst, void *src, GPU_Resource *footprint_refe
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Memory info hooks //~ @hookdef Memory info hooks
GPU_MemoryInfo GPU_QueryMemoryInfo(void) GPU_MemoryStats GPU_QueryDedicatedMemoryStats(void)
{ {
/* TODO */ GPU_D12_SharedState *g = &GPU_D12_shared_state;
return (GPU_MemoryInfo) ZI; GPU_MemoryStats result = ZI;
{
DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info);
result.budget = info.Budget;
result.committed = info.CurrentUsage;
result.reserved = info.CurrentReservation;
result.available_to_reserve = info.AvailableForReservation;
}
return result;
}
GPU_MemoryStats GPU_QuerySharedMemoryStats(void)
{
GPU_D12_SharedState *g = &GPU_D12_shared_state;
GPU_MemoryStats result = ZI;
{
DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info);
result.budget = info.Budget;
result.committed = info.CurrentUsage;
result.reserved = info.CurrentReservation;
result.available_to_reserve = info.AvailableForReservation;
}
return result;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -313,7 +313,7 @@ Struct(GPU_D12_SharedState)
/* Device */ /* Device */
IDXGIFactory6 *factory; IDXGIFactory6 *factory;
IDXGIAdapter1 *adapter; IDXGIAdapter3 *adapter;
ID3D12Device *device; ID3D12Device *device;
} extern GPU_D12_shared_state; } extern GPU_D12_shared_state;

View File

@ -2057,7 +2057,8 @@ void UpdateUser(void)
//- Query vram //- Query vram
GPU_MemoryInfo vram = GPU_QueryMemoryInfo(); GPU_MemoryStats vram_dedi = GPU_QueryDedicatedMemoryStats();
GPU_MemoryStats vram_shared = GPU_QuerySharedMemoryStats();
////////////////////////////// //////////////////////////////
//- Debug draw //- Debug draw
@ -2124,8 +2125,8 @@ void UpdateUser(void)
UI_BuildLabelF("Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS))); UI_BuildLabelF("Arenas allocated: %F", FmtUint(GetGstat(GSTAT_NUM_ARENAS)));
UI_BuildSpacer(UI_PixelSize(20, 0)); UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("Video memory (GPU): %F MiB", FmtFloat((f64)vram.local_used / 1024 / 1024)); UI_BuildLabelF("Video memory (GPU): %F MiB", FmtFloat((f64)vram_dedi.committed / 1024 / 1024));
UI_BuildLabelF("Video memory (shared): %F MiB", FmtFloat((f64)vram.non_local_used / 1024 / 1024)); UI_BuildLabelF("Video memory (shared): %F MiB", FmtFloat((f64)vram_shared.committed / 1024 / 1024));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
@ -2388,7 +2389,7 @@ void UpdateUser(void)
} }
Vec2 backbuffer_dst_f = MulXformV2(g->ui_to_screen_xf, VEC2(0, 0)); Vec2 backbuffer_dst_f = MulXformV2(g->ui_to_screen_xf, VEC2(0, 0));
Vec2I32 backbuffer_dst = VEC2I32(RoundF32ToI32(backbuffer_dst_f.x), RoundF32ToI32(backbuffer_dst_f.y)); Vec2I32 backbuffer_dst = VEC2I32(RoundF32ToI32(backbuffer_dst_f.x), RoundF32ToI32(backbuffer_dst_f.y));
g->gpu_submit_fence_target = GPU_PresentSwapchain(g->swapchain, g->ui_target, g->screen_size, backbuffer_dst, VSYNC); g->gpu_submit_fence_target = GPU_PresentSwapchain(g->swapchain, g->ui_target, window_frame.monitor_size, backbuffer_dst, VSYNC);
} }
WND_EndFrame(window_frame); WND_EndFrame(window_frame);

View File

@ -39,6 +39,7 @@ Struct(WND_Frame)
/* Window info */ /* Window info */
Vec2I32 draw_size; Vec2I32 draw_size;
Vec2I32 monitor_size;
String restore; String restore;
b32 minimized; b32 minimized;
b32 maximized; b32 maximized;

View File

@ -444,6 +444,7 @@ WND_Frame WND_BeginFrame(Arena *arena)
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &monitor_info); GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &monitor_info);
monitor_rect = monitor_info.rcMonitor; monitor_rect = monitor_info.rcMonitor;
} }
result.monitor_size = VEC2I32(monitor_rect.right - monitor_rect.left, monitor_rect.bottom - monitor_rect.top);
/* Client rect */ /* Client rect */
RECT client_rect = ZI; RECT client_rect = ZI;