CLI: translate --count counts the instructions of the emitted shaders #2115
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!2115
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2115"
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?
@r4tedx on GitHub · 2026-11-25 05:17 UTC · original
r4tedx:cli/translate-count→main· +781 −10 · 6 files · 7 commits · openSummary:
victory translate --countcounts the instructions of every emitted shader: the total, by stage and by kind. With--listit 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 recordsbitcode.rswrites) and countsmain: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 asfadd,fsub,fmul,fdivorfrem(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.
bitcastis 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
--validatethe 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 everytranslaterun, with or without--count.main
940d32fover the title'sshaders.rpfLocal 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.23,918 of the 25,591 validate, as without
--count. The largest kinds, recounted at2729d8ewith the float forms named apart (every total above is unchanged, and each pair sums to the shared count measured at4d34d76):bitcastselectfcmpandicmporaddextractvaluedx.op.tertiary.f32fmullshrdx.op.rawBufferLoad.f32phifsubdx.op.annotateHandlesubdx.op.createHandleFromHeapfadddx.op.getDimensionsmulfdivNo integer
sdiv/sremand nofremwere 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::withVICTORY_WARP=1: 6 passed (at2729d8e). 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 --checkon the changed files: clean.cargo xtask policy: ok.victory-shaderlib suite on WARP at2729d8e: 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 onmain940d32fon this machine's WARP. The PR changes no emitted byte.AI-assisted.
🤖 Generated with Claude Code
842b0cb) into the translate count branch 7a2e5f73dd@Dathinel on GitHub · 2026-11-25 05:29 UTC · original
One caveat for revision-to-revision comparisons: at
35cf1c44,translate --count missing bundleexits 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
retin the first and a barrier call plusretin the second. A clean scan exited 0 in both builds.AI-assisted. Synthetic inputs only.
@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: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:
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
pixelone.3. One line reads wrong in a report that is meant to be posted. Without
--validate, the stage lines say:— and a reader of a pasted report will take "0 validated" for "nothing passed".
--countdoes 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:
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. Thestructuredline'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;--listper-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
bitcastshould 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.
@r4tedx on GitHub · 2026-11-25 06:15 UTC · original
Thank you both. Head is now
4d34d76.@Dathinel: reproduced at
35cf1c4.translate --counton 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
--validatethe stage lines now readvalidation not checked, and without--pipelinespipelines not made:(the first without
--validate, the second with it). This changes the summary of everytranslaterun, not only--countones. Onbitcast: 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
@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
4d34d763ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
@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--listadds 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 themain.rsmerge keeps main'sOption<NonZeroUsize>jobs.CI: passing.
Generated by Claude Code
@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 themadd/fadd,sub/fsub,mul/fmul,sdiv/fdivandsrem/frem. LLVM's DXIL writerThe 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.
@r4tedx on GitHub · 2026-11-25 14:18 UTC · original
Addressed the triage point in
42121a86and2729d8e(on4d34d76): binary ops are now named from the first operand's type, the first of the two options in the triage note. A floatadd/sub/mul/sdiv/sremrecord is counted asfadd/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/faddbucket 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 in2729d8e, 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 halffmul, and checks that integer vectoradd/sdivand scalarsremstay integer.victory-shader,victory, all targets,-D warnings) is clean.cargo xtask policyis ok. Thevictorytests pass, 10 + 2.victory-shaderlib suite on WARP: 251 passed, 2 failed. The two failures aregathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out. Both fail the same way onmain940d32fon this machine's WARP, and this branch changes onlycounts.rs.The description now says how kinds are named. The title-data table in it was counted before this change, so its
addandmulrows hold both forms and are now labelledadd/faddandmul/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:38 UTC · original
Recount at
2729d8ewith the float forms named apart. The "largest kinds" table in the description now uses the split names. Every total is unchanged from4d34d76(25,591 emitted, 23,918 validated, 190,954,569 instructions, 3,213,914 blocks), and each pair adds up to the old shared row:add9,248,571 +fadd1,686,821 = 10,935,392;mul642,551 +fmul6,858,888 = 7,501,439;sub2,100,756 +fsub3,535,490 = 5,636,246;fdiv583,544, with no integersdivand nosrem/frem.Local title data, offline, CPU only (
translate --validate --list --count); counts only.AI-assisted
@r4tedx on GitHub · 2026-11-25 14:57 UTC · original
On the triage's non-blocking note (values not reset per
FUNCTION_BLOCK): addressed inb0f0b2e.Module::blockkeeps the length of the value table before eachFUNCTION_BLOCKand truncates back to it after the body, so each body starts from the module-level values only.counts_each_body_from_module_valuesreads a synthetic two-body bitstream throughcount(): the first body adds the i32 constant, the second the float constant, with the same relative id. It expects oneaddand onefadd; a value carried over from the first body would make bothadd.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-26 03:20 UTC · original
Merged main
842b0cbinto the branch (merge7a2e5f73, no force-push), head now4524dde1. It merges cleanly with currentmain63bcca4.apps/victory/src/main.rs: main changedjobstoOption<NonZeroUsize>, with new help text. This branch keeps main'sjobsand adds only itscountflag. The call is nowtranslate::run(paths, validate, pipelines, list, count, jobs.map(NonZeroUsize::get)). The summary wording ("validation not checked" / "pipelines not made") is unchanged.4524dde1): main's286a00e(the DXIL writer leaves out what no reader reaches) dropped the unused last values of twocounts::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.4524dde1:counts::tests withVICTORY_WARP=1: 7 passed, 0 failed;cargo test -p victory --bins: 14 passed;victoryandvictory-shader,--all-targets -D warnings: clean;cargo xtask policy: ok.Synthetic tests only for this update; no title data used.
AI-assisted
@DenRakEiw on GitHub · 2026-11-25 05:26 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory— 12 passed, 0 failedcargo clippy -p victory --all-targets— 0 warningscargo xtask policy— ok (184 files ok)Clean
translate --countinstruction counter for emitted DXIL shaders. Looks good.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 06:33 UTC · original · approved these changes
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.148 passed / 0 failed / 2 ignored. translate --count counts emitted-instruction instructions (+4 tests) — CLI metric accuracy; mixed apps+shader+docs.
@fuzeofficlal on GitHub · 2026-11-26 18:02 UTC · original · approved these changes
Looks good. Verified merged onto
main(63bcca43) on Windows 11:crates/victory-shader/src/emit/counts.rsaccurately parses the emitted DXIL bitcode afterModule::write()dead-code elimination, resets function-local value IDs perFUNCTION_BLOCK, distinguishes integer vs. float binary ops, and rejects abbreviated/malformed streams cleanly.cargo xtask policy(192 files ok),cargo clippy --locked -p victory-shader -p victory --all-targets -- -D warnings(default and--all-features), all 7emit::counts::tests::*tests invictory-shader, and all 18 tests invictorypass.Module::write()are not counted, malformed abbreviation widths (0/1) and non-containers return errors cleanly, andvictory translateCLI checks confirm--help,--count --cacheconflict rejection (exit 2), and--count/--count --list --jobs 2output formatting (validation not checked, pipelines not made).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.