Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
# Compiled and build artifacts
# Compiled and binary files
*.o
*.obj
*.exe
Expand All @@ -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
Expand All @@ -34,7 +36,10 @@ Thumbs.db
.env.local
*.env.*

# Coverage reports
# Logs
*.log

# Coverage
coverage/
htmlcov/
.coverage
Expand Down
14 changes: 13 additions & 1 deletion FarmEngine/src/rendering/graph/RenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<VkMemoryBarrier> memoryBarriers;
for (const auto& dep : pass.passLevelDependencies) {
Expand All @@ -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)
Expand Down Expand Up @@ -421,7 +433,7 @@ void RenderGraph::recordBarriers(VkCommandBuffer cmd, const CompiledPass& pass,
cmd,
srcStage,
dstStage,
0,
combinedDependencyFlags,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using combinedDependencyFlags (which currently aggregates VK_DEPENDENCY_BY_REGION_BIT for pass-level dependencies) in vkCmdPipelineBarrier without validating the pipeline stages is risky. According to the Vulkan specification, VK_DEPENDENCY_BY_REGION_BIT can only be used if all pipeline stages in srcStageMask and dstStageMask are graphics stages. If any barrier in this call (including resource barriers) involves compute (VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT) or transfer stages, this will result in a validation error or undefined behavior. Consider only applying this flag if the aggregated stages are compatible with graphics-only operations.

static_cast<uint32_t>(memoryBarriers.size()),
memoryBarriers.data(),
0, nullptr,
Expand Down
4 changes: 4 additions & 0 deletions FarmEngine/src/rendering/graph/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ class RenderGraphBuilder {
const std::function<void(RenderPass&)>& 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,
Expand Down