Shaders: one arena per program for instruction operands and effects #1757

Open
github-bot wants to merge 1 commit from github-bot/gh-1757 into main AGit
Owner

@⁠Luislariosss on GitHub · 2026-11-24 22:00 UTC · original
Luislariosss:perf/ir-instruction-arena → main · +832 −477 · 12 files · 1 commits · open

FIND-1 (claimed here): translating one instruction still cost about five heap allocations (~180 ns of ~880 ns per instruction) — the decoder's Vec of source operands and Inst's reads/writes Vecs, each built from a temporary Vec, plus effects()' scratch and dedup buffers. This replaces those Vecs with one arena per program.

What is in it

  • Fields' variable-length lists (Sop.src, Ds.data, Image.addr, Valu.src) are now gfx10::Span { start, len } into Program::operands: Vec<Operand>; Inst.reads/Inst.writes are spans into Program::effects: Vec<(Reg, Value)>.
  • Instruction::fields takes the arena to append to; ir::build reuses one scratch pair for the per-instruction register lists, so the decoder and effects stop allocating per instruction.
  • Readers go through Program::operands(span) and Inst::reads/writes/read/write(&Program, ..). Exp.src stays a fixed array; Instruction.words is unchanged (per instruction, out of scope here).
  • Dropped instructions' operands are truncated; node splitting copies a block's effect spans, so each copy renames its own values (without the copy the clones would share and overwrite each other).
  • No behavior change: Inst, Fields and Program stay Clone/PartialEq/Eq/Debug; the offline victory translate path is adapted as well.
  • New test ir::tests::operand_and_effect_spans_slice_back_each_instructions_lists: 0, 2 and 3 sources, an implicit VCC operand, reads/writes order, and no gaps in either arena. A second test ir::tests::split_block_copies_get_their_own_effect_spans pins the block-split path: the split copy's spans do not overlap the original's, its write values differ, and renaming through one copy leaves the other unchanged.

Tested

  • Windows 11 26200, AMD RX 9060 XT 16 GB (RDNA4, driver 32.0.32015.7029), Ryzen 5 9600X, 16 GB RAM, Rust 1.98.1 (from rust-toolchain.toml).
  • cargo test --workspace --no-fail-fast: 478 passed, 0 failed, 7 ignored at this head (29d5f6e, rebased onto upstream 70564ae). Upstream main alone on the same machine: 476 passed, 0 failed, 7 ignored — the difference of two is the two new tests, so no upstream test regressed. The GPU-executed valu/waterfall tests ran on the RX 9060 XT (no GPU skips on this adapter).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean. cargo check --workspace --all-targets: passed.
  • This machine needs CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 — rustc 1.98.1 here dies with 0xc0000005 while compiling with debuginfo; the test behavior is unchanged by that.

Not tested / not measured

  • The allocation count and the ns per instruction were not measured: the tree has no counting allocator and one was not added. The five allocations above are the finding's own count.
  • Instruction.words and the other per-instruction Vecs the finding names remain, out of scope here.

AI use

  • opencode: HY4 Flash Free gathered the call-site map; implementation and commit by Sonnet (Claude, medium); an independent Sonnet review gate covered span aliasing, block splitting and the truncation path before this was pushed. The test counts are cargo's own output.
**@⁠Luislariosss** on GitHub · 2026-11-24 22:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1757) `Luislariosss:perf/ir-instruction-arena` → `main` · +832 −477 · 12 files · 1 commits · open FIND-1 (claimed [here](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633)): translating one instruction still cost about five heap allocations (~180 ns of ~880 ns per instruction) — the decoder's Vec of source operands and `Inst`'s `reads`/`writes` Vecs, each built from a temporary Vec, plus `effects()`' scratch and dedup buffers. This replaces those Vecs with one arena per program. **What is in it** - `Fields`' variable-length lists (`Sop.src`, `Ds.data`, `Image.addr`, `Valu.src`) are now `gfx10::Span { start, len }` into `Program::operands: Vec<Operand>`; `Inst.reads`/`Inst.writes` are spans into `Program::effects: Vec<(Reg, Value)>`. - `Instruction::fields` takes the arena to append to; `ir::build` reuses one scratch pair for the per-instruction register lists, so the decoder and `effects` stop allocating per instruction. - Readers go through `Program::operands(span)` and `Inst::reads/writes/read/write(&Program, ..)`. `Exp.src` stays a fixed array; `Instruction.words` is unchanged (per instruction, out of scope here). - Dropped instructions' operands are truncated; node splitting copies a block's effect spans, so each copy renames its own values (without the copy the clones would share and overwrite each other). - No behavior change: `Inst`, `Fields` and `Program` stay `Clone`/`PartialEq`/`Eq`/`Debug`; the offline `victory translate` path is adapted as well. - New test `ir::tests::operand_and_effect_spans_slice_back_each_instructions_lists`: 0, 2 and 3 sources, an implicit VCC operand, reads/writes order, and no gaps in either arena. A second test `ir::tests::split_block_copies_get_their_own_effect_spans` pins the block-split path: the split copy's spans do not overlap the original's, its write values differ, and renaming through one copy leaves the other unchanged. **Tested** - Windows 11 26200, AMD RX 9060 XT 16 GB (RDNA4, driver 32.0.32015.7029), Ryzen 5 9600X, 16 GB RAM, Rust 1.98.1 (from `rust-toolchain.toml`). - `cargo test --workspace --no-fail-fast`: **478 passed, 0 failed, 7 ignored** at this head (`29d5f6e`, rebased onto upstream `70564ae`). Upstream `main` alone on the same machine: 476 passed, 0 failed, 7 ignored — the difference of two is the two new tests, so no upstream test regressed. The GPU-executed `valu`/`waterfall` tests ran on the RX 9060 XT (no GPU skips on this adapter). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. `cargo check --workspace --all-targets`: passed. - This machine needs `CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0` — rustc 1.98.1 here dies with 0xc0000005 while compiling with debuginfo; the test behavior is unchanged by that. **Not tested / not measured** - The allocation count and the ns per instruction were **not measured**: the tree has no counting allocator and one was not added. The five allocations above are the finding's own count. - `Instruction.words` and the other per-instruction Vecs the finding names remain, out of scope here. **AI use** - opencode: HY4 Flash Free gathered the call-site map; implementation and commit by Sonnet (Claude, medium); an independent Sonnet review gate covered span aliasing, block splitting and the truncation path before this was pushed. The test counts are cargo's own output.
FIND-1: translating one instruction still cost about five heap
allocations (~180 ns of ~880 ns): the decoder's Vec of source operands,
and Inst's reads and writes Vecs, each built from a temporary Vec, plus
effects' scratch and dedup buffers.

Fields' variable-length lists (Sop.src, Ds.data, Image.addr, Valu.src)
are now a gfx10::Span { start, len } into Program::operands, and
Inst.reads/writes a Span into Program::effects. Instruction::fields takes
the arena to append to. Readers go through Program::operands(span) and
Inst::reads/writes/read/write(&Program, ..). ir::build reuses one scratch
pair for the registers of each instruction and drops the operands of
dropped instructions. Node splitting copies a block's effects spans so
each copy still renames its own values. Exp.src stays a fixed array;
Instruction.words is unchanged.

No behavior change. Inst, Fields and Program stay Clone/PartialEq/Eq/Debug.

Tests: cargo test --workspace --no-fail-fast: 478 passed, 0 failed, 7 ignored
(upstream main alone: 476 passed, 0 failed, 7 ignored; the difference is the new
operand_and_effect_spans_slice_back_each_instructions_lists and
split_block_copies_get_their_own_effect_spans). cargo clippy --workspace
--all-targets --locked -- -D warnings is clean. The allocation count and the ns
per instruction were not measured (no counting allocator in the tree).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:45 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 22:14 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-24 22:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1757#issuecomment-7145979350) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 23:05 UTC · original

NVIDIA counterpart to the RX 9060 XT runs: RTX 3070 8 GB, driver 616.56, Windows 11, debug, 29d5f6e (on main 70564ae). cargo test -p victory-shader --locked: 208 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures on main, so there are no new failures from the arena change.

AI-assisted (Claude Code). Synthetic tests only.

**@⁠upipibi** on GitHub · 2026-11-24 23:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1757#issuecomment-7146993959) NVIDIA counterpart to the RX 9060 XT runs: RTX 3070 8 GB, driver 616.56, Windows 11, debug, `29d5f6e` (on `main` `70564ae`). `cargo test -p victory-shader --locked`: 208 passed, 3 failed, 2 ignored. The 3 are #1744's NVIDIA heap-cap failures on `main`, so there are no new failures from the arena change. AI-assisted (Claude Code). Synthetic tests only.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:40 UTC · original · edited 2026-11-25 22:18 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs, ir.rs and structure.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: a green CI check at the head, and a before/after timing (e.g. translate over a synthetic corpus) for this wide refactor.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1757#issuecomment-7152141767) · edited 2026-11-25 22:18 UTC <!-- victory-triage v1 head=e18d930287b2865d39405997ac5be77bdd9ca032 verdict=needs-rebase at=2026-11-25T22:21:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`, `ir.rs` and `structure.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: a green CI `check` at the head, and a before/after timing (e.g. `translate` over a synthetic corpus) for this wide refactor. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/ir.rs
  • crates/victory-shader/src/structure.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1757/head:github-bot/gh-1757'
git switch 'github-bot/gh-1757'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1757'
git switch 'github-bot/gh-1757'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1757'
git switch 'github-bot/gh-1757'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1757'
git switch 'main'
git merge --squash 'github-bot/gh-1757'
git switch 'main'
git merge --ff-only 'github-bot/gh-1757'
git switch 'main'
git merge 'github-bot/gh-1757'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1757
No description provided.