summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/ShaderCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoCommon/ShaderCache.cpp')
-rw-r--r--Source/Core/VideoCommon/ShaderCache.cpp134
1 files changed, 2 insertions, 132 deletions
diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp
index a3d07368f6..e67a23a785 100644
--- a/Source/Core/VideoCommon/ShaderCache.cpp
+++ b/Source/Core/VideoCommon/ShaderCache.cpp
@@ -15,6 +15,7 @@
#include "VideoCommon/DriverDetails.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/FramebufferShaderGen.h"
+#include "VideoCommon/PipelineUtils.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexLoaderManager.h"
@@ -604,141 +605,10 @@ AbstractPipelineConfig ShaderCache::GetGXPipelineConfig(
return config;
}
-/// Edits the UID based on driver bugs and other special configurations
-static GXPipelineUid ApplyDriverBugs(const GXPipelineUid& in)
-{
- GXPipelineUid out;
- // TODO: static_assert(std::is_trivially_copyable_v<GXPipelineUid>);
- // GXPipelineUid is not trivially copyable because RasterizationState and BlendingState aren't
- // either, but we can pretend it is for now. This will be improved after PR #10848 is finished.
- memcpy(static_cast<void*>(&out), static_cast<const void*>(&in), sizeof(out)); // copy padding
- pixel_shader_uid_data* ps = out.ps_uid.GetUidData();
- BlendingState& blend = out.blending_state;
-
- if (ps->ztest == EmulatedZ::ForcedEarly && !out.depth_state.update_enable)
- {
- // No need to force early depth test if you're not writing z
- ps->ztest = EmulatedZ::Early;
- }
-
- // If framebuffer fetch is available, we can emulate logic ops in the fragment shader
- // and don't need the below blend approximation
- if (blend.logic_op_enable && !g_backend_info.bSupportsLogicOp &&
- !g_backend_info.bSupportsFramebufferFetch)
- {
- if (!blend.LogicOpApproximationIsExact())
- WARN_LOG_FMT(VIDEO,
- "Approximating logic op with blending, this will produce incorrect rendering.");
- if (blend.LogicOpApproximationWantsShaderHelp())
- {
- ps->emulate_logic_op_with_blend = true;
- ps->logic_op_mode = static_cast<u32>(blend.logic_mode.Value());
- }
- blend.ApproximateLogicOpWithBlending();
- }
-
- const bool benefits_from_ps_dual_source_off =
- (!g_backend_info.bSupportsDualSourceBlend && g_backend_info.bSupportsFramebufferFetch) ||
- DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DUAL_SOURCE_BLENDING);
- if (benefits_from_ps_dual_source_off && !blend.RequiresDualSrc())
- {
- // Only use dual-source blending when required on drivers that don't support it very well.
- ps->no_dual_src = true;
- blend.use_dual_src = false;
- }
-
- if (g_backend_info.bSupportsFramebufferFetch)
- {
- bool fbfetch_blend = false;
- if ((DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z) ||
- !g_backend_info.bSupportsEarlyZ) &&
- ps->ztest == EmulatedZ::ForcedEarly)
- {
- ps->ztest = EmulatedZ::EarlyWithFBFetch;
- fbfetch_blend |= static_cast<bool>(out.blending_state.blend_enable);
- ps->no_dual_src = true;
- }
- fbfetch_blend |= blend.logic_op_enable && !g_backend_info.bSupportsLogicOp;
- fbfetch_blend |= blend.use_dual_src && !g_backend_info.bSupportsDualSourceBlend;
- if (fbfetch_blend)
- {
- ps->no_dual_src = true;
- if (blend.logic_op_enable)
- {
- ps->logic_op_enable = true;
- ps->logic_op_mode = static_cast<u32>(blend.logic_mode.Value());
- blend.logic_op_enable = false;
- }
- if (blend.blend_enable)
- {
- ps->blend_enable = true;
- ps->blend_src_factor = blend.src_factor;
- ps->blend_src_factor_alpha = blend.src_factor_alpha;
- ps->blend_dst_factor = blend.dst_factor;
- ps->blend_dst_factor_alpha = blend.dst_factor_alpha;
- ps->blend_subtract = blend.subtract;
- ps->blend_subtract_alpha = blend.subtract_alpha;
- blend.blend_enable = false;
- }
- }
- }
-
- // force dual src off if we can't support it
- if (!g_backend_info.bSupportsDualSourceBlend)
- {
- ps->no_dual_src = true;
- blend.use_dual_src = false;
- }
-
- if (ps->ztest == EmulatedZ::ForcedEarly && !g_backend_info.bSupportsEarlyZ)
- {
- // These things should be false
- ASSERT(!ps->zfreeze);
- // ZCOMPLOC HACK:
- // The only way to emulate alpha test + early-z is to force early-z in the shader.
- // As this isn't available on all drivers and as we can't emulate this feature otherwise,
- // we are only able to choose which one we want to respect more.
- // Tests seem to have proven that writing depth even when the alpha test fails is more
- // important that a reliable alpha test, so we just force the alpha test to always succeed.
- // At least this seems to be less buggy.
- ps->ztest = EmulatedZ::EarlyWithZComplocHack;
- }
-
- if (g_ActiveConfig.UseVSForLinePointExpand() &&
- (out.rasterization_state.primitive == PrimitiveType::Points ||
- out.rasterization_state.primitive == PrimitiveType::Lines))
- {
- // All primitives are expanded to triangles in the vertex shader
- vertex_shader_uid_data* vs = out.vs_uid.GetUidData();
- const PortableVertexDeclaration& decl = out.vertex_format->GetVertexDeclaration();
- vs->position_has_3_elems = decl.position.components >= 3;
- vs->texcoord_elem_count = 0;
- for (int i = 0; i < 8; i++)
- {
- if (decl.texcoords[i].enable)
- {
- ASSERT(decl.texcoords[i].components <= 3);
- vs->texcoord_elem_count |= decl.texcoords[i].components << (i * 2);
- }
- }
- out.vertex_format = nullptr;
- if (out.rasterization_state.primitive == PrimitiveType::Points)
- vs->vs_expand = VSExpand::Point;
- else
- vs->vs_expand = VSExpand::Line;
- PrimitiveType prim = g_backend_info.bSupportsPrimitiveRestart ? PrimitiveType::TriangleStrip :
- PrimitiveType::Triangles;
- out.rasterization_state.primitive = prim;
- out.gs_uid.GetUidData()->primitive_type = static_cast<u32>(prim);
- }
-
- return out;
-}
-
std::optional<AbstractPipelineConfig>
ShaderCache::GetGXPipelineConfig(const GXPipelineUid& config_in)
{
- GXPipelineUid config = ApplyDriverBugs(config_in);
+ GXPipelineUid config = VideoCommon::ApplyDriverBugs(config_in);
const AbstractShader* vs;
auto vs_iter = m_vs_cache.shader_map.find(config.vs_uid);
if (vs_iter != m_vs_cache.shader_map.end() && !vs_iter->second.pending)