renderer: share graphics resource preparation across shader stages

This commit is contained in:
nmzik
2026-09-13 07:10:36 +04:00
parent 00a16f3120
commit 6d1ba5870a
3 changed files with 20 additions and 33 deletions
@@ -857,32 +857,21 @@ void RenderExecutor::RebindImages(PreparedBindings& prepared) {
} }
} }
RenderExecutor::GraphicsBindings void RenderExecutor::PrepareGraphicsBindings(std::span<PreparedBindings* const> stages) {
RenderExecutor::PrepareGraphicsBindings(const ShaderStageRuntime& vertex, bool uses_dma = false;
const ShaderStageRuntime& pixel, bool pixel_active) { for (auto* stage: stages) {
GraphicsBindings bindings { FindBuffers(*stage);
.vertex = PrepareBindings(vertex), uses_dma |= stage->runtime->program->info.uses_dma;
};
if (pixel_active) {
bindings.pixel.emplace(PrepareBindings(pixel));
} }
FindBuffers(bindings.vertex); if (uses_dma) {
if (bindings.pixel) {
FindBuffers(*bindings.pixel);
}
if (bindings.vertex.runtime->program->info.uses_dma ||
(bindings.pixel && bindings.pixel->runtime->program->info.uses_dma)) {
m_context.PrepareBda(); m_context.PrepareBda();
} }
RebindBuffers(bindings.vertex); for (auto* stage: stages) {
if (bindings.pixel) { RebindBuffers(*stage);
RebindBuffers(*bindings.pixel);
} }
RebindImages(bindings.vertex); for (auto* stage: stages) {
if (bindings.pixel) { RebindImages(*stage);
RebindImages(*bindings.pixel);
} }
return bindings;
} }
void RenderExecutor::CommitBindings(CommandBuffer& buffer, void RenderExecutor::CommitBindings(CommandBuffer& buffer,
+1 -3
View File
@@ -176,9 +176,7 @@ private:
[[nodiscard]] TextureBinding ResolveTexture(const ShaderRecompiler::IR::ImageResource& resource, [[nodiscard]] TextureBinding ResolveTexture(const ShaderRecompiler::IR::ImageResource& resource,
const ShaderRecompiler::IR::DescriptorValue& value); const ShaderRecompiler::IR::DescriptorValue& value);
[[nodiscard]] GraphicsBindings PrepareGraphicsBindings(const ShaderStageRuntime& vertex, void PrepareGraphicsBindings(std::span<PreparedBindings* const> stages);
const ShaderStageRuntime& pixel,
bool pixel_active);
void ResolveRenderColorTarget(CommandBuffer& buffer, RenderColorInfo& target, void ResolveRenderColorTarget(CommandBuffer& buffer, RenderColorInfo& target,
uint32_t render_target_slice_offset, uint32_t render_target_slot, uint32_t render_target_slice_offset, uint32_t render_target_slot,
bool ignore_target_mask = false, bool exact_format = false); bool ignore_target_mask = false, bool exact_format = false);
@@ -1100,8 +1100,14 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff
index_source.guest_element_size); index_source.guest_element_size);
} }
LogDrawPhase(draw.Name(), "PrepareBindings"); LogDrawPhase(draw.Name(), "PrepareBindings");
auto bindings = PrepareGraphicsBindings(state.vs_input_info.stage, state.ps_input_info.stage, GraphicsBindings bindings {.vertex = PrepareBindings(state.vs_input_info.stage)};
state.ps_active); std::array<PreparedBindings*, 2> 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; PreparedVertexBuffers vertex_bindings;
PreparedIndexBuffer index_binding; PreparedIndexBuffer index_binding;
if (!mesh_active) { if (!mesh_active) {
@@ -1132,13 +1138,7 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff
if (bindings.pixel && !draw.IsIndexed()) { if (bindings.pixel && !draw.IsIndexed()) {
SetDrawDebugPhase(buffer, submit_id, draw, 0x300u); SetDrawDebugPhase(buffer, submit_id, draw, 0x300u);
} }
std::array<PreparedBindings*, 2> descriptor_stages {&bindings.vertex, nullptr}; CommitBindings(buffer, vk::PipelineBindPoint::eGraphics, pipeline, stages);
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});
if (mesh_active) { if (mesh_active) {
const uint32_t draw_data[] { const uint32_t draw_data[] {
draw.index_count, draw.index_count,