CLI: translate --count counts the instructions of the emitted shaders #2115

Open
github-bot wants to merge 7 commits from github-bot/gh-2115 into main AGit
Owner

@⁠r4tedx on GitHub · 2026-11-25 05:17 UTC · original
r4tedx:cli/translate-count → main · +781 −10 · 6 files · 7 commits · open

Summary: victory translate --count counts the instructions of every emitted shader: the total, by stage and by kind. With --list it also prints a line per program. The report holds counts only, so it can be posted as it is.

Why

Three open PRs make the emitted DXIL smaller (#697, #1716, #1646), and triage asks each for "a benefit it can show". The repository has no shared number for that. This adds one, read from the container itself, so any revision of the translator can be compared with any other, program by program, next to the validator's verdict.

What it counts

emit::counts::of(container) reads the DXIL part's bitcode back (the unabbreviated records bitcode.rs writes) and counts main:

  • basic blocks
  • instructions, terminators among them
  • instructions by kind: LLVM's name of the instruction, and for a call the function called (dx.op.rawBufferLoad.f32, ...). LLVM shares one opcode between the integer and float forms of add, sub, mul, div and rem; the kind is taken from the first operand's type, so a float operation is counted as fadd, fsub, fmul, fdiv or frem (half, float, double, and vectors of them)

It counts what was written, not what a pass believes it wrote. A module with abbreviations (one DXC made) is refused, not miscounted.

The counts are static: one per instruction, however often it runs. They show what the translation adds and what a change takes out. They are not a measure of GPU time.

bitcast is counted like any other instruction: it is one in the module, and the host's compiler has to read it. It becomes no machine instruction, which is one more reason the count is not a measure of GPU time.

When comparing two revisions

  • A path that does not exist is skipped without a message and the run still exits 0 (existing scan behaviour, reported by @⁠Dathinel below; #517 makes it exit 1 and name the path). Until that lands, check that both listings have the same number of containers and programs before comparing their counts.
  • Without --validate the summary used to read "0 validated, 0 pipelines". After @⁠fiestorra's review the second commit makes it say "validation not checked" and "pipelines not made" when those checks were not asked for. This changes the summary of every translate run, with or without --count.

main 940d32f over the title's shaders.rpf

Local title data, offline, CPU only (translate --validate --list --count, dxil.dll 10.0.26100.0). Counts only; no names or data from the title are in this PR.

programs emitted instructions blocks
all 25,591 190,954,569 3,213,914
pixel 12,014 83,218,479 1,342,176
compute 2,621 66,145,610 1,232,982
mesh 8,765 37,272,912 571,098
vertex 2,191 4,317,568 67,658

23,918 of the 25,591 validate, as without --count. The largest kinds, recounted at 2729d8e with the float forms named apart (every total above is unchanged, and each pair sums to the shared count measured at 4d34d76):

instructions kind share
52,353,145 bitcast 27.4 %
17,571,950 select 9.2 %
13,519,677 fcmp 7.1 %
13,356,308 and 7.0 %
9,627,997 icmp 5.0 %
9,423,326 or 4.9 %
9,248,571 add 4.8 %
8,529,523 extractvalue 4.5 %
7,027,346 dx.op.tertiary.f32 3.7 %
6,858,888 fmul 3.6 %
6,015,504 lshr 3.2 %
4,973,419 dx.op.rawBufferLoad.f32 2.6 %
3,912,057 phi 2.0 %
3,535,490 fsub 1.9 %
2,244,896 dx.op.annotateHandle 1.2 %
2,100,756 sub 1.1 %
2,032,676 dx.op.createHandleFromHeap 1.1 %
1,686,821 fadd 0.9 %
915,828 dx.op.getDimensions 0.5 %
642,551 mul 0.3 %
583,544 fdiv 0.3 %

No integer sdiv/srem and no frem were emitted.

The console code of these programs is 40,601,701 IR instructions, so the translation writes 4.7 host instructions for each.

Checks

  • cargo test -p victory-shader counts:: with VICTORY_WARP=1: 6 passed (at 2729d8e). They are synthetic and use no device: a module holding every instruction the writer has (with an unread phi and a folded latch) counted exactly, each shared opcode in its integer and float form with the float typed by a constant, a call, a field, a cast, a load, a select and a phi (22 instructions, kinds summing to the total), half and vector operands, a whole container, the sum of two counts, and streams that are refused.
  • cargo test -p victory --bins translate: 1 passed. The new summary lines were read from a run on a path that does not exist, with and without --validate.
  • cargo clippy -p victory-shader -p victory --all-targets: clean.
  • rustfmt --edition 2024 --check on the changed files: clean. cargo xtask policy: ok.
  • Full victory-shader lib suite on WARP at 2729d8e: 251 passed, 2 failed (gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out), which fail the same way on main 940d32f on this machine's WARP. The PR changes no emitted byte.

AI-assisted.

🤖 Generated with Claude Code

**@⁠r4tedx** on GitHub · 2026-11-25 05:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115) `r4tedx:cli/translate-count` → `main` · +781 −10 · 6 files · 7 commits · open **Summary:** `victory translate --count` counts the instructions of every emitted shader: the total, by stage and by kind. With `--list` it also prints a line per program. The report holds counts only, so it can be posted as it is. ## Why Three open PRs make the emitted DXIL smaller (#697, #1716, #1646), and triage asks each for "a benefit it can show". The repository has no shared number for that. This adds one, read from the container itself, so any revision of the translator can be compared with any other, program by program, next to the validator's verdict. ## What it counts `emit::counts::of(container)` reads the DXIL part's bitcode back (the unabbreviated records `bitcode.rs` writes) and counts `main`: - basic blocks - instructions, terminators among them - instructions by kind: LLVM's name of the instruction, and for a call the function called (`dx.op.rawBufferLoad.f32`, ...). LLVM shares one opcode between the integer and float forms of add, sub, mul, div and rem; the kind is taken from the first operand's type, so a float operation is counted as `fadd`, `fsub`, `fmul`, `fdiv` or `frem` (half, float, double, and vectors of them) It counts what was written, not what a pass believes it wrote. A module with abbreviations (one DXC made) is refused, not miscounted. The counts are static: one per instruction, however often it runs. They show what the translation adds and what a change takes out. They are not a measure of GPU time. `bitcast` is counted like any other instruction: it is one in the module, and the host's compiler has to read it. It becomes no machine instruction, which is one more reason the count is not a measure of GPU time. ## When comparing two revisions - A path that does not exist is skipped without a message and the run still exits 0 (existing scan behaviour, reported by @⁠Dathinel below; #517 makes it exit 1 and name the path). Until that lands, check that both listings have the same number of containers and programs before comparing their counts. - Without `--validate` the summary used to read "0 validated, 0 pipelines". After @⁠fiestorra's review the second commit makes it say "validation not checked" and "pipelines not made" when those checks were not asked for. This changes the summary of every `translate` run, with or without `--count`. ## main `940d32f` over the title's `shaders.rpf` Local title data, offline, CPU only (`translate --validate --list --count`, dxil.dll 10.0.26100.0). Counts only; no names or data from the title are in this PR. | | programs emitted | instructions | blocks | | --- | ---: | ---: | ---: | | all | 25,591 | 190,954,569 | 3,213,914 | | pixel | 12,014 | 83,218,479 | 1,342,176 | | compute | 2,621 | 66,145,610 | 1,232,982 | | mesh | 8,765 | 37,272,912 | 571,098 | | vertex | 2,191 | 4,317,568 | 67,658 | 23,918 of the 25,591 validate, as without `--count`. The largest kinds, recounted at `2729d8e` with the float forms named apart (every total above is unchanged, and each pair sums to the shared count measured at `4d34d76`): | instructions | kind | share | | ---: | --- | ---: | | 52,353,145 | `bitcast` | 27.4 % | | 17,571,950 | `select` | 9.2 % | | 13,519,677 | `fcmp` | 7.1 % | | 13,356,308 | `and` | 7.0 % | | 9,627,997 | `icmp` | 5.0 % | | 9,423,326 | `or` | 4.9 % | | 9,248,571 | `add` | 4.8 % | | 8,529,523 | `extractvalue` | 4.5 % | | 7,027,346 | `dx.op.tertiary.f32` | 3.7 % | | 6,858,888 | `fmul` | 3.6 % | | 6,015,504 | `lshr` | 3.2 % | | 4,973,419 | `dx.op.rawBufferLoad.f32` | 2.6 % | | 3,912,057 | `phi` | 2.0 % | | 3,535,490 | `fsub` | 1.9 % | | 2,244,896 | `dx.op.annotateHandle` | 1.2 % | | 2,100,756 | `sub` | 1.1 % | | 2,032,676 | `dx.op.createHandleFromHeap` | 1.1 % | | 1,686,821 | `fadd` | 0.9 % | | 915,828 | `dx.op.getDimensions` | 0.5 % | | 642,551 | `mul` | 0.3 % | | 583,544 | `fdiv` | 0.3 % | No integer `sdiv`/`srem` and no `frem` were emitted. The console code of these programs is 40,601,701 IR instructions, so the translation writes 4.7 host instructions for each. ## Checks - `cargo test -p victory-shader counts::` with `VICTORY_WARP=1`: 6 passed (at `2729d8e`). They are synthetic and use no device: a module holding every instruction the writer has (with an unread phi and a folded latch) counted exactly, each shared opcode in its integer and float form with the float typed by a constant, a call, a field, a cast, a load, a select and a phi (22 instructions, kinds summing to the total), half and vector operands, a whole container, the sum of two counts, and streams that are refused. - `cargo test -p victory --bins translate`: 1 passed. The new summary lines were read from a run on a path that does not exist, with and without `--validate`. - `cargo clippy -p victory-shader -p victory --all-targets`: clean. - `rustfmt --edition 2024 --check` on the changed files: clean. `cargo xtask policy`: ok. - Full `victory-shader` lib suite on WARP at `2729d8e`: 251 passed, 2 failed (`gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`), which fail the same way on `main` `940d32f` on this machine's WARP. The PR changes no emitted byte. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The emitted DXIL's `main` is read back from the container (the
unabbreviated records the writer makes) and counted: blocks, and
instructions by kind, a call by the function called. `translate --count`
prints the total, by stage and by kind; with `--list`, a line per
program. The report holds counts only.

So a change to the translation shows what it takes out of the code the
host's compiler is given, program by program, next to the validator's
verdict on each.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Without `--validate` the summary read "0 validated", and without
`--pipelines` "0 pipelines": zeros that a reader of a pasted report takes
for "none passed". The lines now say "validation not checked" and
"pipelines not made" for a check nobody asked for (review of #2115).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The writer test now runs each shared binary opcode it has in both forms
(add, sub, mul, udiv, sdiv, urem against fadd, fsub, fmul, fdiv), with
the float operands typed by a constant, a call's result, a field, a
cast, a load, a select and a phi, and integer ops after the floats so a
value id off by one would name one wrongly. It checks that the kinds
add up to the instruction total (22 in 2 blocks).

The record test adds a scalar half, an integer vector and a scalar
integer srem, which stay integer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main's 286a00e9 writes only instructions with effects and what they
read. The tests' last values were read by nothing, so the writer left
them out with all they read. Both tests now store them, and count the
stores, to keep every instruction they name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:55:17 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 05:29 UTC · original

One caveat for revision-to-revision comparisons: at 35cf1c44, translate --count missing bundle exits 0 when the first input does not exist. It prints the valid bundle's totals with no missing-path diagnostic. I checked the same command after locally merging #517 (d8cd94a2): the totals were preserved, stderr named the missing path, and the exit status was 1. The branches merged cleanly. This is existing scan behavior; the counting code can stay independent.

The synthetic bundle contained an end-only compute program, a barrier then end, and a byte-identical copy of the first. With either 1 or 3 jobs, both builds reported 3 instructions in 2 blocks across 2 emitted programs. SDK DXC disassembly showed one ret in the first and a barrier call plus ret in the second. A clean scan exited 0 in both builds.

AI-assisted. Synthetic inputs only.

**@⁠Dathinel** on GitHub · 2026-11-25 05:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7153830198) One caveat for revision-to-revision comparisons: at `35cf1c44`, `translate --count missing bundle` exits **0** when the first input does not exist. It prints the valid bundle's totals with no missing-path diagnostic. I checked the same command after locally merging #517 (`d8cd94a2`): the totals were preserved, stderr named the missing path, and the exit status was **1**. The branches merged cleanly. This is existing scan behavior; the counting code can stay independent. The synthetic bundle contained an end-only compute program, a barrier then end, and a byte-identical copy of the first. With either 1 or 3 jobs, both builds reported 3 instructions in 2 blocks across 2 emitted programs. SDK DXC disassembly showed one `ret` in the first and a barrier call plus `ret` in the second. A clean scan exited 0 in both builds. AI-assisted. Synthetic inputs only.
Author
Owner

@⁠fiestorra on GitHub · 2026-11-25 06:02 UTC · original

Reviewed by running it twice: the number reproduces exactly, it adds up, and one line reads wrong in a report meant to be quoted

This is the shared number my own triage has been missing: I have been comparing revisions by "programs that validate" and nothing else, and a count of what the host's compiler is actually handed is the metric several of the open pull requests need. So I checked the three things that make such a number usable.

1. It reproduces. Two runs over the same local 1.0.2.1 archive (26,503 containers), translate --count --jobs 10:

host code 190,954,569 instructions in 3,213,914 blocks of 25,591 emitted programs
host code 190,954,569 instructions in 3,213,914 blocks of 25,591 emitted programs

Byte-identical lines, and the top of the by-kind table in the same order on both runs. A metric that moves between runs is not a metric.

2. It adds up. The stage lines sum to the total exactly:

compute  66,145,610 in 1,232,982 blocks of 2,621 programs
mesh     37,272,912 in   571,098 blocks of 8,765 programs
pixel    83,218,479 in 1,342,176 blocks of 12,014 programs
vertex    4,317,568 in    67,658 blocks of 2,191 programs
        ───────────
        190,954,569

I checked that because a breakdown that does not sum is worse than no breakdown — and I checked it before writing this, having first convinced myself the vertex line was missing when it was only below the pixel one.

3. One line reads wrong in a report that is meant to be posted. Without --validate, the stage lines say:

14205 emitted of 14247 vertex and pixel programs; 0 validated, 0 pipelines

— and a reader of a pasted report will take "0 validated" for "nothing passed". --count does not validate, so the honest thing is to say not checked when the validator is not asked for, rather than a zero that means "we did not look". That is the one change I would ask for before this becomes the repository's number: the whole point is that someone can paste it into a triage thread without a caveat.

Two smaller notes, both positive:

  • it counts from the emitted container (counts::of(&shader.dxil)), not from the translator's internal structures, which is what makes it comparable across revisions of the translator — the thing the description asks for. The structured line's IR instructions (40,601,701 here) and this host count (190,954,569) are different quantities and it is worth keeping the words "host" and "IR" in front of them exactly as they are;
  • counts only, no names: the report is postable as it stands, which matters given this repository's rule about game-derived text. I would keep the --list per-program lines behind the flag as they are now, since those do carry names.

What I did not verify: that the counter is right instruction by instruction — I checked that it is deterministic, that it partitions correctly by stage, and that the kinds are plausible (bitcast, select, fcmp, and, add at the top). Whether bitcast should count as an instruction at all is a judgement for the author; it is 52 million of the 190 million, so it is worth a sentence in the description either way.

No game data is involved: counts and instruction kinds.

Written with an AI assistant.

**@⁠fiestorra** on GitHub · 2026-11-25 06:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7154376551) **Reviewed by running it twice: the number reproduces exactly, it adds up, and one line reads wrong in a report meant to be quoted** This is the shared number my own triage has been missing: I have been comparing revisions by "programs that validate" and nothing else, and a count of what the host's compiler is actually handed is the metric several of the open pull requests need. So I checked the three things that make such a number usable. **1. It reproduces.** Two runs over the same local 1.0.2.1 archive (26,503 containers), `translate --count --jobs 10`: ``` host code 190,954,569 instructions in 3,213,914 blocks of 25,591 emitted programs host code 190,954,569 instructions in 3,213,914 blocks of 25,591 emitted programs ``` Byte-identical lines, and the top of the by-kind table in the same order on both runs. A metric that moves between runs is not a metric. **2. It adds up.** The stage lines sum to the total exactly: ``` compute 66,145,610 in 1,232,982 blocks of 2,621 programs mesh 37,272,912 in 571,098 blocks of 8,765 programs pixel 83,218,479 in 1,342,176 blocks of 12,014 programs vertex 4,317,568 in 67,658 blocks of 2,191 programs ─────────── 190,954,569 ``` I checked that because a breakdown that does not sum is worse than no breakdown — and I checked it *before* writing this, having first convinced myself the vertex line was missing when it was only below the `pixel` one. **3. One line reads wrong in a report that is meant to be posted.** Without `--validate`, the stage lines say: ``` 14205 emitted of 14247 vertex and pixel programs; 0 validated, 0 pipelines ``` — and a reader of a pasted report will take "0 validated" for "nothing passed". `--count` does not validate, so the honest thing is to say **not checked** when the validator is not asked for, rather than a zero that means "we did not look". That is the one change I would ask for before this becomes the repository's number: the whole point is that someone can paste it into a triage thread without a caveat. Two smaller notes, both positive: - **it counts from the emitted container** (`counts::of(&shader.dxil)`), not from the translator's internal structures, which is what makes it comparable across revisions of the translator — the thing the description asks for. The `structured` line's *IR* instructions (40,601,701 here) and this host count (190,954,569) are different quantities and it is worth keeping the words "host" and "IR" in front of them exactly as they are; - **counts only, no names**: the report is postable as it stands, which matters given this repository's rule about game-derived text. I would keep the `--list` per-program lines behind the flag as they are now, since those do carry names. What I did not verify: that the counter is right instruction by instruction — I checked that it is deterministic, that it partitions correctly by stage, and that the kinds are plausible (bitcast, select, fcmp, and, add at the top). Whether `bitcast` should count as an instruction at all is a judgement for the author; it is 52 million of the 190 million, so it is worth a sentence in the description either way. No game data is involved: counts and instruction kinds. Written with an AI assistant.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 06:15 UTC · original

Thank you both. Head is now 4d34d76.

@⁠Dathinel: reproduced at 35cf1c4. translate --count on a path that does not exist prints zero totals and exits 0, with no message. As you say, that is the scan's behaviour and not the count's, and #517 is the right place for it. The description now tells anyone comparing two revisions to check that both listings hold the same number of containers and programs. Your synthetic result (3 instructions in 2 blocks over 2 emitted programs, the duplicate skipped) is what the counter should give.

@⁠fiestorra: done in the second commit. Without --validate the stage lines now read validation not checked, and without --pipelines pipelines not made:

DXIL         0 emitted of 0 vertex and pixel programs; validation not checked, pipelines not made
DXIL         0 emitted of 0 vertex and pixel programs; 0 validated, pipelines not made

(the first without --validate, the second with it). This changes the summary of every translate run, not only --count ones. On bitcast: it stays in the count, because it is an instruction in the module and the host's compiler has to read it. The description now says that it becomes no machine instruction.

What I ran for this update: the two runs above on a path that does not exist (no input read), cargo test -p victory --bins translate (1 passed) and clippy. The title's data was not used for it; the counts in the description are from the earlier offline run over local title data.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7154609583) Thank you both. Head is now `4d34d76`. @⁠Dathinel: reproduced at `35cf1c4`. `translate --count` on a path that does not exist prints zero totals and exits 0, with no message. As you say, that is the scan's behaviour and not the count's, and #517 is the right place for it. The description now tells anyone comparing two revisions to check that both listings hold the same number of containers and programs. Your synthetic result (3 instructions in 2 blocks over 2 emitted programs, the duplicate skipped) is what the counter should give. @⁠fiestorra: done in the second commit. Without `--validate` the stage lines now read `validation not checked`, and without `--pipelines` `pipelines not made`: ``` DXIL 0 emitted of 0 vertex and pixel programs; validation not checked, pipelines not made DXIL 0 emitted of 0 vertex and pixel programs; 0 validated, pipelines not made ``` (the first without `--validate`, the second with it). This changes the summary of every `translate` run, not only `--count` ones. On `bitcast`: it stays in the count, because it is an instruction in the module and the host's compiler has to read it. The description now says that it becomes no machine instruction. What I ran for this update: the two runs above on a path that does not exist (no input read), `cargo test -p victory --bins translate` (1 passed) and clippy. The title's data was not used for it; the counts in the description are from the earlier offline run over local title data. AI-assisted
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:41 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 4d34d763 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7157360715) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 4d34d763 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:43 UTC · original · edited 2026-11-26 04:22 UTC

Automated triage for the maintainers.

Merge candidate. Now merges cleanly. This adds translate --count: a small reader for the bitcode VIctory itself writes (emit/counts.rs) counts the instructions and blocks of every emitted shader by stage and kind, and --list adds a per-program line. It prints counts only, no names, so reports can be posted. The tests use synthetic bitcode and check exact totals and kind names, and the main.rs merge keeps main's Option<NonZeroUsize> jobs.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7160096244) · edited 2026-11-26 04:22 UTC <!-- victory-triage v1 head=4524dde155cac775b7376e55b6b4e7e59b4fc9aa verdict=merge-candidate at=2026-11-26T04:22:18Z --> Automated triage for the maintainers. **Merge candidate.** Now merges cleanly. This adds `translate --count`: a small reader for the bitcode VIctory itself writes (`emit/counts.rs`) counts the instructions and blocks of every emitted shader by stage and kind, and `--list` adds a per-program line. It prints counts only, no names, so reports can be posted. The tests use synthetic bitcode and check exact totals and kind names, and the `main.rs` merge keeps main's `Option<NonZeroUsize>` jobs. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 13:34 UTC · original

I addressed the instruction labels in the review with 1cf8787 on 4d34d76. The emitted bitcode uses the same code for both members of five integer and floating-point pairs, so the table names them add/fadd, sub/fsub, mul/fmul, sdiv/fdiv and srem/frem. LLVM's DXIL writer

The expanded synthetic emitter test has two integer additions, one floating-point addition, and one each of floating-point subtract, multiply and divide. The old reader reports those under integer-only names. The changed reader reports the shared buckets and preserves the 27-instruction total. All four count tests, strict workspace Clippy and the asset policy passed on Windows.

Please preserve the Git author if you take the commit. Claim. AI-assisted with Codex. Synthetic bitcode only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 13:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7163985012) I addressed the instruction labels in [the review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2115) with [1cf8787](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/1cf87873ea42006525f276ac8a29ebc2c5b38c05) on `4d34d76`. The emitted bitcode uses the same code for both members of five integer and floating-point pairs, so the table names them `add/fadd`, `sub/fsub`, `mul/fmul`, `sdiv/fdiv` and `srem/frem`. [LLVM's DXIL writer](https://llvm.org/doxygen/DXILBitcodeWriter_8cpp_source.html#l00477) The expanded synthetic emitter test has two integer additions, one floating-point addition, and one each of floating-point subtract, multiply and divide. The old reader reports those under integer-only names. The changed reader reports the shared buckets and preserves the 27-instruction total. All four count tests, strict workspace Clippy and the asset policy passed on Windows. Please preserve the Git author if you take the commit. [Claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). AI-assisted with Codex. Synthetic bitcode only.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 14:18 UTC · original

Addressed the triage point in 42121a86 and 2729d8e (on 4d34d76): binary ops are now named from the first operand's type, the first of the two options in the triage note. A float add/sub/mul/sdiv/srem record is counted as fadd/fsub/fmul/fdiv/frem. Half, float and double count as float, and a vector counts by its element type. udiv, urem, the shifts and the logic ops stay integer, because they have no float form.

Why this option and not a combined label: the count is for comparing two translator revisions, and float and integer arithmetic move for different reasons. An add/fadd bucket would hide which of the two changed, and the label would become part of the printed format.

@⁠andrewpozdnakov7-jpg, thanks for 1cf8787. I did not take the commit, since it implements the combined-label option, so your authorship question does not come up. Two ideas from its test are in 2729d8e, written separately: a float that gets its type from a cast, and checking that the kinds sum to the exact total.

Verified at 2729d8e (synthetic only, no title data):

  • counts:: tests (VICTORY_WARP=1): 6 passed. The writer test runs each shared opcode in its integer and float forms. The float operand gets its type from a constant, a call result, an extracted field, a bitcast, a load, a select and a phi. An integer add follows the floats, so an off-by-one value id would show up as a wrong name. The test has 22 instructions in 2 blocks, and the kinds sum to that total. The record-level test adds a half fmul, and checks that integer vector add/sdiv and scalar srem stay integer.
  • Clippy (victory-shader, victory, all targets, -D warnings) is clean. cargo xtask policy is ok. The victory tests pass, 10 + 2.
  • Full victory-shader lib suite on WARP: 251 passed, 2 failed. The two failures are gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out. Both fail the same way on main 940d32f on this machine's WARP, and this branch changes only counts.rs.

The description now says how kinds are named. The title-data table in it was counted before this change, so its add and mul rows hold both forms and are now labelled add/fadd and mul/fmul. The other rows are unaffected. A recount with the split names will replace that table. It will hold counts only, from local title data, offline.

AI-assisted.

**@⁠r4tedx** on GitHub · 2026-11-25 14:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7165081037) Addressed the triage point in `42121a86` and `2729d8e` (on `4d34d76`): binary ops are now named from the first operand's type, the first of the two options in the triage note. A float `add`/`sub`/`mul`/`sdiv`/`srem` record is counted as `fadd`/`fsub`/`fmul`/`fdiv`/`frem`. Half, float and double count as float, and a vector counts by its element type. `udiv`, `urem`, the shifts and the logic ops stay integer, because they have no float form. Why this option and not a combined label: the count is for comparing two translator revisions, and float and integer arithmetic move for different reasons. An `add/fadd` bucket would hide which of the two changed, and the label would become part of the printed format. @⁠andrewpozdnakov7-jpg, thanks for `1cf8787`. I did not take the commit, since it implements the combined-label option, so your authorship question does not come up. Two ideas from its test are in `2729d8e`, written separately: a float that gets its type from a cast, and checking that the kinds sum to the exact total. Verified at `2729d8e` (synthetic only, no title data): - `counts::` tests (`VICTORY_WARP=1`): 6 passed. The writer test runs each shared opcode in its integer and float forms. The float operand gets its type from a constant, a call result, an extracted field, a bitcast, a load, a select and a phi. An integer add follows the floats, so an off-by-one value id would show up as a wrong name. The test has 22 instructions in 2 blocks, and the kinds sum to that total. The record-level test adds a half `fmul`, and checks that integer vector `add`/`sdiv` and scalar `srem` stay integer. - Clippy (`victory-shader`, `victory`, all targets, `-D warnings`) is clean. `cargo xtask policy` is ok. The `victory` tests pass, 10 + 2. - Full `victory-shader` lib suite on WARP: 251 passed, 2 failed. The two failures are `gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`. Both fail the same way on `main` `940d32f` on this machine's WARP, and this branch changes only `counts.rs`. The description now says how kinds are named. The title-data table in it was counted before this change, so its `add` and `mul` rows hold both forms and are now labelled `add/fadd` and `mul/fmul`. The other rows are unaffected. A recount with the split names will replace that table. It will hold counts only, from local title data, offline. AI-assisted.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 14:38 UTC · original

Recount at 2729d8e with the float forms named apart. The "largest kinds" table in the description now uses the split names. Every total is unchanged from 4d34d76 (25,591 emitted, 23,918 validated, 190,954,569 instructions, 3,213,914 blocks), and each pair adds up to the old shared row: add 9,248,571 + fadd 1,686,821 = 10,935,392; mul 642,551 + fmul 6,858,888 = 7,501,439; sub 2,100,756 + fsub 3,535,490 = 5,636,246; fdiv 583,544, with no integer sdiv and no srem/frem.

Local title data, offline, CPU only (translate --validate --list --count); counts only.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 14:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7165604527) Recount at `2729d8e` with the float forms named apart. The "largest kinds" table in the description now uses the split names. Every total is unchanged from `4d34d76` (25,591 emitted, 23,918 validated, 190,954,569 instructions, 3,213,914 blocks), and each pair adds up to the old shared row: `add` 9,248,571 + `fadd` 1,686,821 = 10,935,392; `mul` 642,551 + `fmul` 6,858,888 = 7,501,439; `sub` 2,100,756 + `fsub` 3,535,490 = 5,636,246; `fdiv` 583,544, with no integer `sdiv` and no `srem`/`frem`. Local title data, offline, CPU only (`translate --validate --list --count`); counts only. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 14:57 UTC · original

On the triage's non-blocking note (values not reset per FUNCTION_BLOCK): addressed in b0f0b2e.

  • Module::block keeps the length of the value table before each FUNCTION_BLOCK and truncates back to it after the body, so each body starts from the module-level values only.
  • New test counts_each_body_from_module_values reads a synthetic two-body bitstream through count(): the first body adds the i32 constant, the second the float constant, with the same relative id. It expects one add and one fadd; a value carried over from the first body would make both add.

Checked: the count tests pass under WARP with one test thread (7 passed), clippy has no warnings, and the asset-policy hook passes. Synthetic test only; no title data was used for this change.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7166075120) On the triage's non-blocking note (values not reset per `FUNCTION_BLOCK`): addressed in b0f0b2e. - `Module::block` keeps the length of the value table before each `FUNCTION_BLOCK` and truncates back to it after the body, so each body starts from the module-level values only. - New test `counts_each_body_from_module_values` reads a synthetic two-body bitstream through `count()`: the first body adds the i32 constant, the second the float constant, with the same relative id. It expects one `add` and one `fadd`; a value carried over from the first body would make both `add`. Checked: the count tests pass under WARP with one test thread (7 passed), clippy has no warnings, and the asset-policy hook passes. Synthetic test only; no title data was used for this change. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-26 03:20 UTC · original

Merged main 842b0cb into the branch (merge 7a2e5f73, no force-push), head now 4524dde1. It merges cleanly with current main 63bcca4.

  • The conflict was in apps/victory/src/main.rs: main changed jobs to Option<NonZeroUsize>, with new help text. This branch keeps main's jobs and adds only its count flag. The call is now translate::run(paths, validate, pipelines, list, count, jobs.map(NonZeroUsize::get)). The summary wording ("validation not checked" / "pipelines not made") is unchanged.
  • A test fix (4524dde1): main's 286a00e (the DXIL writer leaves out what no reader reaches) dropped the unused last values of two counts:: tests, together with everything they read. Both tests now store those values and count the stores, so every instruction they name stays in the module. The counting code itself is unchanged.
  • Checks at 4524dde1:
    • counts:: tests with VICTORY_WARP=1: 7 passed, 0 failed;
    • cargo test -p victory --bins: 14 passed;
    • clippy on victory and victory-shader, --all-targets -D warnings: clean;
    • cargo xtask policy: ok.

Synthetic tests only for this update; no title data used.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-26 03:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2115#issuecomment-7181631628) Merged main `842b0cb` into the branch (merge `7a2e5f73`, no force-push), head now **`4524dde1`**. It merges cleanly with current `main` `63bcca4`. - **The conflict** was in `apps/victory/src/main.rs`: main changed `jobs` to `Option<NonZeroUsize>`, with new help text. This branch keeps main's `jobs` and adds only its `count` flag. The call is now `translate::run(paths, validate, pipelines, list, count, jobs.map(NonZeroUsize::get))`. The summary wording ("validation not checked" / "pipelines not made") is unchanged. - **A test fix** (`4524dde1`): main's 286a00e (the DXIL writer leaves out what no reader reaches) dropped the unused last values of two `counts::` tests, together with everything they read. Both tests now store those values and count the stores, so every instruction they name stays in the module. The counting code itself is unchanged. - **Checks at `4524dde1`:** - `counts::` tests with `VICTORY_WARP=1`: 7 passed, 0 failed; - `cargo test -p victory --bins`: 14 passed; - clippy on `victory` and `victory-shader`, `--all-targets -D warnings`: clean; - `cargo xtask policy`: ok. Synthetic tests only for this update; no title data used. AI-assisted
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2115'
git switch 'github-bot/gh-2115'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2115'
git switch 'github-bot/gh-2115'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2115'
git switch 'main'
git merge --squash 'github-bot/gh-2115'
git switch 'main'
git merge --ff-only 'github-bot/gh-2115'
git switch 'main'
git merge 'github-bot/gh-2115'
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!2115
No description provided.