From 5daf408aac52774970525315fbf9fb599d9cdb64 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 6 Jun 2025 22:40:01 -0500 Subject: [PATCH] remove device = null test --- src/gpu_dx12.c | 77 +++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/src/gpu_dx12.c b/src/gpu_dx12.c index 2db9d481..df04a6b9 100644 --- a/src/gpu_dx12.c +++ b/src/gpu_dx12.c @@ -93,6 +93,45 @@ GLOBAL struct { * ========================== */ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown); +INTERNAL void dx12_init_base(struct sys_window *window); +INTERNAL void dx12_init_shaders(void); + +struct gpu_startup_receipt gpu_startup(struct sys_window *window) +{ + /* Initialize handles pool */ + G.handle_entries_mutex = sys_mutex_alloc(); + G.handle_entries_arena = arena_alloc(GIGABYTE(64)); + + /* Initialize dx12 */ + dx12_init_base(window); + dx12_init_shaders(); + + /* Register callbacks */ + app_register_exit_callback(gpu_shutdown); + + struct gpu_startup_receipt res = ZI; + return res; +} + +INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown) +{ +#if DX12_DEBUG + /* Release objects to make live object reporting less noisy */ + for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_rtvs); ++i) { + ID3D12Resource_Release(G.swapchain_rtvs[i]); + } + ID3D12DescriptorHeap_Release(G.swapchain_rtv_heap); + ID3D12CommandQueue_Release(G.swapchain_ca); + ID3D12CommandQueue_Release(G.cq_direct); + ID3D12CommandQueue_Release(G.cq_compute); + IDXGISwapChain3_Release(G.swapchain); + ID3D12Device_Release(G.device); +#endif +} + +/* ========================== * + * Dx12 base initialization + * ========================== */ INTERNAL void dx12_init_error(struct string error) { @@ -102,7 +141,7 @@ INTERNAL void dx12_init_error(struct string error) scratch_end(scratch); } -INTERNAL void dx12_init(struct sys_window *window) +INTERNAL void dx12_init_base(struct sys_window *window) { __prof; struct temp_arena scratch = scratch_begin_no_conflict(); @@ -174,7 +213,6 @@ INTERNAL void dx12_init(struct sys_window *window) break; } } - device = NULL; if (!device) { if (first_gpu_name.len > 0) { struct string fmt = LIT("Could not initialize device '%F' with D3D_FEATURE_LEVEL_12_0. Ensure that the device is capable and drivers are up to date."); @@ -311,7 +349,6 @@ INTERNAL void dx12_init(struct sys_window *window) dx12_init_error(LIT("Failed to create swapchain RTV")); } ID3D12Device_CreateRenderTargetView(device, swapchain_rtvs[i], NULL, rtv_handle); - rtv_handle.ptr += desc_size_rtv; } } @@ -330,36 +367,12 @@ INTERNAL void dx12_init(struct sys_window *window) scratch_end(scratch); } -struct gpu_startup_receipt gpu_startup(struct sys_window *window) +/* ========================== * + * Dx12 shader initialization + * ========================== */ + +INTERNAL void dx12_init_shaders(void) { - /* Initialize handles pool */ - G.handle_entries_mutex = sys_mutex_alloc(); - G.handle_entries_arena = arena_alloc(GIGABYTE(64)); - - /* Initialize dx12 */ - dx12_init(window); - - /* Register callbacks */ - app_register_exit_callback(gpu_shutdown); - - struct gpu_startup_receipt res = ZI; - return res; -} - -INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(gpu_shutdown) -{ -#if DX12_DEBUG - /* Release objects to make live object reporting less noisy */ - for (u64 i = 0; i < ARRAY_COUNT(G.swapchain_rtvs); ++i) { - ID3D12Resource_Release(G.swapchain_rtvs[i]); - } - ID3D12DescriptorHeap_Release(G.swapchain_rtv_heap); - ID3D12CommandQueue_Release(G.swapchain_ca); - ID3D12CommandQueue_Release(G.cq_direct); - ID3D12CommandQueue_Release(G.cq_compute); - IDXGISwapChain3_Release(G.swapchain); - ID3D12Device_Release(G.device); -#endif } /* ========================== *