Skip to content

add empty handle for hiz - #148

Merged
QiuShui1012 merged 1 commit into
Anvil-Dev:dev/26.1from
ZhuRuoLing:fix/empty_hiz
Oct 10, 2026
Merged

QiuShui1012 merged 1 commit into
Anvil-Dev:dev/26.1from
ZhuRuoLing:fix/empty_hiz

Conversation

@ZhuRuoLing

Copy link
Copy Markdown
Contributor

No description provided.

@Gugle2308

Copy link
Copy Markdown

代码审查摘要 — PR #148(Anvil-Dev/AnvilLib)

操作: opened(PR 状态 pullOpened,base = dev/26.1 @ 432b60d6,已与本地 refs/remotes/rvdev26 对齐)
范围: 1 个文件 / +2 −1 行(HierarchicalZOcclusionCuller.java,无新增/删除文件,无 ghost 文件)

变更内容

  1. processFeatures() 在调用 dispatch(...) 前新增早退:if (this.currentFrameState.keyAssociations.isEmpty()) return;
  2. 注释更新:// TODO check if mojang added coherent flag → 追加 UPDATE: seems not, pray for driver handles this correctly

🟢 结论方向:这个早退在语义上是安全的

shouldDraw(feature) 是靠 currentFrameState.keyAssociations.get(feature) 反查 key 的(第 328 行)。当 keyAssociations 为空时,所有查询都会走 key == null → return true,也就是说本帧本来就不会剔除任何东西;此时跳过 dispatch 只会省下 staging buffer 上传 + 一次 compute dispatch,不会造成 false-cull(保守方向),也不会影响 mipmap 节奏(mipmapUpdateCd 递减/runConvert 都在早退之前)。这个 guard 确实不是纯冗余:submitFeatureKey(key, feature) 是先无条件 keys.add(key) 再按 feature 列表 put 关联,所以「keys 非空但 keyAssociations 为空」唯一来源就是某条 occlussion record 在 begin/end 之间没有产生任何 submit(wasUsed()==true 但各提交列表为空,submitFeatureToCuller 传入空 collectedFeatures)——这正是标题所说的 "empty handle"。

⚠️ 警告

  • HierarchicalZOcclusionCuller.java:187 与 :192 两个空判据不一致,且旧判据已成死代码 — dispatch() 内部仍有 if (this.currentFrameState.size() <= 0) return;(size() = keys.size())。由于 keyAssociations 非空 ⟹ keys 非空,而 dispatch 现在只可能从这条新 guard 之后被调用(private 方法,仅此一处调用者),该内部检查已恒为 false。建议把判据统一到一处(要么把新 guard 也写进 dispatch() 开头、与旧判据合并,要么删掉不再可达的那行),避免以后读代码的人以为 keys 仍可能为空。
  • fetchResults() 的读取长度可能与 outputBuffer 容量脱节(低概率崩溃路径) — outputBuffer 只在 dispatch() → ensureBuffers(elementCount) 里按 keys.size()*4 增长;而 beginRenderingFrame() → fetchResults() 是用 previousFrameState.size()(上一帧的 keys.size())直接 intBuffer.get(0, results, 0, size) 读取。改动之后,一个「关联为空但 keys 计数大于上次 dispatch 时容量」的帧会跳过 ensureBuffers,其下一帧的 fetchResults() 就可能读越界抛 IndexOutOfBoundsException(改动前该帧会走 dispatch 顺带把 buffer 扩容,因此不会出现此路径)。建议顺手加固,例如:
    int size = Math.min(this.previousFrameState.size(), outputBuffer.size() / Integer.BYTES);
    或让 fetchResults() 复用同一空判据。属于稳健性建议,非阻塞。

💡 建议

  • 注释语义 — 第二条 hunk 现在已经把 TODO 的答案写出来了(结论是「没有 coherent flag,依赖驱动正确处理」)。这里已经不再是待办事项,建议把 // TODO ... UPDATE: ... 改成一条陈述性注释(说明 barrier 与驱动的假设),并顺手修一下语法/语气(pray for driver handles this correctly → e.g. relies on the driver handling this correctly)。另外仍保留了 buf 屏障调用,注释若说明「已验证仍需保留」会更有信息量。
  • 空行 — 原先 dispatch 前有一个空行分隔 mipmap 更新块与调度块,这次被删除换成 guard 行。功能无影响,仅提示逻辑分块的可读性(若项目 checkstyle 无相关规则可忽略,已确认本仓库 checkstyle 未配置 EmptyLineSeparator)。
  • 同实现互参 — GpuQueryOcclusionCuller.processFeatures()(currentFrameState.runQueries(camera))没有对应的空短路;其 runQueries 在 keySamplesMap 为空时会建一个无 draw 的 RenderPass,行为上不崩,故本 PR 只改 hiz 是合理的,无需扩大范围。

🟢 看起来不错

  • 早退放在 mipmap 更新之后、dispatch 之前,位置正确:既跳过了无意义 GPU 工作,又不打断深度金字塔的更新节拍。
  • dispatch 是 processFeatures 的最后一句,早退不会漏掉任何后续语句。
  • 判据用 keyAssociations(而非 keys)与公开 API isEmpty()(:310 同为 previousFrameState.keyAssociations.isEmpty())保持一致,语义正确。

📋 声称验证表

声称 状态 证据
add empty handle for hiz ✅ processFeatures 新增 keyAssociations.isEmpty() 早退,覆盖「有 key 无关联」的退化帧;且与 isEmpty() 判据一致
(附带的注释更新) ✅ dispatch 内 coherent flag TODO 已补充结论

结论:APPROVE(可合并) — 改动小、方向正确、不改变可见语义;两条 ⚠️ 属于判据一致性/稳健性加固,可在本 PR 顺手处理或在后续跟进。若采纳,建议把 dispatch 的空判据与新增 guard 合并为一处。

标题

gh auth status 显示 /opt/data/home/.config/gh/hosts.yml 的 token 已失效(Active account: Gugle2308 / invalid token),按流程不执行 gh pr edit。建议标题:

Skip Hi-Z occlusion dispatch when no features are associated 无特征关联时跳过 Hi-Z 遮挡剔除调度


由 Hermes Agent 审查

@Gugle2308

Copy link
Copy Markdown

💾 Self-improvement review: Patched SKILL.md in skill 'removed-guard-regression-review' (1 replacement). · Skill updated

@Gugle2308

Copy link
Copy Markdown

🌿 Roseau API Breaking Change Report

Module Status Breaking Changes
codec ✅ Compatible 0
collision ✅ Compatible 0
cube ✅ Compatible 0
config ✅ Compatible 0
integration ✅ Compatible 0
moveable-entity-block ✅ Compatible 0
network ✅ Compatible 0
rendering ✅ Compatible 0
space-select ✅ Compatible 0
font ✅ Compatible 0
util ✅ Compatible 0
explosion ✅ Compatible 0
rpc ✅ Compatible 0
math ✅ Compatible 0
multiblock ✅ Compatible 0
recipe ✅ Compatible 0
registrum ✅ Compatible 0
sync ✅ Compatible 0
wheel ✅ Compatible 0
main ✅ Compatible 0

Full CSVs: see the Artifacts section of this workflow run.

@QiuShui1012
QiuShui1012 merged commit f92f856 into Anvil-Dev:dev/26.1 Oct 10, 2026
42 checks passed
@Gugle2308

Copy link
Copy Markdown

PR #148 状态为 closed,按约束 1 停止审查,不发布评论。

(操作类型 = closed → 不审查、不评论、不修改标题。)

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.

3 participants