Skip to content

Commit

Permalink
Swapchain's queue to write its buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
locke-lunarg committed Sep 5, 2024
1 parent 208eb66 commit 5b3dde3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 3 additions & 3 deletions framework/decode/dx12_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void Dx12ReplayConsumerBase::ApplyBatchedResourceInitInfo(
// 4. After ExecuteCommandLists, the current back buffer index has to back init.
IDXGISwapChain3* swapchain = nullptr;
DxgiSwapchainInfo* swapchain_extra_info = nullptr;
ID3D12CommandQueue* swapchain_queue = nullptr;
ID3D12CommandQueue* queue = nullptr;

resource_data_util_->ResetCommandList();

Expand All @@ -398,7 +398,7 @@ void Dx12ReplayConsumerBase::ApplyBatchedResourceInitInfo(
{
auto swapchain_info = GetObjectInfo(extra_info->swap_chain_id);
swapchain_extra_info = GetExtraInfo<DxgiSwapchainInfo>(swapchain_info);
swapchain_queue = swapchain_extra_info->command_queue;
queue = swapchain_extra_info->command_queue;
swapchain = reinterpret_cast<IDXGISwapChain3*>(swapchain_info->object);
while (extra_info->buffer_index != swapchain->GetCurrentBackBufferIndex())
{
Expand All @@ -407,7 +407,7 @@ void Dx12ReplayConsumerBase::ApplyBatchedResourceInitInfo(
}
}
resource_data_util_->CloseCommandList();
resource_data_util_->ExecuteAndWaitForCommandList(swapchain_queue);
resource_data_util_->ExecuteAndWaitForCommandList(queue);

if (swapchain && swapchain_extra_info)
{
Expand Down
2 changes: 2 additions & 0 deletions framework/encode/d3d12_capture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ void D3D12CaptureManager::InitializeSwapChainBufferResourceInfo(IDXGISwapChain_W
auto info = resource_wrapper->GetObjectInfo();
GFXRECON_ASSERT(info);

info->swapchain_wrapper = wrapper;

// Get the swapchain's native ID3D12Device
graphics::dx12::ID3D12DeviceComPtr device;
wrapper->GetDevice(IID_PPV_ARGS(&device));
Expand Down
3 changes: 3 additions & 0 deletions framework/encode/dx12_object_wrapper_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct IUnknown_Wrapper;
class ID3D12Resource_Wrapper;
class ID3D12Device_Wrapper;
class ID3D12Heap_Wrapper;
class IDXGISwapChain_Wrapper;

struct GUID_Hash
{
Expand Down Expand Up @@ -414,6 +415,8 @@ struct ID3D12ResourceInfo : public DxWrapperInfo

ID3D12Heap_Wrapper* heap_wrapper{ nullptr };
uint64_t heap_offset;

IDXGISwapChain_Wrapper* swapchain_wrapper{ nullptr };
};

struct ID3D12HeapInfo : public DxWrapperInfo
Expand Down
11 changes: 10 additions & 1 deletion framework/encode/dx12_state_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,23 @@ void Dx12StateWriter::WriteResourceSnapshot(graphics::Dx12ResourceDataUtil* reso

bool try_map_and_copy = !is_reserved_resouce && !is_texture_with_unknown_layout;

graphics::dx12::ID3D12CommandQueueComPtr queue = nullptr;
if (resource_info->swapchain_wrapper)
{
// Needs swapchain's queue to write its buffer.
auto swapchain_info = resource_info->swapchain_wrapper->GetObjectInfo();
queue = swapchain_info->command_queue;
}
// Read the data from the resource.
HRESULT result = resource_data_util->ReadFromResource(resource,
try_map_and_copy,
resource_info->subresource_transitions,
resource_info->subresource_transitions,
temp_subresource_data_,
temp_subresource_offsets_,
temp_subresource_sizes_);
temp_subresource_sizes_,
nullptr,
queue);

if (SUCCEEDED(result))
{
Expand Down
11 changes: 7 additions & 4 deletions framework/graphics/dx12_resource_data_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ HRESULT Dx12ResourceDataUtil::ReadFromResource(ID3D12Resource*
std::vector<uint8_t>& data,
std::vector<uint64_t>& subresource_offsets,
std::vector<uint64_t>& subresource_sizes,
ID3D12Resource* staging_buffer_for_batching)
ID3D12Resource* staging_buffer_for_batching,
ID3D12CommandQueue* queue)
{
HRESULT result = E_FAIL;

Expand Down Expand Up @@ -441,7 +442,8 @@ HRESULT Dx12ResourceDataUtil::ReadFromResource(ID3D12Resource*
before_states,
after_states,
staging_resource,
batching);
batching,
queue);

// After the command list has completed, map the copy resource and read its data.
if (!batching && SUCCEEDED(result))
Expand Down Expand Up @@ -778,7 +780,8 @@ Dx12ResourceDataUtil::ExecuteCopyCommandList(ID3D12Resource*
const std::vector<dx12::ResourceStateInfo>& before_states,
const std::vector<dx12::ResourceStateInfo>& after_states,
ID3D12Resource* staging_buffer,
bool batching)
bool batching,
ID3D12CommandQueue* queue)
{
// Make sure the target resource is resident.
ID3D12Pageable* const pageable = target_resource;
Expand Down Expand Up @@ -822,7 +825,7 @@ Dx12ResourceDataUtil::ExecuteCopyCommandList(ID3D12Resource*
result = command_list_->Close();
if (SUCCEEDED(result))
{
result = ExecuteAndWaitForCommandList();
result = ExecuteAndWaitForCommandList(queue);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions framework/graphics/dx12_resource_data_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class Dx12ResourceDataUtil
std::vector<uint8_t>& data,
std::vector<uint64_t>& subresource_offsets,
std::vector<uint64_t>& subresource_sizes,
ID3D12Resource* staging_buffer_for_batching = nullptr);
ID3D12Resource* staging_buffer_for_batching = nullptr,
ID3D12CommandQueue* queue = nullptr);

HRESULT WriteToResource(ID3D12Resource* target_resource,
bool try_map_and_copy,
Expand Down Expand Up @@ -114,7 +115,8 @@ class Dx12ResourceDataUtil
const std::vector<dx12::ResourceStateInfo>& before_states,
const std::vector<dx12::ResourceStateInfo>& after_states,
ID3D12Resource* staging_buffer = nullptr,
bool batching = false);
bool batching = false,
ID3D12CommandQueue* queue = nullptr);

// Build and execute a command list to transition the target resource's subresources from before_states to
// after_states.
Expand Down

0 comments on commit 5b3dde3

Please sign in to comment.