From 6d1ba5870ac3731ba7c556df9d14ddec66989fc8 Mon Sep 17 00:00:00 2001 From: nmzik Date: Sun, 13 Sep 2026 07:10:36 +0400 Subject: [PATCH] renderer: share graphics resource preparation across shader stages --- .../renderer/pipeline/descriptors.cpp | 31 ++++++------------- src/graphics/host_gpu/renderer/render.h | 4 +-- src/graphics/host_gpu/renderer/renderDraw.cpp | 18 +++++------ 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp b/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp index d93250ca3..26525ca19 100644 --- a/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp +++ b/src/graphics/host_gpu/renderer/pipeline/descriptors.cpp @@ -857,32 +857,21 @@ void RenderExecutor::RebindImages(PreparedBindings& prepared) { } } -RenderExecutor::GraphicsBindings -RenderExecutor::PrepareGraphicsBindings(const ShaderStageRuntime& vertex, - const ShaderStageRuntime& pixel, bool pixel_active) { - GraphicsBindings bindings { - .vertex = PrepareBindings(vertex), - }; - if (pixel_active) { - bindings.pixel.emplace(PrepareBindings(pixel)); +void RenderExecutor::PrepareGraphicsBindings(std::span stages) { + bool uses_dma = false; + for (auto* stage: stages) { + FindBuffers(*stage); + uses_dma |= stage->runtime->program->info.uses_dma; } - FindBuffers(bindings.vertex); - if (bindings.pixel) { - FindBuffers(*bindings.pixel); - } - if (bindings.vertex.runtime->program->info.uses_dma || - (bindings.pixel && bindings.pixel->runtime->program->info.uses_dma)) { + if (uses_dma) { m_context.PrepareBda(); } - RebindBuffers(bindings.vertex); - if (bindings.pixel) { - RebindBuffers(*bindings.pixel); + for (auto* stage: stages) { + RebindBuffers(*stage); } - RebindImages(bindings.vertex); - if (bindings.pixel) { - RebindImages(*bindings.pixel); + for (auto* stage: stages) { + RebindImages(*stage); } - return bindings; } void RenderExecutor::CommitBindings(CommandBuffer& buffer, diff --git a/src/graphics/host_gpu/renderer/render.h b/src/graphics/host_gpu/renderer/render.h index fdc5fca57..540b4668f 100644 --- a/src/graphics/host_gpu/renderer/render.h +++ b/src/graphics/host_gpu/renderer/render.h @@ -176,9 +176,7 @@ private: [[nodiscard]] TextureBinding ResolveTexture(const ShaderRecompiler::IR::ImageResource& resource, const ShaderRecompiler::IR::DescriptorValue& value); - [[nodiscard]] GraphicsBindings PrepareGraphicsBindings(const ShaderStageRuntime& vertex, - const ShaderStageRuntime& pixel, - bool pixel_active); + void PrepareGraphicsBindings(std::span stages); void ResolveRenderColorTarget(CommandBuffer& buffer, RenderColorInfo& target, uint32_t render_target_slice_offset, uint32_t render_target_slot, bool ignore_target_mask = false, bool exact_format = false); diff --git a/src/graphics/host_gpu/renderer/renderDraw.cpp b/src/graphics/host_gpu/renderer/renderDraw.cpp index 5129eb927..6a21b5f32 100644 --- a/src/graphics/host_gpu/renderer/renderDraw.cpp +++ b/src/graphics/host_gpu/renderer/renderDraw.cpp @@ -1100,8 +1100,14 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff index_source.guest_element_size); } LogDrawPhase(draw.Name(), "PrepareBindings"); - auto bindings = PrepareGraphicsBindings(state.vs_input_info.stage, state.ps_input_info.stage, - state.ps_active); + GraphicsBindings bindings {.vertex = PrepareBindings(state.vs_input_info.stage)}; + std::array descriptor_stages {&bindings.vertex, nullptr}; + if (state.ps_active) { + bindings.pixel.emplace(PrepareBindings(state.ps_input_info.stage)); + descriptor_stages[1] = &*bindings.pixel; + } + const auto stages = std::span {descriptor_stages.data(), state.ps_active ? 2u : 1u}; + PrepareGraphicsBindings(stages); PreparedVertexBuffers vertex_bindings; PreparedIndexBuffer index_binding; if (!mesh_active) { @@ -1132,13 +1138,7 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff if (bindings.pixel && !draw.IsIndexed()) { SetDrawDebugPhase(buffer, submit_id, draw, 0x300u); } - std::array descriptor_stages {&bindings.vertex, nullptr}; - const size_t descriptor_stage_count = bindings.pixel.has_value() ? 2u : 1u; - if (bindings.pixel) { - descriptor_stages[1] = &*bindings.pixel; - } - CommitBindings(buffer, vk::PipelineBindPoint::eGraphics, pipeline, - std::span {descriptor_stages.data(), descriptor_stage_count}); + CommitBindings(buffer, vk::PipelineBindPoint::eGraphics, pipeline, stages); if (mesh_active) { const uint32_t draw_data[] { draw.index_count,