VideoCommon: Make dst_alpha state implicit.

This commit is contained in:
degasus
2016-12-28 01:37:41 +01:00
parent b7d8bd13a6
commit 41b0c74e30
33 changed files with 79 additions and 149 deletions

View File

@ -156,13 +156,15 @@ static const char* tevAOutputTable[] = {"prev.a", "c0.a", "c1.a", "c2.a"};
// leak
// into this UID; This is really unhelpful if these UIDs ever move from one machine to
// another.
PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode)
PixelShaderUid GetPixelShaderUid()
{
PixelShaderUid out;
pixel_shader_uid_data* uid_data = out.GetUidData<pixel_shader_uid_data>();
memset(uid_data, 0, sizeof(*uid_data));
uid_data->dstAlphaMode = dstAlphaMode;
uid_data->useDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
uid_data->genMode_numindstages = bpmem.genMode.numindstages;
uid_data->genMode_numtevstages = bpmem.genMode.numtevstages;
uid_data->genMode_numtexgens = bpmem.genMode.numtexgens;
@ -327,13 +329,9 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode)
uid_data->ztex_op = bpmem.ztex2.op;
uid_data->early_ztest = bpmem.UseEarlyDepthTest();
uid_data->fog_fsel = bpmem.fog.c_proj_fsel.fsel;
if (dstAlphaMode != DSTALPHA_ALPHA_PASS)
{
uid_data->fog_fsel = bpmem.fog.c_proj_fsel.fsel;
uid_data->fog_proj = bpmem.fog.c_proj_fsel.proj;
uid_data->fog_RangeBaseEnabled = bpmem.fogRange.Base.Enabled;
}
uid_data->fog_fsel = bpmem.fog.c_proj_fsel.fsel;
uid_data->fog_proj = bpmem.fog.c_proj_fsel.proj;
uid_data->fog_RangeBaseEnabled = bpmem.fogRange.Base.Enabled;
return out;
}
@ -510,7 +508,7 @@ ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data*
const bool use_dual_source =
g_ActiveConfig.backend_info.bSupportsDualSourceBlend &&
(!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DUAL_SOURCE_BLENDING) ||
uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND);
uid_data->useDstAlpha);
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
{
@ -795,8 +793,7 @@ 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)
WriteFog(out, uid_data);
WriteFog(out, uid_data);
// Write the color and alpha values to the framebuffer
WriteColor(out, uid_data, use_dual_source);
@ -1308,7 +1305,7 @@ static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, b
// 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)
if (!uid_data->useDstAlpha)
{
out.Write("\tocol0.a = float(prev.a >> 2) / 63.0;\n");
if (use_dual_source)
@ -1322,7 +1319,7 @@ static void WriteColor(ShaderCode& out, const pixel_shader_uid_data* uid_data, b
// Use dual-source color blending to perform dst alpha in a single pass
if (use_dual_source)
{
if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
if (uid_data->useDstAlpha)
out.Write("\tocol1.a = float(prev.a) / 255.0;\n");
else
out.Write("\tocol1.a = float(" I_ALPHA ".a) / 255.0;\n");

View File

@ -10,14 +10,6 @@
enum class APIType;
// Different ways to achieve rendering with destination alpha
enum DSTALPHA_MODE
{
DSTALPHA_NONE, // Render normally, without destination alpha
DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha
DSTALPHA_DUAL_SOURCE_BLEND // Use dual-source blending
};
#pragma pack(1)
struct pixel_shader_uid_data
{
@ -26,7 +18,8 @@ struct pixel_shader_uid_data
u32 num_values; // TODO: Shouldn't be a u32
u32 NumValues() const { return num_values; }
u32 components : 2;
u32 dstAlphaMode : 2;
u32 pad0 : 1;
u32 useDstAlpha : 1;
u32 Pretest : 2;
u32 nIndirectStagesUsed : 4;
u32 stereo : 1;
@ -170,4 +163,4 @@ struct pixel_shader_uid_data
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data);
PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode);
PixelShaderUid GetPixelShaderUid();

View File

@ -74,7 +74,7 @@ public:
virtual void SetViewport() {}
virtual void SetFullscreen(bool enable_fullscreen) {}
virtual bool IsFullscreen() const { return false; }
virtual void ApplyState(bool bUseDstAlpha) {}
virtual void ApplyState() {}
virtual void RestoreState() {}
virtual void ResetAPIState() {}
virtual void RestoreAPIState() {}

View File

@ -253,12 +253,9 @@ void VertexManagerBase::Flush()
GeometryShaderManager::SetConstants();
PixelShaderManager::SetConstants();
bool useDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate &&
bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
if (PerfQueryBase::ShouldEmulate())
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
g_vertex_manager->vFlush(useDstAlpha);
g_vertex_manager->vFlush();
if (PerfQueryBase::ShouldEmulate())
g_perf_query->DisableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);
}

View File

@ -82,7 +82,7 @@ protected:
private:
bool m_is_flushed = true;
virtual void vFlush(bool useDstAlpha) = 0;
virtual void vFlush() = 0;
virtual void CreateDeviceObjects() {}
virtual void DestroyDeviceObjects() {}