Move more of GPU init to the loader thread. Some log cleanup.

This commit is contained in:
Henrik Rydgård
2025-05-15 10:43:51 +02:00
parent 9293afa1c0
commit 751e4fad2e
17 changed files with 49 additions and 29 deletions
+1 -1
View File
@@ -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();
{
+3 -1
View File
@@ -61,8 +61,10 @@ bool Atlas::Load(const uint8_t *data, size_t data_size) {
return false;
}
images = reader.ReadMultipleAlloc<AtlasImage>(num_images, header.version >= 1);
delete[] images;
delete[] fonts;
images = reader.ReadMultipleAlloc<AtlasImage>(num_images, header.version >= 1);
fonts = new AtlasFont[num_fonts];
for (int i = 0; i < num_fonts; i++) {
AtlasFontHeader font_header = reader.Read<AtlasFontHeader>();
+1 -1
View File
@@ -23,7 +23,7 @@
#include "Core/Compatibility.h"
#include "Core/Loaders.h"
enum GPUCore {
enum GPUCore : int {
GPUCORE_GLES,
GPUCORE_SOFTWARE,
GPUCORE_DIRECTX9,
+18 -14
View File
@@ -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);
+1 -1
View File
@@ -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;
}
+5 -2
View File
@@ -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();
}
+2
View File
@@ -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;
+5 -1
View File
@@ -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;
+1
View File
@@ -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;
-2
View File
@@ -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() {
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -21,7 +21,7 @@
#include <cstring>
#include <cstdint>
enum GPUCore;
enum GPUCore : int;
class GPUCommon;
class GPUDebugInterface;
+5 -1
View File
@@ -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.");
+2
View File
@@ -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;
+1 -1
View File
@@ -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();
+2 -1
View File
@@ -151,9 +151,10 @@ private:
ImGuiContext *ctx_ = nullptr;
// TODO: Ugly!
bool frameStep_ = false;
#ifdef MOBILE_DEVICE
bool startDumping_ = false;
#endif
};
bool MustRunBehind();
-1
View File
@@ -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");