From 863326b5cdad7dd0a7775cc6944f4d5d2babe5b2 Mon Sep 17 00:00:00 2001 From: Asuka <6732524+Inori@users.noreply.github.com> Date: Tue, 5 Apr 2022 07:54:28 +0800 Subject: [PATCH] fix presenter bug caused by forget to update frame index add some comments on submission and presentation loop disable GPCS4_NO_GRAPHICS again --- GPCS4/GPCS4Common.h | 2 +- GPCS4/GPCS4Config.h | 2 +- GPCS4/Graphics/Gnm/GnmDataFormat.cpp | 2 +- GPCS4/Graphics/Sce/SceGnmDriver.cpp | 8 ++++++++ GPCS4/Graphics/Sce/ScePresenter.cpp | 8 +++++++- GPCS4/Graphics/Violet/VltQueue.cpp | 15 ++++++++++++++- GPCS4/Graphics/VirtualGPU.h | 4 ++-- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/GPCS4/GPCS4Common.h b/GPCS4/GPCS4Common.h index 9356188f..de553830 100644 --- a/GPCS4/GPCS4Common.h +++ b/GPCS4/GPCS4Common.h @@ -4,6 +4,6 @@ #include "GPCS4Types.h" #include "GPCS4Log.h" #include "GPCS4Decoration.h" -#include "IntelliSenseClang.h" +#include "IntellisenseClang.h" #include "UtilMath.h" diff --git a/GPCS4/GPCS4Config.h b/GPCS4/GPCS4Config.h index 99cb3f65..8751395c 100644 --- a/GPCS4/GPCS4Config.h +++ b/GPCS4/GPCS4Config.h @@ -24,5 +24,5 @@ // Graphics switch // Define this will turn off graphics output, // useful when developing non-graphics parts of GPCS4 -#define GPCS4_NO_GRAPHICS +// #define GPCS4_NO_GRAPHICS diff --git a/GPCS4/Graphics/Gnm/GnmDataFormat.cpp b/GPCS4/Graphics/Gnm/GnmDataFormat.cpp index 9946352b..ef851de4 100644 --- a/GPCS4/Graphics/Gnm/GnmDataFormat.cpp +++ b/GPCS4/Graphics/Gnm/GnmDataFormat.cpp @@ -625,7 +625,7 @@ bool DataFormat::getRenderTargetChannelOrder(RenderTargetChannelOrder* outOrder) } goto LABEL_42; } - v11 = 288231505728184512LL; + v11 = 0x4000107000120C0LL; v12 = v5 == 4 && v6 == 5; v13 = v12 && v8 == 6; if (_bittest64(&v11, v3)) diff --git a/GPCS4/Graphics/Sce/SceGnmDriver.cpp b/GPCS4/Graphics/Sce/SceGnmDriver.cpp index 9e292f76..17c147f2 100644 --- a/GPCS4/Graphics/Sce/SceGnmDriver.cpp +++ b/GPCS4/Graphics/Sce/SceGnmDriver.cpp @@ -173,6 +173,9 @@ namespace sce LOG_ASSERT(count == 1, "Currently only support 1 cmdbuff at one call."); + // track currently display buffer + // so that we can find it during command buffer recording + // and use it as render target. trackSwapImage(displayBufferIndex); SceGpuCommand cmd = {}; @@ -182,6 +185,7 @@ namespace sce submitPresent(cmdList, displayBufferIndex); + // clear resource tracker every frame resetResourceTracker(); return SCE_OK; @@ -222,6 +226,10 @@ namespace sce // Currently I didn't find a very good place, so I place it here. glfwPollEvents(); + + // TODO: + // Execute the Gnm::DrawCommandBuffer::InitializeDefaultHardwareState command. + return SCE_OK; } diff --git a/GPCS4/Graphics/Sce/ScePresenter.cpp b/GPCS4/Graphics/Sce/ScePresenter.cpp index e02cf10e..59ea96e5 100644 --- a/GPCS4/Graphics/Sce/ScePresenter.cpp +++ b/GPCS4/Graphics/Sce/ScePresenter.cpp @@ -64,7 +64,13 @@ namespace sce info.pSwapchains = &m_swapchain; info.pImageIndices = &m_imageIndex; info.pResults = nullptr; - return vkQueuePresentKHR(m_device.queue, &info); + + VkResult status = vkQueuePresentKHR(m_device.queue, &info); + + m_frameIndex += 1; + m_frameIndex %= m_semaphores.size(); + + return status; } VkResult ScePresenter::recreateSwapChain(const PresenterDesc& desc) diff --git a/GPCS4/Graphics/Violet/VltQueue.cpp b/GPCS4/Graphics/Violet/VltQueue.cpp index fafa3f77..d59164ae 100644 --- a/GPCS4/Graphics/Violet/VltQueue.cpp +++ b/GPCS4/Graphics/Violet/VltQueue.cpp @@ -18,6 +18,8 @@ namespace sce::vlt { auto& cmdList = submission.cmdList; cmdList->submit(submission.waitSync, submission.wakeSync); + + // simulate async m_submitQueue.push(std::move(cmdList)); } @@ -28,10 +30,21 @@ namespace sce::vlt auto& presenter = presentInfo.presenter; presenter->presentImage(); - + // simulate async auto cmdList = m_submitQueue.front(); m_submitQueue.pop(); + // TODO: + // Calling synchronize will block the CPU waiting for the submission done on GPU, + // thus will block the submit thread, slow down the submit speed and drop FPS. + // DXVK's solution is to use another thread dedicated for cmdlist submission + // thus overcome the performance problem, + // see https://github.com/doitsujin/dxvk/blob/master/src/dxvk/dxvk_queue.cpp + // + // This can be easily implemented, but for now, our bottleneck is not here obviously. + // So I keep it single threaded to make debugging easier. + + // Wait for command buffer submit finish. cmdList->synchronize(); diff --git a/GPCS4/Graphics/VirtualGPU.h b/GPCS4/Graphics/VirtualGPU.h index 92823e1d..26288d52 100644 --- a/GPCS4/Graphics/VirtualGPU.h +++ b/GPCS4/Graphics/VirtualGPU.h @@ -47,9 +47,9 @@ namespace sce /** * \brief Global GPU mode. * - * Any calls from HLE or emulator to + * Equalrant/implementation of * Gnm::GpuMode getGpuMode(void); - * should be replaced by this mode. + * */ Gnm::GpuMode mode();