Shaders: track GFX10 instruction starts with a bitmap (order-independent decode) #2796
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2796
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2796"
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?
@brainbudt on GitHub · 2026-11-25 20:46 UTC · original
brainbudt:perf/gfx10-decode→main· +272 −11 · 1 files · 1 commits · openIn
gfx10::decode, anif/elsediscovers its else arm after the join. The previousDecoded::Ascendingfast path drained into aBTreeMapon the first out-of-order insert and paid tree costs for the rest of the shader.What changed
BTreeMapandDecodedenum with a byte-start bitmap +Vec<Instruction>, sorting once at the end only when discovery was out of order (crates/victory-shader/src/gfx10/mod.rs).Benchmark on realistic branching CFG (457 instructions, 32 nested
if/elsediamond loops, first backward insert at 11%; median of 5 alternating release runs)Verification
BTreeMaptraversal and downstream SSA output byte for byte.cargo check -p victory-shader --target x86_64-pc-windows-msvc --tests, all-target Clippy-D warnings, andrustfmt --checkpassed.Reviewed with mistral-loop: 1 round with Mistral Large 4 and DeepSeek V4.1 Flash on high. Verdict: approved.
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
Shaders: speed up GFX10 decoding by 57-111% in ascending address orderto Shaders: track GFX10 instruction starts with a bitmap (order-independent decode)c3b74a838fto57172f6456@fuzeofficlal on GitHub · 2026-11-25 21:10 UTC · original
Reviewed and benchmarked
c3b74a83on Windows 11 againstmain(13f91ca).Code review
Decoded::Ascending(Vec<Instruction>)maintains strictly ascending offsets cleanly:containsO(1)-short-circuits abovelast.offsetand binary-searches otherwise;before(at)viapartition_point(|i| i.offset < at)matchesBTreeMap::range(..at).next_back(); any non-ascending insert drains seamlessly intoUnordered(BTreeMap), preserving exact overlap checks and visit semantics.13f91ca,#2761,#2765,#2771,#2789,#2793, and#2798; conflicts ingfx10/mod.rswith#2686(decode_with_flows).Verification & same-machine
--releasebenchmark (rustc 1.98.1MSVC)cargo test --locked -p victory-shader --lib -- gfx10::: 19 passed, 0 failed, 1 ignored (including differential checks vsreference_decode);ir::: 9 passed, 0 failed.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 184 files ok.gfx10_decode_throughput(--release, same machine vs13f91ca):13.018 M inst/s (86.73 MB/s)->19.131 M inst/s (127.45 MB/s)(+47.0% / 1.47x).@rezioliver-collab on GitHub · 2026-11-25 21:15 UTC · original
On an Apple M1, switching to
BTreeMapafter 10%, 50%, or 90% of the instructions retained 4.9%, 26.9%, or 59.9%, respectively, of the throughput gain measured on the ascending-order control.mainµs/decodemainI compared native release builds of
main(13f91ca) and this PR (c3b74a8) on macOS 14.7 with Rust 1.98.1. All four synthetic GFX10 shaders had the same 1,000-instruction mix and byte length. Only the branch displacements changed, making the decoder visit two adjacent instructions in reverse order at the selected point. A separate instrumented build confirmed the exact switch points.Each case had 40 paired runs, alternating which build went first, with 256 warm-up decodes and 1,024 timed decodes per sample. Times are medians. Throughput gains are the median of the per-pair ratios (
maintime / PR time − 1).The full ordered instruction lists matched in all four cases. I compared the complete dumps byte for byte, including every instruction’s offset, encoding, opcode, raw words, and resolved name.
@Marvisak on GitHub · 2026-11-25 23:22 UTC · original · edited 2026-11-26 07:18 UTC
Automated triage for the maintainers.
Merge candidate. Re-reviewed at
57172f6. This is the order-independent approach suggested last time.gfx10::decode(crates/victory-shader/src/gfx10/mod.rs) now records instruction starts in a byte bitmap and pushes instructions into aVec, sorting once at the end only if the list is out of order. TheBTreeMapand the switch to it are gone.beforefor far jumps scans back at mostmax_bytes(the longest instruction seen so far) and re-decodes the nearest start. Any instruction ending atatmust start in that window, sofar_jump'sprev.offset + len == atcheck gives the same results.controlis now generic overBorrow<Instruction>, andir.rsstill compiles against it. The new tests compare against the old tree decoder kept as a reference: opcode ranges, truncations, branch targets, random streams, overlap error precedence, unaligned far targets. The benchmark is#[ignore].Reply to the author: thanks. The gain is modest (decode is about 2-4% of translation), but the core change is now small and well covered.
CI:
checkpassing.Generated by Claude Code
@brainbudt on GitHub · 2026-11-26 05:29 UTC · original
Replaced the
BTreeMapfallback with an order-independent byte-start bitmap +Vec<Instruction>(sorting once at the end only if out of order), and re-benchmarked on a 457-instruction shader with 32 nestedif/elsediamond loops (first backward insert at 51/457, recurring in every loop):29.05 → 22.18 µs(-23.6%) on ARM64;60.65 → 32.73 µs(-46.0%) on x86-64.2.80% → 1.98%(ARM64) and3.72% → 2.12%(x86-64); total through-DXIL time moved-5.1%on x86-64 and was noisy on ARM64, so the claim is scoped strictly to decoding.@kotekompotek on GitHub · 2026-11-25 21:17 UTC · original · reviewed
Verified order-equivalent:
Decoded::before(partition_point + last) returns exactly the greatest-offset-below-atinstruction therange(..at).next_back()did;containson Ascending islast-offset-or-below && binary_search, matchingcontains_keyon a set built the same way;insertdedups via the precedingcontainsguard, so the equal-offset case can't reach the push arm. Finalinto_valuesordering is identical to the old BTreeMap output. The ascending fast path pays off whenever discovery is mostly in-order — which is the common case for linear code with forward branches. LGTM.@futurepro62 on GitHub · 2026-11-26 09:54 UTC · original
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head
57172f6(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: 871 passed, 0 failed, 11 ignored.matches_tree_decoder_across_encodings_and_truncations,matches_tree_decoder_across_opcode_ranges,matches_tree_decoder_across_branch_targets,matches_tree_on_nested_loops_and_random_streams,preserves_overlap_error_precedence_and_unaligned_far_targets.--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
@fuzeofficlal on GitHub · 2026-11-26 11:01 UTC · original · approved these changes
Reviewed
57172f64and verified locally: replacing theBTreeMapingfx10::decodewith a byte-start bitmap, an unsortedVec<Instruction>sorted once at completion, and a bounded backward bitmap scan up tomax_bytespreserves unalignedfar_jumptargets, instruction uniqueness, and overlap/decode error precedence. The five differential test suites cover unaligned jumps, out-of-order overlaps, and error precedence thoroughly.Verified locally on Windows 11 x64 (
57172f64):rustfmt --edition 2024 --check crates/victory-shader/src/gfx10/mod.rs: clean.cargo run --locked -p xtask -- policy(191 files ok) andcargo clippy --workspace --all-targets -- -D warnings(default and--all-features): clean.gfx10::tests(21 passed, 1 ignored),ir::tests(9 passed),structure::tests(13 passed, 1 ignored),emit::lower::tests(33 passed): all passed.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.