From b958457e514e5d95227fb4cb0724791c4c572982 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 7 Sep 2016 17:19:26 +0200 Subject: [PATCH 1/9] PixelShaderGen: Add support for RGBA6 EFB format truncation. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 24 ++++++++++++++++++---- Source/Core/VideoCommon/PixelShaderGen.h | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index ce63752b86..45ac231544 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -169,6 +169,7 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode) uid_data->per_pixel_lighting = g_ActiveConfig.bEnablePixelLighting; uid_data->bounding_box = g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable && BoundingBox::active; + uid_data->rgba6_format = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; u32 numStages = uid_data->genMode_numtevstages + 1; @@ -344,6 +345,8 @@ static void SampleTexture(ShaderCode& out, const char* texcoords, const char* te static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType, bool per_pixel_depth); static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data); +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* type, + const char* color); ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data) { @@ -779,12 +782,14 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS) { out.SetConstantsUsed(C_ALPHA, C_ALPHA); - out.Write("\tocol0 = float4(float3(prev.rgb), float(" I_ALPHA ".a)) / 255.0;\n"); + out.Write("\tocol0 = "); + WriteColor(out, uid_data, "float4", "prev.rgb, " I_ALPHA ".a"); } else { WriteFog(out, uid_data); - out.Write("\tocol0 = float4(prev) / 255.0;\n"); + out.Write("\tocol0 = "); + WriteColor(out, uid_data, "float4", "prev"); } // Use dual-source color blending to perform dst alpha in a single pass @@ -794,8 +799,10 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* // Colors will be blended against the alpha from ocol1 and // the alpha from ocol0 will be written to the framebuffer. - out.Write("\tocol1 = float4(prev) / 255.0;\n"); - out.Write("\tocol0.a = float(" I_ALPHA ".a) / 255.0;\n"); + out.Write("\tocol1 = "); + WriteColor(out, uid_data, "float4", "prev"); + out.Write("\tocol0.a = "); + WriteColor(out, uid_data, "float", I_ALPHA ".a"); } if (uid_data->bounding_box) @@ -1295,3 +1302,12 @@ static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data) out.Write("\tint ifog = iround(fog * 256.0);\n"); out.Write("\tprev.rgb = (prev.rgb * (256 - ifog) + " I_FOGCOLOR ".rgb * ifog) >> 8;\n"); } + +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* type, + const char* color) +{ + if (uid_data->rgba6_format) + out.Write("%s(%s >> 2) / 63.0;\n", type, color); + else + out.Write("%s(%s) / 255.0;\n", type, color); +} diff --git a/Source/Core/VideoCommon/PixelShaderGen.h b/Source/Core/VideoCommon/PixelShaderGen.h index 46fdcc36aa..86806cf877 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.h +++ b/Source/Core/VideoCommon/PixelShaderGen.h @@ -53,7 +53,8 @@ struct pixel_shader_uid_data u32 msaa : 1; u32 ssaa : 1; u32 numColorChans : 2; - u32 pad : 14; + u32 rgba6_format : 1; + u32 pad : 13; u32 texMtxInfo_n_projection : 8; // 8x1 bit u32 tevindref_bi0 : 3; From 9bc466a4439e9a95655b9036072c2d7237286111 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 8 Sep 2016 01:34:18 +0200 Subject: [PATCH 2/9] PixelShaderGen: Add support for dithering. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 7 +++++++ Source/Core/VideoCommon/PixelShaderGen.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 45ac231544..a0ef76546d 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -170,6 +170,7 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode) uid_data->bounding_box = g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable && BoundingBox::active; uid_data->rgba6_format = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; + uid_data->dither = bpmem.blendmode.dither; u32 numStages = uid_data->genMode_numtevstages + 1; @@ -779,6 +780,12 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); } + if (uid_data->dither && uid_data->rgba6_format) + { + out.Write("\tint2 dither = int2(rawpos.xy) & 1;\n"); + out.Write("\tprev.rgb = (prev.rgb - (prev.rgb >> 6)) + abs(dither.y * 3 - dither.x * 2);\n"); + } + if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS) { out.SetConstantsUsed(C_ALPHA, C_ALPHA); diff --git a/Source/Core/VideoCommon/PixelShaderGen.h b/Source/Core/VideoCommon/PixelShaderGen.h index 86806cf877..d141fd57f8 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.h +++ b/Source/Core/VideoCommon/PixelShaderGen.h @@ -54,7 +54,8 @@ struct pixel_shader_uid_data u32 ssaa : 1; u32 numColorChans : 2; u32 rgba6_format : 1; - u32 pad : 13; + u32 dither : 1; + u32 pad : 12; u32 texMtxInfo_n_projection : 8; // 8x1 bit u32 tevindref_bi0 : 3; From 31a4ee7bfce6c593e96f27a56574a320162bfb9c Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 8 Sep 2016 02:43:05 +0200 Subject: [PATCH 3/9] PixelShaderGen: Always truncate the alpha channel to 6-bit. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 41 +++++++++++++++------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index a0ef76546d..a6c74f49cd 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -346,8 +346,8 @@ static void SampleTexture(ShaderCode& out, const char* texcoords, const char* te static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType, bool per_pixel_depth); static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data); -static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* type, - const char* color); +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* color); +static void WriteAlpha(ShaderCode& out, const char* alpha); ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data) { @@ -780,8 +780,11 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* out.Write("\tdepth = float(zCoord) / 16777216.0;\n"); } + // No dithering for RGB8 mode if (uid_data->dither && uid_data->rgba6_format) { + // Flipper uses a standard 2x2 Bayer Matrix for 6 bit dithering + // Here the matrix is encoded into the two factor constants out.Write("\tint2 dither = int2(rawpos.xy) & 1;\n"); out.Write("\tprev.rgb = (prev.rgb - (prev.rgb >> 6)) + abs(dither.y * 3 - dither.x * 2);\n"); } @@ -789,14 +792,18 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS) { out.SetConstantsUsed(C_ALPHA, C_ALPHA); - out.Write("\tocol0 = "); - WriteColor(out, uid_data, "float4", "prev.rgb, " I_ALPHA ".a"); + out.Write("\tocol0.rgb = "); + WriteColor(out, uid_data, "prev.rgb"); + out.Write("\tocol0.a = "); + WriteAlpha(out, I_ALPHA ".a"); } else { WriteFog(out, uid_data); - out.Write("\tocol0 = "); - WriteColor(out, uid_data, "float4", "prev"); + out.Write("\tocol0.rgb = "); + WriteColor(out, uid_data, "prev.rgb"); + out.Write("\tocol0.a = "); + WriteAlpha(out, "prev.a"); } // Use dual-source color blending to perform dst alpha in a single pass @@ -806,10 +813,12 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* // Colors will be blended against the alpha from ocol1 and // the alpha from ocol0 will be written to the framebuffer. - out.Write("\tocol1 = "); - WriteColor(out, uid_data, "float4", "prev"); + out.Write("\tocol1.rgb = "); + WriteColor(out, uid_data, "prev.rgb"); + out.Write("\tocol1.a = "); + WriteAlpha(out, "prev.a"); out.Write("\tocol0.a = "); - WriteColor(out, uid_data, "float", I_ALPHA ".a"); + WriteAlpha(out, I_ALPHA ".a"); } if (uid_data->bounding_box) @@ -1310,11 +1319,17 @@ static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data) out.Write("\tprev.rgb = (prev.rgb * (256 - ifog) + " I_FOGCOLOR ".rgb * ifog) >> 8;\n"); } -static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* type, - const char* color) +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* color) { if (uid_data->rgba6_format) - out.Write("%s(%s >> 2) / 63.0;\n", type, color); + out.Write("float3(%s >> 2) / 63.0;\n", color); else - out.Write("%s(%s) / 255.0;\n", type, color); + out.Write("float3(%s) / 255.0;\n", color); +} + +static void WriteAlpha(ShaderCode& out, const char* color) +{ + // Always truncate the alpha to 6-bit, as there is no format available + // on flipper that supports 8-bit. + out.Write("float(%s >> 2) / 63.0;\n", color); } From 365e88e311409cd74a0f1f6158081e72816a1a5f Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 8 Sep 2016 02:43:34 +0200 Subject: [PATCH 4/9] VideoConfig: Add an option to force RGB8 EFB format. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 6 ++++++ Source/Core/VideoCommon/PixelShaderGen.cpp | 3 ++- Source/Core/VideoCommon/VideoConfig.cpp | 3 +++ Source/Core/VideoCommon/VideoConfig.h | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index b494659ca7..834651be40 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -275,6 +275,10 @@ static wxString validation_layer_desc = static wxString backend_multithreading_desc = wxTRANSLATE("Enables multi-threading in the video backend, which may result in performance " "gains in some scenarios.\n\nIf unsure, leave this unchecked."); +static wxString true_color_desc = + wxTRANSLATE("Forces the game to render the RGB color channels in 24-bit, thereby increasing " + "quality by reducing color banding.\nIt has no impact on performance and causes " + "few graphical issues.\n\n\nIf unsure, leave this unchecked."); #if !defined(__APPLE__) // Search for available resolutions - TODO: Move to Common? @@ -618,6 +622,8 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title) vconfig.bWidescreenHack)); cb_szr->Add(CreateCheckBox(page_enh, _("Disable Fog"), wxGetTranslation(disable_fog_desc), vconfig.bDisableFog)); + cb_szr->Add(CreateCheckBox(page_enh, _("Force True Color"), wxGetTranslation(true_color_desc), + vconfig.bForceTrueColor)); szr_enh->Add(cb_szr, wxGBPosition(row, 0), wxGBSpan(1, 3)); row += 1; diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index a6c74f49cd..2996ac46ed 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -169,7 +169,8 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode) uid_data->per_pixel_lighting = g_ActiveConfig.bEnablePixelLighting; uid_data->bounding_box = g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable && BoundingBox::active; - uid_data->rgba6_format = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; + uid_data->rgba6_format = + bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24 && !g_ActiveConfig.bForceTrueColor; uid_data->dither = bpmem.blendmode.dither; u32 numStages = uid_data->genMode_numtevstages + 1; diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 73e6eafa12..6106e3ea81 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -103,6 +103,7 @@ void VideoConfig::Load(const std::string& ini_file) enhancements->Get("ForceFiltering", &bForceFiltering, 0); enhancements->Get("MaxAnisotropy", &iMaxAnisotropy, 0); // NOTE - this is x in (1 << x) enhancements->Get("PostProcessingShader", &sPostProcessingShader, ""); + enhancements->Get("ForceTrueColor", &bForceTrueColor, false); IniFile::Section* stereoscopy = iniFile.GetOrCreateSection("Stereoscopy"); stereoscopy->Get("StereoMode", &iStereoMode, 0); @@ -167,6 +168,7 @@ void VideoConfig::GameIniLoad() CHECK_SETTING("Video_Settings", "FastDepthCalc", bFastDepthCalc); CHECK_SETTING("Video_Settings", "MSAA", iMultisamples); CHECK_SETTING("Video_Settings", "SSAA", bSSAA); + CHECK_SETTING("Video_Settings", "ForceTrueColor", bForceTrueColor); int tmp = -9000; CHECK_SETTING("Video_Settings", "EFBScale", tmp); // integral @@ -317,6 +319,7 @@ void VideoConfig::Save(const std::string& ini_file) enhancements->Set("ForceFiltering", bForceFiltering); enhancements->Set("MaxAnisotropy", iMaxAnisotropy); enhancements->Set("PostProcessingShader", sPostProcessingShader); + enhancements->Set("ForceTrueColor", bForceTrueColor); IniFile::Section* stereoscopy = iniFile.GetOrCreateSection("Stereoscopy"); stereoscopy->Set("StereoMode", iStereoMode); diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index a08024b849..b866ce6343 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -79,6 +79,7 @@ struct VideoConfig final bool bForceFiltering; int iMaxAnisotropy; std::string sPostProcessingShader; + bool bForceTrueColor; // Information bool bShowFPS; From e8cddae132c32dcd74ab2744b8252b7bf30d625f Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 21 Sep 2016 11:35:55 +0200 Subject: [PATCH 5/9] VideoConfig: Turn on ForceTrueColor by default. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 2 +- Source/Core/VideoCommon/VideoConfig.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 834651be40..862b273246 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -278,7 +278,7 @@ static wxString backend_multithreading_desc = static wxString true_color_desc = wxTRANSLATE("Forces the game to render the RGB color channels in 24-bit, thereby increasing " "quality by reducing color banding.\nIt has no impact on performance and causes " - "few graphical issues.\n\n\nIf unsure, leave this unchecked."); + "few graphical issues.\n\n\nIf unsure, leave this checked."); #if !defined(__APPLE__) // Search for available resolutions - TODO: Move to Common? diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index 6106e3ea81..0e79b4b180 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -103,7 +103,7 @@ void VideoConfig::Load(const std::string& ini_file) enhancements->Get("ForceFiltering", &bForceFiltering, 0); enhancements->Get("MaxAnisotropy", &iMaxAnisotropy, 0); // NOTE - this is x in (1 << x) enhancements->Get("PostProcessingShader", &sPostProcessingShader, ""); - enhancements->Get("ForceTrueColor", &bForceTrueColor, false); + enhancements->Get("ForceTrueColor", &bForceTrueColor, true); IniFile::Section* stereoscopy = iniFile.GetOrCreateSection("Stereoscopy"); stereoscopy->Get("StereoMode", &iStereoMode, 0); From 23d9d91411e0c85d1c46c25bf8f94b4139ea7c5e Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Thu, 22 Sep 2016 18:46:43 +0200 Subject: [PATCH 6/9] VideoConfigDiag: True color means 24-bit, not hw color. --- Source/Core/DolphinWX/VideoConfigDiag.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index 862b273246..0fcb6a70f5 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -622,7 +622,7 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title) vconfig.bWidescreenHack)); cb_szr->Add(CreateCheckBox(page_enh, _("Disable Fog"), wxGetTranslation(disable_fog_desc), vconfig.bDisableFog)); - cb_szr->Add(CreateCheckBox(page_enh, _("Force True Color"), wxGetTranslation(true_color_desc), + cb_szr->Add(CreateCheckBox(page_enh, _("Force 24-bit Color"), wxGetTranslation(true_color_desc), vconfig.bForceTrueColor)); szr_enh->Add(cb_szr, wxGBPosition(row, 0), wxGBSpan(1, 3)); row += 1; From d61ae5a88a9d57272f05edcc716dd2d25b6fd11d Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 30 Sep 2016 23:11:12 +0200 Subject: [PATCH 7/9] PixelShaderGen: Only set dither uid bit if actually used. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 2996ac46ed..b3470a130b 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -171,7 +171,7 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode) g_ActiveConfig.bBBoxEnable && BoundingBox::active; uid_data->rgba6_format = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24 && !g_ActiveConfig.bForceTrueColor; - uid_data->dither = bpmem.blendmode.dither; + uid_data->dither = bpmem.blendmode.dither && uid_data->rgba6_format; u32 numStages = uid_data->genMode_numtevstages + 1; @@ -782,7 +782,7 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* } // No dithering for RGB8 mode - if (uid_data->dither && uid_data->rgba6_format) + if (uid_data->dither) { // Flipper uses a standard 2x2 Bayer Matrix for 6 bit dithering // Here the matrix is encoded into the two factor constants From 93109df65409dd9ba4fe21e9f0753204904aa913 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 10 Oct 2016 15:34:55 +0200 Subject: [PATCH 8/9] PixelShaderGen: Use dual source blending to do 8-bit blending. --- Source/Core/VideoCommon/PixelShaderGen.cpp | 91 ++++++++-------------- 1 file changed, 34 insertions(+), 57 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index b3470a130b..f3a91433c6 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -347,8 +347,7 @@ static void SampleTexture(ShaderCode& out, const char* texcoords, const char* te static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType, bool per_pixel_depth); static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data); -static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* color); -static void WriteAlpha(ShaderCode& out, const char* alpha); +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data); ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data) { @@ -508,22 +507,15 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan) { - if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) + if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_FRAGMENT_SHADER_INDEX_DECORATION)) { - if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_FRAGMENT_SHADER_INDEX_DECORATION)) - { - out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;\n"); - out.Write("FRAGMENT_OUTPUT_LOCATION(1) out vec4 ocol1;\n"); - } - else - { - out.Write("FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 0) out vec4 ocol0;\n"); - out.Write("FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 1) out vec4 ocol1;\n"); - } + out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;\n"); + out.Write("FRAGMENT_OUTPUT_LOCATION(1) out vec4 ocol1;\n"); } else { - out.Write("FRAGMENT_OUTPUT_LOCATION(0) out vec4 ocol0;\n"); + out.Write("FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 0) out vec4 ocol0;\n"); + out.Write("FRAGMENT_OUTPUT_LOCATION_INDEXED(0, 1) out vec4 ocol1;\n"); } if (uid_data->per_pixel_depth) @@ -579,11 +571,10 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* else // D3D { out.Write("void main(\n"); - out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n", - uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? - "\n out float4 ocol1 : SV_Target1," : - "", - uid_data->per_pixel_depth ? "\n out float depth : SV_Depth," : ""); + out.Write(" out float4 ocol0 : SV_Target0,\n" + " out float4 ocol1 : SV_Target1,\n%s" + " in float4 rawpos : SV_Position,\n", + uid_data->per_pixel_depth ? " out float depth : SV_Depth,\n" : ""); out.Write(" in %s float4 colors_0 : COLOR0,\n", GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); @@ -790,37 +781,11 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* out.Write("\tprev.rgb = (prev.rgb - (prev.rgb >> 6)) + abs(dither.y * 3 - dither.x * 2);\n"); } - if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS) - { - out.SetConstantsUsed(C_ALPHA, C_ALPHA); - out.Write("\tocol0.rgb = "); - WriteColor(out, uid_data, "prev.rgb"); - out.Write("\tocol0.a = "); - WriteAlpha(out, I_ALPHA ".a"); - } - else - { + if (uid_data->dstAlphaMode != DSTALPHA_ALPHA_PASS) WriteFog(out, uid_data); - out.Write("\tocol0.rgb = "); - WriteColor(out, uid_data, "prev.rgb"); - out.Write("\tocol0.a = "); - WriteAlpha(out, "prev.a"); - } - // Use dual-source color blending to perform dst alpha in a single pass - if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) - { - out.SetConstantsUsed(C_ALPHA, C_ALPHA); - - // Colors will be blended against the alpha from ocol1 and - // the alpha from ocol0 will be written to the framebuffer. - out.Write("\tocol1.rgb = "); - WriteColor(out, uid_data, "prev.rgb"); - out.Write("\tocol1.a = "); - WriteAlpha(out, "prev.a"); - out.Write("\tocol0.a = "); - WriteAlpha(out, I_ALPHA ".a"); - } + // Write the color and alpha values to the framebuffer + WriteColor(out, uid_data); if (uid_data->bounding_box) { @@ -1320,17 +1285,29 @@ static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data) out.Write("\tprev.rgb = (prev.rgb * (256 - ifog) + " I_FOGCOLOR ".rgb * ifog) >> 8;\n"); } -static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, const char* color) +static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data) { if (uid_data->rgba6_format) - out.Write("float3(%s >> 2) / 63.0;\n", color); + out.Write("\tocol0.rgb = (prev.rgb >> 2) / 63.0;\n"); else - out.Write("float3(%s) / 255.0;\n", color); -} + out.Write("\tocol0.rgb = prev.rgb / 255.0;\n"); -static void WriteAlpha(ShaderCode& out, const char* color) -{ - // Always truncate the alpha to 6-bit, as there is no format available - // on flipper that supports 8-bit. - out.Write("float(%s >> 2) / 63.0;\n", color); + // Colors will be blended against the 8-bit alpha from ocol1 and + // the 6-bit alpha from ocol0 will be written to the framebuffer + if (uid_data->dstAlphaMode == DSTALPHA_NONE) + { + out.Write("\tocol0.a = (prev.a >> 2) / 63.0;\n"); + out.Write("\tocol1.a = prev.a / 255.0;\n"); + } + else + { + out.SetConstantsUsed(C_ALPHA, C_ALPHA); + out.Write("\tocol0.a = (" I_ALPHA ".a >> 2) / 63.0;\n"); + + // Use dual-source color blending to perform dst alpha in a single pass + if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) + out.Write("\tocol1.a = prev.a / 255.0;\n"); + else + out.Write("\tocol1.a = " I_ALPHA ".a / 255.0;\n"); + } } From ab5054c34e8fc528fc5808d7f8254a6cdd89a376 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Mon, 10 Oct 2016 17:19:00 +0200 Subject: [PATCH 9/9] VideoBackends: Always enable dual-source blending if supported. --- Source/Core/VideoBackends/D3D/D3DState.cpp | 16 ++-------------- Source/Core/VideoBackends/D3D/Render.cpp | 8 ++++---- Source/Core/VideoBackends/D3D12/D3DState.cpp | 12 ------------ Source/Core/VideoBackends/D3D12/Render.cpp | 8 ++++---- Source/Core/VideoBackends/OGL/Render.cpp | 8 ++++---- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 12 ++++++------ 6 files changed, 20 insertions(+), 44 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/D3DState.cpp b/Source/Core/VideoBackends/D3D/D3DState.cpp index e82f103586..09d8dec3e2 100644 --- a/Source/Core/VideoBackends/D3D/D3DState.cpp +++ b/Source/Core/VideoBackends/D3D/D3DState.cpp @@ -380,7 +380,7 @@ ID3D11BlendState* StateCache::Get(BlendState state) blenddc.RenderTarget[0].BlendOpAlpha = state.blend_op; if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_SRC_COLOR) - blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; + blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC1_ALPHA; else if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_INV_SRC_COLOR) blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; else if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_DEST_COLOR) @@ -391,7 +391,7 @@ ID3D11BlendState* StateCache::Get(BlendState state) blenddc.RenderTarget[0].SrcBlendAlpha = blenddc.RenderTarget[0].SrcBlend; if (blenddc.RenderTarget[0].DestBlend == D3D11_BLEND_SRC_COLOR) - blenddc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC_ALPHA; + blenddc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC1_ALPHA; else if (blenddc.RenderTarget[0].DestBlend == D3D11_BLEND_INV_SRC_COLOR) blenddc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; else if (blenddc.RenderTarget[0].DestBlend == D3D11_BLEND_DEST_COLOR) @@ -403,18 +403,6 @@ ID3D11BlendState* StateCache::Get(BlendState state) if (state.use_dst_alpha) { - // Colors should blend against SRC1_ALPHA - if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_SRC_ALPHA) - blenddc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_ALPHA; - else if (blenddc.RenderTarget[0].SrcBlend == D3D11_BLEND_INV_SRC_ALPHA) - blenddc.RenderTarget[0].SrcBlend = D3D11_BLEND_INV_SRC1_ALPHA; - - // Colors should blend against SRC1_ALPHA - if (blenddc.RenderTarget[0].DestBlend == D3D11_BLEND_SRC_ALPHA) - blenddc.RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_ALPHA; - else if (blenddc.RenderTarget[0].DestBlend == D3D11_BLEND_INV_SRC_ALPHA) - blenddc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC1_ALPHA; - blenddc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blenddc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blenddc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 9452d03f86..d98ff2eb4f 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -675,8 +675,8 @@ void Renderer::SetBlendMode(bool forceUpdate) D3D11_BLEND_ONE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_INV_DEST_COLOR, - D3D11_BLEND_SRC_ALPHA, - D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled! + D3D11_BLEND_SRC1_ALPHA, + D3D11_BLEND_INV_SRC1_ALPHA, (target_has_alpha) ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_ONE, (target_has_alpha) ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_ZERO}; const D3D11_BLEND d3dDestFactors[8] = { @@ -684,8 +684,8 @@ void Renderer::SetBlendMode(bool forceUpdate) D3D11_BLEND_ONE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_INV_SRC_COLOR, - D3D11_BLEND_SRC_ALPHA, - D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled! + D3D11_BLEND_SRC1_ALPHA, + D3D11_BLEND_INV_SRC1_ALPHA, (target_has_alpha) ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_ONE, (target_has_alpha) ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_ZERO}; diff --git a/Source/Core/VideoBackends/D3D12/D3DState.cpp b/Source/Core/VideoBackends/D3D12/D3DState.cpp index 36e997d895..6d87c974ea 100644 --- a/Source/Core/VideoBackends/D3D12/D3DState.cpp +++ b/Source/Core/VideoBackends/D3D12/D3DState.cpp @@ -301,18 +301,6 @@ D3D12_BLEND_DESC StateCache::GetDesc12(BlendState state) if (state.use_dst_alpha) { - // Colors should blend against SRC1_ALPHA - if (blenddc.RenderTarget[0].SrcBlend == D3D12_BLEND_SRC_ALPHA) - blenddc.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC1_ALPHA; - else if (blenddc.RenderTarget[0].SrcBlend == D3D12_BLEND_INV_SRC_ALPHA) - blenddc.RenderTarget[0].SrcBlend = D3D12_BLEND_INV_SRC1_ALPHA; - - // Colors should blend against SRC1_ALPHA - if (blenddc.RenderTarget[0].DestBlend == D3D12_BLEND_SRC_ALPHA) - blenddc.RenderTarget[0].DestBlend = D3D12_BLEND_SRC1_ALPHA; - else if (blenddc.RenderTarget[0].DestBlend == D3D12_BLEND_INV_SRC_ALPHA) - blenddc.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC1_ALPHA; - blenddc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE; blenddc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_ZERO; blenddc.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD; diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index 7e94638321..fad23685e9 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -592,8 +592,8 @@ void Renderer::SetBlendMode(bool force_update) D3D12_BLEND_ONE, D3D12_BLEND_DEST_COLOR, D3D12_BLEND_INV_DEST_COLOR, - D3D12_BLEND_SRC_ALPHA, - D3D12_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled! + D3D12_BLEND_SRC1_ALPHA, + D3D12_BLEND_INV_SRC1_ALPHA, (target_has_alpha) ? D3D12_BLEND_DEST_ALPHA : D3D12_BLEND_ONE, (target_has_alpha) ? D3D12_BLEND_INV_DEST_ALPHA : D3D12_BLEND_ZERO}; const D3D12_BLEND d3d_dst_factors[8] = { @@ -601,8 +601,8 @@ void Renderer::SetBlendMode(bool force_update) D3D12_BLEND_ONE, D3D12_BLEND_SRC_COLOR, D3D12_BLEND_INV_SRC_COLOR, - D3D12_BLEND_SRC_ALPHA, - D3D12_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled! + D3D12_BLEND_SRC1_ALPHA, + D3D12_BLEND_INV_SRC1_ALPHA, (target_has_alpha) ? D3D12_BLEND_DEST_ALPHA : D3D12_BLEND_ONE, (target_has_alpha) ? D3D12_BLEND_INV_DEST_ALPHA : D3D12_BLEND_ZERO}; diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 047ac0f69e..2c30f4f62c 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1241,7 +1241,7 @@ void Renderer::SetBlendMode(bool forceUpdate) bool target_has_alpha = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; bool useDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && target_has_alpha; - bool useDualSource = useDstAlpha && g_ActiveConfig.backend_info.bSupportsDualSourceBlend; + bool useDualSource = g_ActiveConfig.backend_info.bSupportsDualSourceBlend; const GLenum glSrcFactors[8] = { GL_ZERO, @@ -1269,7 +1269,7 @@ void Renderer::SetBlendMode(bool forceUpdate) // 3-5 - srcRGB function // 6-8 - dstRGB function - u32 newval = useDualSource << 1; + u32 newval = useDstAlpha << 1; newval |= bpmem.blendmode.subtract << 2; if (bpmem.blendmode.subtract) @@ -1295,7 +1295,7 @@ void Renderer::SetBlendMode(bool forceUpdate) { // subtract enable change GLenum equation = newval & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD; - GLenum equationAlpha = useDualSource ? GL_FUNC_ADD : equation; + GLenum equationAlpha = useDstAlpha ? GL_FUNC_ADD : equation; glBlendEquationSeparate(equation, equationAlpha); } @@ -1308,7 +1308,7 @@ void Renderer::SetBlendMode(bool forceUpdate) GLenum dstFactor = glDestFactors[dstidx]; // adjust alpha factors - if (useDualSource) + if (useDstAlpha) { srcidx = BlendMode::ONE; dstidx = BlendMode::ZERO; diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index 7192f93169..aacf3c3c03 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -1107,8 +1107,8 @@ void Renderer::SetBlendMode(bool force_update) // Our render target always uses an alpha channel, so we need to override the blend functions to // assume a destination alpha of 1 if the render target isn't supposed to have an alpha channel. bool target_has_alpha = bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; - bool use_dst_alpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && target_has_alpha && - g_vulkan_context->SupportsDualSourceBlend(); + bool use_dst_alpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && target_has_alpha; + bool use_dual_src = g_vulkan_context->SupportsDualSourceBlend(); new_blend_state.blend_enable = VK_TRUE; new_blend_state.blend_op = VK_BLEND_OP_ADD; @@ -1129,11 +1129,11 @@ void Renderer::SetBlendMode(bool force_update) break; case BlendMode::SRCALPHA: new_blend_state.src_blend = - use_dst_alpha ? VK_BLEND_FACTOR_SRC1_ALPHA : VK_BLEND_FACTOR_SRC_ALPHA; + use_dual_src ? VK_BLEND_FACTOR_SRC1_ALPHA : VK_BLEND_FACTOR_SRC_ALPHA; break; case BlendMode::INVSRCALPHA: new_blend_state.src_blend = - use_dst_alpha ? VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA : VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + use_dual_src ? VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA : VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; break; case BlendMode::DSTALPHA: new_blend_state.src_blend = target_has_alpha ? VK_BLEND_FACTOR_DST_ALPHA : VK_BLEND_FACTOR_ONE; @@ -1163,11 +1163,11 @@ void Renderer::SetBlendMode(bool force_update) break; case BlendMode::SRCALPHA: new_blend_state.dst_blend = - use_dst_alpha ? VK_BLEND_FACTOR_SRC1_ALPHA : VK_BLEND_FACTOR_SRC_ALPHA; + use_dual_src ? VK_BLEND_FACTOR_SRC1_ALPHA : VK_BLEND_FACTOR_SRC_ALPHA; break; case BlendMode::INVSRCALPHA: new_blend_state.dst_blend = - use_dst_alpha ? VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA : VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + use_dual_src ? VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA : VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; break; case BlendMode::DSTALPHA: new_blend_state.dst_blend = target_has_alpha ? VK_BLEND_FACTOR_DST_ALPHA : VK_BLEND_FACTOR_ONE;