From 8ba665e2586ca9b13b228eb4b0c57f88ec5c89b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 25 Feb 2023 16:12:24 +0100 Subject: [PATCH] More unification work --- GPU/D3D11/GPU_D3D11.cpp | 13 ++++--------- GPU/Directx9/GPU_DX9.cpp | 18 ++++-------------- GPU/Directx9/GPU_DX9.h | 1 - GPU/GLES/GPU_GLES.cpp | 26 ++++++-------------------- GPU/GLES/GPU_GLES.h | 1 - GPU/GPUCommonHW.cpp | 14 ++++++++++++++ GPU/GPUCommonHW.h | 1 + GPU/Vulkan/GPU_Vulkan.cpp | 17 +++++++---------- GPU/Vulkan/TextureCacheVulkan.cpp | 1 - 9 files changed, 36 insertions(+), 56 deletions(-) diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 1b58db17c8..c0b419184a 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -87,16 +87,11 @@ GPU_D3D11::GPU_D3D11(GraphicsContext *gfxCtx, Draw::DrawContext *draw) } GPU_D3D11::~GPU_D3D11() { - framebufferManagerD3D11_->DestroyAllFBOs(); - delete framebufferManagerD3D11_; - shaderManagerD3D11_->ClearShaders(); - delete shaderManagerD3D11_; - delete textureCacheD3D11_; stockD3D11.Destroy(); } u32 GPU_D3D11::CheckGPUFeatures() const { - u32 features = GPUCommon::CheckGPUFeatures(); + u32 features = GPUCommonHW::CheckGPUFeatures(); // Accurate depth is required because the Direct3D API does not support inverse Z. // So we cannot incorrectly use the viewport transform as the depth range on Direct3D. @@ -124,11 +119,11 @@ void GPU_D3D11::DeviceLost() { drawEngine_.ClearInputLayoutMap(); textureCache_->Clear(false); - GPUCommon::DeviceLost(); + GPUCommonHW::DeviceLost(); } void GPU_D3D11::DeviceRestore() { - GPUCommon::DeviceRestore(); + GPUCommonHW::DeviceRestore(); // Nothing needed. } @@ -139,7 +134,7 @@ void GPU_D3D11::InitClear() { } void GPU_D3D11::BeginFrame() { - GPUCommon::BeginFrame(); + GPUCommonHW::BeginFrame(); textureCache_->StartFrame(); drawEngine_.BeginFrame(); diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index b857fcfa80..a95c6155fd 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -94,7 +94,7 @@ GPU_DX9::GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw) } u32 GPU_DX9::CheckGPUFeatures() const { - u32 features = GPUCommon::CheckGPUFeatures(); + u32 features = GPUCommonHW::CheckGPUFeatures(); features |= GPU_USE_16BIT_FORMATS; features |= GPU_USE_TEXTURE_LOD_CONTROL; @@ -105,19 +105,9 @@ u32 GPU_DX9::CheckGPUFeatures() const { return CheckGPUFeaturesLate(features); } -GPU_DX9::~GPU_DX9() { - framebufferManager_->DestroyAllFBOs(); - delete framebufferManager_; - delete textureCache_; - shaderManager_->ClearShaders(); - delete shaderManager_; -} - void GPU_DX9::DeviceLost() { // Simply drop all caches and textures. - shaderManager_->ClearShaders(); - textureCache_->Clear(false); - GPUCommon::DeviceLost(); + GPUCommonHW::DeviceLost(); } void GPU_DX9::InitClear() { @@ -130,14 +120,14 @@ void GPU_DX9::InitClear() { void GPU_DX9::ReapplyGfxState() { dxstate.Restore(); - GPUCommon::ReapplyGfxState(); + GPUCommonHW::ReapplyGfxState(); } void GPU_DX9::BeginFrame() { textureCache_->StartFrame(); drawEngine_.BeginFrame(); - GPUCommon::BeginFrame(); + GPUCommonHW::BeginFrame(); shaderManagerDX9_->DirtyShader(); framebufferManager_->BeginFrame(); diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 7e1132175e..eda85cb387 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -33,7 +33,6 @@ class TextureCacheDX9; class GPU_DX9 : public GPUCommonHW { public: GPU_DX9(GraphicsContext *gfxCtx, Draw::DrawContext *draw); - ~GPU_DX9(); u32 CheckGPUFeatures() const override; diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 4d5abeadb7..6bf1046764 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -138,22 +138,14 @@ GPU_GLES::~GPU_GLES() { INFO_LOG(G3D, "Shader cache disabled. Not saving."); } } - - framebufferManager_->DestroyAllFBOs(); - shaderManager_->ClearShaders(); fragmentTestCache_.Clear(); - - delete shaderManager_; - shaderManager_ = nullptr; - delete framebufferManager_; - delete textureCache_; } // Take the raw GL extension and versioning data and turn into feature flags. // TODO: This should use DrawContext::GetDeviceCaps() more and more, and eventually // this can be shared between all the backends. u32 GPU_GLES::CheckGPUFeatures() const { - u32 features = GPUCommon::CheckGPUFeatures(); + u32 features = GPUCommonHW::CheckGPUFeatures(); features |= GPU_USE_16BIT_FORMATS; @@ -246,16 +238,14 @@ void GPU_GLES::DeviceLost() { // FBOs appear to survive? Or no? // TransformDraw has registered as a GfxResourceHolder. CancelReady(); - shaderManager_->DeviceLost(); - textureCache_->DeviceLost(); fragmentTestCache_.DeviceLost(); drawEngine_.DeviceLost(); - GPUCommon::DeviceLost(); + GPUCommonHW::DeviceLost(); } void GPU_GLES::DeviceRestore() { - GPUCommon::DeviceRestore(); + GPUCommonHW::DeviceRestore(); UpdateCmdInfo(); UpdateVsyncInterval(true); @@ -266,15 +256,11 @@ void GPU_GLES::DeviceRestore() { fragmentTestCache_.DeviceRestore(draw_); } -void GPU_GLES::Reinitialize() { - GPUCommon::Reinitialize(); -} - void GPU_GLES::InitClear() { } void GPU_GLES::BeginHostFrame() { - GPUCommon::BeginHostFrame(); + GPUCommonHW::BeginHostFrame(); drawEngine_.BeginFrame(); if (gstate_c.useFlagsChanged) { @@ -292,11 +278,11 @@ void GPU_GLES::EndHostFrame() { } void GPU_GLES::ReapplyGfxState() { - GPUCommon::ReapplyGfxState(); + GPUCommonHW::ReapplyGfxState(); } void GPU_GLES::BeginFrame() { - GPUCommon::BeginFrame(); + GPUCommonHW::BeginFrame(); textureCache_->StartFrame(); diff --git a/GPU/GLES/GPU_GLES.h b/GPU/GLES/GPU_GLES.h index 912c253188..4ab375840a 100644 --- a/GPU/GLES/GPU_GLES.h +++ b/GPU/GLES/GPU_GLES.h @@ -64,7 +64,6 @@ private: void InitClear() override; void BeginFrame() override; - void Reinitialize() override; FramebufferManagerGLES *framebufferManagerGL_; TextureCacheGLES *textureCacheGL_; diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 8f587d6f77..0ab31d9cbd 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -14,6 +14,20 @@ GPUCommonHW::GPUCommonHW(GraphicsContext *gfxCtx, Draw::DrawContext *draw) : GPU GPUCommonHW::~GPUCommonHW() { // Clear features so they're not visible in system info. gstate_c.SetUseFlags(0); + + // Delete the various common managers. + framebufferManager_->DestroyAllFBOs(); + delete framebufferManager_; + delete textureCache_; + shaderManager_->ClearShaders(); + delete shaderManager_; +} + +void GPUCommonHW::DeviceLost() { + textureCache_->Clear(false); + framebufferManager_->DeviceLost(); + textureCache_->DeviceLost(); + shaderManager_->DeviceLost(); } void GPUCommonHW::PreExecuteOp(u32 op, u32 diff) { diff --git a/GPU/GPUCommonHW.h b/GPU/GPUCommonHW.h index 924a60c5f4..a427f27963 100644 --- a/GPU/GPUCommonHW.h +++ b/GPU/GPUCommonHW.h @@ -11,6 +11,7 @@ public: void CopyDisplayToOutput(bool reallyDirty) override; void DoState(PointerWrap &p) override; + void DeviceLost() override; protected: void PreExecuteOp(u32 op, u32 diff); diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 11d7b562cc..ffe2e61755 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -185,16 +185,15 @@ GPU_Vulkan::~GPU_Vulkan() { SaveCache(shaderCachePath_); // Note: We save the cache in DeviceLost DestroyDeviceObjects(); - framebufferManagerVulkan_->DestroyAllFBOs(); drawEngine_.DeviceLost(); - delete textureCache_; + shaderManager_->ClearShaders(); + delete pipelineManager_; - delete shaderManager_; - delete framebufferManager_; + // other managers are deleted in ~GPUCommonHW. } u32 GPU_Vulkan::CheckGPUFeatures() const { - uint32_t features = GPUCommon::CheckGPUFeatures(); + uint32_t features = GPUCommonHW::CheckGPUFeatures(); VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT); switch (vulkan->GetPhysicalDeviceProperties().properties.vendorID) { @@ -289,7 +288,7 @@ u32 GPU_Vulkan::CheckGPUFeatures() const { } void GPU_Vulkan::BeginHostFrame() { - GPUCommon::BeginHostFrame(); + GPUCommonHW::BeginHostFrame(); drawEngine_.BeginFrame(); textureCache_->StartFrame(); @@ -336,7 +335,7 @@ void GPU_Vulkan::EndHostFrame() { drawEngine_.EndFrame(); - GPUCommon::EndHostFrame(); + GPUCommonHW::EndHostFrame(); } // Needs to be called on GPU thread, not reporting thread. @@ -445,7 +444,7 @@ void GPU_Vulkan::DestroyDeviceObjects() { } void GPU_Vulkan::CheckRenderResized() { - GPUCommon::CheckRenderResized(); + GPUCommonHW::CheckRenderResized(); if (renderResized_) { pipelineManager_->InvalidateMSAAPipelines(); framebufferManager_->ReleasePipelines(); @@ -463,8 +462,6 @@ void GPU_Vulkan::DeviceLost() { DestroyDeviceObjects(); drawEngine_.DeviceLost(); pipelineManager_->DeviceLost(); - textureCacheVulkan_->DeviceLost(); - shaderManagerVulkan_->DeviceLost(); GPUCommonHW::DeviceLost(); } diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index da69158dc3..d47ed1ee2d 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -217,7 +217,6 @@ void TextureCacheVulkan::DeviceLost() { Clear(true); samplerCache_.DeviceLost(); - if (samplerNearest_) vulkan->Delete().QueueDeleteSampler(samplerNearest_);