From 6349704924cd0f8d274d38351b0ffbdfed8295b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 7 Nov 2021 13:12:28 +0100 Subject: [PATCH] Switch texture scaling shaders to a fixed scale model, preparing for the next change. --- GPU/Common/PostShader.cpp | 7 ++++--- GPU/Common/PostShader.h | 4 +++- GPU/Vulkan/TextureCacheVulkan.cpp | 19 +++++++++++-------- GPU/Vulkan/TextureCacheVulkan.h | 2 +- UI/GameSettingsScreen.cpp | 11 ++++++----- assets/shaders/defaultshaders.ini | 7 ++++--- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index 152e6477a3..6a682481e7 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -208,10 +208,11 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector &direct info.section = section.name(); section.Get("Name", &info.name, section.name().c_str()); section.Get("Compute", &temp, ""); - section.Get("MaxScale", &info.maxScale, 255); + section.Get("Scale", &info.scaleFactor, 0); info.computeShaderFile = path / temp; - - appendTextureShader(info); + if (info.scaleFactor >= 2 && info.scaleFactor < 8) { + appendTextureShader(info); + } } } } diff --git a/GPU/Common/PostShader.h b/GPU/Common/PostShader.h index cd0cb8e39d..5226638078 100644 --- a/GPU/Common/PostShader.h +++ b/GPU/Common/PostShader.h @@ -72,7 +72,9 @@ struct TextureShaderInfo { std::string name; Path computeShaderFile; - int maxScale; + + // Upscaling shaders have a fixed scale factor. + int scaleFactor; bool operator == (const std::string &other) { return name == other; diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 979d88a9b1..5593c5b410 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -299,7 +299,7 @@ void TextureCacheVulkan::CompileScalingShader() { if (uploadCS_ != VK_NULL_HANDLE) vulkan_->Delete().QueueDeleteShaderModule(uploadCS_); textureShader_.clear(); - maxScaleFactor_ = 255; + shaderScaleFactor_ = 0; // no texture scaling shader } else if (uploadCS_) { // No need to recreate. return; @@ -321,7 +321,7 @@ void TextureCacheVulkan::CompileScalingShader() { _dbg_assert_msg_(uploadCS_ != VK_NULL_HANDLE, "failed to compile upload shader"); textureShader_ = g_Config.sTextureShaderName; - maxScaleFactor_ = shaderInfo->maxScale; + shaderScaleFactor_ = shaderInfo->scaleFactor; } void TextureCacheVulkan::ReleaseTexture(TexCacheEntry *entry, bool delete_them) { @@ -677,11 +677,15 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { } int scaleFactor = standardScaleFactor_; - if (scaleFactor > maxScaleFactor_) - scaleFactor = maxScaleFactor_; + bool hardwareScaling = g_Config.bTexHardwareScaling && uploadCS_ != VK_NULL_HANDLE; + if (hardwareScaling) { + _assert_(shaderScaleFactor_ != 0); + scaleFactor = shaderScaleFactor_; + } // Rachet down scale factor in low-memory mode. - if (lowMemoryMode_) { + // TODO: I think really we should just turn it off? + if (lowMemoryMode_ && !hardwareScaling) { // Keep it even, though, just in case of npot troubles. scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); } @@ -696,11 +700,10 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) { badMipSizes = false; } - bool hardwareScaling = g_Config.bTexHardwareScaling && uploadCS_ != VK_NULL_HANDLE; - // Don't scale the PPGe texture. - if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) + if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) { scaleFactor = 1; + } if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && scaleFactor != 1 && !hardwareScaling) { // Remember for later that we /wanted/ to scale this texture. entry->status |= TexCacheEntry::STATUS_TO_SCALE; diff --git a/GPU/Vulkan/TextureCacheVulkan.h b/GPU/Vulkan/TextureCacheVulkan.h index 12183be09f..da2cf9ee76 100644 --- a/GPU/Vulkan/TextureCacheVulkan.h +++ b/GPU/Vulkan/TextureCacheVulkan.h @@ -135,7 +135,7 @@ private: Vulkan2D *vulkan2D_; std::string textureShader_; - int maxScaleFactor_ = 255; + int shaderScaleFactor_ = 0; VkShaderModule uploadCS_ = VK_NULL_HANDLE; // Bound state to emulate an API similar to the others diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 39398ae7fe..cd750d0b7a 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -533,6 +533,11 @@ void GameSettingsScreen::CreateViews() { static const char *texScaleLevels[] = {"Off", "2x", "3x"}; #endif + static const char *texScaleAlgos[] = { "xBRZ", "Hybrid", "Bicubic", "Hybrid + Bicubic", }; + PopupMultiChoice *texScalingType = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTexScalingType, gr->T("Upscale Type"), texScaleAlgos, 0, ARRAY_SIZE(texScaleAlgos), gr->GetName(), screenManager())); + texScalingType->SetEnabledFunc([]() { + return !g_Config.bSoftwareRendering && !UsingHardwareTextureScaling(); + }); PopupMultiChoice *texScalingChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTexScalingLevel, gr->T("Upscale Level"), texScaleLevels, 1, ARRAY_SIZE(texScaleLevels), gr->GetName(), screenManager())); // TODO: Better check? When it won't work, it scales down anyway. if (!gl_extensions.OES_texture_npot && GetGPUBackend() == GPUBackend::OPENGL) { @@ -545,11 +550,7 @@ void GameSettingsScreen::CreateViews() { } return UI::EVENT_CONTINUE; }); - texScalingChoice->SetDisabledPtr(&g_Config.bSoftwareRendering); - - static const char *texScaleAlgos[] = { "xBRZ", "Hybrid", "Bicubic", "Hybrid + Bicubic", }; - PopupMultiChoice *texScalingType = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTexScalingType, gr->T("Upscale Type"), texScaleAlgos, 0, ARRAY_SIZE(texScaleAlgos), gr->GetName(), screenManager())); - texScalingType->SetEnabledFunc([]() { + texScalingChoice->SetEnabledFunc([]() { return !g_Config.bSoftwareRendering && !UsingHardwareTextureScaling(); }); diff --git a/assets/shaders/defaultshaders.ini b/assets/shaders/defaultshaders.ini index e3d4c35bcd..273ad7716a 100644 --- a/assets/shaders/defaultshaders.ini +++ b/assets/shaders/defaultshaders.ini @@ -151,13 +151,14 @@ Fragment=psp_color.fsh Vertex=fxaa.vsh [Tex4xBRZ] Type=Texture -Name=4xBRZ +Name=4xBRZ (4x) Author=Hyllian Compute=tex_4xbrz.csh VendorBlacklist=ARM +Scale=4 [TexMMPX] Type=Texture -Name=MMPX +Name=MMPX (2x) Author=Morgan McGuire and Mara Gagiu Compute=tex_mmpx.csh -MaxScale=2 +Scale=2