gfx10: pin the operand widths to their opcode names #612

Open
qnjk wants to merge 1 commit from qnjk/Darner:gfx10-fields-tests into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited).

  • What it pins: the operand-sizing helpers in crates/darner-shader/src/gfx10/fields.rs — data_dwords, ds_pair, salu_dwords, valu_dwords, image_addr_dwords — decide how many dwords an instruction takes from its name, and the decoder trusts that answer for every later instruction in the stream. Their rules are non-obvious (a buffer_atomic_cmpswap carries two dwords, s_bfm_b64 is two dwords and its width comes from a suffix letter, ds_read2_b32 is a pair, an image address is 4 or 2 dwords by dimension and 1 more with a16 or a cl suffix), and no unit test existed for any of them.

  • This change adds five tests, one per helper, covering the opcode families each claims to size.

How it was tested

  • Tested revision: c933664 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-shader --lib gfx10:: — 21 passed (5 new plus the 16 existing in that module).
    • cargo clippy --locked -p darner-shader --all-targets -- -D warnings passes.
    • Fail-before (tests-only, so each rule was mutated in turn and the corresponding assertion watched failing; every mutation reverted with file copies, never git stash):
      • cmpswap sized n *= 3 → buffer_atomic_cmpswap … left: 3 right: 2
      • "read2" → "read3" → ds_read2_b32 fails
      • salu bm widths (2,1,1) → (2,2,1) → s_bfm_b64 fails
      • valu shift widths [1,2,2] → [2,2,2] → v_lshlrev_b64 fails
      • image DIMS row 7 (4,2) → (3,2), a16 div_ceil(2) → /2, and dropping the cl suffix each fail their own assertion.
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not green on this machine, and one of the reasons is worth a separate report — crates/darner-shader's oracle64::legacy_mul_forms_are_exact loops for bits in 0..=u32::MAX twice over ~104 constants (about 31 billion checks) and does not finish in debug here; I let it run over 45 minutes and stopped it. That test is untouched by this change and is pre-existing. With only it skipped, the suite is test result: ok. 572 passed; 0 failed; 16 ignored; 1 filtered out in 594 s. The other pre-existing blockers are the darner-gpu test deadlock (#224) and the emit::waterfall_tests fixture failure (#227).
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: not applicable — these are encoding widths, not wave shapes.
  • Hardware dependence: none.
  • Coverage gaps: image_sample_cd/_cd_cl/_c_cd/_c_cd_cl (0x68–0x6f) and the _g16 forms are not pinned. emit/lower.rs rejects them today and fields.rs treats cd as gradients without a compare dword; if the ISA's CD form carries a compare, that is a latent one-dword undercount, but it is unexercised and could not be proven from the tree, so it is reported rather than pinned or changed.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: 576 files ok).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-shader/src/gfx10/fields.rs (checked against the file list of all 189 open pull requests), and no open or closed issue mentions these helpers.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited). - What it pins: the operand-sizing helpers in `crates/darner-shader/src/gfx10/fields.rs` — `data_dwords`, `ds_pair`, `salu_dwords`, `valu_dwords`, `image_addr_dwords` — decide how many dwords an instruction takes from its **name**, and the decoder trusts that answer for every later instruction in the stream. Their rules are non-obvious (a `buffer_atomic_cmpswap` carries two dwords, `s_bfm_b64` is two dwords and its width comes from a suffix letter, `ds_read2_b32` is a pair, an image address is 4 or 2 dwords by dimension and 1 more with `a16` or a `cl` suffix), and no unit test existed for any of them. - This change adds five tests, one per helper, covering the opcode families each claims to size. ## How it was tested - Tested revision: `c933664` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-shader --lib gfx10::` — 21 passed (5 new plus the 16 existing in that module). - `cargo clippy --locked -p darner-shader --all-targets -- -D warnings` passes. - Fail-before (tests-only, so each rule was mutated in turn and the corresponding assertion watched failing; every mutation reverted with file copies, never `git stash`): - `cmpswap` sized `n *= 3` → `buffer_atomic_cmpswap … left: 3 right: 2` - `"read2"` → `"read3"` → `ds_read2_b32` fails - `salu` `bm` widths `(2,1,1)` → `(2,2,1)` → `s_bfm_b64` fails - `valu` shift widths `[1,2,2]` → `[2,2,2]` → `v_lshlrev_b64` fails - image DIMS row 7 `(4,2)` → `(3,2)`, `a16` `div_ceil(2)` → `/2`, and dropping the `cl` suffix each fail their own assertion. - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not green on this machine, and one of the reasons is worth a separate report — `crates/darner-shader`'s `oracle64::legacy_mul_forms_are_exact` loops `for bits in 0..=u32::MAX` twice over ~104 constants (about 31 billion checks) and does not finish in debug here; I let it run over 45 minutes and stopped it. That test is untouched by this change and is pre-existing. With only it skipped, the suite is `test result: ok. 572 passed; 0 failed; 16 ignored; 1 filtered out` in 594 s. The other pre-existing blockers are the `darner-gpu` test deadlock (#224) and the `emit::waterfall_tests` fixture failure (#227). - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: not applicable — these are encoding widths, not wave shapes. - Hardware dependence: none. - Coverage gaps: `image_sample_cd`/`_cd_cl`/`_c_cd`/`_c_cd_cl` (0x68–0x6f) and the `_g16` forms are not pinned. `emit/lower.rs` rejects them today and `fields.rs` treats `cd` as gradients without a compare dword; if the ISA's CD form carries a compare, that is a latent one-dword undercount, but it is unexercised and could not be proven from the tree, so it is reported rather than pinned or changed. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: 576 files ok). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-shader/src/gfx10/fields.rs` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions these helpers. - Replaces or overlaps: none found
`fields_raw` asks `data_dwords`, `ds_pair`, `salu_dwords`, `valu_dwords` and
`image_addr_dwords` for every operand width, and none of those widths is in the
encoding: each is read from the opcode name. A wrong answer is silent, because
the instruction then reads or writes the wrong registers, and an image address
one dword short makes `lower` lose the access with "an image address"
(`fields.rs:376` sizes `addr` from `image_addr_dwords`, and `lower.rs` reads it
by index), yet the module had no test for any of the five.

One table per helper now names the rule each exists for rather than one
representative opcode: the dword/xN/format/d16 and cmpswap tokens and the LDS
b96/b128 widths; the two-address LDS forms by token (`ds_read2st64_b64`, which
has no `read2_` prefix, and `ds_condxchg32_rtn_b64`, which takes one address);
the 64-bit scalar and vector rows whose trailing operand is 32 bits
(`s_lshl_b64`, `v_lshlrev_b64`, `v_ldexp_f64`, the `v_cvt_<dst>_<src>` rule,
`v_mqsad_u32_u8`); and the image dimension table, the offset/bias/compare,
gradient, LOD/clamp and a16 packing rules, `lz` not matching `l`, and the fixed
ray-tracing widths. Each table was checked to fail with a one-line mutation of
the rule it covers (`n *= 3` for cmpswap, `"read3"` for read2, `packed / 2` for
the a16 rounding, dropping `"cl"` from the packed token arm, and one row of the
salu, valu and `DIMS` tables).

No production code changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TrustNo1 changed title from [pr-tests][shaders] gfx10: pin the operand widths to their opcode names to gfx10: pin the operand widths to their opcode names 2026-12-06 03:26:16 +00:00
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 'gfx10-fields-tests:qnjk-gfx10-fields-tests'
git switch 'qnjk-gfx10-fields-tests'

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.

git switch 'Main'
git merge --no-ff 'qnjk-gfx10-fields-tests'
git switch 'qnjk-gfx10-fields-tests'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-gfx10-fields-tests'
git switch 'qnjk-gfx10-fields-tests'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-gfx10-fields-tests'
git switch 'Main'
git merge --squash 'qnjk-gfx10-fields-tests'
git switch 'Main'
git merge --ff-only 'qnjk-gfx10-fields-tests'
git switch 'Main'
git merge 'qnjk-gfx10-fields-tests'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
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
TrustNo1/Darner!612
No description provided.