From fb4a1fb7dde207502123b7ff49025efce906b1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 24 Sep 2023 11:20:27 +0200 Subject: [PATCH] Simplify disk-cache-load on GLES as well, for the same reasons as #18216 --- GPU/GLES/GPU_GLES.cpp | 9 ------ GPU/GLES/GPU_GLES.h | 3 -- GPU/GLES/ShaderManagerGLES.cpp | 59 ++++++++++++++-------------------- GPU/GLES/ShaderManagerGLES.h | 27 ---------------- GPU/GPU.cpp | 15 ++------- GPU/GPUCommon.h | 4 --- GPU/GPUInterface.h | 2 -- GPU/Vulkan/GPU_Vulkan.cpp | 4 --- 8 files changed, 28 insertions(+), 95 deletions(-) diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 293954271514..e4eaa274c59c 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -201,14 +201,6 @@ u32 GPU_GLES::CheckGPUFeatures() const { return features; } -bool GPU_GLES::IsReady() { - return shaderManagerGL_->ContinuePrecompile(); -} - -void GPU_GLES::CancelReady() { - shaderManagerGL_->CancelPrecompile(); -} - void GPU_GLES::BuildReportingInfo() { GLRenderManager *render = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); @@ -238,7 +230,6 @@ void GPU_GLES::DeviceLost() { // Simply drop all caches and textures. // FBOs appear to survive? Or no? // TransformDraw has registered as a GfxResourceHolder. - CancelReady(); fragmentTestCache_.DeviceLost(); GPUCommonHW::DeviceLost(); diff --git a/GPU/GLES/GPU_GLES.h b/GPU/GLES/GPU_GLES.h index 9e03285ee99b..b6ae9492fb1d 100644 --- a/GPU/GLES/GPU_GLES.h +++ b/GPU/GLES/GPU_GLES.h @@ -40,9 +40,6 @@ class GPU_GLES : public GPUCommonHW { // This gets called on startup and when we get back from settings. u32 CheckGPUFeatures() const override; - bool IsReady() override; - void CancelReady() override; - void GetStats(char *buffer, size_t bufsize) override; void DeviceLost() override; // Only happens on Android. Drop all textures and shaders. diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index 54b3b4edaceb..70ea62d8bdc1 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -821,7 +821,6 @@ Shader *ShaderManagerGLES::ApplyVertexShader(bool useHWTransform, bool useHWTess } vsCache_.Insert(*VSID, vs); - diskCacheDirty_ = true; return vs; } @@ -860,7 +859,6 @@ LinkedShader *ShaderManagerGLES::ApplyFragmentShader(VShaderID VSID, Shader *vs, // Still insert it so we don't end up spamming generation. } fsCache_.Insert(FSID, fs); - diskCacheDirty_ = true; } // Okay, we have both shaders. Let's see if there's a linked one. @@ -1012,6 +1010,31 @@ bool ShaderManagerGLES::LoadCacheFlags(File::IOFile &f, DrawEngineGLES *drawEngi } bool ShaderManagerGLES::LoadCache(File::IOFile &f) { + // TODO: Get rid of this struct. + struct { + std::vector vert; + std::vector frag; + std::vector> link; + + size_t vertPos = 0; + size_t fragPos = 0; + size_t linkPos = 0; + double start; + + void Clear() { + vert.clear(); + frag.clear(); + link.clear(); + vertPos = 0; + fragPos = 0; + linkPos = 0; + } + + bool Done() { + return vertPos >= vert.size() && fragPos >= frag.size() && linkPos >= link.size(); + } + } diskCachePending_; + u64 sz = f.GetSize(); f.Seek(0, SEEK_SET); CacheHeader header; @@ -1066,12 +1089,6 @@ bool ShaderManagerGLES::LoadCache(File::IOFile &f) { diskCachePending_.link.emplace_back(vsid, fsid); } - // Actual compilation happens in ContinuePrecompile(), called by GPU_GLES's IsReady. - diskCacheDirty_ = false; - return true; -} - -bool ShaderManagerGLES::ContinuePrecompile(float sliceTime) { auto &pending = diskCachePending_; if (pending.Done()) { return true; @@ -1080,15 +1097,8 @@ bool ShaderManagerGLES::ContinuePrecompile(float sliceTime) { PSP_SetLoading("Compiling shaders..."); double start = time_now_d(); - // Let's try to keep it under sliceTime if possible. - double end = start + sliceTime; for (size_t &i = pending.vertPos; i < pending.vert.size(); i++) { - if (time_now_d() >= end) { - // We'll finish later. - return false; - } - const VShaderID &id = pending.vert[i]; if (!vsCache_.ContainsKey(id)) { if (id.Bit(VS_BIT_IS_THROUGH) && id.Bit(VS_BIT_USE_HW_TRANSFORM)) { @@ -1114,11 +1124,6 @@ bool ShaderManagerGLES::ContinuePrecompile(float sliceTime) { } for (size_t &i = pending.fragPos; i < pending.frag.size(); i++) { - if (time_now_d() >= end) { - // We'll finish later. - return false; - } - const FShaderID &id = pending.frag[i]; if (!fsCache_.ContainsKey(id)) { Shader *fs = CompileFragmentShader(id); @@ -1137,11 +1142,6 @@ bool ShaderManagerGLES::ContinuePrecompile(float sliceTime) { } for (size_t &i = pending.linkPos; i < pending.link.size(); i++) { - if (time_now_d() >= end) { - // We'll finish later. - return false; - } - const VShaderID &vsid = pending.link[i].first; const FShaderID &fsid = pending.link[i].second; Shader *vs = nullptr; @@ -1164,14 +1164,7 @@ bool ShaderManagerGLES::ContinuePrecompile(float sliceTime) { return true; } -void ShaderManagerGLES::CancelPrecompile() { - diskCachePending_.Clear(); -} - void ShaderManagerGLES::SaveCache(const Path &filename, DrawEngineGLES *drawEngine) { - if (!diskCacheDirty_) { - return; - } if (linkedShaderCache_.empty()) { return; } @@ -1179,7 +1172,6 @@ void ShaderManagerGLES::SaveCache(const Path &filename, DrawEngineGLES *drawEngi FILE *f = File::OpenCFile(filename, "wb"); if (!f) { // Can't save, give up for now. - diskCacheDirty_ = false; return; } CacheHeader header; @@ -1213,5 +1205,4 @@ void ShaderManagerGLES::SaveCache(const Path &filename, DrawEngineGLES *drawEngi fwrite(&fsid, 1, sizeof(fsid), f); } fclose(f); - diskCacheDirty_ = false; } diff --git a/GPU/GLES/ShaderManagerGLES.h b/GPU/GLES/ShaderManagerGLES.h index 3ae0aaa60ae7..5a91bc7f7c3b 100644 --- a/GPU/GLES/ShaderManagerGLES.h +++ b/GPU/GLES/ShaderManagerGLES.h @@ -183,8 +183,6 @@ class ShaderManagerGLES : public ShaderManagerCommon { bool LoadCacheFlags(File::IOFile &f, DrawEngineGLES *drawEngine); bool LoadCache(File::IOFile &f); - bool ContinuePrecompile(float sliceTime = 1.0f / 60.0f); - void CancelPrecompile(); void SaveCache(const Path &filename, DrawEngineGLES *drawEngine); private: @@ -219,29 +217,4 @@ class ShaderManagerGLES : public ShaderManagerCommon { typedef DenseHashMap VSCache; VSCache vsCache_; - - bool diskCacheDirty_ = false; - struct { - std::vector vert; - std::vector frag; - std::vector> link; - - size_t vertPos = 0; - size_t fragPos = 0; - size_t linkPos = 0; - double start; - - void Clear() { - vert.clear(); - frag.clear(); - link.clear(); - vertPos = 0; - fragPos = 0; - linkPos = 0; - } - - bool Done() { - return vertPos >= vert.size() && fragPos >= frag.size() && linkPos >= link.size(); - } - } diskCachePending_; }; diff --git a/GPU/GPU.cpp b/GPU/GPU.cpp index 2a7d477204c1..21ad2d3f0f3a 100644 --- a/GPU/GPU.cpp +++ b/GPU/GPU.cpp @@ -53,14 +53,12 @@ static void SetGPU(T *obj) { #endif bool GPU_IsReady() { - if (gpu) - return gpu->IsReady(); - return false; + return gpu != nullptr; } bool GPU_IsStarted() { if (gpu) - return gpu->IsReady() && gpu->IsStarted(); + return gpu->IsStarted(); return false; } @@ -112,7 +110,7 @@ bool GPU_Init(GraphicsContext *ctx, Draw::DrawContext *draw) { #endif } - if (gpu && gpu->IsReady() && !gpu->IsStarted()) + if (gpu && !gpu->IsStarted()) SetGPU(nullptr); return gpu != nullptr; @@ -126,13 +124,6 @@ void GPU_Shutdown() { // Reduce the risk for weird races with the Windows GE debugger. gpuDebug = nullptr; - // Wait for IsReady, since it might be running on a thread. - if (gpu) { - gpu->CancelReady(); - while (!gpu->IsReady()) { - sleep_ms(10); - } - } delete gpu; gpu = nullptr; } diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 8b3f59b9dd23..f523f41d5b52 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -78,13 +78,9 @@ class GPUCommon : public GPUInterface, public GPUDebugInterface { virtual void UpdateCmdInfo() = 0; - bool IsReady() override { - return true; - } bool IsStarted() override { return true; } - void CancelReady() override {} void Reinitialize() override; void BeginHostFrame() override; diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index d48713942dfd..f31c5b097f4b 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -190,8 +190,6 @@ class GPUInterface { virtual Draw::DrawContext *GetDrawContext() = 0; // Initialization - virtual bool IsReady() = 0; - virtual void CancelReady() = 0; virtual bool IsStarted() = 0; virtual void Reinitialize() = 0; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 10a46ca9ee64..2eefea2bdbf3 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -422,10 +422,6 @@ void GPU_Vulkan::CheckRenderResized() { } void GPU_Vulkan::DeviceLost() { - CancelReady(); - while (!IsReady()) { - sleep_ms(10); - } // draw_ is normally actually still valid here in Vulkan. But we null it out in GPUCommonHW::DeviceLost so we don't try to use it again. Draw::DrawContext *draw = draw_; if (draw) {