diff options
| author | Marc Sunet <marc.sunet@amd.com> | 2025-11-18 18:47:12 -0800 |
|---|---|---|
| committer | Marc Sunet <marc.sunet@amd.com> | 2025-11-18 18:47:12 -0800 |
| commit | ed86aad6d36294e219bc7ffa1f14d2e39fad7ade (patch) | |
| tree | ba53e2b21091de7f056868a0b44d6e39a098dddf /hello | |
| parent | fba8184491e0b7ae6fab7ac01b4600d230dc4569 (diff) | |
Tidy
Diffstat (limited to 'hello')
| -rw-r--r-- | hello/main.cc | 19 |
1 files changed, 7 insertions, 12 deletions
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: | |||
| 111 | _countof(command_lists), command_lists); | 111 | _countof(command_lists), command_lists); |
| 112 | 112 | ||
| 113 | ThrowIfFailed(m_swap_chain->Present(/*SyncInterval=*/1, /*Flags=*/0)); | 113 | ThrowIfFailed(m_swap_chain->Present(/*SyncInterval=*/1, /*Flags=*/0)); |
| 114 | m_current_back_buffer = m_swap_chain->GetCurrentBackBufferIndex(); | ||
| 115 | 114 | ||
| 116 | // It is not efficient to wait for the frame to complete here, but it | 115 | // It is not efficient to wait for the frame to complete here, but it |
| 117 | // is simple and sufficient for this application. | 116 | // is simple and sufficient for this application. |
| @@ -138,7 +137,7 @@ private: | |||
| 138 | 137 | ||
| 139 | // A command list can be reset as soon as it is executed with | 138 | // A command list can be reset as soon as it is executed with |
| 140 | // ExecuteCommandList(). Reset() does require that the command list is | 139 | // ExecuteCommandList(). Reset() does require that the command list is |
| 141 | // in a "closed" state, however, which is why we close it right away | 140 | // in a "closed" state, however, which is why we Close() it right away |
| 142 | // after creation. | 141 | // after creation. |
| 143 | ThrowIfFailed(m_command_list->Reset( | 142 | ThrowIfFailed(m_command_list->Reset( |
| 144 | m_command_allocator.Get(), | 143 | m_command_allocator.Get(), |
| @@ -152,7 +151,7 @@ private: | |||
| 152 | m_command_list->ResourceBarrier(1, &render_barrier); | 151 | m_command_list->ResourceBarrier(1, &render_barrier); |
| 153 | 152 | ||
| 154 | // Record commands. | 153 | // Record commands. |
| 155 | const float clear_colour[] = { 0.0f, 0.0f, 0.0f, 0.0f }; | 154 | const float clear_colour[] = { 0.0f, 0.502f, 0.494f, 0.0f }; |
| 156 | m_command_list->ClearRenderTargetView( | 155 | m_command_list->ClearRenderTargetView( |
| 157 | GetCurrentBackBufferView(), | 156 | GetCurrentBackBufferView(), |
| 158 | clear_colour, | 157 | clear_colour, |
| @@ -174,6 +173,7 @@ private: | |||
| 174 | D3D12_RESOURCE_STATE_PRESENT); | 173 | D3D12_RESOURCE_STATE_PRESENT); |
| 175 | m_command_list->ResourceBarrier(1, &present_barrier); | 174 | m_command_list->ResourceBarrier(1, &present_barrier); |
| 176 | 175 | ||
| 176 | // A command list must be closed before it can be executed. | ||
| 177 | ThrowIfFailed(m_command_list->Close()); | 177 | ThrowIfFailed(m_command_list->Close()); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| @@ -196,10 +196,11 @@ private: | |||
| 196 | // execution. | 196 | // execution. |
| 197 | 197 | ||
| 198 | // Indicate that |m_fence_event| is to be fired when |m_fence| | 198 | // Indicate that |m_fence_event| is to be fired when |m_fence| |
| 199 | // reaches the |fence| value. | 199 | // reaches the new fence value. |
| 200 | ThrowIfFailed(m_fence->SetEventOnCompletion( | 200 | ThrowIfFailed(m_fence->SetEventOnCompletion( |
| 201 | m_fence_value, m_fence_event)); | 201 | m_fence_value, m_fence_event)); |
| 202 | 202 | ||
| 203 | // Will wake up when the fence takes on the new fence value. | ||
| 203 | WaitForSingleObject(m_fence_event, INFINITE); | 204 | WaitForSingleObject(m_fence_event, INFINITE); |
| 204 | } | 205 | } |
| 205 | } | 206 | } |
| @@ -266,8 +267,6 @@ private: | |||
| 266 | /*pRestrictToOutput=*/nullptr, | 267 | /*pRestrictToOutput=*/nullptr, |
| 267 | &swap_chain)); | 268 | &swap_chain)); |
| 268 | ThrowIfFailed(swap_chain.As(&m_swap_chain)); | 269 | ThrowIfFailed(swap_chain.As(&m_swap_chain)); |
| 269 | |||
| 270 | m_current_back_buffer = m_swap_chain->GetCurrentBackBufferIndex(); | ||
| 271 | } | 270 | } |
| 272 | 271 | ||
| 273 | /// Creates RTVs for all of the swap chain's buffers. | 272 | /// Creates RTVs for all of the swap chain's buffers. |
| @@ -341,7 +340,7 @@ private: | |||
| 341 | 340 | ||
| 342 | ID3D12Resource* GetCurrentBackBuffer() const | 341 | ID3D12Resource* GetCurrentBackBuffer() const |
| 343 | { | 342 | { |
| 344 | return m_swap_chain_buffer[m_current_back_buffer].Get(); | 343 | return m_swap_chain_buffer[m_swap_chain->GetCurrentBackBufferIndex()].Get(); |
| 345 | } | 344 | } |
| 346 | 345 | ||
| 347 | D3D12_CPU_DESCRIPTOR_HANDLE GetCurrentBackBufferView() const | 346 | D3D12_CPU_DESCRIPTOR_HANDLE GetCurrentBackBufferView() const |
| @@ -350,7 +349,7 @@ private: | |||
| 350 | assert(m_rtv_descriptor_size > 0); | 349 | assert(m_rtv_descriptor_size > 0); |
| 351 | return CD3DX12_CPU_DESCRIPTOR_HANDLE( | 350 | return CD3DX12_CPU_DESCRIPTOR_HANDLE( |
| 352 | m_rtv_heap->GetCPUDescriptorHandleForHeapStart(), | 351 | m_rtv_heap->GetCPUDescriptorHandleForHeapStart(), |
| 353 | m_current_back_buffer, | 352 | m_swap_chain->GetCurrentBackBufferIndex(), |
| 354 | m_rtv_descriptor_size); | 353 | m_rtv_descriptor_size); |
| 355 | } | 354 | } |
| 356 | 355 | ||
| @@ -385,10 +384,6 @@ private: | |||
| 385 | HANDLE m_fence_event = 0; | 384 | HANDLE m_fence_event = 0; |
| 386 | UINT64 m_fence_value = 0; | 385 | UINT64 m_fence_value = 0; |
| 387 | 386 | ||
| 388 | // Index to the buffer in the RTV descriptor heap that represents the | ||
| 389 | // current back buffer. | ||
| 390 | int m_current_back_buffer = 0; | ||
| 391 | |||
| 392 | UINT m_rtv_descriptor_size = 0; | 387 | UINT m_rtv_descriptor_size = 0; |
| 393 | UINT m_dsv_descriptor_size = 0; | 388 | UINT m_dsv_descriptor_size = 0; |
| 394 | UINT m_cbv_descriptor_size = 0; | 389 | UINT m_cbv_descriptor_size = 0; |
