Skip to content

Commit

Permalink
D3D: gpu scalers:
Browse files Browse the repository at this point in the history
- rework xbrz: improve performance and make it scale independant, move
the old xbrz code to 4xbrz.hlsl.
- better handling of alpha in xbr/xbrz shaders, fixes text scaling with
some games.
  • Loading branch information
aliaspider committed Apr 4, 2018
1 parent 45a0809 commit e74e7ad
Show file tree
Hide file tree
Showing 16 changed files with 652 additions and 304 deletions.
1 change: 1 addition & 0 deletions GPU/Common/TextureScalerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ bool TextureScalerCommon::ScaleInto(u32 *outputBuf, u32 *src, u32 &dstFmt, int &
case XBR:
case SABR:
// no cpu implementation, fall back to xbrz
case _4XBRZ:
case XBRZ:
ScaleXBRZ(factor, inputBuf, outputBuf, width, height);
break;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/TextureScalerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TextureScalerCommon {
bool Scale(u32 *&data, u32 &dstfmt, int &width, int &height, int factor);
bool ScaleInto(u32 *out, u32 *src, u32 &dstfmt, int &width, int &height, int factor);

enum { XBRZ = 0, HYBRID = 1, BICUBIC = 2, HYBRID_BICUBIC = 3, XBR = 4, SABR = 5, GAUSSIAN = 6, COSINE = 7 };
enum { XBRZ = 0, HYBRID = 1, BICUBIC = 2, HYBRID_BICUBIC = 3, _4XBRZ = 4, XBR = 5, SABR = 6, GAUSSIAN = 7, COSINE = 8 };

protected:
virtual void ConvertTo8888(u32 format, u32 *source, u32 *&dest, int width, int height) = 0;
Expand Down
1 change: 1 addition & 0 deletions GPU/D3D11/ShaderManagerD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void ShaderManagerD3D11::GetShaders(int prim, u32 vertType, D3D11VertexShader **
"scalers/hybrid.hlsl",
"scalers/bicubic.hlsl",
"scalers/hybrid_bicubic.hlsl",
"scalers/4xbrz.hlsl",
"scalers/xbr.hlsl",
"scalers/sabr.hlsl",
"scalers/gaussian.hlsl",
Expand Down
7 changes: 1 addition & 6 deletions GPU/Directx9/PixelShaderGeneratorDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,7 @@ bool GenerateFragmentShaderHLSL(const FShaderID &id, char *buffer, char* scalerC

if (!isModeClear && doTexture) {
if (doTextureAlpha) {
// TODO: check why the [0.0,1.0] clamp is necessary here
WRITE(p, "float4 premultiply_alpha(float4 c) { float a = clamp(c.a, 0.0, 1.0); return float4(c.rgb * a, a); }");
WRITE(p, "float4 postdivide_alpha(float4 c) { return c.a < 0.0001f? 0.0f : float4(c.rgb / c.a, c.a); }\n");
} else {
WRITE(p, "#define premultiply_alpha(c) (c)\n");
WRITE(p, "#define postdivide_alpha(c) (c)\n");
WRITE(p, "#define BLEND_ALPHA\n");
}

WRITE(p, "float4 tex_sample_direct(float2 coord) {\n");
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ void GameSettingsScreen::CreateViews() {
});
texScalingChoice->SetDisabledPtr(&g_Config.bSoftwareRendering);

static const char *texScaleAlgos[] = { "xBRZ", "Hybrid", "Bicubic", "Hybrid + Bicubic", "XBR", "SABR", "Gaussian", "Cosine"};
static const char *texScaleAlgos[] = { "xBRZ", "Hybrid", "Bicubic", "Hybrid + Bicubic", "4xBRZ", "xBR", "SABR", "Gaussian", "Cosine"};
PopupMultiChoice *texScalingType = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTexScalingType, gr->T("Upscale Type"), texScaleAlgos, 0, ARRAY_SIZE(texScaleAlgos), gr->GetName(), screenManager()));
texScalingType->SetDisabledPtr(&g_Config.bSoftwareRendering);

Expand Down
4 changes: 4 additions & 0 deletions Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ namespace MainWindow {
TranslateMenuItem(menu, ID_TEXTURESCALING_HYBRID);
TranslateMenuItem(menu, ID_TEXTURESCALING_BICUBIC);
TranslateMenuItem(menu, ID_TEXTURESCALING_HYBRID_BICUBIC);
TranslateMenuItem(menu, ID_TEXTURESCALING_4XBRZ);
TranslateMenuItem(menu, ID_TEXTURESCALING_XBR);
TranslateMenuItem(menu, ID_TEXTURESCALING_SABR);
TranslateMenuItem(menu, ID_TEXTURESCALING_GAUSSIAN);
TranslateMenuItem(menu, ID_TEXTURESCALING_COSINE);
Expand Down Expand Up @@ -787,6 +789,7 @@ namespace MainWindow {
case ID_TEXTURESCALING_HYBRID: setTexScalingType(TextureScalerCommon::HYBRID); break;
case ID_TEXTURESCALING_BICUBIC: setTexScalingType(TextureScalerCommon::BICUBIC); break;
case ID_TEXTURESCALING_HYBRID_BICUBIC: setTexScalingType(TextureScalerCommon::HYBRID_BICUBIC); break;
case ID_TEXTURESCALING_4XBRZ: setTexScalingType(TextureScalerCommon::_4XBRZ); break;
case ID_TEXTURESCALING_XBR: setTexScalingType(TextureScalerCommon::XBR); break;
case ID_TEXTURESCALING_SABR: setTexScalingType(TextureScalerCommon::SABR); break;
case ID_TEXTURESCALING_GAUSSIAN: setTexScalingType(TextureScalerCommon::GAUSSIAN); break;
Expand Down Expand Up @@ -1215,6 +1218,7 @@ namespace MainWindow {
ID_TEXTURESCALING_HYBRID,
ID_TEXTURESCALING_BICUBIC,
ID_TEXTURESCALING_HYBRID_BICUBIC,
ID_TEXTURESCALING_4XBRZ,
ID_TEXTURESCALING_XBR,
ID_TEXTURESCALING_SABR,
ID_TEXTURESCALING_GAUSSIAN,
Expand Down
3 changes: 2 additions & 1 deletion Windows/ppsspp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ BEGIN
MENUITEM "Hybrid", ID_TEXTURESCALING_HYBRID
MENUITEM "Bicubic", ID_TEXTURESCALING_BICUBIC
MENUITEM "Hybrid + Bicubic", ID_TEXTURESCALING_HYBRID_BICUBIC
MENUITEM "XBR", ID_TEXTURESCALING_XBR
MENUITEM "4xBRZ", ID_TEXTURESCALING_4XBRZ
MENUITEM "xBR", ID_TEXTURESCALING_XBR
MENUITEM "SABR", ID_TEXTURESCALING_SABR
MENUITEM "Gaussian", ID_TEXTURESCALING_GAUSSIAN
MENUITEM "Cosine", ID_TEXTURESCALING_COSINE
Expand Down
9 changes: 5 additions & 4 deletions Windows/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,11 @@

#define ID_TEXTURESCALING_REALTIME 40177
#define ID_TEXTURESCALING_REALTIME_HC 40178
#define ID_TEXTURESCALING_XBR 40179
#define ID_TEXTURESCALING_SABR 40180
#define ID_TEXTURESCALING_GAUSSIAN 40181
#define ID_TEXTURESCALING_COSINE 40182
#define ID_TEXTURESCALING_4XBRZ 40179
#define ID_TEXTURESCALING_XBR 40180
#define ID_TEXTURESCALING_SABR 40181
#define ID_TEXTURESCALING_GAUSSIAN 40182
#define ID_TEXTURESCALING_COSINE 40183

// Dummy option to let the buffered rendering hotkey cycle through all the options.
#define ID_OPTIONS_BUFFEREDRENDERINGDUMMY 40500
Expand Down
Loading

0 comments on commit e74e7ad

Please sign in to comment.