@@ -153,30 +153,10 @@ void D3D12Quad::LoadAssets()
153153 // in a resource dimension buffer. This will be used for inference in ORT
154154 CreateCurrentBuffer ();
155155
156- const auto present_to_copy_src = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_SOURCE);
157- m_commandList->ResourceBarrier (1 , &present_to_copy_src);
158-
159- auto desc = m_renderTargets[m_frameIndex]->GetDesc ();
160- UINT64 rowSizeInBytes, totalSizeInBytes;
161- m_device->GetCopyableFootprints (&desc, 0 , 1 , 0 , nullptr , nullptr , &rowSizeInBytes, &totalSizeInBytes);
162- D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
163- bufferFootprint.Footprint .Width = static_cast <UINT>(desc.Width );
164- bufferFootprint.Footprint .Height = desc.Height ;
165- bufferFootprint.Footprint .Depth = 1 ;
166- bufferFootprint.Footprint .RowPitch = static_cast <UINT>((rowSizeInBytes + 255 ) & ~255 );
167- bufferFootprint.Footprint .Format = desc.Format ;
168-
169- const CD3DX12_TEXTURE_COPY_LOCATION copyDest (currentBuffer.Get (), bufferFootprint);
170- const CD3DX12_TEXTURE_COPY_LOCATION copySrc (m_renderTargets[m_frameIndex].Get (), 0 );
171-
172- m_commandList->CopyTextureRegion (©Dest, 0 , 0 , 0 , ©Src, nullptr );
173-
174- const auto copy_src_to_present = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PRESENT);
175- m_commandList->ResourceBarrier (1 , ©_src_to_present);
156+ CopyTextureIntoCurrentBuffer ();
176157
177158 // Close the command list and execute it to begin the initial GPU setup.
178- // ThrowIfFailed(m_commandList->Close());
179- auto close_hr = m_commandList->Close ();
159+ ThrowIfFailed (m_commandList->Close ());
180160 ID3D12CommandList* ppCommandLists[] = { m_commandList.Get () };
181161 m_commandQueue->ExecuteCommandLists (_countof (ppCommandLists), ppCommandLists);
182162
@@ -424,6 +404,30 @@ void D3D12Quad::CreateCurrentBuffer()
424404 // IID_PPV_ARGS(¤tBuffer)));
425405}
426406
407+ void D3D12Quad::CopyTextureIntoCurrentBuffer ()
408+ {
409+ const auto present_to_copy_src = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_SOURCE);
410+ m_commandList->ResourceBarrier (1 , &present_to_copy_src);
411+
412+ auto desc = m_renderTargets[m_frameIndex]->GetDesc ();
413+ UINT64 rowSizeInBytes, totalSizeInBytes;
414+ m_device->GetCopyableFootprints (&desc, 0 , 1 , 0 , nullptr , nullptr , &rowSizeInBytes, &totalSizeInBytes);
415+ D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
416+ bufferFootprint.Footprint .Width = static_cast <UINT>(desc.Width );
417+ bufferFootprint.Footprint .Height = desc.Height ;
418+ bufferFootprint.Footprint .Depth = 1 ;
419+ bufferFootprint.Footprint .RowPitch = static_cast <UINT>((rowSizeInBytes + 255 ) & ~255 );
420+ bufferFootprint.Footprint .Format = desc.Format ;
421+
422+ const CD3DX12_TEXTURE_COPY_LOCATION copyDest (currentBuffer.Get (), bufferFootprint);
423+ const CD3DX12_TEXTURE_COPY_LOCATION copySrc (m_renderTargets[m_frameIndex].Get (), 0 );
424+
425+ m_commandList->CopyTextureRegion (©Dest, 0 , 0 , 0 , ©Src, nullptr );
426+
427+ const auto copy_src_to_present = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PRESENT);
428+ m_commandList->ResourceBarrier (1 , ©_src_to_present);
429+ }
430+
427431// Create synchronization objects and wait until assets have been uploaded to the GPU.
428432void D3D12Quad::CreateFence ()
429433{
@@ -528,33 +532,7 @@ void D3D12Quad::PopulateCommandList()
528532 auto render_to_present = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT);
529533 m_commandList->ResourceBarrier (1 , &render_to_present);
530534
531- // copy the current texture into a resource dimension buffer
532- const auto present_to_copy_src = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_SOURCE);
533- m_commandList->ResourceBarrier (1 , &present_to_copy_src);
534-
535- // m_commandList->CopyResource(currentBuffer.Get(), m_renderTargets[m_frameIndex].Get());
536-
537- auto desc = m_renderTargets[m_frameIndex]->GetDesc ();
538- UINT64 rowSizeInBytes, totalSizeInBytes;
539- m_device->GetCopyableFootprints (&desc, 0 , 1 , 0 , nullptr , nullptr , &rowSizeInBytes, &totalSizeInBytes);
540- D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
541- bufferFootprint.Footprint .Width = desc.Width ;
542- bufferFootprint.Footprint .Height = desc.Height ;
543- bufferFootprint.Footprint .Depth = 1 ;
544- bufferFootprint.Footprint .RowPitch = static_cast <UINT>((rowSizeInBytes + 255 ) & ~255 );
545- bufferFootprint.Footprint .Format = desc.Format ;
546-
547- const CD3DX12_TEXTURE_COPY_LOCATION copyDest (currentBuffer.Get (), bufferFootprint);
548- const CD3DX12_TEXTURE_COPY_LOCATION copySrc (m_renderTargets[m_frameIndex].Get (), 0 );
549-
550- // Copy the texture
551- m_commandList->CopyTextureRegion (©Dest, 0 , 0 , 0 , ©Src, nullptr );
552-
553- const auto copy_src_to_present = CD3DX12_RESOURCE_BARRIER::Transition (m_renderTargets[m_frameIndex].Get (), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PRESENT);
554- m_commandList->ResourceBarrier (1 , ©_src_to_present);
555-
556- auto close_hr = m_commandList->Close ();
557- return ;
535+ ThrowIfFailed (m_commandList->Close ());
558536}
559537
560538void D3D12Quad::WaitForPreviousFrame ()
0 commit comments