Skip to content

Commit

Permalink
Merge: PixelShaderGen: Add support for RGBA6 EFB format truncation. #…
Browse files Browse the repository at this point in the history
…4194
  • Loading branch information
Tinob committed Sep 30, 2016
1 parent bfda1ac commit 7ffb18a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Source/Core/DolphinWX/VideoConfigDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ static wxString stc_desc = _("The safer you adjust this, the less likely the emu
static wxString bbox_desc = _("Selects wish implementation is used to emulate Bounding Box. By Default GPU will be used if supported.");
static wxString wireframe_desc = _("Render the scene as a wireframe.\n\nIf unsure, leave this unchecked.");
static wxString disable_fog_desc = _("Makes distant objects more visible by removing fog, thus increasing the overall detail.\nDisabling fog will break some games which rely on proper fog emulation.\n\nIf unsure, leave this unchecked.");
static wxString true_color_desc = _("Forces the game to render the RGB color channels in 24-bit, thereby increasing "
"quality by reducing color banding.\nIt improves performance and causes "
"few graphical issues.\n\n\nIf unsure, leave this checked.");
static wxString disable_dstalpha_desc = _("Disables emulation of a hardware feature called destination alpha, which is used in many games for various graphical effects.\n\nIf unsure, leave this unchecked.");
static wxString show_fps_desc =
wxTRANSLATE("Show the number of frames rendered per second as a measure of "
Expand Down Expand Up @@ -458,6 +461,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string &title)

szr_enh->Add(CreateCheckBox(page_enh, _("Widescreen Hack"), (ws_hack_desc), vconfig.bWidescreenHack));
szr_enh->Add(CreateCheckBox(page_enh, _("Disable Fog"), (disable_fog_desc), vconfig.bDisableFog));
szr_enh->Add(CreateCheckBox(page_enh, _("Force 24-bit Color"), (true_color_desc), vconfig.bForceTrueColor));
szr_enh->Add(pixel_lighting = CreateCheckBox(page_enh, _("Per-Pixel Lighting"), (pixel_lighting_desc), vconfig.bEnablePixelLighting));
szr_enh->Add(phong_lighting = CreateCheckBox(page_enh, _("Phong Lighting"), (phong_lighting_desc), vconfig.bForcePhongShading));
szr_enh->Add(sim_bump = CreateCheckBox(page_enh, _("Auto Bumps"), (bump_desc), vconfig.bSimBumpEnabled));
Expand Down
56 changes: 45 additions & 11 deletions Source/Core/VideoCommon/PixelShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ float4 CHK_O_U8(float4 x)
{
return frac(((x) + 1024.0) * (1.0/256.0)) * 256.0;
}
#define CAST_TO_U6(x) (floor((x) * 0.25) * 4.0)
#define BOR(x, n) ((x) + (n))
#define BSHR(x, n) floor((x) * exp2(-(n)))
float2 BSH(float2 x, float n)
Expand Down Expand Up @@ -287,6 +288,7 @@ int4 CHK_O_U8(int4 x)
{
return x & 255;
}
#define CAST_TO_U6(x) ((x) & 252)
#define BOR(x, n) ((x) | (n))
#define BSHR(x, n) ((x) >> (n))
int2 BSH(int2 x, int n)
Expand Down Expand Up @@ -490,6 +492,11 @@ void GetPixelShaderUID(PixelShaderUid& out, PIXEL_SHADER_RENDER_MODE render_mode
}
uid_data.stereo = g_ActiveConfig.iStereoMode > 0;
uid_data.bounding_box = g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active && g_ActiveConfig.iBBoxMode == BBoxGPU;
if (!g_ActiveConfig.bForceTrueColor)
{
uid_data.rgba6_format = bpmem.zcontrol.pixel_format != PEControl::RGB8_Z24;
uid_data.dither = bpmem.blendmode.dither;
}
if ((g_ActiveConfig.backend_info.APIType & API_D3D9) == 0)
{
uid_data.msaa = g_ActiveConfig.iMultisamples > 1;
Expand Down Expand Up @@ -2124,6 +2131,36 @@ inline void GeneratePixelShader(ShaderCode& out, const pixel_shader_uid_data& ui
else
out.Write("\tdepth = %s zCoord;\n", ApiType == API_OPENGL ? "" : "1.0 - ");
}

if (render_mode == PSRM_ALPHA_PASS)
{
out.Write("prev.a = " I_ALPHA ".a;\n");
}
else
{
WriteFog<Use_integer_math>(out, uid_data);
}

if (uid_data.dither && uid_data.rgba6_format)
{
if (ApiType & API_D3D9)
{
out.Write("\tfloat2 dither = round(rawpos.xy) % 4;\n");
out.Write("\tfloat bayer[16] = {-7.0,1.0,-5.0,3.0,5.0,-3.0,7.0,-1.0,-4.0,4.0,-6.0,2.0,8.0,0.0,6.0,-2.0};\n");
}
else
{
out.Write("\tint2 dither = int2(rawpos.xy) & 3;\n");
out.Write("\tint bayer[16] = {-7,1,-5,3,5,-3,7,-1,-4,4,-6,2,8,0,6,-2};\n");
}
out.Write("\tprev.rgb = prev.rgb + bayer[dither.y * 4 + dither.x];\n");
}

if (uid_data.rgba6_format)
{
out.Write("\tprev = CAST_TO_U6(clamp(prev, 0, 255));\n");
}

if (forcePhong)
{
out.Write(
Expand All @@ -2138,16 +2175,6 @@ inline void GeneratePixelShader(ShaderCode& out, const pixel_shader_uid_data& ui
out.Write("prev.rgb += wu3(emmisive_mask);\n");
out.Write("}\n");
}

if (render_mode == PSRM_ALPHA_PASS)
{
out.Write("ocol0 = float4(prev.rgb," I_ALPHA ".a) * (1.0/255.0);\n");
}
else
{
WriteFog<Use_integer_math>(out, uid_data);
out.Write("ocol0 = float4(prev) * (1.0/255.0);\n");
}
// Use dual-source color blending to perform dst alpha in a single pass
if (render_mode == PSRM_DUAL_SOURCE_BLEND)
{
Expand All @@ -2163,8 +2190,15 @@ inline void GeneratePixelShader(ShaderCode& out, const pixel_shader_uid_data& ui
out.Write("ocol1 = float4(prev) * (1.0/255.0);\n");
}
// ...and the alpha from ocol0 will be written to the framebuffer.
out.Write("ocol0.a = " I_ALPHA ".a*(1.0/255.0);\n");
out.Write("prev.a = " I_ALPHA ".a;\n");
if (uid_data.rgba6_format)
{
out.Write("\tprev.a = CAST_TO_U6(prev.a);\n");
}
}

out.Write("ocol0 = float4(prev) * (1.0/255.0);\n");

if (uid_data.bounding_box)
{
const char* atomic_op = ApiType == API_OPENGL ? "atomic" : "Interlocked";
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/VideoCommon/PixelShaderGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ struct pixel_shader_uid_data
u32 ssaa : 1;
u32 numColorChans : 2;
u32 late_ztest : 1;
u32 pad0 : 12;
u32 rgba6_format : 1;
u32 dither : 1;
u32 pad0 : 10;

u32 render_mode : 2;
u32 Pretest : 2;
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/VideoCommon/VideoConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void VideoConfig::Load(const std::string& ini_file)
enhancements->Get("TessellationMax", &iTessellationMax, 6);
enhancements->Get("TessellationRoundingIntensity", &iTessellationRoundingIntensity, 0);
enhancements->Get("TessellationDisplacementIntensity", &iTessellationDisplacementIntensity, 0);
enhancements->Get("ForceTrueColor", &bForceTrueColor, true);

IniFile::Section* stereoscopy = iniFile.GetOrCreateSection("Stereoscopy");
stereoscopy->Get("StereoMode", &iStereoMode, 0);
Expand Down Expand Up @@ -293,6 +294,7 @@ void VideoConfig::GameIniLoad()
CHECK_SETTING("Video_Enhancements", "PostProcessingTrigger", iPostProcessingTrigger);
CHECK_SETTING("Video_Enhancements", "PostProcessingShaders", sPostProcessingShaders);
CHECK_SETTING("Video_Enhancements", "ScalingShader", sScalingShader);
CHECK_SETTING("Video_Enhancements", "ForceTrueColor", bForceTrueColor);

CHECK_SETTING("Video_Stereoscopy", "StereoMode", iStereoMode);
CHECK_SETTING("Video_Stereoscopy", "StereoDepth", iStereoDepth);
Expand Down Expand Up @@ -481,6 +483,7 @@ void VideoConfig::Save(const std::string& ini_file)
enhancements->Set("TessellationMax", iTessellationMax);
enhancements->Set("TessellationRoundingIntensity", iTessellationRoundingIntensity);
enhancements->Set("TessellationDisplacementIntensity", iTessellationDisplacementIntensity);
enhancements->Set("ForceTrueColor", bForceTrueColor);

IniFile::Section* stereoscopy = iniFile.GetOrCreateSection("Stereoscopy");
stereoscopy->Set("StereoMode", iStereoMode);
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoCommon/VideoConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ struct VideoConfig final
int iTessellationMax;
int iTessellationRoundingIntensity;
int iTessellationDisplacementIntensity;
bool bForceTrueColor;

// Information
bool bShowFPS;
bool bShowNetPlayPing;
Expand Down

0 comments on commit 7ffb18a

Please sign in to comment.