more gpu stats

This commit is contained in:
jacob 2025-10-27 02:32:23 -05:00
parent 054fe159f5
commit 444db417a5
4 changed files with 71 additions and 61 deletions

View File

@ -349,14 +349,19 @@ Struct(GPU_Scissor)
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Memory info types //~ Statistic types
Struct(GPU_MemoryStats) Struct(GPU_Stats)
{ {
u64 budget; /* Memory usage */
u64 committed; u64 local_committed;
u64 reserved; u64 local_budget;
u64 available_to_reserve; u64 non_local_committed;
u64 non_local_budget;
/* Resources */
u64 driver_resources_allocated;
u64 driver_descriptors_allocated;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -468,10 +473,9 @@ void GPU_Unmap(GPU_Mapped mapped);
void GPU_CopyBytesToFootprint(void *dst, void *src, GPU_Resource *footprint_reference); void GPU_CopyBytesToFootprint(void *dst, void *src, GPU_Resource *footprint_reference);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Memory info operations //~ @hookdecl Statistics
GPU_MemoryStats GPU_QueryDedicatedMemoryStats(void); GPU_Stats GPU_QueryStats(void);
GPU_MemoryStats GPU_QuerySharedMemoryStats(void);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdecl Swapchain available_to_reserve //~ @hookdecl Swapchain available_to_reserve

View File

@ -565,6 +565,7 @@ GPU_D12_Descriptor *GPU_D12_AcquireDescriptor(GPU_D12_DescriptorHeap *heap)
d = PushStructNoZero(heap->arena, GPU_D12_Descriptor); d = PushStructNoZero(heap->arena, GPU_D12_Descriptor);
index = heap->allocated_count++; index = heap->allocated_count++;
handle.ptr = heap->start_handle.ptr + (index * heap->descriptor_size); handle.ptr = heap->start_handle.ptr + (index * heap->descriptor_size);
Atomic64FetchAdd(&GPU_D12_shared_state.driver_descriptors_allocated, 1);
} }
Unlock(&lock); Unlock(&lock);
} }
@ -886,6 +887,7 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS * !!(desc.flags & GPU_ResourceFlag_Writable); d3d_desc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS * !!(desc.flags & GPU_ResourceFlag_Writable);
r->state = desc.buffer.heap_kind == GPU_HeapKind_Upload ? D3D12_RESOURCE_STATE_GENERIC_READ : D3D12_RESOURCE_STATE_COPY_DEST; r->state = desc.buffer.heap_kind == GPU_HeapKind_Upload ? D3D12_RESOURCE_STATE_GENERIC_READ : D3D12_RESOURCE_STATE_COPY_DEST;
HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, 0, &IID_ID3D12Resource, (void **)&r->d3d_resource); HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, 0, &IID_ID3D12Resource, (void **)&r->d3d_resource);
Atomic64FetchAdd(&g->driver_resources_allocated, 1);
if (FAILED(hr)) if (FAILED(hr))
{ {
/* TODO: Don't panic */ /* TODO: Don't panic */
@ -924,6 +926,7 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
clear_value.Color[3] = desc.clear_color.w; clear_value.Color[3] = desc.clear_color.w;
D3D12_CLEAR_VALUE *clear_value_ptr = d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ? &clear_value : 0; D3D12_CLEAR_VALUE *clear_value_ptr = d3d_desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET ? &clear_value : 0;
HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, clear_value_ptr, &IID_ID3D12Resource, (void **)&r->d3d_resource); HRESULT hr = ID3D12Device_CreateCommittedResource(g->device, &heap_props, heap_flags, &d3d_desc, r->state, clear_value_ptr, &IID_ID3D12Resource, (void **)&r->d3d_resource);
Atomic64FetchAdd(&g->driver_resources_allocated, 1);
if (FAILED(hr)) if (FAILED(hr))
{ {
/* TODO: Don't panic */ /* TODO: Don't panic */
@ -1092,13 +1095,15 @@ void GPU_ReleaseResource(GPU_Resource *gpu_resource, GPU_ReleaseFlag flags)
{ {
switch (r->desc.kind) switch (r->desc.kind)
{ {
default: break;
case GPU_ResourceKind_Buffer: case GPU_ResourceKind_Buffer:
case GPU_ResourceKind_Texture1D: case GPU_ResourceKind_Texture1D:
case GPU_ResourceKind_Texture2D: case GPU_ResourceKind_Texture2D:
case GPU_ResourceKind_Texture3D: case GPU_ResourceKind_Texture3D:
{ {
ID3D12Resource_Release(r->d3d_resource); ID3D12Resource_Release(r->d3d_resource);
} Atomic64FetchAdd(&g->driver_resources_allocated, -1);
} break;
} }
Lock lock = LockE(&g->free_resources_mutex); Lock lock = LockE(&g->free_resources_mutex);
r->next_free = g->first_free_resource; r->next_free = g->first_free_resource;
@ -1808,37 +1813,33 @@ void GPU_CopyBytesToFootprint(void *dst, void *src, GPU_Resource *footprint_refe
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ @hookdef Memory info hooks //~ @hookdef Statistics
GPU_MemoryStats GPU_QueryDedicatedMemoryStats(void) GPU_Stats GPU_QueryStats(void)
{ {
GPU_D12_SharedState *g = &GPU_D12_shared_state; GPU_D12_SharedState *g = &GPU_D12_shared_state;
GPU_MemoryStats result = ZI; GPU_Stats result = ZI;
{ {
DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI; DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info); IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info);
result.budget = info.Budget; result.local_committed = info.CurrentUsage;
result.committed = info.CurrentUsage; result.local_budget = info.Budget;
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; DXGI_QUERY_VIDEO_MEMORY_INFO info = ZI;
IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info); IDXGIAdapter3_QueryVideoMemoryInfo(g->adapter, 0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info);
result.budget = info.Budget; result.non_local_budget = info.Budget;
result.committed = info.CurrentUsage; result.non_local_committed = info.CurrentUsage;
result.reserved = info.CurrentReservation;
result.available_to_reserve = info.AvailableForReservation;
} }
result.driver_resources_allocated = Atomic64Fetch(&g->driver_resources_allocated);
result.driver_descriptors_allocated = Atomic64Fetch(&g->driver_descriptors_allocated);
return result;
}
GPU_Stats GPU_QuerySharedMemoryStats(void)
{
GPU_D12_SharedState *g = &GPU_D12_shared_state;
GPU_Stats result = ZI;
return result; return result;
} }

View File

@ -12,8 +12,8 @@
//~ Tweakable defines //~ Tweakable defines
#define GPU_D12_TearingIsAllowed 1 #define GPU_D12_TearingIsAllowed 1
#define GPU_D12_FrameLatency 2 #define GPU_D12_FrameLatency 1
#define GPU_D12_SwapchainBufferCount 2 #define GPU_D12_SwapchainBufferCount 3
#define GPU_D12_SwapchainFlags (((GPU_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \ #define GPU_D12_SwapchainFlags (((GPU_D12_TearingIsAllowed != 0) * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) \
| ((GPU_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)) | ((GPU_D12_FrameLatency != 0) * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT))
@ -288,6 +288,10 @@ Struct(GPU_D12_SharedState)
Atomic64Padded resource_barrier_gen; Atomic64Padded resource_barrier_gen;
/* Stats */
Atomic64 driver_resources_allocated;
Atomic64 driver_descriptors_allocated;
/* Queues */ /* Queues */
GPU_D12_Queue *queues[GPU_NumQueues]; GPU_D12_Queue *queues[GPU_NumQueues];

View File

@ -2055,14 +2055,11 @@ void UpdateUser(void)
} }
#endif #endif
//- Query vram
GPU_MemoryStats vram_dedi = GPU_QueryDedicatedMemoryStats();
GPU_MemoryStats vram_shared = GPU_QuerySharedMemoryStats();
////////////////////////////// //////////////////////////////
//- Debug draw //- Debug draw
GPU_Stats gpu_stats = GPU_QueryStats();
/* Draw debug info */ /* Draw debug info */
if (g->debug_draw) if (g->debug_draw)
{ {
@ -2125,8 +2122,12 @@ 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_dedi.committed / 1024 / 1024)); UI_BuildLabelF("GPU dedicated memory usage: %F MiB", FmtFloat((f64)gpu_stats.local_committed / 1024 / 1024));
UI_BuildLabelF("Video memory (shared): %F MiB", FmtFloat((f64)vram_shared.committed / 1024 / 1024)); UI_BuildLabelF("GPU shared memory usage: %F MiB", FmtFloat((f64)gpu_stats.non_local_committed / 1024 / 1024));
UI_BuildSpacer(UI_PixelSize(20, 0));
UI_BuildLabelF("GPU resources: %F", FmtUint(gpu_stats.driver_resources_allocated));
UI_BuildLabelF("GPU descriptors: %F", FmtUint(gpu_stats.driver_descriptors_allocated));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));
//UI_BuildLabelF(\n")); //UI_BuildLabelF(\n"));