diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index a29c92b331..07ed882d30 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -102,8 +102,7 @@ void D3D12GSRender::ResourceStorage::Reset() m_currentSamplerIndex = 0; m_samplerDescriptorHeapIndex = 0; - m_commandAllocator->Reset(); - m_nextAvailableCommandListIndex = 0; + ThrowIfFailed(m_commandAllocator->Reset()); setNewCommandList(); m_singleFrameLifetimeResources.clear(); @@ -111,19 +110,7 @@ void D3D12GSRender::ResourceStorage::Reset() void D3D12GSRender::ResourceStorage::setNewCommandList() { - if (m_availableCommandLists.size() > m_nextAvailableCommandListIndex) - { - m_currentCommandList = m_availableCommandLists[m_nextAvailableCommandListIndex].Get(); - m_currentCommandList->Reset(m_commandAllocator.Get(), nullptr); - } - else - { - ComPtr commandList; - ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), nullptr, IID_PPV_ARGS(commandList.GetAddressOf()))); - m_availableCommandLists.push_back(commandList); - m_currentCommandList = m_availableCommandLists.back().Get(); - } - m_nextAvailableCommandListIndex++; + ThrowIfFailed(m_commandList->Reset(m_commandAllocator.Get(), nullptr)); } void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device) @@ -133,6 +120,9 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device) // Create a global command allocator ThrowIfFailed(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(m_commandAllocator.GetAddressOf()))); + ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), nullptr, IID_PPV_ARGS(m_commandList.GetAddressOf()))); + ThrowIfFailed(m_commandList->Close()); + D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapDesc = {}; descriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; descriptorHeapDesc.NumDescriptors = 10000; // For safety @@ -164,7 +154,10 @@ void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device) void D3D12GSRender::ResourceStorage::WaitAndClean(const std::vector &dirtyTextures) { - WaitForSingleObjectEx(m_frameFinishedHandle, INFINITE, FALSE); + if (!m_isUseable) + WaitForSingleObjectEx(m_frameFinishedHandle, INFINITE, FALSE); + else + ThrowIfFailed(m_commandList->Close()); Reset(); @@ -178,7 +171,6 @@ void D3D12GSRender::ResourceStorage::WaitAndClean(const std::vector startDuration = std::chrono::system_clock::now(); - PrepareRenderTargets(getCurrentResourceStorage().m_currentCommandList); + PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get()); assert(cmd == NV4097_CLEAR_SURFACE); - PrepareRenderTargets(getCurrentResourceStorage().m_currentCommandList); + PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get()); /* if (m_set_color_mask) { @@ -473,11 +465,11 @@ void D3D12GSRender::Clear(u32 cmd) if (m_clear_surface_mask & 0x1) { u32 max_depth_value = m_surface_depth_format == CELL_GCM_SURFACE_Z16 ? 0x0000ffff : 0x00ffffff; - getCurrentResourceStorage().m_currentCommandList->ClearDepthStencilView(m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, m_clear_surface_z / (float)max_depth_value, 0, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearDepthStencilView(m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, m_clear_surface_z / (float)max_depth_value, 0, 0, nullptr); } if (m_clear_surface_mask & 0x2) - getCurrentResourceStorage().m_currentCommandList->ClearDepthStencilView(m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_STENCIL, 0.f, m_clear_surface_s, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearDepthStencilView(m_rtts.m_depthStencilDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_STENCIL, 0.f, m_clear_surface_s, 0, nullptr); if (m_clear_surface_mask & 0xF0) { @@ -497,26 +489,26 @@ void D3D12GSRender::Clear(u32 cmd) case CELL_GCM_SURFACE_TARGET_0: case CELL_GCM_SURFACE_TARGET_1: - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); break; case CELL_GCM_SURFACE_TARGET_MRT1: - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); break; case CELL_GCM_SURFACE_TARGET_MRT2: - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); handle.ptr += g_RTTIncrement; - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr); break; case CELL_GCM_SURFACE_TARGET_MRT3: - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 0), clearColor, 0, nullptr); handle.ptr += g_RTTIncrement; - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, g_descriptorStrideRTV), clearColor, 0, nullptr); handle.ptr += g_RTTIncrement; - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 2 * g_descriptorStrideRTV), clearColor, 0, nullptr); handle.ptr += g_RTTIncrement; - getCurrentResourceStorage().m_currentCommandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 3 * g_descriptorStrideRTV), clearColor, 0, nullptr); + getCurrentResourceStorage().m_commandList->ClearRenderTargetView(getCPUDescriptorHandle(m_rtts.m_renderTargetsDescriptorsHeap, 3 * g_descriptorStrideRTV), clearColor, 0, nullptr); break; default: LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target); @@ -526,12 +518,19 @@ void D3D12GSRender::Clear(u32 cmd) std::chrono::time_point endDuration = std::chrono::system_clock::now(); m_timers.m_drawCallDuration += std::chrono::duration_cast(endDuration - startDuration).count(); m_timers.m_drawCallCount++; + + if (Ini.GSDebugOutputEnable.GetValue()) + { + ThrowIfFailed(getCurrentResourceStorage().m_commandList->Close()); + m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().m_commandList.GetAddressOf()); + getCurrentResourceStorage().setNewCommandList(); + } } void D3D12GSRender::Draw() { std::chrono::time_point startDuration = std::chrono::system_clock::now(); - PrepareRenderTargets(getCurrentResourceStorage().m_currentCommandList); + PrepareRenderTargets(getCurrentResourceStorage().m_commandList.Get()); // Init vertex count // TODO: Very hackish, clean this @@ -563,9 +562,9 @@ void D3D12GSRender::Draw() { const std::vector &vertexBufferViews = UploadVertexBuffers(m_indexed_array.m_count ? true : false); const D3D12_INDEX_BUFFER_VIEW &indexBufferView = uploadIndexBuffers(m_indexed_array.m_count ? true : false); - getCurrentResourceStorage().m_currentCommandList->IASetVertexBuffers(0, (UINT)vertexBufferViews.size(), vertexBufferViews.data()); + getCurrentResourceStorage().m_commandList->IASetVertexBuffers(0, (UINT)vertexBufferViews.size(), vertexBufferViews.data()); if (m_renderingInfo.m_indexed) - getCurrentResourceStorage().m_currentCommandList->IASetIndexBuffer(&indexBufferView); + getCurrentResourceStorage().m_commandList->IASetIndexBuffer(&indexBufferView); } if (!LoadProgram()) @@ -575,13 +574,13 @@ void D3D12GSRender::Draw() return; } - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootSignature(m_rootSignatures[m_PSO->second].Get()); - getCurrentResourceStorage().m_currentCommandList->OMSetStencilRef(m_stencil_func_ref); + getCurrentResourceStorage().m_commandList->SetGraphicsRootSignature(m_rootSignatures[m_PSO->second].Get()); + getCurrentResourceStorage().m_commandList->OMSetStencilRef(m_stencil_func_ref); // Constants setScaleOffset(); - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_scaleOffsetDescriptorHeap.GetAddressOf()); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(0, + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_scaleOffsetDescriptorHeap.GetAddressOf()); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(0, getGPUDescriptorHandle(getCurrentResourceStorage().m_scaleOffsetDescriptorHeap.Get(), getCurrentResourceStorage().m_currentScaleOffsetBufferIndex * g_descriptorStrideSRVCBVUAV) ); @@ -593,16 +592,16 @@ void D3D12GSRender::Draw() FillPixelShaderConstantsBuffer(); getCurrentResourceStorage().m_constantsBufferIndex++; - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_constantsBufferDescriptorsHeap.GetAddressOf()); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(1, + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_constantsBufferDescriptorsHeap.GetAddressOf()); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(1, getGPUDescriptorHandle(getCurrentResourceStorage().m_constantsBufferDescriptorsHeap.Get(), currentBufferIndex * g_descriptorStrideSRVCBVUAV) ); - getCurrentResourceStorage().m_currentCommandList->SetPipelineState(m_PSO->first); + getCurrentResourceStorage().m_commandList->SetPipelineState(m_PSO->first); if (m_PSO->second > 0) { - size_t usedTexture = UploadTextures(getCurrentResourceStorage().m_currentCommandList); + size_t usedTexture = UploadTextures(getCurrentResourceStorage().m_commandList.Get()); // Fill empty slots for (; usedTexture < m_PSO->second; usedTexture++) @@ -632,14 +631,14 @@ void D3D12GSRender::Draw() ); } - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_textureDescriptorsHeap.GetAddressOf()); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(2, + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_textureDescriptorsHeap.GetAddressOf()); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(2, getGPUDescriptorHandle(getCurrentResourceStorage().m_textureDescriptorsHeap.Get(), getCurrentResourceStorage().m_currentTextureIndex * g_descriptorStrideSRVCBVUAV) ); - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].GetAddressOf()); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(3, + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].GetAddressOf()); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(3, getGPUDescriptorHandle(getCurrentResourceStorage().m_samplerDescriptorHeap[getCurrentResourceStorage().m_samplerDescriptorHeapIndex].Get(), getCurrentResourceStorage().m_currentSamplerIndex * g_descriptorStrideSamplers) ); @@ -669,7 +668,7 @@ void D3D12GSRender::Draw() LOG_ERROR(RSX, "Bad surface color target: %d", m_surface_color_target); } - getCurrentResourceStorage().m_currentCommandList->OMSetRenderTargets((UINT)numRTT, &m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(), true, + getCurrentResourceStorage().m_commandList->OMSetRenderTargets((UINT)numRTT, &m_rtts.m_renderTargetsDescriptorsHeap->GetCPUDescriptorHandleForHeapStart(), true, &getCPUDescriptorHandle(m_rtts.m_depthStencilDescriptorHeap, 0)); D3D12_VIEWPORT viewport = @@ -681,7 +680,7 @@ void D3D12GSRender::Draw() -1.f, 1.f }; - getCurrentResourceStorage().m_currentCommandList->RSSetViewports(1, &viewport); + getCurrentResourceStorage().m_commandList->RSSetViewports(1, &viewport); D3D12_RECT box = { @@ -690,49 +689,56 @@ void D3D12GSRender::Draw() (LONG)m_surface_clip_w, (LONG)m_surface_clip_h, }; - getCurrentResourceStorage().m_currentCommandList->RSSetScissorRects(1, &box); + getCurrentResourceStorage().m_commandList->RSSetScissorRects(1, &box); switch (m_draw_mode - 1) { case GL_POINTS: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST); break; case GL_LINES: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST); break; case GL_LINE_LOOP: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ); break; case GL_LINE_STRIP: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINESTRIP); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_LINESTRIP); break; case GL_TRIANGLES: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); break; case GL_TRIANGLE_STRIP: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); break; case GL_TRIANGLE_FAN: case GL_QUADS: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); break; case GL_QUAD_STRIP: case GL_POLYGON: default: - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); LOG_ERROR(RSX, "Unsupported primitive type"); break; } if (m_renderingInfo.m_indexed) - getCurrentResourceStorage().m_currentCommandList->DrawIndexedInstanced((UINT)m_renderingInfo.m_count, 1, 0, (UINT)m_renderingInfo.m_baseVertex, 0); + getCurrentResourceStorage().m_commandList->DrawIndexedInstanced((UINT)m_renderingInfo.m_count, 1, 0, (UINT)m_renderingInfo.m_baseVertex, 0); else - getCurrentResourceStorage().m_currentCommandList->DrawInstanced((UINT)m_renderingInfo.m_count, 1, (UINT)m_renderingInfo.m_baseVertex, 0); + getCurrentResourceStorage().m_commandList->DrawInstanced((UINT)m_renderingInfo.m_count, 1, (UINT)m_renderingInfo.m_baseVertex, 0); m_indexed_array.Reset(); std::chrono::time_point endDuration = std::chrono::system_clock::now(); m_timers.m_drawCallDuration += std::chrono::duration_cast(endDuration - startDuration).count(); m_timers.m_drawCallCount++; + + if (Ini.GSDebugOutputEnable.GetValue()) + { + ThrowIfFailed(getCurrentResourceStorage().m_commandList->Close()); + m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().m_commandList.GetAddressOf()); + getCurrentResourceStorage().setNewCommandList(); + } } static bool @@ -818,20 +824,20 @@ void D3D12GSRender::Flip() src.PlacedFootprint.Footprint.Height = (UINT)h; src.PlacedFootprint.Footprint.Depth = (UINT)1; src.PlacedFootprint.Footprint.RowPitch = (UINT)rowPitch; - getCurrentResourceStorage().m_currentCommandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + getCurrentResourceStorage().m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ)); resourceToFlip = storage.m_RAMFramebuffer.Get(); viewport_w = (float)w, viewport_h = (float)h; } else { if (m_rtts.m_currentlyBoundRenderTargets[0] != nullptr) - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_GENERIC_READ)); resourceToFlip = m_rtts.m_currentlyBoundRenderTargets[0]; } - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET)); D3D12_VIEWPORT viewport = { @@ -842,7 +848,7 @@ void D3D12GSRender::Flip() 0.f, 1.f }; - getCurrentResourceStorage().m_currentCommandList->RSSetViewports(1, &viewport); + getCurrentResourceStorage().m_commandList->RSSetViewports(1, &viewport); D3D12_RECT box = { @@ -851,9 +857,9 @@ void D3D12GSRender::Flip() (LONG)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Width, (LONG)m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()]->GetDesc().Height, }; - getCurrentResourceStorage().m_currentCommandList->RSSetScissorRects(1, &box); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootSignature(m_outputScalingPass.m_rootSignature); - getCurrentResourceStorage().m_currentCommandList->SetPipelineState(m_outputScalingPass.m_PSO); + getCurrentResourceStorage().m_commandList->RSSetScissorRects(1, &box); + getCurrentResourceStorage().m_commandList->SetGraphicsRootSignature(m_outputScalingPass.m_rootSignature); + getCurrentResourceStorage().m_commandList->SetPipelineState(m_outputScalingPass.m_PSO); D3D12_CPU_DESCRIPTOR_HANDLE CPUHandle; CPUHandle = m_outputScalingPass.m_textureDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); CPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * m_swapChain->GetCurrentBackBufferIndex(); @@ -885,30 +891,30 @@ void D3D12GSRender::Flip() D3D12_GPU_DESCRIPTOR_HANDLE GPUHandle; GPUHandle = m_outputScalingPass.m_textureDescriptorHeap->GetGPUDescriptorHandleForHeapStart(); GPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) * m_swapChain->GetCurrentBackBufferIndex(); - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_textureDescriptorHeap); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(0, GPUHandle); + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_textureDescriptorHeap); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(0, GPUHandle); GPUHandle = m_outputScalingPass.m_samplerDescriptorHeap->GetGPUDescriptorHandleForHeapStart(); GPUHandle.ptr += m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) * m_swapChain->GetCurrentBackBufferIndex(); - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_samplerDescriptorHeap); - getCurrentResourceStorage().m_currentCommandList->SetGraphicsRootDescriptorTable(1, GPUHandle); + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &m_outputScalingPass.m_samplerDescriptorHeap); + getCurrentResourceStorage().m_commandList->SetGraphicsRootDescriptorTable(1, GPUHandle); CPUHandle = m_backbufferAsRendertarget[m_swapChain->GetCurrentBackBufferIndex()]->GetCPUDescriptorHandleForHeapStart(); - getCurrentResourceStorage().m_currentCommandList->OMSetRenderTargets(1, &CPUHandle, true, nullptr); + getCurrentResourceStorage().m_commandList->OMSetRenderTargets(1, &CPUHandle, true, nullptr); D3D12_VERTEX_BUFFER_VIEW vbv = {}; vbv.BufferLocation = m_outputScalingPass.m_vertexBuffer->GetGPUVirtualAddress(); vbv.StrideInBytes = 4 * sizeof(float); vbv.SizeInBytes = 16 * sizeof(float); - getCurrentResourceStorage().m_currentCommandList->IASetVertexBuffers(0, 1, &vbv); - getCurrentResourceStorage().m_currentCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); + getCurrentResourceStorage().m_commandList->IASetVertexBuffers(0, 1, &vbv); + getCurrentResourceStorage().m_commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); if (m_rtts.m_currentlyBoundRenderTargets[0] != nullptr) - getCurrentResourceStorage().m_currentCommandList->DrawInstanced(4, 1, 0, 0); + getCurrentResourceStorage().m_commandList->DrawInstanced(4, 1, 0, 0); if (!Ini.GSOverlay.GetValue()) - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_backBuffer[m_swapChain->GetCurrentBackBufferIndex()].Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT)); if (isFlipSurfaceInLocalMemory(m_surface_color_target) && m_rtts.m_currentlyBoundRenderTargets[0] != nullptr) - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET)); - ThrowIfFailed(getCurrentResourceStorage().m_currentCommandList->Close()); - m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&(getCurrentResourceStorage().m_currentCommandList)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundRenderTargets[0], D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_RENDER_TARGET)); + ThrowIfFailed(getCurrentResourceStorage().m_commandList->Close()); + m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().m_commandList.GetAddressOf()); if(Ini.GSOverlay.GetValue()) renderOverlay(); @@ -1151,13 +1157,13 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) m_device->CreateUnorderedAccessView(depthConverted.Get(), nullptr, &uavDesc, Handle); // Convert - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_DEPTH_WRITE, D3D12_RESOURCE_STATE_GENERIC_READ)); - getCurrentResourceStorage().m_currentCommandList->SetPipelineState(m_convertPSO); - getCurrentResourceStorage().m_currentCommandList->SetComputeRootSignature(m_convertRootSignature); - getCurrentResourceStorage().m_currentCommandList->SetDescriptorHeaps(1, &descriptorHeap); - getCurrentResourceStorage().m_currentCommandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart()); - getCurrentResourceStorage().m_currentCommandList->Dispatch(m_surface_clip_w / 8, m_surface_clip_h / 8, 1); + getCurrentResourceStorage().m_commandList->SetPipelineState(m_convertPSO); + getCurrentResourceStorage().m_commandList->SetComputeRootSignature(m_convertRootSignature); + getCurrentResourceStorage().m_commandList->SetDescriptorHeaps(1, &descriptorHeap); + getCurrentResourceStorage().m_commandList->SetComputeRootDescriptorTable(0, descriptorHeap->GetGPUDescriptorHandleForHeapStart()); + getCurrentResourceStorage().m_commandList->Dispatch(m_surface_clip_w / 8, m_surface_clip_h / 8, 1); // Flush UAV D3D12_RESOURCE_BARRIER uavbarrier = {}; @@ -1169,8 +1175,8 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) getResourceBarrierTransition(m_rtts.m_currentlyBoundDepthStencil, D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_DEPTH_WRITE), uavbarrier, }; - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(2, barriers); - getCurrentResourceStorage().m_currentCommandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE)); + getCurrentResourceStorage().m_commandList->ResourceBarrier(2, barriers); + getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &getResourceBarrierTransition(depthConverted.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE)); } if (m_set_context_dma_z && Ini.GSDumpDepthBuffer.GetValue()) @@ -1187,7 +1193,7 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) dst.PlacedFootprint.Footprint.Height = m_surface_clip_h; dst.PlacedFootprint.Footprint.Width = m_surface_clip_w; dst.PlacedFootprint.Footprint.RowPitch = (UINT)depthRowPitch; - getCurrentResourceStorage().m_currentCommandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); + getCurrentResourceStorage().m_commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); invalidateTexture(GetAddress(m_surface_offset_z, m_context_dma_z - 0xfeed0000)); } @@ -1201,29 +1207,29 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) break; case CELL_GCM_SURFACE_TARGET_0: - if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_currentCommandList); + if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_commandList.Get()); break; case CELL_GCM_SURFACE_TARGET_1: - if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_currentCommandList); + if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_commandList.Get()); break; case CELL_GCM_SURFACE_TARGET_MRT1: - if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_currentCommandList); + if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_commandList.Get()); break; case CELL_GCM_SURFACE_TARGET_MRT2: - if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_c) rtt2 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[2], getCurrentResourceStorage().m_currentCommandList); + if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_c) rtt2 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[2], getCurrentResourceStorage().m_commandList.Get()); break; case CELL_GCM_SURFACE_TARGET_MRT3: - if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_c) rtt2 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[2], getCurrentResourceStorage().m_currentCommandList); - if (m_context_dma_color_d) rtt3 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[3], getCurrentResourceStorage().m_currentCommandList); + if (m_context_dma_color_a) rtt0 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[0], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_b) rtt1 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[1], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_c) rtt2 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[2], getCurrentResourceStorage().m_commandList.Get()); + if (m_context_dma_color_d) rtt3 = writeColorBuffer(m_rtts.m_currentlyBoundRenderTargets[3], getCurrentResourceStorage().m_commandList.Get()); break; } @@ -1234,8 +1240,8 @@ void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) } if (needTransfer) { - ThrowIfFailed(getCurrentResourceStorage().m_currentCommandList->Close()); - m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)&(getCurrentResourceStorage().m_currentCommandList)); + ThrowIfFailed(getCurrentResourceStorage().m_commandList->Close()); + m_commandQueueGraphic->ExecuteCommandLists(1, (ID3D12CommandList**)getCurrentResourceStorage().m_commandList.GetAddressOf()); getCurrentResourceStorage().setNewCommandList(); } diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index 6471e6055f..1d4f58d323 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -307,8 +307,7 @@ private: // Pointer to device, not owned by ResourceStorage ID3D12Device *m_device; ComPtr m_commandAllocator; - std::vector > m_availableCommandLists; - size_t m_nextAvailableCommandListIndex; + ComPtr m_commandList; // Constants storage ComPtr m_constantsBufferDescriptorsHeap; @@ -328,7 +327,6 @@ private: // List of resources that can be freed after frame is flipped std::vector > m_singleFrameLifetimeResources; - ID3D12GraphicsCommandList *m_currentCommandList; void Reset(); void Init(ID3D12Device *device);