From 5629a8248e974001c505794ff2f3f2dcfd18c5e4 Mon Sep 17 00:00:00 2001 From: Triang3l Date: Fri, 20 Jul 2018 17:18:57 +0300 Subject: [PATCH] [D3D12] Use a single command list for all composition --- src/xenia/ui/d3d12/d3d12_context.cc | 19 +++++--------- src/xenia/ui/d3d12/d3d12_context.h | 6 +++-- src/xenia/ui/d3d12/d3d12_immediate_drawer.cc | 27 +++++--------------- src/xenia/ui/d3d12/d3d12_immediate_drawer.h | 10 +++++--- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/xenia/ui/d3d12/d3d12_context.cc b/src/xenia/ui/d3d12/d3d12_context.cc index 6ff4d7eed..4feefa00c 100644 --- a/src/xenia/ui/d3d12/d3d12_context.cc +++ b/src/xenia/ui/d3d12/d3d12_context.cc @@ -108,14 +108,11 @@ bool D3D12Context::Initialize() { return false; } - // Create command lists for swap chain back buffer state transitions. + // Create command lists for compositing. for (uint32_t i = 0; i < kQueuedFrames; ++i) { - swap_command_lists_begin_[i] = CommandList::Create( + swap_command_lists_[i] = CommandList::Create( device, direct_queue, D3D12_COMMAND_LIST_TYPE_DIRECT); - swap_command_lists_end_[i] = CommandList::Create( - device, direct_queue, D3D12_COMMAND_LIST_TYPE_DIRECT); - if (swap_command_lists_begin_[i] == nullptr || - swap_command_lists_end_[i] == nullptr) { + if (swap_command_lists_[i] == nullptr) { Shutdown(); return false; } @@ -172,8 +169,7 @@ void D3D12Context::Shutdown() { if (swap_chain_ != nullptr) { for (uint32_t i = 0; i < kQueuedFrames; ++i) { - swap_command_lists_end_[i].reset(); - swap_command_lists_begin_[i].reset(); + swap_command_lists_[i].reset(); } for (uint32_t i = 0; i < kSwapChainBufferCount; ++i) { @@ -254,7 +250,7 @@ void D3D12Context::BeginSwap() { } // Make the back buffer a render target. - auto command_list = swap_command_lists_begin_[current_queue_frame_].get(); + auto command_list = swap_command_lists_[current_queue_frame_].get(); auto graphics_command_list = command_list->BeginRecording(); D3D12_RESOURCE_BARRIER barrier; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; @@ -265,7 +261,6 @@ void D3D12Context::BeginSwap() { barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; graphics_command_list->ResourceBarrier(1, &barrier); - command_list->Execute(); } } @@ -276,8 +271,8 @@ void D3D12Context::EndSwap() { if (target_window_ != nullptr) { // Switch the back buffer to presentation state. - auto command_list = swap_command_lists_end_[current_queue_frame_].get(); - auto graphics_command_list = command_list->BeginRecording(); + auto command_list = swap_command_lists_[current_queue_frame_].get(); + auto graphics_command_list = command_list->GetCommandList(); D3D12_RESOURCE_BARRIER barrier; barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; diff --git a/src/xenia/ui/d3d12/d3d12_context.h b/src/xenia/ui/d3d12/d3d12_context.h index 62cd3ea81..ff48c8cfd 100644 --- a/src/xenia/ui/d3d12/d3d12_context.h +++ b/src/xenia/ui/d3d12/d3d12_context.h @@ -67,6 +67,9 @@ class D3D12Context : public GraphicsContext { D3D12_CPU_DESCRIPTOR_HANDLE GetSwapChainBackBufferRTV() const { return GetSwapChainBufferRTV(GetSwapChainBackBufferIndex()); } + ID3D12GraphicsCommandList* GetSwapCommandList() const { + return swap_command_lists_[current_queue_frame_]->GetCommandList(); + } private: friend class D3D12Provider; @@ -94,8 +97,7 @@ class D3D12Context : public GraphicsContext { uint32_t swap_chain_back_buffer_index_ = 0; ID3D12DescriptorHeap* swap_chain_rtv_heap_ = nullptr; D3D12_CPU_DESCRIPTOR_HANDLE swap_chain_rtv_heap_start_; - std::unique_ptr swap_command_lists_begin_[kQueuedFrames] = {}; - std::unique_ptr swap_command_lists_end_[kQueuedFrames] = {}; + std::unique_ptr swap_command_lists_[kQueuedFrames] = {}; std::unique_ptr immediate_drawer_ = nullptr; }; diff --git a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc index e13c03b70..185a6dc54 100644 --- a/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc +++ b/src/xenia/ui/d3d12/d3d12_immediate_drawer.cc @@ -83,16 +83,8 @@ bool D3D12ImmediateDrawer::Initialize() { uint32_t(SamplerIndex::kLinearRepeat) * sampler_size; device->CreateSampler(&sampler_desc, sampler_handle); - // Create the command lists. - ID3D12CommandQueue* direct_queue = provider->GetDirectQueue(); - for (uint32_t i = 0; i < D3D12Context::kQueuedFrames; ++i) { - command_lists_[i] = CommandList::Create(device, direct_queue, - D3D12_COMMAND_LIST_TYPE_DIRECT); - if (command_lists_[i] == nullptr) { - Shutdown(); - return false; - } - } + // Reset the current state. + current_command_list_ = nullptr; return true; } @@ -103,10 +95,6 @@ void D3D12ImmediateDrawer::Shutdown() { } texture_uploads_submitted_.clear(); - for (uint32_t i = 0; i < D3D12Context::kQueuedFrames; ++i) { - command_lists_[i].reset(); - } - if (sampler_heap_ != nullptr) { sampler_heap_->Release(); sampler_heap_ = nullptr; @@ -128,6 +116,9 @@ void D3D12ImmediateDrawer::UpdateTexture(ImmediateTexture* texture, void D3D12ImmediateDrawer::Begin(int render_target_width, int render_target_height) { + // Use the compositing command list. + current_command_list_ = context_->GetSwapCommandList(); + uint32_t queue_frame = context_->GetCurrentQueueFrame(); uint64_t last_completed_frame = context_->GetLastCompletedFrame(); @@ -144,10 +135,6 @@ void D3D12ImmediateDrawer::Begin(int render_target_width, } texture_uploads_submitted_.erase(texture_uploads_submitted_.begin(), erase_uploads_end); - - // Start a command list recording. - ID3D12GraphicsCommandList* command_list = - command_lists_[queue_frame]->BeginRecording(); } void D3D12ImmediateDrawer::BeginDrawBatch(const ImmediateDrawBatch& batch) { @@ -162,9 +149,7 @@ void D3D12ImmediateDrawer::EndDrawBatch() { // TODO(Triang3l): Implement EndDrawBatch. } -void D3D12ImmediateDrawer::End() { - command_lists_[context_->GetCurrentQueueFrame()]->Execute(); -} +void D3D12ImmediateDrawer::End() { current_command_list_ = nullptr; } } // namespace d3d12 } // namespace ui diff --git a/src/xenia/ui/d3d12/d3d12_immediate_drawer.h b/src/xenia/ui/d3d12/d3d12_immediate_drawer.h index 165aaa27a..39b4b4e15 100644 --- a/src/xenia/ui/d3d12/d3d12_immediate_drawer.h +++ b/src/xenia/ui/d3d12/d3d12_immediate_drawer.h @@ -30,9 +30,11 @@ class D3D12ImmediateDrawer : public ImmediateDrawer { bool Initialize(); void Shutdown(); - std::unique_ptr CreateTexture( - uint32_t width, uint32_t height, ImmediateTextureFilter filter, - bool repeat, const uint8_t* data) override; + std::unique_ptr CreateTexture(uint32_t width, + uint32_t height, + ImmediateTextureFilter filter, + bool repeat, + const uint8_t* data) override; void UpdateTexture(ImmediateTexture* texture, const uint8_t* data) override; void Begin(int render_target_width, int render_target_height) override; @@ -56,7 +58,7 @@ class D3D12ImmediateDrawer : public ImmediateDrawer { D3D12_CPU_DESCRIPTOR_HANDLE sampler_heap_cpu_start_; D3D12_GPU_DESCRIPTOR_HANDLE sampler_heap_gpu_start_; - std::unique_ptr command_lists_[D3D12Context::kQueuedFrames] = {}; + ID3D12GraphicsCommandList* current_command_list_ = nullptr; struct SubmittedTextureUpload { ID3D12Resource* data_resource;