Skip to content

Commit 28df502

Browse files
committed
Fixing cmd list close err
1 parent e5c9d88 commit 28df502

File tree

2 files changed

+83
-22
lines changed

2 files changed

+83
-22
lines changed

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/D3D12Quad.cpp

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,28 @@ 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+
D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
161+
bufferFootprint.Footprint.Width = static_cast<UINT>(desc.Width);
162+
bufferFootprint.Footprint.Height = desc.Height;
163+
bufferFootprint.Footprint.Depth = 1;
164+
bufferFootprint.Footprint.RowPitch = static_cast<UINT>(imageBytesPerRow);
165+
bufferFootprint.Footprint.Format = desc.Format;
166+
167+
const CD3DX12_TEXTURE_COPY_LOCATION copyDest(currentBuffer.Get(), bufferFootprint);
168+
const CD3DX12_TEXTURE_COPY_LOCATION copySrc(m_renderTargets[m_frameIndex].Get(), 0);
169+
170+
m_commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, nullptr);
171+
172+
const auto copy_src_to_present = CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PRESENT);
173+
m_commandList->ResourceBarrier(1, &copy_src_to_present);
174+
156175
// Close the command list and execute it to begin the initial GPU setup.
157-
ThrowIfFailed(m_commandList->Close());
176+
//ThrowIfFailed(m_commandList->Close());
177+
auto close_hr = m_commandList->Close();
158178
ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
159179
m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
160180

@@ -288,7 +308,6 @@ void D3D12Quad::CreateVertexBuffer()
288308
void D3D12Quad::LoadImageTexture() {
289309
// Load the image from file
290310
D3D12_RESOURCE_DESC textureDesc;
291-
int imageBytesPerRow;
292311
BYTE* imageData;
293312
int imageSize = LoadImageDataFromFile(&imageData, textureDesc, fileNames[fileIndex].c_str(), imageBytesPerRow);
294313

@@ -356,27 +375,51 @@ void D3D12Quad::LoadImageTexture() {
356375
// in a resource dimension buffer. This will be used for inference in ORT
357376
void D3D12Quad::CreateCurrentBuffer()
358377
{
359-
D3D12_RESOURCE_DESC resourceDesc = {
360-
D3D12_RESOURCE_DIMENSION_BUFFER,
361-
0,
362-
static_cast<uint64_t>(800 * 600 * 3 * 4),
363-
1,
364-
1,
365-
1,
366-
DXGI_FORMAT_UNKNOWN,
367-
{1, 0},
368-
D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
369-
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS
370-
};
371-
372-
auto heap_properties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
373-
ThrowIfFailed(m_device->CreateCommittedResource(
374-
&heap_properties,
378+
//D3D12_RESOURCE_DESC resourceDesc = {
379+
// D3D12_RESOURCE_DIMENSION_BUFFER,
380+
// 0,
381+
// static_cast<uint64_t>(800 * 600 * 3 * 4),
382+
// 1,
383+
// 1,
384+
// 1,
385+
// DXGI_FORMAT_UNKNOWN,
386+
// {1, 0},
387+
// D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
388+
// D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS
389+
//};
390+
391+
// Readback resources must be buffers
392+
auto desc = m_renderTargets[m_frameIndex]->GetDesc();
393+
D3D12_RESOURCE_DESC bufferDesc = {};
394+
bufferDesc.DepthOrArraySize = 1;
395+
bufferDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
396+
bufferDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
397+
bufferDesc.Format = DXGI_FORMAT_UNKNOWN;
398+
//bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
399+
bufferDesc.Height = 1;
400+
bufferDesc.Width = imageBytesPerRow * desc.Height;
401+
//bufferDesc.Width = static_cast<uint64_t>(800 * 600 * 3 * 4);
402+
bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
403+
//bufferDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
404+
bufferDesc.MipLevels = 1;
405+
bufferDesc.SampleDesc.Count = 1;
406+
407+
//auto heap_properties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
408+
const CD3DX12_HEAP_PROPERTIES readBackHeapProperties(D3D12_HEAP_TYPE_READBACK);
409+
auto some_hr = m_device->CreateCommittedResource(
410+
&readBackHeapProperties,
375411
D3D12_HEAP_FLAG_NONE,
376-
&resourceDesc,
412+
&bufferDesc,
377413
D3D12_RESOURCE_STATE_COPY_DEST,
378414
nullptr,
379-
IID_PPV_ARGS(&currentBuffer)));
415+
IID_PPV_ARGS(&currentBuffer));
416+
//ThrowIfFailed(m_device->CreateCommittedResource(
417+
// &readBackHeapProperties,
418+
// D3D12_HEAP_FLAG_NONE,
419+
// &bufferDesc,
420+
// D3D12_RESOURCE_STATE_COPY_DEST,
421+
// nullptr,
422+
// IID_PPV_ARGS(&currentBuffer)));
380423
}
381424

382425
// Create synchronization objects and wait until assets have been uploaded to the GPU.
@@ -486,11 +529,28 @@ void D3D12Quad::PopulateCommandList()
486529
// copy the current texture into a resource dimension buffer
487530
const auto present_to_copy_src = CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_COPY_SOURCE);
488531
m_commandList->ResourceBarrier(1, &present_to_copy_src);
489-
m_commandList->CopyResource(currentBuffer.Get(), m_renderTargets[m_frameIndex].Get());
532+
533+
//m_commandList->CopyResource(currentBuffer.Get(), m_renderTargets[m_frameIndex].Get());
534+
535+
auto desc = m_renderTargets[m_frameIndex]->GetDesc();
536+
D3D12_PLACED_SUBRESOURCE_FOOTPRINT bufferFootprint = {};
537+
bufferFootprint.Footprint.Width = desc.Width;
538+
bufferFootprint.Footprint.Height = desc.Height;
539+
bufferFootprint.Footprint.Depth = 1;
540+
bufferFootprint.Footprint.RowPitch = static_cast<UINT>(imageBytesPerRow);
541+
bufferFootprint.Footprint.Format = desc.Format;
542+
543+
const CD3DX12_TEXTURE_COPY_LOCATION copyDest(currentBuffer.Get(), bufferFootprint);
544+
const CD3DX12_TEXTURE_COPY_LOCATION copySrc(m_renderTargets[m_frameIndex].Get(), 0);
545+
546+
// Copy the texture
547+
m_commandList->CopyTextureRegion(&copyDest, 0, 0, 0, &copySrc, nullptr);
548+
490549
const auto copy_src_to_present = CD3DX12_RESOURCE_BARRIER::Transition(m_renderTargets[m_frameIndex].Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PRESENT);
491550
m_commandList->ResourceBarrier(1, &copy_src_to_present);
492551

493-
ThrowIfFailed(m_commandList->Close());
552+
auto close_hr = m_commandList->Close();
553+
return;
494554
}
495555

496556
void D3D12Quad::WaitForPreviousFrame()

Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/D3D12Quad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ class D3D12Quad
100100
// holds the texture currently being drawn to the screen in
101101
// a resource dimension buffer that will be used by ORT for inference
102102
ComPtr<ID3D12Resource> currentBuffer;
103+
int imageBytesPerRow;
103104
};
104105

0 commit comments

Comments
 (0)