Switch texture scaling shaders to a fixed scale model, preparing for the next change.

This commit is contained in:
Henrik Rydgård 2021-11-07 13:12:28 +01:00
parent c111d6cc2d
commit 6349704924
6 changed files with 29 additions and 21 deletions

View File

@ -208,14 +208,15 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector<Path> &direct
info.section = section.name(); info.section = section.name();
section.Get("Name", &info.name, section.name().c_str()); section.Get("Name", &info.name, section.name().c_str());
section.Get("Compute", &temp, ""); section.Get("Compute", &temp, "");
section.Get("MaxScale", &info.maxScale, 255); section.Get("Scale", &info.scaleFactor, 0);
info.computeShaderFile = path / temp; info.computeShaderFile = path / temp;
if (info.scaleFactor >= 2 && info.scaleFactor < 8) {
appendTextureShader(info); appendTextureShader(info);
} }
} }
} }
} }
}
// We always want the not visible ones at the end. Makes menus easier. // We always want the not visible ones at the end. Makes menus easier.
for (const auto &info : notVisible) { for (const auto &info : notVisible) {

View File

@ -72,7 +72,9 @@ struct TextureShaderInfo {
std::string name; std::string name;
Path computeShaderFile; Path computeShaderFile;
int maxScale;
// Upscaling shaders have a fixed scale factor.
int scaleFactor;
bool operator == (const std::string &other) { bool operator == (const std::string &other) {
return name == other; return name == other;

View File

@ -299,7 +299,7 @@ void TextureCacheVulkan::CompileScalingShader() {
if (uploadCS_ != VK_NULL_HANDLE) if (uploadCS_ != VK_NULL_HANDLE)
vulkan_->Delete().QueueDeleteShaderModule(uploadCS_); vulkan_->Delete().QueueDeleteShaderModule(uploadCS_);
textureShader_.clear(); textureShader_.clear();
maxScaleFactor_ = 255; shaderScaleFactor_ = 0; // no texture scaling shader
} else if (uploadCS_) { } else if (uploadCS_) {
// No need to recreate. // No need to recreate.
return; return;
@ -321,7 +321,7 @@ void TextureCacheVulkan::CompileScalingShader() {
_dbg_assert_msg_(uploadCS_ != VK_NULL_HANDLE, "failed to compile upload shader"); _dbg_assert_msg_(uploadCS_ != VK_NULL_HANDLE, "failed to compile upload shader");
textureShader_ = g_Config.sTextureShaderName; textureShader_ = g_Config.sTextureShaderName;
maxScaleFactor_ = shaderInfo->maxScale; shaderScaleFactor_ = shaderInfo->scaleFactor;
} }
void TextureCacheVulkan::ReleaseTexture(TexCacheEntry *entry, bool delete_them) { void TextureCacheVulkan::ReleaseTexture(TexCacheEntry *entry, bool delete_them) {
@ -677,11 +677,15 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
} }
int scaleFactor = standardScaleFactor_; int scaleFactor = standardScaleFactor_;
if (scaleFactor > maxScaleFactor_) bool hardwareScaling = g_Config.bTexHardwareScaling && uploadCS_ != VK_NULL_HANDLE;
scaleFactor = maxScaleFactor_; if (hardwareScaling) {
_assert_(shaderScaleFactor_ != 0);
scaleFactor = shaderScaleFactor_;
}
// Rachet down scale factor in low-memory mode. // 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. // Keep it even, though, just in case of npot troubles.
scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1); scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1);
} }
@ -696,11 +700,10 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
badMipSizes = false; badMipSizes = false;
} }
bool hardwareScaling = g_Config.bTexHardwareScaling && uploadCS_ != VK_NULL_HANDLE;
// Don't scale the PPGe texture. // Don't scale the PPGe texture.
if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd()) {
scaleFactor = 1; scaleFactor = 1;
}
if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && scaleFactor != 1 && !hardwareScaling) { if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && scaleFactor != 1 && !hardwareScaling) {
// Remember for later that we /wanted/ to scale this texture. // Remember for later that we /wanted/ to scale this texture.
entry->status |= TexCacheEntry::STATUS_TO_SCALE; entry->status |= TexCacheEntry::STATUS_TO_SCALE;

View File

@ -135,7 +135,7 @@ private:
Vulkan2D *vulkan2D_; Vulkan2D *vulkan2D_;
std::string textureShader_; std::string textureShader_;
int maxScaleFactor_ = 255; int shaderScaleFactor_ = 0;
VkShaderModule uploadCS_ = VK_NULL_HANDLE; VkShaderModule uploadCS_ = VK_NULL_HANDLE;
// Bound state to emulate an API similar to the others // Bound state to emulate an API similar to the others

View File

@ -533,6 +533,11 @@ void GameSettingsScreen::CreateViews() {
static const char *texScaleLevels[] = {"Off", "2x", "3x"}; static const char *texScaleLevels[] = {"Off", "2x", "3x"};
#endif #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())); 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. // TODO: Better check? When it won't work, it scales down anyway.
if (!gl_extensions.OES_texture_npot && GetGPUBackend() == GPUBackend::OPENGL) { if (!gl_extensions.OES_texture_npot && GetGPUBackend() == GPUBackend::OPENGL) {
@ -545,11 +550,7 @@ void GameSettingsScreen::CreateViews() {
} }
return UI::EVENT_CONTINUE; return UI::EVENT_CONTINUE;
}); });
texScalingChoice->SetDisabledPtr(&g_Config.bSoftwareRendering); texScalingChoice->SetEnabledFunc([]() {
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(); return !g_Config.bSoftwareRendering && !UsingHardwareTextureScaling();
}); });

View File

@ -151,13 +151,14 @@ Fragment=psp_color.fsh
Vertex=fxaa.vsh Vertex=fxaa.vsh
[Tex4xBRZ] [Tex4xBRZ]
Type=Texture Type=Texture
Name=4xBRZ Name=4xBRZ (4x)
Author=Hyllian Author=Hyllian
Compute=tex_4xbrz.csh Compute=tex_4xbrz.csh
VendorBlacklist=ARM VendorBlacklist=ARM
Scale=4
[TexMMPX] [TexMMPX]
Type=Texture Type=Texture
Name=MMPX Name=MMPX (2x)
Author=Morgan McGuire and Mara Gagiu Author=Morgan McGuire and Mara Gagiu
Compute=tex_mmpx.csh Compute=tex_mmpx.csh
MaxScale=2 Scale=2