diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index e28efceba7..dea5fde04e 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -410,7 +410,7 @@ void VulkanRenderManager::StopThreads() { presentWaitThread_.join(); } - INFO_LOG(Log::G3D, "Vulkan compiler thread joined. Now wait for any straggling compile tasks."); + INFO_LOG(Log::G3D, "Vulkan compiler thread joined. Now wait for any straggling compile tasks. runCompileThread_ = %d", (int)runCompileThread_); CreateMultiPipelinesTask::WaitForAll(); { diff --git a/Common/Render/TextureAtlas.cpp b/Common/Render/TextureAtlas.cpp index f41cbc1402..24eb22f63c 100644 --- a/Common/Render/TextureAtlas.cpp +++ b/Common/Render/TextureAtlas.cpp @@ -61,8 +61,10 @@ bool Atlas::Load(const uint8_t *data, size_t data_size) { return false; } - images = reader.ReadMultipleAlloc(num_images, header.version >= 1); + delete[] images; + delete[] fonts; + images = reader.ReadMultipleAlloc(num_images, header.version >= 1); fonts = new AtlasFont[num_fonts]; for (int i = 0; i < num_fonts; i++) { AtlasFontHeader font_header = reader.Read(); diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index d51b3c727c..43d5549a58 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -23,7 +23,7 @@ #include "Core/Compatibility.h" #include "Core/Loaders.h" -enum GPUCore { +enum GPUCore : int { GPUCORE_GLES, GPUCORE_SOFTWARE, GPUCORE_DIRECTX9, diff --git a/Core/System.cpp b/Core/System.cpp index abd78a9909..d785e0835f 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -577,6 +577,19 @@ bool PSP_InitStart(const CoreParameter &coreParam) { // Initialize the GPU as far as we can here (do things like load cache files). + if (!gpu) { // should be! + INFO_LOG(Log::Loader, "Starting graphics..."); + Draw::DrawContext *draw = g_CoreParameter.graphicsContext ? g_CoreParameter.graphicsContext->GetDrawContext() : nullptr; + // This set the `gpu` global. + GPUCore gpuCore = PSP_CoreParameter().gpuCore; + bool success = GPU_Init(gpuCore, g_CoreParameter.graphicsContext, draw); + if (!success) { + *error_string = "Unable to initialize rendering engine."; + CPU_Shutdown(false); + g_bootState = BootState::Failed; + } + } + g_bootState = BootState::Complete; }); @@ -606,20 +619,11 @@ BootState PSP_InitUpdate(std::string *error_string) { return BootState::Failed; } - // Ok, async boot completed, let's finish up things on the main thread. - if (!gpu) { // should be! - INFO_LOG(Log::Loader, "Starting graphics..."); - Draw::DrawContext *draw = g_CoreParameter.graphicsContext ? g_CoreParameter.graphicsContext->GetDrawContext() : nullptr; - // This set the `gpu` global. - GPUCore gpuCore = PSP_CoreParameter().gpuCore; - bool success = GPU_Init(gpuCore, g_CoreParameter.graphicsContext, draw); - if (!success) { - *error_string = "Unable to initialize rendering engine."; - PSP_Shutdown(false); - g_bootState = BootState::Off; - Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE); - return BootState::Failed; - } + // Ok, async part of the boot completed, let's finish up things on the main thread. + if (gpu) { + gpu->FinishInitOnMainThread(); + } else { + _dbg_assert_(gpu); } Core_NotifyLifecycle(CoreLifecycle::START_COMPLETE); diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index e45e7ab8bf..350f6d9fd6 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -2783,7 +2783,7 @@ void FramebufferManagerCommon::NotifyBlockTransferAfter(u32 dstBasePtr, int dstS // A few games use this INSTEAD of actually drawing the video image to the screen, they just blast it to // the backbuffer. Detect this and have the framebuffermanager draw the pixels. - if (!useBufferedRendering_ && currentRenderVfb_ != dstRect.vfb) { + if ((!useBufferedRendering_ && currentRenderVfb_ != dstRect.vfb) || dstRect.vfb == nullptr) { return; } diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 496b51c2d0..d59b24850a 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -39,8 +39,6 @@ GPU_D3D11::GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw) context_ = (ID3D11DeviceContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT); D3D_FEATURE_LEVEL featureLevel = (D3D_FEATURE_LEVEL)draw->GetNativeObject(Draw::NativeObject::FEATURE_LEVEL); - stockD3D11.Create(device_); - shaderManagerD3D11_ = new ShaderManagerD3D11(draw, device_, context_, featureLevel); framebufferManagerD3D11_ = new FramebufferManagerD3D11(draw); framebufferManager_ = framebufferManagerD3D11_; @@ -77,6 +75,11 @@ GPU_D3D11::GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw) textureCache_->NotifyConfigChanged(); } +void GPU_D3D11::FinishInitOnMainThread() { + textureCacheD3D11_->InitDeviceObjects(); + stockD3D11.Create(device_); +} + GPU_D3D11::~GPU_D3D11() { stockD3D11.Destroy(); } diff --git a/GPU/D3D11/GPU_D3D11.h b/GPU/D3D11/GPU_D3D11.h index e1d7c5115d..007607f883 100644 --- a/GPU/D3D11/GPU_D3D11.h +++ b/GPU/D3D11/GPU_D3D11.h @@ -34,6 +34,8 @@ public: GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw); ~GPU_D3D11(); + void FinishInitOnMainThread() override; + u32 CheckGPUFeatures() const override; void GetStats(char *buffer, size_t bufsize) override; diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 2adf0c6222..092af920ee 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -75,7 +75,6 @@ GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw) // Some of our defaults are different from hw defaults, let's assert them. // We restore each frame anyway, but here is convenient for tests. - dxstate.Restore(); textureCache_->NotifyConfigChanged(); if (g_Config.bHardwareTessellation) { @@ -87,6 +86,11 @@ GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw) } } +void GPU_DX9::FinishInitOnMainThread() { + textureCacheDX9_->InitDeviceObjects(); + dxstate.Restore(); +} + u32 GPU_DX9::CheckGPUFeatures() const { u32 features = GPUCommonHW::CheckGPUFeatures(); features |= GPU_USE_16BIT_FORMATS; diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 5b675ae481..e199ed17b7 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -34,6 +34,7 @@ class FramebufferManagerDX9; class GPU_DX9 : public GPUCommonHW { public: GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw); + void FinishInitOnMainThread() override; u32 CheckGPUFeatures() const override; diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 49dc7b384d..d263a7e057 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -73,8 +73,6 @@ TextureCacheDX9::TextureCacheDX9(Draw::DrawContext *draw, Draw2D *draw2D) lastBoundTexture = INVALID_TEX; device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE); deviceEx_ = (LPDIRECT3DDEVICE9EX)draw->GetNativeObject(Draw::NativeObject::DEVICE_EX); - - InitDeviceObjects(); } TextureCacheDX9::~TextureCacheDX9() { diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 036fbb4097..109e4d48eb 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -46,6 +46,7 @@ public: void DeviceLost() override { draw_ = nullptr; } void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } + void InitDeviceObjects(); protected: void BindTexture(TexCacheEntry *entry) override; void Unbind() override; @@ -54,7 +55,6 @@ protected: void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override; private: - void InitDeviceObjects(); void ApplySamplingParams(const SamplerCacheKey &key) override; D3DFORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; diff --git a/GPU/GPU.h b/GPU/GPU.h index 9f5a16ce6e..50957e8002 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -21,7 +21,7 @@ #include #include -enum GPUCore; +enum GPUCore : int; class GPUCommon; class GPUDebugInterface; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index dfad60acc8..ff712c3236 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -65,7 +65,6 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) framebufferManagerVulkan_->SetTextureCache(textureCacheVulkan_); framebufferManagerVulkan_->SetDrawEngine(&drawEngine_); framebufferManagerVulkan_->SetShaderManager(shaderManagerVulkan_); - framebufferManagerVulkan_->Init(msaaLevel_); textureCacheVulkan_->SetFramebufferManager(framebufferManagerVulkan_); textureCacheVulkan_->SetShaderManager(shaderManagerVulkan_); textureCacheVulkan_->SetDrawEngine(&drawEngine_); @@ -92,6 +91,11 @@ GPU_Vulkan::GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw) InitDeviceObjects(); } +void GPU_Vulkan::FinishInitOnMainThread() { + // This can end up stopping/starting the vulkan render manager. + framebufferManagerVulkan_->Init(msaaLevel_); +} + void GPU_Vulkan::LoadCache(const Path &filename) { if (!g_Config.bShaderCache) { WARN_LOG(Log::G3D, "Shader cache disabled. Not loading."); diff --git a/GPU/Vulkan/GPU_Vulkan.h b/GPU/Vulkan/GPU_Vulkan.h index 3d943de1cf..7e21011ef1 100644 --- a/GPU/Vulkan/GPU_Vulkan.h +++ b/GPU/Vulkan/GPU_Vulkan.h @@ -38,6 +38,8 @@ public: GPU_Vulkan(GraphicsContext *gfxCtx, Draw::DrawContext *draw); ~GPU_Vulkan(); + void FinishInitOnMainThread() override; + // This gets called on startup and when we get back from settings. u32 CheckGPUFeatures() const override; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 04b0393fd8..b7bc33b270 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1208,7 +1208,7 @@ void EmuScreen::CreateViews() { root_->Add(buttons); resumeButton_ = buttons->Add(new Button(dev->T("Resume"))); - resumeButton_->OnClick.Add([this](UI::EventParams &) { + resumeButton_->OnClick.Add([](UI::EventParams &) { if (coreState == CoreState::CORE_RUNTIME_ERROR) { // Force it! Memory::MemFault_IgnoreLastCrash(); diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index b0a2a87587..d55bf97ebc 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -151,9 +151,10 @@ private: ImGuiContext *ctx_ = nullptr; - // TODO: Ugly! bool frameStep_ = false; +#ifdef MOBILE_DEVICE bool startDumping_ = false; +#endif }; bool MustRunBehind(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 7e4e908aa9..969e572786 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1282,7 +1282,6 @@ bool NativeIsAtTopLevel() { Screen *currentScreen = g_screenManager->topScreen(); if (currentScreen) { bool top = currentScreen->isTopLevel(); - INFO_LOG(Log::System, "Screen toplevel: %i", (int)top); return currentScreen->isTopLevel(); } else { ERROR_LOG(Log::System, "No current screen");