From befe93784f6d3ab09e43caa78abc910f8287f2e0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 12 Aug 2015 16:46:32 +0200 Subject: [PATCH] d3d12: Do not create/submit an extra command list for texture upload/rtt state change --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 17 ++++++++--------- rpcs3/Emu/RSX/D3D12/D3D12GSRender.h | 15 +++++++++++---- rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp | 9 +-------- rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp | 14 +++----------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index 46729ee55e..8e06c9348a 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -431,12 +431,12 @@ void D3D12GSRender::Clear(u32 cmd) { assert(cmd == NV4097_CLEAR_SURFACE); - PrepareRenderTargets(); - ID3D12GraphicsCommandList *commandList; check(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList))); getCurrentResourceStorage().m_inflightCommandList.push_back(commandList); + PrepareRenderTargets(commandList); + /* if (m_set_color_mask) { glColorMask(m_color_mask_r, m_color_mask_g, m_color_mask_b, m_color_mask_a); @@ -509,7 +509,11 @@ void D3D12GSRender::Clear(u32 cmd) void D3D12GSRender::Draw() { - PrepareRenderTargets(); + ID3D12GraphicsCommandList *commandList; + m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList)); + getCurrentResourceStorage().m_inflightCommandList.push_back(commandList); + + PrepareRenderTargets(commandList); // Init vertex count // TODO: Very hackish, clean this @@ -536,11 +540,6 @@ void D3D12GSRender::Draw() } } - ID3D12GraphicsCommandList *commandList; - m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(&commandList)); - getCurrentResourceStorage().m_inflightCommandList.push_back(commandList); - - std::chrono::time_point startVertexTime = std::chrono::system_clock::now(); if (m_indexed_array.m_count || m_draw_array_count) { @@ -588,7 +587,7 @@ void D3D12GSRender::Draw() if (m_PSO->second > 0) { std::chrono::time_point startTextureTime = std::chrono::system_clock::now(); - size_t usedTexture = UploadTextures(); + size_t usedTexture = UploadTextures(commandList); // Fill empty slots for (; usedTexture < m_PSO->second; usedTexture++) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index 87cdbabe62..14e0c405f1 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -402,12 +402,19 @@ private: void FillVertexShaderConstantsBuffer(); void FillPixelShaderConstantsBuffer(); /** - * Upload textures to Data heap if necessary and create necessary descriptor in the per frame storage struct. - * returns the number of texture uploaded + * Fetch all textures recorded in the state in the render target cache and in the texture cache. + * If a texture is not cached, populate cmdlist with uploads command. + * Create necessary resource view/sampler descriptors in the per frame storage struct. + * returns the number of texture uploaded. */ - size_t UploadTextures(); + size_t UploadTextures(ID3D12GraphicsCommandList *cmdlist); - void PrepareRenderTargets(); + /** + * Creates render target if necessary. + * Populate cmdlist with render target state change (from RTT to generic read for previous rtt, + * from generic to rtt for rtt in cache). + */ + void PrepareRenderTargets(ID3D12GraphicsCommandList *cmdlist); protected: virtual void OnInit() override; virtual void OnInitThread() override; diff --git a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp index f131d0b102..dc2684c3a9 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12RenderTargetSets.cpp @@ -12,7 +12,7 @@ #include "D3D12.h" #include "D3D12GSRender.h" -void D3D12GSRender::PrepareRenderTargets() +void D3D12GSRender::PrepareRenderTargets(ID3D12GraphicsCommandList *copycmdlist) { // FBO location has changed, previous data might be copied u32 address_a = m_set_context_dma_color_a ? GetAddress(m_surface_offset_a, m_context_dma_color_a - 0xfeed0000) : 0; @@ -21,10 +21,6 @@ void D3D12GSRender::PrepareRenderTargets() u32 address_d = m_set_context_dma_color_d ? GetAddress(m_surface_offset_d, m_context_dma_color_d - 0xfeed0000) : 0; u32 address_z = m_set_context_dma_z ? GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000) : 0; - ID3D12GraphicsCommandList *copycmdlist; - check(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_commandAllocator, nullptr, IID_PPV_ARGS(©cmdlist))); - getCurrentResourceStorage().m_inflightCommandList.push_back(copycmdlist); - // Make previous RTTs sampleable for (unsigned i = 0; i < 4; i++) { @@ -141,9 +137,6 @@ void D3D12GSRender::PrepareRenderTargets() } depthStencilViewDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; m_device->CreateDepthStencilView(ds, &depthStencilViewDesc, m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart()); - - check(copycmdlist->Close()); - m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)©cmdlist); } ID3D12Resource *RenderTargets::bindAddressAsRenderTargets(ID3D12Device *device, ID3D12GraphicsCommandList *cmdList, size_t slot, u32 address, diff --git a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp index 2038ec5b52..2ca3963d90 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12Texture.cpp @@ -726,7 +726,7 @@ size_t getTextureSize(const RSXTexture &texture) } } -size_t D3D12GSRender::UploadTextures() +size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist) { std::lock_guard lock(mut); size_t usedTexture = 0; @@ -758,15 +758,7 @@ size_t D3D12GSRender::UploadTextures() } else { - // Upload at each iteration to take advantage of overlapping transfer - ID3D12GraphicsCommandList *commandList; - check(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, getCurrentResourceStorage().m_textureUploadCommandAllocator, nullptr, IID_PPV_ARGS(&commandList))); - - vramTexture = uploadSingleTexture(m_textures[i], m_device, commandList, m_textureUploadData); - - check(commandList->Close()); - m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&commandList); - getCurrentResourceStorage().m_inflightCommandList.push_back(commandList); + vramTexture = uploadSingleTexture(m_textures[i], m_device, cmdlist, m_textureUploadData); m_texturesCache[texaddr] = vramTexture; u32 s = (u32)align(getTextureSize(m_textures[i]), 4096); @@ -897,4 +889,4 @@ size_t D3D12GSRender::UploadTextures() return usedTexture; } -#endif +#endif \ No newline at end of file