From ed86aad6d36294e219bc7ffa1f14d2e39fad7ade Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Tue, 18 Nov 2025 18:47:12 -0800 Subject: Tidy --- hello/main.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'hello/main.cc') diff --git a/hello/main.cc b/hello/main.cc index 1b94cf6..8e41d4b 100644 --- a/hello/main.cc +++ b/hello/main.cc @@ -111,7 +111,6 @@ public: _countof(command_lists), command_lists); ThrowIfFailed(m_swap_chain->Present(/*SyncInterval=*/1, /*Flags=*/0)); - m_current_back_buffer = m_swap_chain->GetCurrentBackBufferIndex(); // It is not efficient to wait for the frame to complete here, but it // is simple and sufficient for this application. @@ -138,7 +137,7 @@ private: // A command list can be reset as soon as it is executed with // ExecuteCommandList(). Reset() does require that the command list is - // in a "closed" state, however, which is why we close it right away + // in a "closed" state, however, which is why we Close() it right away // after creation. ThrowIfFailed(m_command_list->Reset( m_command_allocator.Get(), @@ -152,7 +151,7 @@ private: m_command_list->ResourceBarrier(1, &render_barrier); // Record commands. - const float clear_colour[] = { 0.0f, 0.0f, 0.0f, 0.0f }; + const float clear_colour[] = { 0.0f, 0.502f, 0.494f, 0.0f }; m_command_list->ClearRenderTargetView( GetCurrentBackBufferView(), clear_colour, @@ -174,6 +173,7 @@ private: D3D12_RESOURCE_STATE_PRESENT); m_command_list->ResourceBarrier(1, &present_barrier); + // A command list must be closed before it can be executed. ThrowIfFailed(m_command_list->Close()); } @@ -196,10 +196,11 @@ private: // execution. // Indicate that |m_fence_event| is to be fired when |m_fence| - // reaches the |fence| value. + // reaches the new fence value. ThrowIfFailed(m_fence->SetEventOnCompletion( m_fence_value, m_fence_event)); + // Will wake up when the fence takes on the new fence value. WaitForSingleObject(m_fence_event, INFINITE); } } @@ -266,8 +267,6 @@ private: /*pRestrictToOutput=*/nullptr, &swap_chain)); ThrowIfFailed(swap_chain.As(&m_swap_chain)); - - m_current_back_buffer = m_swap_chain->GetCurrentBackBufferIndex(); } /// Creates RTVs for all of the swap chain's buffers. @@ -341,7 +340,7 @@ private: ID3D12Resource* GetCurrentBackBuffer() const { - return m_swap_chain_buffer[m_current_back_buffer].Get(); + return m_swap_chain_buffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(); } D3D12_CPU_DESCRIPTOR_HANDLE GetCurrentBackBufferView() const @@ -350,7 +349,7 @@ private: assert(m_rtv_descriptor_size > 0); return CD3DX12_CPU_DESCRIPTOR_HANDLE( m_rtv_heap->GetCPUDescriptorHandleForHeapStart(), - m_current_back_buffer, + m_swap_chain->GetCurrentBackBufferIndex(), m_rtv_descriptor_size); } @@ -385,10 +384,6 @@ private: HANDLE m_fence_event = 0; UINT64 m_fence_value = 0; - // Index to the buffer in the RTV descriptor heap that represents the - // current back buffer. - int m_current_back_buffer = 0; - UINT m_rtv_descriptor_size = 0; UINT m_dsv_descriptor_size = 0; UINT m_cbv_descriptor_size = 0; -- cgit v1.2.3