aboutsummaryrefslogtreecommitdiff
path: root/hello/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'hello/main.cc')
-rw-r--r--hello/main.cc62
1 files changed, 31 insertions, 31 deletions
diff --git a/hello/main.cc b/hello/main.cc
index 47a2aba..bd76cc3 100644
--- a/hello/main.cc
+++ b/hello/main.cc
@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
11 11
12struct D3DSettings 12struct D3DSettings
13{ 13{
14 int width = 0; 14 int width = 0;
15 int height = 0; 15 int height = 0;
16}; 16};
17 17
@@ -52,7 +52,7 @@ public:
52 m_cbv_descriptor_size = m_device->GetDescriptorHandleIncrementSize( 52 m_cbv_descriptor_size = m_device->GetDescriptorHandleIncrementSize(
53 D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); 53 D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
54 54
55 const D3D12_COMMAND_QUEUE_DESC queue_desc = 55 const D3D12_COMMAND_QUEUE_DESC queue_desc
56 { 56 {
57 .Type = D3D12_COMMAND_LIST_TYPE_DIRECT, 57 .Type = D3D12_COMMAND_LIST_TYPE_DIRECT,
58 .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE, 58 .Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
@@ -61,12 +61,12 @@ public:
61 &queue_desc, 61 &queue_desc,
62 IID_PPV_ARGS(&m_command_queue))); 62 IID_PPV_ARGS(&m_command_queue)));
63 63
64 // The command allocator is the memory backing for the command list.
65 // It is in the allocator's memory where the commands are stored.
64 ThrowIfFailed(m_device->CreateCommandAllocator( 66 ThrowIfFailed(m_device->CreateCommandAllocator(
65 queue_desc.Type, 67 queue_desc.Type,
66 IID_PPV_ARGS(&m_command_allocator))); 68 IID_PPV_ARGS(&m_command_allocator)));
67 69
68 // The command allocator is the memory backing for the command list.
69 // It is in the allocator's memory where the commands are stored.
70 ThrowIfFailed(m_device->CreateCommandList( 70 ThrowIfFailed(m_device->CreateCommandList(
71 /*nodeMask=*/0, 71 /*nodeMask=*/0,
72 queue_desc.Type, 72 queue_desc.Type,
@@ -105,7 +105,7 @@ public:
105 { 105 {
106 PopulateCommandList(); 106 PopulateCommandList();
107 107
108 ID3D12CommandList* command_lists[] = { m_command_list.Get() }; 108 ID3D12CommandList* command_lists[] { m_command_list.Get() };
109 m_command_queue->ExecuteCommandLists( 109 m_command_queue->ExecuteCommandLists(
110 _countof(command_lists), command_lists); 110 _countof(command_lists), command_lists);
111 111
@@ -150,20 +150,20 @@ private:
150 m_command_list->ResourceBarrier(1, &render_barrier); 150 m_command_list->ResourceBarrier(1, &render_barrier);
151 151
152 // Record commands. 152 // Record commands.
153 const float clear_colour[] = { 0.0f, 0.502f, 0.494f, 0.0f }; 153 const float clear_colour[] { 0.0f, 0.502f, 0.494f, 0.0f };
154 m_command_list->ClearRenderTargetView( 154 m_command_list->ClearRenderTargetView(
155 GetCurrentBackBufferView(), 155 GetCurrentBackBufferView(),
156 clear_colour, 156 clear_colour,
157 0, // Number of rectangles in the following array. 157 0, // Number of rectangles in the following array.
158 nullptr); // No rectangles; clear the entire resource. 158 nullptr); // No rectangles; clear the entire resource.
159 159
160 m_command_list->ClearDepthStencilView( 160 m_command_list->ClearDepthStencilView(
161 GetDepthStencilView(), 161 GetDepthStencilView(),
162 D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 162 D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL,
163 1.0f, // Depth. 163 1.0f, // Depth.
164 0, // Stencil. 164 0, // Stencil.
165 0, // Number of rectangles in the following array. 165 0, // Number of rectangles in the following array.
166 nullptr); // No rectangles; clear the entire resource view. 166 nullptr); // No rectangles; clear the entire resource view.
167 167
168 // Indicate that we now intend to use the back buffer to present. 168 // Indicate that we now intend to use the back buffer to present.
169 const auto present_barrier = CD3DX12_RESOURCE_BARRIER::Transition( 169 const auto present_barrier = CD3DX12_RESOURCE_BARRIER::Transition(
@@ -211,7 +211,7 @@ private:
211 211
212 // The RTV heap must hold as many descriptors as we have buffers in the 212 // The RTV heap must hold as many descriptors as we have buffers in the
213 // swap chain. 213 // swap chain.
214 const D3D12_DESCRIPTOR_HEAP_DESC rtv_heap_desc = 214 const D3D12_DESCRIPTOR_HEAP_DESC rtv_heap_desc
215 { 215 {
216 .Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 216 .Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
217 .NumDescriptors = SWAP_CHAIN_BUFFER_COUNT, 217 .NumDescriptors = SWAP_CHAIN_BUFFER_COUNT,
@@ -222,7 +222,7 @@ private:
222 &rtv_heap_desc, IID_PPV_ARGS(&m_rtv_heap))); 222 &rtv_heap_desc, IID_PPV_ARGS(&m_rtv_heap)));
223 223
224 // For the depth/stencil buffer, we just need one view. 224 // For the depth/stencil buffer, we just need one view.
225 const D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc = 225 const D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc
226 { 226 {
227 .Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 227 .Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV,
228 .NumDescriptors = 1, 228 .NumDescriptors = 1,
@@ -243,19 +243,19 @@ private:
243 243
244 SafeRelease(m_swap_chain); 244 SafeRelease(m_swap_chain);
245 245
246 DXGI_SWAP_CHAIN_DESC1 desc = 246 DXGI_SWAP_CHAIN_DESC1 desc
247 { 247 {
248 .Width = static_cast<UINT>(m_settings.width), 248 .Width = static_cast<UINT>(m_settings.width),
249 .Height = static_cast<UINT>(m_settings.height), 249 .Height = static_cast<UINT>(m_settings.height),
250 .Format = DXGI_FORMAT_R8G8B8A8_UNORM, 250 .Format = DXGI_FORMAT_R8G8B8A8_UNORM,
251 .SampleDesc = DXGI_SAMPLE_DESC 251 .SampleDesc = DXGI_SAMPLE_DESC
252 { 252 {
253 .Count = 1, 253 .Count = 1,
254 .Quality = 0, 254 .Quality = 0,
255 }, 255 },
256 .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, 256 .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
257 .BufferCount = SWAP_CHAIN_BUFFER_COUNT, 257 .BufferCount = SWAP_CHAIN_BUFFER_COUNT,
258 .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD, 258 .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
259 }; 259 };
260 ComPtr<IDXGISwapChain1> swap_chain; 260 ComPtr<IDXGISwapChain1> swap_chain;
261 ThrowIfFailed(m_dxgi_factory->CreateSwapChainForHwnd( 261 ThrowIfFailed(m_dxgi_factory->CreateSwapChainForHwnd(
@@ -295,29 +295,29 @@ private:
295 { 295 {
296 assert(m_device); 296 assert(m_device);
297 297
298 const D3D12_RESOURCE_DESC depth_stencil_desc = 298 const D3D12_RESOURCE_DESC depth_stencil_desc
299 { 299 {
300 .Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D, 300 .Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D,
301 .Alignment = 0, 301 .Alignment = 0,
302 .Width = static_cast<UINT64>(m_settings.width), 302 .Width = static_cast<UINT64>(m_settings.width),
303 .Height = static_cast<UINT>(m_settings.height), 303 .Height = static_cast<UINT>(m_settings.height),
304 .DepthOrArraySize = 1, 304 .DepthOrArraySize = 1,
305 .MipLevels = 1, 305 .MipLevels = 1,
306 .Format = DXGI_FORMAT_D24_UNORM_S8_UINT, 306 .Format = DXGI_FORMAT_D24_UNORM_S8_UINT,
307 .SampleDesc = DXGI_SAMPLE_DESC 307 .SampleDesc = DXGI_SAMPLE_DESC
308 { 308 {
309 .Count = 1, 309 .Count = 1,
310 .Quality = 0, 310 .Quality = 0,
311 }, 311 },
312 .Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN, 312 .Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
313 .Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, 313 .Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL,
314 }; 314 };
315 const D3D12_CLEAR_VALUE opt_clear_value = 315 const D3D12_CLEAR_VALUE opt_clear_value
316 { 316 {
317 .Format = depth_stencil_desc.Format, 317 .Format = depth_stencil_desc.Format,
318 .DepthStencil = D3D12_DEPTH_STENCIL_VALUE 318 .DepthStencil = D3D12_DEPTH_STENCIL_VALUE
319 { 319 {
320 .Depth = 1.0f, 320 .Depth = 1.0f,
321 .Stencil = 0, 321 .Stencil = 0,
322 }, 322 },
323 }; 323 };
@@ -395,7 +395,7 @@ int main()
395 const D3DSettings settings = 395 const D3DSettings settings =
396 { 396 {
397 // TODO: use 960x600 or 1920x1200 depending on native resolution. 397 // TODO: use 960x600 or 1920x1200 depending on native resolution.
398 .width = 1920, 398 .width = 1920,
399 .height = 1200, 399 .height = 1200,
400 }; 400 };
401 401