@@ -311,10 +311,13 @@ void D3D12MeshletCull::LoadPipeline()
311311 depthOptimizedClearValue.DepthStencil .Depth = 1 .0f ;
312312 depthOptimizedClearValue.DepthStencil .Stencil = 0 ;
313313
314+ const CD3DX12_HEAP_PROPERTIES depthStencilHeapProps (D3D12_HEAP_TYPE_DEFAULT);
315+ const CD3DX12_RESOURCE_DESC depthStencilTextureDesc = CD3DX12_RESOURCE_DESC::Tex2D (DXGI_FORMAT_D32_FLOAT, m_width, m_height, 1 , 0 , 1 , 0 , D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
316+
314317 ThrowIfFailed (m_device->CreateCommittedResource (
315- &CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT) ,
318+ &depthStencilHeapProps ,
316319 D3D12_HEAP_FLAG_NONE,
317- &CD3DX12_RESOURCE_DESC::Tex2D (DXGI_FORMAT_D32_FLOAT, m_width, m_height, 1 , 0 , 1 , 0 , D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) ,
320+ &depthStencilTextureDesc ,
318321 D3D12_RESOURCE_STATE_DEPTH_WRITE,
319322 &depthOptimizedClearValue,
320323 IID_PPV_ARGS (&m_depthStencil)
@@ -329,10 +332,13 @@ void D3D12MeshletCull::LoadPipeline()
329332 {
330333 const UINT64 constantBufferSize = sizeof (Constants) * FrameCount;
331334
335+ const CD3DX12_HEAP_PROPERTIES constantBufferHeapProps (D3D12_HEAP_TYPE_UPLOAD);
336+ const CD3DX12_RESOURCE_DESC constantBufferDesc = CD3DX12_RESOURCE_DESC::Buffer (constantBufferSize);
337+
332338 ThrowIfFailed (m_device->CreateCommittedResource (
333- &CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD) ,
339+ &constantBufferHeapProps ,
334340 D3D12_HEAP_FLAG_NONE,
335- &CD3DX12_RESOURCE_DESC::Buffer (constantBufferSize) ,
341+ &constantBufferDesc ,
336342 D3D12_RESOURCE_STATE_GENERIC_READ,
337343 nullptr ,
338344 IID_PPV_ARGS (&m_constantBuffer)));
@@ -426,12 +432,15 @@ void D3D12MeshletCull::LoadAssets()
426432 // For per-frame uploads consider using the D3D12_COMMAND_LIST_TYPE_COPY command queue.
427433 obj.Model .LoadFromFile (c_modelFilenames[def.ModelIndex ]);
428434 obj.Model .UploadGpuResources (m_device.Get (), m_commandQueue.Get (), m_commandAllocators[m_frameIndex].Get (), m_commandList.Get ());
429-
435+
436+ const CD3DX12_HEAP_PROPERTIES instanceBufferHeapProps (D3D12_HEAP_TYPE_UPLOAD);
437+ const CD3DX12_RESOURCE_DESC instanceBufferDesc = CD3DX12_RESOURCE_DESC::Buffer (sizeof (Instance) * 2 );
438+
430439 // Create the per-object instance data buffer
431440 ThrowIfFailed (m_device->CreateCommittedResource (
432- &CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_UPLOAD) ,
441+ &instanceBufferHeapProps ,
433442 D3D12_HEAP_FLAG_NONE,
434- &CD3DX12_RESOURCE_DESC::Buffer ( sizeof (Instance) * 2 ) ,
443+ &instanceBufferDesc ,
435444 D3D12_RESOURCE_STATE_GENERIC_READ,
436445 nullptr ,
437446 IID_PPV_ARGS (&obj.InstanceResource )
@@ -657,7 +666,8 @@ void D3D12MeshletCull::PopulateCommandList()
657666 m_commandList->RSSetScissorRects (1 , &m_scissorRect);
658667
659668 // Indicate that the back buffer will be used as a render target.
660- m_commandList->ResourceBarrier (1 , &CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
669+ const auto toRenderTargetBarrier = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);
670+ m_commandList->ResourceBarrier (1 , &toRenderTargetBarrier);
661671
662672 CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle (m_rtvHeap->GetCPUDescriptorHandleForHeapStart (), m_frameIndex, m_rtvDescriptorSize);
663673 CD3DX12_CPU_DESCRIPTOR_HANDLE dsvHandle (m_dsvHeap->GetCPUDescriptorHandleForHeapStart ());
@@ -712,7 +722,8 @@ void D3D12MeshletCull::PopulateCommandList()
712722 }
713723
714724 // Indicate that the back buffer will now be used to present.
715- m_commandList->ResourceBarrier (1 , &CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
725+ const auto toPresentBarrier = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT);
726+ m_commandList->ResourceBarrier (1 , &toPresentBarrier);
716727
717728 ThrowIfFailed (m_commandList->Close ());
718729}
0 commit comments