Skip to content

Commit

Permalink
Merge pull request #14789 from hrydgard/auto-max-quality-texfilter
Browse files Browse the repository at this point in the history
Add new texture filtering mode "Auto Max Quality"
  • Loading branch information
hrydgard committed Sep 6, 2021
2 parents a5d963f + 1df31e9 commit b5e8e22
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct Config {
bool bVendorBugChecksEnabled;

int iRenderingMode; // 0 = non-buffered rendering 1 = buffered rendering
int iTexFiltering; // 1 = off , 2 = nearest , 3 = linear , 4 = linear(CG)
int iTexFiltering; // 1 = auto , 2 = nearest , 3 = linear , 4 = auto max quality
int iBufFilter; // 1 = linear, 2 = nearest
int iSmallDisplayZoomType; // Used to fit display into screen 0 = stretch, 1 = partial stretch, 2 = auto scaling, 3 = manual scaling.
float fSmallDisplayOffsetX; // Along with Y it goes from 0.0 to 1.0, XY (0.5, 0.5) = center of the screen
Expand Down
7 changes: 7 additions & 0 deletions Core/ConfigValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ enum {
ROTATION_AUTO_HORIZONTAL = 5,
};

enum TextureFiltering {
TEX_FILTER_AUTO = 1,
TEX_FILTER_FORCE_NEAREST = 2,
TEX_FILTER_FORCE_LINEAR = 3,
TEX_FILTER_AUTO_MAX_QUALITY = 4,
};

enum BufferFilter {
SCALE_LINEAR = 1,
SCALE_NEAREST = 2,
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/SplineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic

int vertexSize = vdecoder->VertexSize();
if (vertexSize != sizeof(SimpleVertex)) {
ERROR_LOG(G3D, "Something went really wrong, vertex size: %i vs %i", vertexSize, (int)sizeof(SimpleVertex));
ERROR_LOG(G3D, "Something went really wrong, vertex size: %d vs %d", vertexSize, (int)sizeof(SimpleVertex));
}

// Make an array of pointers to the control points, to get rid of indices.
Expand Down
22 changes: 21 additions & 1 deletion GPU/Common/TextureCacheCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,18 @@ SamplerCacheKey TextureCacheCommon::GetSamplingParams(int maxLevel, const TexCac
}
break;
case TEX_FILTER_FORCE_NEAREST:
default:
// Just force to nearest without checks. Safe (but ugly).
forceFiltering = TEX_FILTER_FORCE_NEAREST;
break;
case TEX_FILTER_AUTO_MAX_QUALITY:
default:
forceFiltering = TEX_FILTER_AUTO_MAX_QUALITY;
if (gstate.isModeThrough() && g_Config.iInternalResolution != 1) {
bool uglyColorTest = gstate.isColorTestEnabled() && !IsColorTestTriviallyTrue() && gstate.getColorTestRef() != 0;
if (uglyColorTest)
forceFiltering = TEX_FILTER_FORCE_NEAREST;
}
break;
}
}

Expand All @@ -260,6 +268,18 @@ SamplerCacheKey TextureCacheCommon::GetSamplingParams(int maxLevel, const TexCac
key.magFilt = 0;
key.minFilt = 0;
break;
case TEX_FILTER_AUTO_MAX_QUALITY:
// NOTE: We do not override magfilt here. If a game should have pixellated filtering,
// let it keep it. But we do enforce minification and mipmap filtering and max out the level.
// Later we'll also auto-generate any missing mipmaps.
key.minFilt = 1;
key.mipFilt = 1;
key.maxLevel = 9 * 256;
key.lodBias = 0.0f;
if (gstate_c.Supports(GPU_SUPPORTS_ANISOTROPY) && g_Config.iAnisotropyLevel > 0) {
key.aniso = true;
}
break;
}

return key;
Expand Down
7 changes: 1 addition & 6 deletions GPU/Common/TextureDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ enum CheckAlphaResult {
#include "Common/Common.h"
#include "Common/Swap.h"
#include "Core/MemMap.h"
#include "Core/ConfigValues.h"
#include "GPU/ge_constants.h"
#include "GPU/Common/TextureDecoderNEON.h"
#include "GPU/GPUState.h"

enum TextureFiltering {
TEX_FILTER_AUTO = 1,
TEX_FILTER_FORCE_NEAREST = 2,
TEX_FILTER_FORCE_LINEAR = 3,
};

void SetupTextureDecoder();

// Pitch must be aligned to 16 bits (as is the case on a PSP)
Expand Down
3 changes: 3 additions & 0 deletions GPU/D3D11/TextureCacheD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,10 @@ void TextureCacheD3D11::BuildTexture(TexCacheEntry *const entry) {

// Adjust maxLevel to actually present levels..
bool badMipSizes = false;

// maxLevel here is the max level to upload. Not the count.
int maxLevel = entry->maxLevel;

for (int i = 0; i <= maxLevel; i++) {
// If encountering levels pointing to nothing, adjust max level.
u32 levelTexaddr = gstate.getTextureAddress(i);
Expand Down
4 changes: 4 additions & 0 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ void DrawEngineVulkan::DoFlush() {
}

shaderManager_->GetShaders(prim, lastVType_, &vshader, &fshader, true, useHWTessellation_, decOptions_.expandAllWeightsToFloat); // usehwtransform
if (!vshader) {
// We're screwed.
return;
}
_dbg_assert_msg_(vshader->UseHWTransform(), "Bad vshader");

Draw::NativeObject object = framebufferManager_->UseBufferedRendering() ? Draw::NativeObject::FRAMEBUFFER_RENDERPASS : Draw::NativeObject::BACKBUFFER_RENDERPASS;
Expand Down
9 changes: 8 additions & 1 deletion GPU/Vulkan/TextureCacheVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,12 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
// such as when using replacement textures - but let's keep the same amount of levels.
int maxLevelToGenerate = maxLevel;

if (g_Config.iTexFiltering == TEX_FILTER_AUTO_MAX_QUALITY) {
// Boost the number of mipmaps.
int maxPossibleMipmaps = log2i(std::min(gstate.getTextureWidth(0), gstate.getTextureHeight(0)));
maxLevelToGenerate = maxPossibleMipmaps;
}

// If GLES3 is available, we can preallocate the storage, which makes texture loading more efficient.
VkFormat dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());

Expand Down Expand Up @@ -798,7 +804,8 @@ void TextureCacheVulkan::BuildTexture(TexCacheEntry *const entry) {
}
}

// TODO
// TODO: Support mip levels for upscaled images.
// Probably can just remove this check?
if (scaleFactor > 1) {
maxLevel = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void GameSettingsScreen::CreateViews() {
PopupMultiChoice *anisoFiltering = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iAnisotropyLevel, gr->T("Anisotropic Filtering"), anisoLevels, 0, ARRAY_SIZE(anisoLevels), gr->GetName(), screenManager()));
anisoFiltering->SetDisabledPtr(&g_Config.bSoftwareRendering);

static const char *texFilters[] = { "Auto", "Nearest", "Linear" };
static const char *texFilters[] = { "Auto", "Nearest", "Linear", "Auto Max Quality"};
graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTexFiltering, gr->T("Texture Filter"), texFilters, 1, ARRAY_SIZE(texFilters), gr->GetName(), screenManager()));

static const char *bufFilters[] = { "Linear", "Nearest", };
Expand Down
13 changes: 8 additions & 5 deletions Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ namespace MainWindow {
TranslateMenuItem(menu, ID_OPTIONS_TEXTUREFILTERING_AUTO);
TranslateMenuItem(menu, ID_OPTIONS_NEARESTFILTERING);
TranslateMenuItem(menu, ID_OPTIONS_LINEARFILTERING);
TranslateMenuItem(menu, ID_OPTIONS_AUTOMAXQUALITYFILTERING);
TranslateMenuItem(menu, ID_OPTIONS_SCREENFILTER_MENU);
TranslateMenuItem(menu, ID_OPTIONS_BUFLINEARFILTER);
TranslateMenuItem(menu, ID_OPTIONS_BUFNEARESTFILTER);
Expand Down Expand Up @@ -979,9 +980,10 @@ namespace MainWindow {
g_Config.iShowFPSCounter = g_Config.iShowFPSCounter ? 0 : 3; // 3 = both speed and FPS
break;

case ID_OPTIONS_TEXTUREFILTERING_AUTO: setTexFiltering(TEX_FILTER_AUTO); break;
case ID_OPTIONS_NEARESTFILTERING: setTexFiltering(TEX_FILTER_FORCE_NEAREST); break;
case ID_OPTIONS_LINEARFILTERING: setTexFiltering(TEX_FILTER_FORCE_LINEAR); break;
case ID_OPTIONS_TEXTUREFILTERING_AUTO: setTexFiltering(TEX_FILTER_AUTO); break;
case ID_OPTIONS_NEARESTFILTERING: setTexFiltering(TEX_FILTER_FORCE_NEAREST); break;
case ID_OPTIONS_LINEARFILTERING: setTexFiltering(TEX_FILTER_FORCE_LINEAR); break;
case ID_OPTIONS_AUTOMAXQUALITYFILTERING: setTexFiltering(TEX_FILTER_AUTO_MAX_QUALITY); break;

case ID_OPTIONS_BUFLINEARFILTER: setBufFilter(SCALE_LINEAR); break;
case ID_OPTIONS_BUFNEARESTFILTER: setBufFilter(SCALE_NEAREST); break;
Expand Down Expand Up @@ -1225,11 +1227,12 @@ namespace MainWindow {
ID_OPTIONS_TEXTUREFILTERING_AUTO,
ID_OPTIONS_NEARESTFILTERING,
ID_OPTIONS_LINEARFILTERING,
ID_OPTIONS_AUTOMAXQUALITYFILTERING,
};
if (g_Config.iTexFiltering < TEX_FILTER_AUTO)
g_Config.iTexFiltering = TEX_FILTER_AUTO;
else if (g_Config.iTexFiltering > TEX_FILTER_FORCE_LINEAR)
g_Config.iTexFiltering = TEX_FILTER_FORCE_LINEAR;
else if (g_Config.iTexFiltering > TEX_FILTER_AUTO_MAX_QUALITY)
g_Config.iTexFiltering = TEX_FILTER_AUTO_MAX_QUALITY;

for (int i = 0; i < ARRAY_SIZE(texfilteringitems); i++) {
CheckMenuItem(menu, texfilteringitems[i], MF_BYCOMMAND | ((i + 1) == g_Config.iTexFiltering ? MF_CHECKED : MF_UNCHECKED));
Expand Down
1 change: 1 addition & 0 deletions Windows/ppsspp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ BEGIN
MENUITEM "Auto", ID_OPTIONS_TEXTUREFILTERING_AUTO
MENUITEM "Nearest", ID_OPTIONS_NEARESTFILTERING
MENUITEM "Linear", ID_OPTIONS_LINEARFILTERING
MENUITEM "Auto Max Quality", ID_OPTIONS_AUTOMAXQUALITYFILTERING
END
POPUP "Screen Scaling Filter", ID_OPTIONS_SCREENFILTER_MENU
BEGIN
Expand Down
1 change: 1 addition & 0 deletions Windows/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
#define ID_OPTIONS_HARDWARETRANSFORM 40030
#define IDC_STEPHLE 40032
#define ID_OPTIONS_LINEARFILTERING 40033
#define ID_OPTIONS_AUTOMAXQUALITYFILTERING 40043
#define ID_FILE_QUICKSAVESTATE 40034
#define ID_FILE_QUICKLOADSTATE 40035
#define ID_FILE_QUICKSAVESTATE_HC 40036
Expand Down

0 comments on commit b5e8e22

Please sign in to comment.