Repository navigation
The kernel's variants by WESL's conditional translation, and the repository's Rust pinned (1.100.0) - #70
Merged
Conversation
…sitory's Rust pinned (1.100.0) The kernel was made for a device and a scene by text patches: the hardware traversal cut in at markers (kernel_base), a device's switches and a scene's source features found and replaced at anchors that were whole lines of code (kernel_switches, kernel_source), an edit of such a line breaking a patch at run time. Now the kernel is one WESL module (pathtrace.wgsl, trace_units.wgsl, trace_hw.wgsl, translucent.wgsl) with every variant in it under @if(flag) on a declaration or a statement, made by wesl-rs 0.6 (natively and in a browser): hwrt; the switches strict, cutout_lite, cutout_lite2, last_direct, light_pick; the source features vcolor, grid, tint, unlit, units, background (gpu.rs KERNEL_FILES, kernel_template, kernel_flags, kernel_wgsl). A flag the source names that is not given is an error. Still text, before the variant: a scene's functions in their slots, the merged layout, the uniform tables, the loop guard. rust-toolchain.toml pins 1.100.0 (wesl-rs 0.6 asks for 1.97.1; it was whatever stable a machine had), and every Rust job of CI runs for it. fetch_update is try_update. WGSL a browser refuses, found on the way: WESL parses by the specification's grammar, as Chrome's Tint does, and the scene library's surface-material hash (`a * b ^ c * d`: a bitwise operator's operands must be unary) did not compile through it; naga had taken it, so those materials and the particle passes (the same, three times) never compiled in a browser. Parenthesised in the order naga read them. A unit test holds the shader files outside the kernel to the grammar. Checks: for all 2,304 combinations of the flags the Metal source naga writes is the patched kernel's (two rewrites allowed for: the light pick's blocks take their condition from a local, and vertex and instance colours multiply in turn: the same products in the same order). On 1.100 the voxel and physics determinism checks give their recorded hashes, and main built with 1.96 and with 1.100 renders the same (render-identity, native and merged). Against main on 1.100, render-identity native, THREERT_MERGED=1, every switch on, the uniform tables: nothing changed. tools/web-hello.ts in Chrome: pass. cargo test (126), npm typecheck / test / npm-pack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Item 6 of the renderer review (6a): the kernel's variants without text patches. One PR, as agreed, together with pinning the toolchain that wesl-rs needs.
The kernel
Before: the kernel was made for a device and a scene by patching its text.
kernel_base).kernel_switches,kernel_source). Each anchor was a whole line of code, comments included, so editing such a line broke a patch, and only at run time.Now: the kernel is one WESL module:
pathtrace.wgsl,trace_units.wgsl,trace_hw.wgsl,translucent.wgsl.Every variant is in it, under WESL's conditional translation (
@if(flag)on a declaration or a statement). WESL is the community's WGSL extension, used by Bevy (bevy_shader0.20) and Vello.wesl-rs 0.6 makes a kernel's WGSL from the flags, natively and in the browser. The flags are named in the head of
pathtrace.wgsl:hwrt;strict,cutout_lite,cutout_lite2,last_direct,light_pick;vcolor,grid,tint,unlit,units,background.gpu.rs:KERNEL_FILES,kernel_template,kernel_flags,kernel_wgslreplace the three patch functions. A flag the source names that is not given is an error.Still done as text, before the variant is made:
6b, the next PR, removes the last three.
The browser module grows: gzip 2.81 → 3.31 MB. This is the agreed long-term trade. Once the variants are few, the browser's can be generated at build time.
The toolchain
rust-toolchain.tomlpins Rust 1.100.0. wesl-rs 0.6 needs 1.97.1, and until now each machine built with whatever stable it had (1.96 here).fetch_update→try_update.Found on the way: WGSL a browser refuses
WESL parses by the specification's grammar, as strictly as Chrome's Tint. The scene library's surface-material hash did not compile through it:
a * b ^ c * dis not valid WGSL, because a bitwise operator's operands must be unary expressions. naga accepts it, so this never showed natively. These materials (windows, grime, puddles, wet surfaces), and the particle passes (the same pattern three times), never compiled in a browser.Merge gate
@ifkernel@if, and those blocks are long), and vertex and instance colours multiply in turn (the same products in the same order)THREERT_MERGED=1/ every switch on /THREERT_UNIFORM_TABLES=1tools/web-hello.tsin Chromecargo test --releasenpm run typecheck,npm test,tools/npm-pack.tsDocs: RUNTIME "The kernel's source"; ROADMAP § 1a records the step.
🤖 Generated with Claude Code
Note
High Risk
Replaces all kernel variant generation for native and browser builds; incorrect
@ifflags or WESL output could change rendering or break wasm compilation, though the PR reports parity across 2,304 flag combinations and render-identity checks.Overview
Kernel compilation no longer splices WGSL with string patches (
kernel_base,kernel_switches,kernel_source). The path-tracing stack is one WESL module (pathtrace.wgslplustrace_units,trace_hw,translucent), andkernel_wgsldrives wesl-rs 0.6 conditional translation fromkernel_flags(@ifforhwrt, device switches, and scene features). Scene-specific slots (material/volume/geometry functions, merged layout, uniform tables, loop guard) are still applied as text before WESL runs.Toolchain and CI: adds
rust-toolchain.tomlat 1.100.0 (wesl-rs needs ≥1.97.1) and extends path filters so Rust jobs run when that file changes.fetch_updateis updated totry_update.Browser WGSL: parentheses fix invalid
a * b ^ c * d-style hashes in scene materials and particle shaders so WESL/spec parsing matches Tint; a unit test checks non-kernel shaders the same way.Docs: ROADMAP and RUNTIME describe WESL-based kernel sourcing and the pinned toolchain.
Reviewed by Cursor Bugbot for commit df45ca5. Bugbot is set up for automated code reviews on this repo. Configure here.