Skip to content

Commit

Permalink
GPU: Move calculating render res to presentation.
Browse files Browse the repository at this point in the history
Since it best understands what the first postshader wants.
  • Loading branch information
unknownbrackets committed May 16, 2020
1 parent 746f053 commit e3231e6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 35 deletions.
40 changes: 6 additions & 34 deletions GPU/Common/FramebufferCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,41 +1669,13 @@ void FramebufferManagerCommon::SetSafeSize(u16 w, u16 h) {
}

void FramebufferManagerCommon::Resized() {
// Check if postprocessing shader is doing upscaling as it requires native resolution
const ShaderInfo *shaderInfo = nullptr;
if (g_Config.sPostShaderName != "Off") {
shaderInfo = GetPostShaderInfo(g_Config.sPostShaderName);
}

postShaderIsUpscalingFilter_ = shaderInfo ? shaderInfo->isUpscalingFilter : false;
postShaderSSAAFilterLevel_ = shaderInfo ? shaderInfo->SSAAFilterLevel : 0;

// Actually, auto mode should be more granular...
// Round up to a zoom factor for the render size.
int zoom = g_Config.iInternalResolution;
if (zoom == 0 || postShaderSSAAFilterLevel_ >= 2) {
// auto mode, use the longest dimension
if (!g_Config.IsPortrait()) {
zoom = (PSP_CoreParameter().pixelWidth + 479) / 480;
} else {
zoom = (PSP_CoreParameter().pixelHeight + 479) / 480;
}
if (postShaderSSAAFilterLevel_ >= 2)
zoom *= postShaderSSAAFilterLevel_;
}
if (zoom <= 1 || postShaderIsUpscalingFilter_)
zoom = 1;

if (g_Config.IsPortrait()) {
PSP_CoreParameter().renderWidth = 272 * zoom;
PSP_CoreParameter().renderHeight = 480 * zoom;
} else {
PSP_CoreParameter().renderWidth = 480 * zoom;
PSP_CoreParameter().renderHeight = 272 * zoom;
}

gstate_c.skipDrawReason &= ~SKIPDRAW_NON_DISPLAYED_FB;

int w, h;
presentation_->CalculateRenderResolution(&w, &h, &postShaderIsUpscalingFilter_, &postShaderIsSupersampling_);
PSP_CoreParameter().renderWidth = w;
PSP_CoreParameter().renderHeight = h;

if (UpdateSize()) {
DestroyAllFBOs();
}
Expand Down Expand Up @@ -1785,7 +1757,7 @@ void FramebufferManagerCommon::ShowScreenResolution() {
messageStream << PSP_CoreParameter().renderWidth << "x" << PSP_CoreParameter().renderHeight << " ";
if (postShaderIsUpscalingFilter_) {
messageStream << gr->T("(upscaling)") << " ";
} else if (postShaderSSAAFilterLevel_ >= 2) {
} else if (postShaderIsSupersampling_) {
messageStream << gr->T("(supersampling)") << " ";
}
messageStream << gr->T("Window Size") << ": ";
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/FramebufferCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class FramebufferManagerCommon {

bool useBufferedRendering_ = false;
bool postShaderIsUpscalingFilter_ = false;
int postShaderSSAAFilterLevel_ = 0;
bool postShaderIsSupersampling_ = false;

std::vector<VirtualFramebuffer *> vfbs_;
std::vector<VirtualFramebuffer *> bvfbs_; // blitting framebuffers (for download)
Expand Down
49 changes: 49 additions & 0 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,52 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u

draw_->BindPipeline(nullptr);
}

void PresentationCommon::CalculateRenderResolution(int *width, int *height, bool *upscaling, bool *ssaa) {
// Check if postprocessing shader is doing upscaling as it requires native resolution
std::vector<const ShaderInfo *> shaderInfo;
if (g_Config.sPostShaderName != "Off") {
ReloadAllPostShaderInfo();
shaderInfo = GetPostShaderChain(g_Config.sPostShaderName);
}

bool firstIsUpscalingFilter = shaderInfo.empty() ? false : shaderInfo.front()->isUpscalingFilter;
int firstSSAAFilterLevel = shaderInfo.empty() ? 0 : shaderInfo.front()->SSAAFilterLevel;

// Actually, auto mode should be more granular...
// Round up to a zoom factor for the render size.
int zoom = g_Config.iInternalResolution;
if (zoom == 0 || firstSSAAFilterLevel >= 2) {
// auto mode, use the longest dimension
if (!g_Config.IsPortrait()) {
zoom = (PSP_CoreParameter().pixelWidth + 479) / 480;
} else {
zoom = (PSP_CoreParameter().pixelHeight + 479) / 480;
}
if (firstSSAAFilterLevel >= 2)
zoom *= firstSSAAFilterLevel;
}
if (zoom <= 1 || firstIsUpscalingFilter)
zoom = 1;

if (upscaling) {
*upscaling = firstIsUpscalingFilter;
for (auto &info : shaderInfo) {
*upscaling = *upscaling || info->isUpscalingFilter;
}
}
if (ssaa) {
*ssaa = firstSSAAFilterLevel >= 2;
for (auto &info : shaderInfo) {
*ssaa = *ssaa || info->SSAAFilterLevel >= 2;
}
}

if (g_Config.IsPortrait()) {
*width = 272 * zoom;
*height = 480 * zoom;
} else {
*width = 480 * zoom;
*height = 272 * zoom;
}
}
2 changes: 2 additions & 0 deletions GPU/Common/PresentationCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class PresentationCommon {
void SourceFramebuffer(Draw::Framebuffer *fb, int bufferWidth, int bufferHeight);
void CopyToOutput(OutputFlags flags, int uvRotation, float u0, float v0, float u1, float v1);

void CalculateRenderResolution(int *width, int *height, bool *upscaling, bool *ssaa);

protected:
void CreateDeviceObjects();
void DestroyDeviceObjects();
Expand Down

0 comments on commit e3231e6

Please sign in to comment.