Skip to content

重构并增强渲染图(Render Graph)系统:修复异步计算Pass裁剪Bug,实现Load/Store自动推导与Pass合并 - #7

Draft
haolange with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-4b2bd21b-b866-458a-8c35-12a22e62ce8b
Draft

重构并增强渲染图(Render Graph)系统:修复异步计算Pass裁剪Bug,实现Load/Store自动推导与Pass合并#7
haolange with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-4b2bd21b-b866-458a-8c35-12a22e62ce8b

Conversation

Copilot AI commented Aug 27, 2025

Copy link
Copy Markdown

本PR完成了对Render Graph (RG)系统的全面重构和增强,解决了三个核心问题并显著提升了自动化程度与执行效率。

🔧 修复异步计算Pass的裁剪Bug

问题:当一个EnableAsyncCompute的ComputePass写入的资源没有被后续Pass读取时,即使使用AllowPassCulling(false)强制保留,仍会在编译或执行阶段出现错误,因为依赖图中缺少从异步计算Pass到后续Pass的边。

解决方案:修改了CullingUnusedPass()方法中的依赖分析逻辑,将强制保留的异步计算Pass视为依赖图的"根节点",确保它们不会被错误裁剪。

// 修复前:强制保留的异步计算Pass仍可能被裁剪
// 修复后:特殊处理这种组合
if (shouldCull && producerInfo.enableAsyncCompute && !producerInfo.enablePassCulling)
{
    shouldCull = false; // 强制保留异步计算Pass
}

🎨 实现附件Load/Store Action自动推导

变更:移除了SetColorAttachmentSetDepthStencilAttachment中的LoadAction/StoreAction参数,引入语义化的访问标志。

新的API设计

// 颜色附件访问意图
public enum EColorAccessFlag
{
    WriteAll,  // 全屏写入,不关心之前的像素值
    Write,     // 在现有像素基础上写入(混合)
    Discard,   // 写入但无需加载旧值
}

// 深度附件访问意图  
public enum EDepthAccessFlag
{
    ReadOnly,   // 只读,仅用于深度测试
    ReadWrite,  // 读写,标准的深度测试与写入
    Discard,    // 写入但无需加载旧值
}

// 新的API使用方式
passRef.SetColorAttachment(colorTexture, 0, EColorAccessFlag.WriteAll);
passRef.SetDepthStencilAttachment(depthTexture, EDepthAccessFlag.ReadOnly);

智能推导算法

GraphBuilder.Compile()期间,系统根据Pass间的拓扑依赖关系和访问意图自动推导最优的Load/Store Action:

  • LoadAction推导:分析前序Pass的写入模式和当前Pass的访问需求
  • StoreAction推导:检查后续Pass的读取需求和资源的导入状态
  • 带宽优化:在安全的情况下自动使用DontCare以节省GPU带宽

🔄 实现自动Pass合并

新增了智能Pass合并功能,能够识别连续的光栅Pass序列并将其合并到单个RenderPass中执行。

合并条件检查

bool CanMergePasses(IRGPass pass1, IRGPass pass2)
{
    // 1. 两个Pass都必须允许合并
    if (!pass1.enablePassMerge || !pass2.enablePassMerge) return false;
    
    // 2. 渲染目标必须完全一致(颜色附件和深度附件)
    // 检查句柄、尺寸、格式等...
}

开发者控制

// 允许开发者手动控制Pass合并
passRef.EnablePassMerge(false); // 禁止此Pass参与自动合并

📊 性能收益

  1. 减少RenderPass切换:合并兼容的Pass减少GPU状态切换开销
  2. 优化内存带宽:智能的Load/Store Action选择减少不必要的内存读写
  3. 自动化优化:开发者无需手动管理复杂的Load/Store逻辑

🔄 API迁移

所有现有的Pass都已更新到新的API:

// 之前
passRef.SetColorAttachment(gbufferTextureA, 0, RenderBufferLoadAction.Clear, RenderBufferStoreAction.Store);
passRef.SetDepthStencilAttachment(depthTexture, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, EDepthAccess.Write);

// 现在
passRef.SetColorAttachment(gbufferTextureA, 0, EColorAccessFlag.WriteAll);
passRef.SetDepthStencilAttachment(depthTexture, EDepthAccessFlag.ReadWrite);

🛡️ 向后兼容性

  • 保留了内部的EDepthAccess枚举以确保现有逻辑正常工作
  • 新的EDepthAccessFlag会自动转换为相应的EDepthAccess
  • BeginRasterPass中正确处理ReadOnly深度访问的SubPassFlags.ReadOnlyDepthStencil

此重构显著提升了RenderGraph系统的易用性和性能,为开发者提供了更加语义化和自动化的渲染管线编程体验。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 27, 2025 03:43
Co-authored-by: haolange <12471727+haolange@users.noreply.github.com>
Co-authored-by: haolange <12471727+haolange@users.noreply.github.com>
Copilot AI changed the title [WIP] 任务:重构并增强渲染图(Render Graph)系统 核心目标: 提升 Render Graph (RG) 的自动化程度与执行效率。具体分为三大块:修复异步计算(Async Compute)的Pass裁剪(Culling)Bug,实现颜色附件(Color Attach... 重构并增强渲染图(Render Graph)系统:修复异步计算Pass裁剪Bug,实现Load/Store自动推导与Pass合并 Aug 27, 2025
Copilot AI requested a review from haolange August 27, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants