Repository navigation
feat(raytracing): share BVH tracing across Canvas2D, WebGL2, and WebGPU - #317
Merged
Merged
Conversation
CPU 光追核心改为 flat BVH(16 箱 SAH,固定栈迭代遍历,零堆分配, MAX_DEPTH=48 上限保证线性链不丢近端子节点),并修正精确求交: t 保留在射线原始参数化下、球用完整二次式、AABB 负方向交换 near/far、 inside 判定为 t_enter<=0&&t_exit>=0、法线朝外、退化几何不再命中。 Canvas2D / WebGL2 / WebGPU 三后端共用 RayTraceRenderer,只有 init 是 async,其余为同步显式 Result。关键修复: - Canvas: ImageData::data() 返回 Rust 侧副本,写入后 put_image_data 仍 blit 初始透明黑;改为持有真实 Uint8ClampedArray 直接 copy_from - WebGL: upload_packed 只 resize 未拷贝,上传的全是零,着色器读到 node_count==0;改为逐元素拷贝并回填尾部归零;删除 512MiB 预分配 - WebGPU: pipeline 错误域此前被吞,init 在真实 GPUValidationError 下 仍成功;现同时检查 promise、popErrorScope 调用与其结果、非空 GPUError - WebGPU: 扩容绑定失败时新 buffer 泄漏(live 2->3);现失败即销毁新 buffer,保留旧 binding/容量并可重试,错误不被清理结果覆盖 - resize 改为事务:validate -> adapter.resize -> 才提交 canvas 与像素缓冲 - WebGL packed_shape: floor sqrt 会产生 height 超限(cap25 601 slots -> 24x26),改 ceil-sqrt,容量检查与形状一致,不再静默截断 性能(同 public closest_hit、同 harness 源码、7 轮交替中位数、 checksum 逐点一致):128 原语 2.90x、1024 原语 10.52x、4096 原语 33.34x;3 原语 0.74x(线性短路已覆盖,差额为新增的方向校验开销, 非 BVH 建树成本,如实记录)。 规范:53/53 PASS,workspace clippy -D warnings 0,fmt 0, 全仓测试 2866 passed / 0 failed,宏展开访问器 2504 个 0 违规。
Replace getter-only Data derives while preserving generated APIs, add vertical spacing and regression tests for wrapped inline code, and bump the workspace to 0.31.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RayTraceRendererAPI across Canvas2D, WebGL2, and WebGPU, with asynchronous initialization and synchronous rendering, scene updates, and resizing.Getterfor getter-only types, and bump the workspace version from0.30.10to0.31.1.Intersection correctness
Ray::at(t); use the full sphere quadratic witha = dot(direction, direction).Backend fixes
Uint8ClampedArraybacking theImageData, rather than modifying the Rust-side copy returned byImageData::data().The example now stops rendering while paused, consumes resize results, and owns timers, observers, and callbacks so navigation can release them.
Getter-only derive cleanup
DatawithGetteronFmtArgsandRayTraceScene, whose fields already explicitly disabled every mutable getter and setter.get_mut(skip)/set(skip)helper attributes no longer accepted byGetter; preserve all getter configuration and other derives.Dataon types that still generate mutable getters or setters. No call-site-based API reduction is included.skipbehavior were verified against lombok-macros 10.2.7. These standards files live outside this repository and are not part of this PR's file diff.Markdown inline-code spacing
margin: .15em 0to inline code while preservingpadding: .45em .4em.Performance
Both arms use identical harness source and the public
closest_hitAPI, isolated build trees and target directories, and seven alternating passes. Values below are median nanoseconds per ray; scene construction is excluded. These measurements are retained from the earlier raytracing snapshot, not rerun for the subsequent getter/CSS cleanup.The three-primitive case regresses despite taking the existing linear shortcut. This remains a known limitation; this PR does not claim universal performance improvement. Background desktop load also limits how broadly the absolute timings should be interpreted.
Local verification
The following checks were rerun on the final source snapshot for the getter/CSS follow-up, with source and dependency fingerprints unchanged throughout execution:
audit_rust_standards.pyDatacandidatescargo clippy --offline --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkandcrate fmt --checkcargo test --offline --workspace --all-features -- --nocaptureeuv-clipackageAn earlier full accessor check inspected 2,504 generated accessors across core, UI, and engine with zero findings. That broader census is historical; the fresh compiler-boundary check above specifically verifies the two getter-only migrations. Macro-expansion checks complement source checks: getter, mutable-getter, and setter visibility must be verified independently.
Outstanding validation and limitations