Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve framebuffer on pause screen even if render resolution is changed #16409

Merged
merged 8 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Common/VR/VRRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void VR_EndFrame( engine_t* engine ) {
int x = vrConfig[VR_CONFIG_MOUSE_X];
int y = vrConfig[VR_CONFIG_MOUSE_Y];
int sx = vrConfig[VR_CONFIG_MOUSE_SIZE];
int sy = sx * VR_GetConfigFloat(VR_CONFIG_CANVAS_ASPECT);
int sy = (int)((float)sx * VR_GetConfigFloat(VR_CONFIG_CANVAS_ASPECT));
ovrRenderer_MouseCursor(&engine->appState.Renderer, x, y, sx, sy);
}

Expand Down
26 changes: 17 additions & 9 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,26 @@ FramebufferManagerCommon::~FramebufferManagerCommon() {

void FramebufferManagerCommon::Init() {
// We may need to override the render size if the shader is upscaling or SSAA.
Resized();
NotifyDisplayResized();
NotifyRenderResized();
}

bool FramebufferManagerCommon::UpdateSize() {
bool FramebufferManagerCommon::UpdateRenderSize() {
const bool newRender = renderWidth_ != (float)PSP_CoreParameter().renderWidth || renderHeight_ != (float)PSP_CoreParameter().renderHeight;

const int effectiveBloomHack = PSP_CoreParameter().compat.flags().ForceLowerResolutionForEffectsOn ? 3 : g_Config.iBloomHack;


bool newBuffered = !g_Config.bSkipBufferEffects;
const bool newSettings = bloomHack_ != effectiveBloomHack || useBufferedRendering_ != newBuffered;

renderWidth_ = (float)PSP_CoreParameter().renderWidth;
renderHeight_ = (float)PSP_CoreParameter().renderHeight;
renderScaleFactor_ = (float)PSP_CoreParameter().renderScaleFactor;
pixelWidth_ = PSP_CoreParameter().pixelWidth;
pixelHeight_ = PSP_CoreParameter().pixelHeight;

bloomHack_ = effectiveBloomHack;
useBufferedRendering_ = newBuffered;

presentation_->UpdateSize(pixelWidth_, pixelHeight_, renderWidth_, renderHeight_);

presentation_->UpdateRenderSize(renderWidth_, renderHeight_);
return newRender || newSettings;
}

Expand Down Expand Up @@ -2333,7 +2331,17 @@ void FramebufferManagerCommon::SetSafeSize(u16 w, u16 h) {
}
}

void FramebufferManagerCommon::Resized() {
void FramebufferManagerCommon::NotifyDisplayResized() {
pixelWidth_ = PSP_CoreParameter().pixelWidth;
pixelHeight_ = PSP_CoreParameter().pixelHeight;
presentation_->UpdateDisplaySize(pixelWidth_, pixelHeight_);

// No drawing is allowed here. This includes anything that might potentially touch a command buffer, like creating images!
// So we need to defer the post processing initialization.
updatePostShaders_ = true;
}

void FramebufferManagerCommon::NotifyRenderResized() {
gstate_c.skipDrawReason &= ~SKIPDRAW_NON_DISPLAYED_FB;

int w, h, scaleFactor;
Expand All @@ -2342,7 +2350,7 @@ void FramebufferManagerCommon::Resized() {
PSP_CoreParameter().renderHeight = h;
PSP_CoreParameter().renderScaleFactor = scaleFactor;

if (UpdateSize()) {
if (UpdateRenderSize()) {
DestroyAllFBOs();
}

Expand Down
6 changes: 4 additions & 2 deletions GPU/Common/FramebufferManagerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ class FramebufferManagerCommon {
}
void SetSafeSize(u16 w, u16 h);

virtual void Resized();
virtual void NotifyRenderResized();
virtual void NotifyDisplayResized();

virtual void DestroyAllFBOs();

virtual void DeviceLost();
Expand Down Expand Up @@ -450,7 +452,7 @@ class FramebufferManagerCommon {
void CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dest);
void CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest);

bool UpdateSize();
bool UpdateRenderSize();

void FlushBeforeCopy();
virtual void DecimateFBOs(); // keeping it virtual to let D3D do a little extra
Expand Down
4 changes: 3 additions & 1 deletion GPU/Common/PresentationCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ class PresentationCommon {
PresentationCommon(Draw::DrawContext *draw);
~PresentationCommon();

void UpdateSize(int w, int h, int rw, int rh) {
void UpdateDisplaySize(int w, int h) {
pixelWidth_ = w;
pixelHeight_ = h;
}
void UpdateRenderSize(int rw, int rh) {
renderWidth_ = rw;
renderHeight_ = rh;
}
Expand Down
5 changes: 1 addition & 4 deletions GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ bool TextureCacheCommon::GetCurrentFramebufferTextureDebug(GPUDebugBuffer &buffe
}

void TextureCacheCommon::NotifyConfigChanged() {
clearCacheNextFrame_ = true;
int scaleFactor = g_Config.iTexScalingLevel;

if (!gstate_c.Use(GPU_USE_TEXTURE_NPOT)) {
Expand Down Expand Up @@ -2554,10 +2555,6 @@ void TextureCacheCommon::InvalidateAll(GPUInvalidationType /*unused*/) {
}
}

void TextureCacheCommon::ClearNextFrame() {
clearCacheNextFrame_ = true;
}

std::string AttachCandidate::ToString() const {
return StringFromFormat("[%s seq:%d rel:%d C:%08x/%d(%s) Z:%08x/%d X:%d Y:%d reint: %s]",
this->channel == RASTER_COLOR ? "COLOR" : "DEPTH",
Expand Down
1 change: 0 additions & 1 deletion GPU/Common/TextureCacheCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ class TextureCacheCommon {
bool SetOffsetTexture(u32 yOffset);
void Invalidate(u32 addr, int size, GPUInvalidationType type);
void InvalidateAll(GPUInvalidationType type);
void ClearNextFrame();

TextureShaderCache *GetTextureShaderCache() { return textureShaderCache_; }

Expand Down
21 changes: 0 additions & 21 deletions GPU/D3D11/GPU_D3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,6 @@ void GPU_D3D11::InitClear() {
}
}

void GPU_D3D11::BeginHostFrame() {
GPUCommon::BeginHostFrame();
UpdateCmdInfo();
CheckResized();
}

void GPU_D3D11::ReapplyGfxState() {
GPUCommon::ReapplyGfxState();

// TODO: Dirty our caches for depth states etc
}

void GPU_D3D11::EndHostFrame() {
// Probably not really necessary.
draw_->InvalidateCachedState();
}

void GPU_D3D11::BeginFrame() {
GPUCommon::BeginFrame();

Expand Down Expand Up @@ -245,10 +228,6 @@ void GPU_D3D11::GetStats(char *buffer, size_t bufsize) {
);
}

void GPU_D3D11::ClearCacheNextFrame() {
textureCacheD3D11_->ClearNextFrame();
}

void GPU_D3D11::ClearShaderCache() {
shaderManagerD3D11_->ClearShaders();
drawEngine_.ClearInputLayoutMap();
Expand Down
5 changes: 0 additions & 5 deletions GPU/D3D11/GPU_D3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class GPU_D3D11 : public GPUCommon {
void PreExecuteOp(u32 op, u32 diff) override;
void ExecuteOp(u32 op, u32 diff) override;

void ReapplyGfxState() override;
void GetStats(char *buffer, size_t bufsize) override;
void ClearCacheNextFrame() override;
void DeviceLost() override; // Only happens on Android. Drop all textures and shaders.
void DeviceRestore() override;

Expand All @@ -54,9 +52,6 @@ class GPU_D3D11 : public GPUCommon {
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override;

void BeginHostFrame() override;
void EndHostFrame() override;

protected:
void FinishDeferred() override;

Expand Down
10 changes: 0 additions & 10 deletions GPU/Directx9/GPU_DX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ void GPU_DX9::InitClear() {
}
}

void GPU_DX9::BeginHostFrame() {
GPUCommon::BeginHostFrame();
UpdateCmdInfo();
CheckResized();
}

void GPU_DX9::ReapplyGfxState() {
dxstate.Restore();
GPUCommon::ReapplyGfxState();
Expand Down Expand Up @@ -226,10 +220,6 @@ void GPU_DX9::GetStats(char *buffer, size_t bufsize) {
);
}

void GPU_DX9::ClearCacheNextFrame() {
textureCacheDX9_->ClearNextFrame();
}

void GPU_DX9::ClearShaderCache() {
shaderManagerDX9_->ClearCache(true);
}
Expand Down
3 changes: 0 additions & 3 deletions GPU/Directx9/GPU_DX9.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class GPU_DX9 : public GPUCommon {

void ReapplyGfxState() override;
void GetStats(char *buffer, size_t bufsize) override;
void ClearCacheNextFrame() override;
void DeviceLost() override; // Only happens on Android. Drop all textures and shaders.
void DeviceRestore() override;

Expand All @@ -53,8 +52,6 @@ class GPU_DX9 : public GPUCommon {
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override;

void BeginHostFrame() override;

protected:
void FinishDeferred() override;

Expand Down
5 changes: 3 additions & 2 deletions GPU/GLES/FramebufferManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ void FramebufferManagerGLES::DeviceLost() {
}
}

void FramebufferManagerGLES::Resized() {
FramebufferManagerCommon::Resized();
void FramebufferManagerGLES::NotifyDisplayResized() {
FramebufferManagerCommon::NotifyDisplayResized();

GLRenderManager *render = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
render->Resize(PSP_CoreParameter().pixelWidth, PSP_CoreParameter().pixelHeight);
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/FramebufferManagerGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FramebufferManagerGLES : public FramebufferManagerCommon {
FramebufferManagerGLES(Draw::DrawContext *draw);
~FramebufferManagerGLES();

void Resized() override;
void NotifyDisplayResized() override;
void DeviceLost() override;

bool GetOutputFramebuffer(GPUDebugBuffer &buffer) override;
Expand Down
7 changes: 0 additions & 7 deletions GPU/GLES/GPU_GLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ void GPU_GLES::InitClear() {

void GPU_GLES::BeginHostFrame() {
GPUCommon::BeginHostFrame();
UpdateCmdInfo();
CheckResized();

drawEngine_.BeginFrame();
}

Expand Down Expand Up @@ -356,10 +353,6 @@ void GPU_GLES::GetStats(char *buffer, size_t bufsize) {
);
}

void GPU_GLES::ClearCacheNextFrame() {
textureCacheGL_->ClearNextFrame();
}

void GPU_GLES::ClearShaderCache() {
shaderManagerGL_->ClearCache(true);
}
Expand Down
1 change: 0 additions & 1 deletion GPU/GLES/GPU_GLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class GPU_GLES : public GPUCommon {
void ReapplyGfxState() override;
void GetStats(char *buffer, size_t bufsize) override;

void ClearCacheNextFrame() override;
void DeviceLost() override; // Only happens on Android. Drop all textures and shaders.
void DeviceRestore() override;

Expand Down
49 changes: 39 additions & 10 deletions GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,23 @@ void GPUCommon::UpdateCmdInfo() {
}

void GPUCommon::BeginHostFrame() {
UpdateVsyncInterval(resized_);
UpdateVsyncInterval(displayResized_);
ReapplyGfxState();

// TODO: Assume config may have changed - maybe move to resize.
gstate_c.Dirty(DIRTY_ALL);

UpdateCmdInfo();
CheckConfigChanged();
CheckDisplayResized();
CheckRenderResized();
}

void GPUCommon::EndHostFrame() {

// Probably not necessary.
if (draw_) {
draw_->InvalidateCachedState();
}
}

void GPUCommon::Reinitialize() {
Expand Down Expand Up @@ -607,21 +615,42 @@ bool GPUCommon::BusyDrawing() {
return false;
}

void GPUCommon::Resized() {
resized_ = true;
void GPUCommon::NotifyConfigChanged() {
configChanged_ = true;
}

void GPUCommon::NotifyRenderResized() {
renderResized_ = true;
}

void GPUCommon::NotifyDisplayResized() {
displayResized_ = true;
}

// Called once per frame. Might also get called during the pause screen
// if "transparent".
void GPUCommon::CheckResized() {
if (resized_) {
void GPUCommon::CheckConfigChanged() {
if (configChanged_) {
gstate_c.useFlags = CheckGPUFeatures();
BuildReportingInfo();
framebufferManager_->Resized();
drawEngineCommon_->NotifyConfigChanged();
shaderManager_->DirtyLastShader(); // Don't think this is needed, at all.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, must be a bug somewhere else if it is. I think it's just come along for the ride through various refactoring since we only had a GLES backend...

-[Unknown]

textureCache_->NotifyConfigChanged();
shaderManager_->DirtyLastShader();
resized_ = false;
BuildReportingInfo();
configChanged_ = false;
}
}

void GPUCommon::CheckDisplayResized() {
if (displayResized_) {
framebufferManager_->NotifyDisplayResized();
displayResized_ = false;
}
}

void GPUCommon::CheckRenderResized() {
if (renderResized_) {
framebufferManager_->NotifyRenderResized();
renderResized_ = false;
}
}

Expand Down
Loading