[D3D12] Use a single command list for all composition
This commit is contained in:
parent
cd1cf3a857
commit
5629a8248e
|
@ -108,14 +108,11 @@ bool D3D12Context::Initialize() {
|
||||||
return false;
|
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) {
|
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);
|
device, direct_queue, D3D12_COMMAND_LIST_TYPE_DIRECT);
|
||||||
swap_command_lists_end_[i] = CommandList::Create(
|
if (swap_command_lists_[i] == nullptr) {
|
||||||
device, direct_queue, D3D12_COMMAND_LIST_TYPE_DIRECT);
|
|
||||||
if (swap_command_lists_begin_[i] == nullptr ||
|
|
||||||
swap_command_lists_end_[i] == nullptr) {
|
|
||||||
Shutdown();
|
Shutdown();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -172,8 +169,7 @@ void D3D12Context::Shutdown() {
|
||||||
|
|
||||||
if (swap_chain_ != nullptr) {
|
if (swap_chain_ != nullptr) {
|
||||||
for (uint32_t i = 0; i < kQueuedFrames; ++i) {
|
for (uint32_t i = 0; i < kQueuedFrames; ++i) {
|
||||||
swap_command_lists_end_[i].reset();
|
swap_command_lists_[i].reset();
|
||||||
swap_command_lists_begin_[i].reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < kSwapChainBufferCount; ++i) {
|
for (uint32_t i = 0; i < kSwapChainBufferCount; ++i) {
|
||||||
|
@ -254,7 +250,7 @@ void D3D12Context::BeginSwap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the back buffer a render target.
|
// 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();
|
auto graphics_command_list = command_list->BeginRecording();
|
||||||
D3D12_RESOURCE_BARRIER barrier;
|
D3D12_RESOURCE_BARRIER barrier;
|
||||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
|
@ -265,7 +261,6 @@ void D3D12Context::BeginSwap() {
|
||||||
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
||||||
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
|
||||||
graphics_command_list->ResourceBarrier(1, &barrier);
|
graphics_command_list->ResourceBarrier(1, &barrier);
|
||||||
command_list->Execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,8 +271,8 @@ void D3D12Context::EndSwap() {
|
||||||
|
|
||||||
if (target_window_ != nullptr) {
|
if (target_window_ != nullptr) {
|
||||||
// Switch the back buffer to presentation state.
|
// Switch the back buffer to presentation state.
|
||||||
auto command_list = swap_command_lists_end_[current_queue_frame_].get();
|
auto command_list = swap_command_lists_[current_queue_frame_].get();
|
||||||
auto graphics_command_list = command_list->BeginRecording();
|
auto graphics_command_list = command_list->GetCommandList();
|
||||||
D3D12_RESOURCE_BARRIER barrier;
|
D3D12_RESOURCE_BARRIER barrier;
|
||||||
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||||
|
|
|
@ -67,6 +67,9 @@ class D3D12Context : public GraphicsContext {
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE GetSwapChainBackBufferRTV() const {
|
D3D12_CPU_DESCRIPTOR_HANDLE GetSwapChainBackBufferRTV() const {
|
||||||
return GetSwapChainBufferRTV(GetSwapChainBackBufferIndex());
|
return GetSwapChainBufferRTV(GetSwapChainBackBufferIndex());
|
||||||
}
|
}
|
||||||
|
ID3D12GraphicsCommandList* GetSwapCommandList() const {
|
||||||
|
return swap_command_lists_[current_queue_frame_]->GetCommandList();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class D3D12Provider;
|
friend class D3D12Provider;
|
||||||
|
@ -94,8 +97,7 @@ class D3D12Context : public GraphicsContext {
|
||||||
uint32_t swap_chain_back_buffer_index_ = 0;
|
uint32_t swap_chain_back_buffer_index_ = 0;
|
||||||
ID3D12DescriptorHeap* swap_chain_rtv_heap_ = nullptr;
|
ID3D12DescriptorHeap* swap_chain_rtv_heap_ = nullptr;
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE swap_chain_rtv_heap_start_;
|
D3D12_CPU_DESCRIPTOR_HANDLE swap_chain_rtv_heap_start_;
|
||||||
std::unique_ptr<CommandList> swap_command_lists_begin_[kQueuedFrames] = {};
|
std::unique_ptr<CommandList> swap_command_lists_[kQueuedFrames] = {};
|
||||||
std::unique_ptr<CommandList> swap_command_lists_end_[kQueuedFrames] = {};
|
|
||||||
|
|
||||||
std::unique_ptr<D3D12ImmediateDrawer> immediate_drawer_ = nullptr;
|
std::unique_ptr<D3D12ImmediateDrawer> immediate_drawer_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,16 +83,8 @@ bool D3D12ImmediateDrawer::Initialize() {
|
||||||
uint32_t(SamplerIndex::kLinearRepeat) * sampler_size;
|
uint32_t(SamplerIndex::kLinearRepeat) * sampler_size;
|
||||||
device->CreateSampler(&sampler_desc, sampler_handle);
|
device->CreateSampler(&sampler_desc, sampler_handle);
|
||||||
|
|
||||||
// Create the command lists.
|
// Reset the current state.
|
||||||
ID3D12CommandQueue* direct_queue = provider->GetDirectQueue();
|
current_command_list_ = nullptr;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -103,10 +95,6 @@ void D3D12ImmediateDrawer::Shutdown() {
|
||||||
}
|
}
|
||||||
texture_uploads_submitted_.clear();
|
texture_uploads_submitted_.clear();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < D3D12Context::kQueuedFrames; ++i) {
|
|
||||||
command_lists_[i].reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sampler_heap_ != nullptr) {
|
if (sampler_heap_ != nullptr) {
|
||||||
sampler_heap_->Release();
|
sampler_heap_->Release();
|
||||||
sampler_heap_ = nullptr;
|
sampler_heap_ = nullptr;
|
||||||
|
@ -128,6 +116,9 @@ void D3D12ImmediateDrawer::UpdateTexture(ImmediateTexture* texture,
|
||||||
|
|
||||||
void D3D12ImmediateDrawer::Begin(int render_target_width,
|
void D3D12ImmediateDrawer::Begin(int render_target_width,
|
||||||
int render_target_height) {
|
int render_target_height) {
|
||||||
|
// Use the compositing command list.
|
||||||
|
current_command_list_ = context_->GetSwapCommandList();
|
||||||
|
|
||||||
uint32_t queue_frame = context_->GetCurrentQueueFrame();
|
uint32_t queue_frame = context_->GetCurrentQueueFrame();
|
||||||
uint64_t last_completed_frame = context_->GetLastCompletedFrame();
|
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(),
|
texture_uploads_submitted_.erase(texture_uploads_submitted_.begin(),
|
||||||
erase_uploads_end);
|
erase_uploads_end);
|
||||||
|
|
||||||
// Start a command list recording.
|
|
||||||
ID3D12GraphicsCommandList* command_list =
|
|
||||||
command_lists_[queue_frame]->BeginRecording();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12ImmediateDrawer::BeginDrawBatch(const ImmediateDrawBatch& batch) {
|
void D3D12ImmediateDrawer::BeginDrawBatch(const ImmediateDrawBatch& batch) {
|
||||||
|
@ -162,9 +149,7 @@ void D3D12ImmediateDrawer::EndDrawBatch() {
|
||||||
// TODO(Triang3l): Implement EndDrawBatch.
|
// TODO(Triang3l): Implement EndDrawBatch.
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D12ImmediateDrawer::End() {
|
void D3D12ImmediateDrawer::End() { current_command_list_ = nullptr; }
|
||||||
command_lists_[context_->GetCurrentQueueFrame()]->Execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace d3d12
|
} // namespace d3d12
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
|
|
@ -30,9 +30,11 @@ class D3D12ImmediateDrawer : public ImmediateDrawer {
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
std::unique_ptr<ImmediateTexture> CreateTexture(
|
std::unique_ptr<ImmediateTexture> CreateTexture(uint32_t width,
|
||||||
uint32_t width, uint32_t height, ImmediateTextureFilter filter,
|
uint32_t height,
|
||||||
bool repeat, const uint8_t* data) override;
|
ImmediateTextureFilter filter,
|
||||||
|
bool repeat,
|
||||||
|
const uint8_t* data) override;
|
||||||
void UpdateTexture(ImmediateTexture* texture, 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;
|
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_CPU_DESCRIPTOR_HANDLE sampler_heap_cpu_start_;
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler_heap_gpu_start_;
|
D3D12_GPU_DESCRIPTOR_HANDLE sampler_heap_gpu_start_;
|
||||||
|
|
||||||
std::unique_ptr<CommandList> command_lists_[D3D12Context::kQueuedFrames] = {};
|
ID3D12GraphicsCommandList* current_command_list_ = nullptr;
|
||||||
|
|
||||||
struct SubmittedTextureUpload {
|
struct SubmittedTextureUpload {
|
||||||
ID3D12Resource* data_resource;
|
ID3D12Resource* data_resource;
|
||||||
|
|
Loading…
Reference in New Issue