Shaders: compute Module::plan once in Shader::finish and reuse for uses and bitcode write #3150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3152"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T10:27:23Z.
Summary
Shader::finish()incrates/victory-shader/src/emit/shader.rsranself.m.uses()(which executes fullModule::plan(): worklist liveness, RPO DFS, predecessor lists, empty-block folding, and block layout) and then ranself.m.write()(which computed the exact sameModule::plan()a second time from scratch).uses()andwrite(),Shader::finish()only appends metadata and constants and never adds or modifies blocks, instructions, or terminators, soPlanis invariant.pub(crate) fn plan,uses_of(&Plan), andwrite_with(&Plan)incrates/victory-shader/src/emit/bitcode.rs, computelet plan = self.m.plan();once inShader::finish(), and addreused_plan_matches_fresh_uses_and_writeverifying byte-identical bitcode and identicalUses.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:31:04Z.
Review: APPROVED
Verified against
origin/main(63bcca4):cargo test -p victory-shader --lib emit::bitcode:: -- --test-threads=1: 13/13 passed (1 ignored bench; includingreused_plan_matches_fresh_uses_and_write).cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 17/17 passed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly computes
Module::planonce inShader::finishand reuses it for bothusesand bitcode emission.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T11:25:19Z.
Independent local verification of head
86eb516on Windows 11, Rust 1.100.0/MSVC:cargo test --locked -p victory-shader --lib reused_plan_matches_fresh_uses_and_write— 1 passed, 0 failed.git diff --check origin/main HEAD— clean.CPU-only lowering test; no D3D12 device or game assets used. Worktree-local
CARGO_TARGET_DIR. AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only). No game data.Imported from Marvisak/VIctory. Originally posted by rezioliver-collab on 2026-11-26T18:01:17Z.
Timing the full Shader::finish() call on Apple M1 showed where reusing the plan pays off. On a compute graph with 256 branch-and-join stages, finalization went from 888 to 776 µs. Building and finalizing that graph together went from 2.98 to 2.85 ms.
finish()finish()I compared
63bcca43and86eb5162in release mode on macOS 14.7 (Rust 1.98.1). Each arm had eight dependent integer operations, followed by a phi at the join. I timed graph construction and finalization separately over 12 alternating pairs. The complete DXBC containers matched byte for byte at all three sizes (2,416, 9,784 and 78,692 bytes).Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T21:24:25Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, cloph-dsp, since none of them names a GPU run. Tested exact head
86eb516(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.reused_plan_matches_fresh_uses_and_write.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:52:37Z.
Review: APPROVED
Verified on
86eb5162:cargo xtask policy:191 files ok.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.rustfmt --edition 2024 --check: clean on all modified hunks incrates/victory-shader/src/emit/bitcode.rsandshader.rs.cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::tests:: emit::lower::: 50 passed, 0 failed under bothVICTORY_WARP=0andVICTORY_WARP=1.Between
self.m.plan()(shader.rs:579) andself.m.write_with(&plan)(shader.rs:922),Shader::finishonly interns types/constants and appends metadata while leaving blocks, instructions, terminators, globals, functions, attributes, and existing branch-condition constants untouched, so the reusedPlanproduces identical bitcode. Two minor non-blocking notes: the doc comments (shader.rs:576,bitcode.rs:730) mention metadata/constant additions without noting type additions or thereplace_constbranch-condition caveat, andreused_plan_matches_fresh_uses_and_write(bitcode.rs:1660) callsm.i32(42)onsynthetic(64, 64, 64)which already pre-interns0..63(so it exercises metadata growth without actually appending a new constant and shifting value IDs). LGTM.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.