mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #4194 from Armada651/efb-source-format
PixelShaderGen: Add support for RGBA6 EFB format truncation.
This commit is contained in:
@ -169,6 +169,9 @@ 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 && !g_ActiveConfig.bForceTrueColor;
|
||||
uid_data->dither = bpmem.blendmode.dither && uid_data->rgba6_format;
|
||||
|
||||
u32 numStages = uid_data->genMode_numtevstages + 1;
|
||||
|
||||
@ -344,6 +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);
|
||||
|
||||
ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data)
|
||||
{
|
||||
@ -503,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)
|
||||
@ -574,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));
|
||||
@ -776,27 +772,20 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data*
|
||||
out.Write("\tdepth = float(zCoord) / 16777216.0;\n");
|
||||
}
|
||||
|
||||
if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS)
|
||||
// No dithering for RGB8 mode
|
||||
if (uid_data->dither)
|
||||
{
|
||||
out.SetConstantsUsed(C_ALPHA, C_ALPHA);
|
||||
out.Write("\tocol0 = float4(float3(prev.rgb), float(" I_ALPHA ".a)) / 255.0;\n");
|
||||
// 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");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (uid_data->dstAlphaMode != DSTALPHA_ALPHA_PASS)
|
||||
WriteFog(out, uid_data);
|
||||
out.Write("\tocol0 = float4(prev) / 255.0;\n");
|
||||
}
|
||||
|
||||
// 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 = float4(prev) / 255.0;\n");
|
||||
out.Write("\tocol0.a = float(" I_ALPHA ".a) / 255.0;\n");
|
||||
}
|
||||
// Write the color and alpha values to the framebuffer
|
||||
WriteColor(out, uid_data);
|
||||
|
||||
if (uid_data->bounding_box)
|
||||
{
|
||||
@ -1295,3 +1284,30 @@ 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)
|
||||
{
|
||||
if (uid_data->rgba6_format)
|
||||
out.Write("\tocol0.rgb = (prev.rgb >> 2) / 63.0;\n");
|
||||
else
|
||||
out.Write("\tocol0.rgb = prev.rgb / 255.0;\n");
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,9 @@ struct pixel_shader_uid_data
|
||||
u32 msaa : 1;
|
||||
u32 ssaa : 1;
|
||||
u32 numColorChans : 2;
|
||||
u32 pad : 14;
|
||||
u32 rgba6_format : 1;
|
||||
u32 dither : 1;
|
||||
u32 pad : 12;
|
||||
|
||||
u32 texMtxInfo_n_projection : 8; // 8x1 bit
|
||||
u32 tevindref_bi0 : 3;
|
||||
|
@ -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, true);
|
||||
|
||||
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);
|
||||
|
@ -79,6 +79,7 @@ struct VideoConfig final
|
||||
bool bForceFiltering;
|
||||
int iMaxAnisotropy;
|
||||
std::string sPostProcessingShader;
|
||||
bool bForceTrueColor;
|
||||
|
||||
// Information
|
||||
bool bShowFPS;
|
||||
|
Reference in New Issue
Block a user