From 2998a97056c3f055f6564f5401f3bff347a37479 Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Thu, 2 Apr 2026 18:45:32 +0000 Subject: [PATCH] Fix Vulkan render graph dependency validation and flag usage - Validate dependency direction in RenderGraph::compile to enforce from < to for correct execution order - Use stored dependencyFlags in PassLevelDependency when calling vkCmdPipelineBarrier - Update RenderGraphBuilder documentation to clarify dependency ordering requirements - Add error handling for invalid dependency indices and directions during compilation --- .gitignore | 19 ++++++++++++------- .../src/rendering/graph/RenderGraph.cpp | 14 +++++++++++++- FarmEngine/src/rendering/graph/RenderGraph.h | 4 ++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index edef6ed..bdb6a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ ``` -# Compiled and build artifacts +# Compiled and binary files *.o *.obj *.exe @@ -18,14 +18,16 @@ __pycache__/ target/ .gradle/ -# Logs and temp files -*.log -*.tmp -*.swp +# Build artifacts +build/ +dist/ -# Editors +# Editor/IDE files .vscode/ .idea/ +*.swp +*.swo +*.tmp # System files .DS_Store @@ -34,7 +36,10 @@ Thumbs.db .env.local *.env.* -# Coverage reports +# Logs +*.log + +# Coverage coverage/ htmlcov/ .coverage diff --git a/FarmEngine/src/rendering/graph/RenderGraph.cpp b/FarmEngine/src/rendering/graph/RenderGraph.cpp index 856c47b..f8412e2 100644 --- a/FarmEngine/src/rendering/graph/RenderGraph.cpp +++ b/FarmEngine/src/rendering/graph/RenderGraph.cpp @@ -244,6 +244,14 @@ void RenderGraph::compile(RenderGraphBuilder&& builder) { " is out of range (pass count: " + std::to_string(compiledPasses.size()) + ")"); } + // Validate dependency direction: producer must execute before consumer + // Since passes execute in sequential order, from must be < to + if (dep.from >= dep.to) { + throw std::runtime_error("Invalid dependency direction: 'from' pass index (" + std::to_string(dep.from) + + ") must be less than 'to' pass index (" + std::to_string(dep.to) + + "). Passes execute in sequential order, so the producer pass must be added before the consumer pass."); + } + if (!dep.resourceName.empty()) { // Resource-specific dependency: store as pending barrier for resolution at execution time const ResourceHandle* res = compiledRegistry.getResource(dep.resourceName); @@ -366,6 +374,9 @@ void RenderGraph::recordBarriers(VkCommandBuffer cmd, const CompiledPass& pass, VkPipelineStageFlags combinedSrcStage = 0; VkPipelineStageFlags combinedDstStage = 0; + // Combine dependency flags from all pass-level dependencies + VkDependencyFlags combinedDependencyFlags = 0; + // Process pass-level dependencies (emit as VkMemoryBarrier) std::vector memoryBarriers; for (const auto& dep : pass.passLevelDependencies) { @@ -377,6 +388,7 @@ void RenderGraph::recordBarriers(VkCommandBuffer cmd, const CompiledPass& pass, combinedSrcStage |= dep.srcStageMask; combinedDstStage |= dep.dstStageMask; + combinedDependencyFlags |= dep.dependencyFlags; } // Process resource-specific barriers (resolve image at runtime) @@ -421,7 +433,7 @@ void RenderGraph::recordBarriers(VkCommandBuffer cmd, const CompiledPass& pass, cmd, srcStage, dstStage, - 0, + combinedDependencyFlags, static_cast(memoryBarriers.size()), memoryBarriers.data(), 0, nullptr, diff --git a/FarmEngine/src/rendering/graph/RenderGraph.h b/FarmEngine/src/rendering/graph/RenderGraph.h index b52525d..c16423f 100644 --- a/FarmEngine/src/rendering/graph/RenderGraph.h +++ b/FarmEngine/src/rendering/graph/RenderGraph.h @@ -105,11 +105,15 @@ class RenderGraphBuilder { const std::function& configureFunc); // Definir dependencias explĂ­citas (opcional, se pueden inferir) + // Note: The 'from' pass index must be less than the 'to' pass index, as passes execute + // in sequential order. Attempting to add a dependency where from >= to will throw an error. RenderGraphBuilder& addDependency(uint32_t from, uint32_t to, VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage, VkAccessFlags srcAccess, VkAccessFlags dstAccess); // Definir dependencias especĂ­ficas de recursos (para barreras de imagen) + // Note: The 'from' pass index must be less than the 'to' pass index, as passes execute + // in sequential order. Attempting to add a dependency where from >= to will throw an error. RenderGraphBuilder& addResourceDependency(uint32_t from, uint32_t to, const std::string& resourceName, VkPipelineStageFlags srcStage, VkPipelineStageFlags dstStage,