Reorganize the DeviceLost code a little. FramebufferManagerCommon now sees it.

This commit is contained in:
Henrik Rydgård 2020-11-07 00:56:48 +01:00
parent e37468700d
commit d9ee06a60d
17 changed files with 56 additions and 40 deletions

View file

@ -465,6 +465,8 @@ public:
uint64_t GetNativeObject(NativeObject obj) override {
switch (obj) {
case NativeObject::CONTEXT:
return (uint64_t)vulkan_;
case NativeObject::FRAMEBUFFER_RENDERPASS:
// Return a representative renderpass.
return (uint64_t)renderManager_.GetFramebufferRenderPass();

View file

@ -2102,3 +2102,14 @@ std::vector<FramebufferInfo> FramebufferManagerCommon::GetFramebufferList() {
return list;
}
void FramebufferManagerCommon::DeviceLost() {
DestroyAllFBOs();
presentation_->DeviceLost();
draw_ = nullptr;
}
void FramebufferManagerCommon::DeviceRestore(Draw::DrawContext *draw) {
draw_ = draw;
presentation_->DeviceRestore(draw);
}

View file

@ -305,6 +305,9 @@ public:
virtual void Resized();
virtual void DestroyAllFBOs();
virtual void DeviceLost();
virtual void DeviceRestore(Draw::DrawContext *draw);
Draw::Framebuffer *GetTempFBO(TempFBO reason, u16 w, u16 h);
// Debug features

View file

@ -468,7 +468,3 @@ void FramebufferManagerD3D11::PackDepthbuffer(VirtualFramebuffer *vfb, int x, in
void FramebufferManagerD3D11::EndFrame() {
}
void FramebufferManagerD3D11::DeviceLost() {
DestroyAllFBOs();
}

View file

@ -42,7 +42,6 @@ public:
void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags) override;
void EndFrame();
void DeviceLost();
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) override;
void BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags);

View file

@ -198,10 +198,12 @@ void GPU_D3D11::DeviceLost() {
shaderManagerD3D11_->ClearShaders();
drawEngine_.ClearInputLayoutMap();
textureCacheD3D11_->Clear(false);
framebufferManagerD3D11_->DeviceLost();
GPUCommon::DeviceLost();
}
void GPU_D3D11::DeviceRestore() {
GPUCommon::DeviceRestore();
// Nothing needed.
}

View file

@ -559,10 +559,6 @@ static const D3DVERTEXELEMENT9 g_FramebufferVertexElements[] = {
void FramebufferManagerDX9::EndFrame() {
}
void FramebufferManagerDX9::DeviceLost() {
DestroyAllFBOs();
}
void FramebufferManagerDX9::DecimateFBOs() {
FramebufferManagerCommon::DecimateFBOs();
for (auto it = offscreenSurfaces_.begin(); it != offscreenSurfaces_.end(); ) {

View file

@ -47,7 +47,6 @@ public:
void DestroyAllFBOs();
void EndFrame();
void DeviceLost();
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) override;
void BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags);

View file

@ -242,13 +242,13 @@ void GPU_DX9::BuildReportingInfo() {
void GPU_DX9::DeviceLost() {
// Simply drop all caches and textures.
// FBOs appear to survive? Or no?
shaderManagerDX9_->ClearCache(false);
textureCacheDX9_->Clear(false);
framebufferManagerDX9_->DeviceLost();
GPUCommon::DeviceLost();
}
void GPU_DX9::DeviceRestore() {
GPUCommon::DeviceRestore();
// Nothing needed.
}

View file

@ -389,16 +389,14 @@ void FramebufferManagerGLES::EndFrame() {
}
void FramebufferManagerGLES::DeviceLost() {
DestroyAllFBOs();
FramebufferManagerCommon::DeviceLost();
DestroyDeviceObjects();
presentation_->DeviceLost();
}
void FramebufferManagerGLES::DeviceRestore(Draw::DrawContext *draw) {
draw_ = draw;
presentation_->DeviceRestore(draw);
render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
FramebufferManagerCommon::DeviceRestore(draw);
CreateDeviceObjects();
render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
}
void FramebufferManagerGLES::Resized() {

View file

@ -46,7 +46,10 @@ public:
virtual void Init() override;
void EndFrame();
void Resized() override;
void DeviceLost();
void DeviceLost() override;
void DeviceRestore(Draw::DrawContext *draw) override;
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) override;
// For use when texturing from a framebuffer. May create a duplicate if target.
@ -56,8 +59,6 @@ public:
bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
void DeviceRestore(Draw::DrawContext *draw);
protected:
// Used by ReadFramebufferToMemory and later framebuffer block copies
void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp) override;

View file

@ -300,21 +300,18 @@ void GPU_GLES::DeviceLost() {
fragmentTestCache_.DeviceLost();
depalShaderCache_.DeviceLost();
drawEngine_.DeviceLost();
framebufferManagerGL_->DeviceLost();
// Don't even try to access the lost device.
draw_ = nullptr;
GPUCommon::DeviceLost();
}
void GPU_GLES::DeviceRestore() {
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
INFO_LOG(G3D, "GPU_GLES: DeviceRestore");
GPUCommon::DeviceRestore();
UpdateCmdInfo();
UpdateVsyncInterval(true);
shaderManagerGL_->DeviceRestore(draw_);
textureCacheGL_->DeviceRestore(draw_);
framebufferManagerGL_->DeviceRestore(draw_);
drawEngine_.DeviceRestore(draw_);
fragmentTestCache_.DeviceRestore(draw_);
depalShaderCache_.DeviceRestore(draw_);

View file

@ -468,6 +468,18 @@ void GPUCommon::Reinitialize() {
framebufferManager_->DestroyAllFBOs();
}
// Call at the END of the GPU implementation's DeviceLost
void GPUCommon::DeviceLost() {
framebufferManager_->DeviceLost();
draw_ = nullptr;
}
// Call at the start of the GPU implementation's DeviceRestore
void GPUCommon::DeviceRestore() {
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
framebufferManager_->DeviceRestore(draw_);
}
void GPUCommon::UpdateVsyncInterval(bool force) {
#if !(PPSSPP_PLATFORM(ANDROID) || defined(USING_QT_UI) || PPSSPP_PLATFORM(UWP) || PPSSPP_PLATFORM(IOS))
int desiredVSyncInterval = g_Config.bVSync ? 1 : 0;

View file

@ -260,6 +260,9 @@ public:
}
protected:
void DeviceLost() override;
void DeviceRestore() override;
void SetDrawType(DrawType type, GEPrimitiveType prim) {
if (type != lastDraw_) {
// We always flush when drawing splines/beziers so no need to do so here

View file

@ -388,15 +388,12 @@ void FramebufferManagerVulkan::EndFrame() {
}
void FramebufferManagerVulkan::DeviceLost() {
DestroyAllFBOs();
FramebufferManagerCommon::DeviceLost();
DestroyDeviceObjects();
presentation_->DeviceLost();
}
void FramebufferManagerVulkan::DeviceRestore(VulkanContext *vulkan, Draw::DrawContext *draw) {
vulkan_ = vulkan;
draw_ = draw;
presentation_->DeviceRestore(draw);
void FramebufferManagerVulkan::DeviceRestore(Draw::DrawContext *draw) {
FramebufferManagerCommon::DeviceRestore(draw);
vulkan_ = (VulkanContext *)draw->GetNativeObject(Draw::NativeObject::CONTEXT);
InitDeviceObjects();
}

View file

@ -49,8 +49,9 @@ public:
void BeginFrameVulkan(); // there's a BeginFrame in the base class, which this calls
void EndFrame();
void DeviceLost();
void DeviceRestore(VulkanContext *vulkan, Draw::DrawContext *draw);
void DeviceLost() override;
void DeviceRestore(Draw::DrawContext *draw) override;
int GetLineWidth();
void ReformatFramebufferFrom(VirtualFramebuffer *vfb, GEBufferFormat old) override;

View file

@ -526,26 +526,25 @@ void GPU_Vulkan::DeviceLost() {
SaveCache(shaderCachePath_);
}
DestroyDeviceObjects();
framebufferManagerVulkan_->DeviceLost();
vulkan2D_.DeviceLost();
drawEngine_.DeviceLost();
pipelineManager_->DeviceLost();
textureCacheVulkan_->DeviceLost();
depalShaderCache_.DeviceLost();
shaderManagerVulkan_->ClearShaders();
draw_ = nullptr;
GPUCommon::DeviceLost();
}
void GPU_Vulkan::DeviceRestore() {
GPUCommon::DeviceRestore();
vulkan_ = (VulkanContext *)PSP_CoreParameter().graphicsContext->GetAPIContext();
draw_ = (Draw::DrawContext *)PSP_CoreParameter().graphicsContext->GetDrawContext();
InitDeviceObjects();
CheckGPUFeatures();
BuildReportingInfo();
UpdateCmdInfo();
framebufferManagerVulkan_->DeviceRestore(vulkan_, draw_);
vulkan2D_.DeviceRestore(vulkan_);
drawEngine_.DeviceRestore(vulkan_, draw_);
pipelineManager_->DeviceRestore(vulkan_);