From 99533d28405f9a9e06d20b8f49793423d73f9009 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Sat, 18 Jun 2022 20:03:28 -0500 Subject: [PATCH] VideoCommon: Add separate pipeline usage for UberShaders --- Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp | 3 ++- Source/Core/VideoBackends/D3D12/DX12Pipeline.cpp | 1 + Source/Core/VideoBackends/Metal/MTLObjectCache.mm | 14 ++++---------- Source/Core/VideoBackends/Metal/MTLStateTracker.mm | 2 +- Source/Core/VideoBackends/Vulkan/StateTracker.cpp | 2 +- Source/Core/VideoBackends/Vulkan/VKPipeline.cpp | 1 + Source/Core/VideoCommon/AbstractPipeline.h | 3 +++ Source/Core/VideoCommon/ShaderCache.cpp | 9 +++++---- Source/Core/VideoCommon/ShaderCache.h | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp b/Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp index b1cb3378ed..bfe44a3a58 100644 --- a/Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp +++ b/Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp @@ -572,7 +572,8 @@ bool Renderer::ApplyState() m_state.sampler_descriptor_base); } - if (static_cast(m_current_pipeline)->GetUsage() == AbstractPipelineUsage::GX) + if (static_cast(m_current_pipeline)->GetUsage() != + AbstractPipelineUsage::Utility) { if (dirty_bits & DirtyState_VS_CBV) { diff --git a/Source/Core/VideoBackends/D3D12/DX12Pipeline.cpp b/Source/Core/VideoBackends/D3D12/DX12Pipeline.cpp index 52b73e6911..bca820a2c3 100644 --- a/Source/Core/VideoBackends/D3D12/DX12Pipeline.cpp +++ b/Source/Core/VideoBackends/D3D12/DX12Pipeline.cpp @@ -165,6 +165,7 @@ std::unique_ptr DXPipeline::Create(const AbstractPipelineConfig& con switch (config.usage) { case AbstractPipelineUsage::GX: + case AbstractPipelineUsage::GXUber: desc.pRootSignature = g_dx_context->GetGXRootSignature(); break; case AbstractPipelineUsage::Utility: diff --git a/Source/Core/VideoBackends/Metal/MTLObjectCache.mm b/Source/Core/VideoBackends/Metal/MTLObjectCache.mm index 3181e1fdee..0110ebb769 100644 --- a/Source/Core/VideoBackends/Metal/MTLObjectCache.mm +++ b/Source/Core/VideoBackends/Metal/MTLObjectCache.mm @@ -377,18 +377,12 @@ public: auto desc = MRCTransfer([MTLRenderPipelineDescriptor new]); [desc setVertexFunction:static_cast(config.vertex_shader)->GetShader()]; [desc setFragmentFunction:static_cast(config.pixel_shader)->GetShader()]; - if (config.usage == AbstractPipelineUsage::GX) - { - if ([[[desc vertexFunction] label] containsString:@"Uber"]) - [desc - setLabel:[NSString stringWithFormat:@"GX Uber Pipeline %d", m_pipeline_counter[0]++]]; - else - [desc setLabel:[NSString stringWithFormat:@"GX Pipeline %d", m_pipeline_counter[1]++]]; - } + if (config.usage == AbstractPipelineUsage::GXUber) + [desc setLabel:[NSString stringWithFormat:@"GX Uber Pipeline %d", m_pipeline_counter[0]++]]; + else if (config.usage == AbstractPipelineUsage::GX) + [desc setLabel:[NSString stringWithFormat:@"GX Pipeline %d", m_pipeline_counter[1]++]]; else - { [desc setLabel:[NSString stringWithFormat:@"Utility Pipeline %d", m_pipeline_counter[2]++]]; - } if (config.vertex_format) [desc setVertexDescriptor:static_cast(config.vertex_format)->Get()]; RasterizationState rs = config.rasterization_state; diff --git a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm index 3ab6224f83..0004c81089 100644 --- a/Source/Core/VideoBackends/Metal/MTLStateTracker.mm +++ b/Source/Core/VideoBackends/Metal/MTLStateTracker.mm @@ -608,7 +608,7 @@ void Metal::StateTracker::PrepareRender() BeginRenderPass(MTLLoadActionLoad); id enc = m_current_render_encoder; const Pipeline* pipe = m_state.render_pipeline; - bool is_gx = pipe->Usage() == AbstractPipelineUsage::GX; + bool is_gx = pipe->Usage() != AbstractPipelineUsage::Utility; NSString* label = is_gx ? LABEL_GX : LABEL_UTIL; if (m_flags.should_apply_label && m_current.label != label) { diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp index db59b16398..f39139cb52 100644 --- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp +++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp @@ -452,7 +452,7 @@ void StateTracker::EndClearRenderPass() bool StateTracker::UpdateDescriptorSet() { - if (m_pipeline->GetUsage() == AbstractPipelineUsage::GX) + if (m_pipeline->GetUsage() != AbstractPipelineUsage::Utility) return UpdateGXDescriptorSet(); else return UpdateUtilityDescriptorSet(); diff --git a/Source/Core/VideoBackends/Vulkan/VKPipeline.cpp b/Source/Core/VideoBackends/Vulkan/VKPipeline.cpp index f21fb9bf5e..32bf931da0 100644 --- a/Source/Core/VideoBackends/Vulkan/VKPipeline.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKPipeline.cpp @@ -249,6 +249,7 @@ std::unique_ptr VKPipeline::Create(const AbstractPipelineConfig& con switch (config.usage) { case AbstractPipelineUsage::GX: + case AbstractPipelineUsage::GXUber: pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_STANDARD); break; case AbstractPipelineUsage::Utility: diff --git a/Source/Core/VideoCommon/AbstractPipeline.h b/Source/Core/VideoCommon/AbstractPipeline.h index 0be46eaf5a..60381d0cd9 100644 --- a/Source/Core/VideoCommon/AbstractPipeline.h +++ b/Source/Core/VideoCommon/AbstractPipeline.h @@ -20,6 +20,8 @@ class NativeVertexFormat; // - Per-stage UBO (VS/GS/PS, VS constants accessible from PS) // - 8 combined image samplers (accessible from PS) // - 1 SSBO, accessible from PS if bounding box is enabled +// - GX Uber +// - Same as GX, plus one VS SSBO for vertices if dynamic vertex loading is enabled // - Utility // - Single UBO, accessible from all stages [set=0, binding=1] // - 8 combined image samplers (accessible from PS) [set=1, binding=0-7] @@ -32,6 +34,7 @@ class NativeVertexFormat; enum class AbstractPipelineUsage { GX, + GXUber, Utility }; diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index e6cd328900..f281024f22 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -588,10 +588,10 @@ AbstractPipelineConfig ShaderCache::GetGXPipelineConfig( const NativeVertexFormat* vertex_format, const AbstractShader* vertex_shader, const AbstractShader* geometry_shader, const AbstractShader* pixel_shader, const RasterizationState& rasterization_state, const DepthState& depth_state, - const BlendingState& blending_state) + const BlendingState& blending_state, AbstractPipelineUsage usage) { AbstractPipelineConfig config = {}; - config.usage = AbstractPipelineUsage::GX; + config.usage = usage; config.vertex_format = vertex_format; config.vertex_shader = vertex_shader; config.geometry_shader = geometry_shader; @@ -735,7 +735,7 @@ ShaderCache::GetGXPipelineConfig(const GXPipelineUid& config_in) } return GetGXPipelineConfig(config.vertex_format, vs, gs, ps, config.rasterization_state, - config.depth_state, config.blending_state); + config.depth_state, config.blending_state, AbstractPipelineUsage::GX); } /// Edits the UID based on driver bugs and other special configurations @@ -800,7 +800,8 @@ ShaderCache::GetGXPipelineConfig(const GXUberPipelineUid& config_in) } return GetGXPipelineConfig(config.vertex_format, vs, gs, ps, config.rasterization_state, - config.depth_state, config.blending_state); + config.depth_state, config.blending_state, + AbstractPipelineUsage::GXUber); } const AbstractPipeline* ShaderCache::InsertGXPipeline(const GXPipelineUid& config, diff --git a/Source/Core/VideoCommon/ShaderCache.h b/Source/Core/VideoCommon/ShaderCache.h index ee59fe9ae7..2721cd7319 100644 --- a/Source/Core/VideoCommon/ShaderCache.h +++ b/Source/Core/VideoCommon/ShaderCache.h @@ -151,7 +151,7 @@ private: GetGXPipelineConfig(const NativeVertexFormat* vertex_format, const AbstractShader* vertex_shader, const AbstractShader* geometry_shader, const AbstractShader* pixel_shader, const RasterizationState& rasterization_state, const DepthState& depth_state, - const BlendingState& blending_state); + const BlendingState& blending_state, AbstractPipelineUsage usage); std::optional GetGXPipelineConfig(const GXPipelineUid& uid); std::optional GetGXPipelineConfig(const GXUberPipelineUid& uid); const AbstractPipeline* InsertGXPipeline(const GXPipelineUid& config,