shader: support scaled byte vertex fetches #49

Merged
shabouwcaw merged 1 commit from upstream-pr/49 into main 2026-11-27 13:05:59 +00:00
shabouwcaw commented 2026-11-26 11:30:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T11:30:54Z.


GFX10 vertex fetches using 8-bit USCALED/SSCALED formats currently stop translation with a vertex fetch format the host's vertex layout lacks. This supports the one-, two-, and four-channel byte formats, including partial loads, through the existing integer vertex layouts and explicit unsigned/signed integer-to-float conversion. For example, unsigned 255 becomes 255.0 and signed byte 0x80 becomes -128.0.

Conversion happens before rectangle reconstruction so the missing corner is computed as floating-point data. Integer and normalized fetches retain their existing paths. Wider and packed scaled formats remain refused. The instruction encodings were independently checked with LLVM's gfx1030 assembler; numeric conversion follows the existing scaled buffer decoder.

Related to #4. This fixes a demonstrated translator gap, but no game shaders were inspected or run, so it does not establish that any of the seven reported title shaders are fixed and does not close the issue.

Regression evidence

  • Before the implementation, a synthetic shader through the native graphics translator failed at the scaled tbuffer load (GFX10 code at 0x48). The original unsigned/signed unit reproducers also failed with the format refusal.
  • After: 3,584 actual Metal draws exercise all 256 byte values in every loaded channel of all six supported formats and every valid partial-load width. RGBA32_FLOAT readback is checked bit-for-bit, including sentinel values in untouched registers. The path includes translation, host input-layout mapping, Metal Shader Converter, vertex fetch, pixel output, and readback.
  • Signed and unsigned rectangle rendering matches an independent explicit four-corner float quad across every output pixel. Clear sentinels are checked to exclude undrawn results.
  • Translation tests cover wave32/wave64, normal/rectangle paths, integer input signatures, excessive channel counts, and retained refusals. Existing 42-format/partial-load tests still pass.
  • Temporary mutation checks: unsigned conversion substituted for signed fails at byte 128; treating scaled attributes as integers during rectangle reconstruction fails the pixel comparison. Both mutations were removed.

Local validation

All builds used nice and at most six jobs, with the configured Metal Shader Converter. The new GPU tests executed on Apple Silicon; they were not skipped.

  • cargo test -j6 --locked -p victory-shader -p victory-hle -p victory -p victory-gpu -p xtask: 506 passed, 0 failed, 4 ignored.
  • cargo test -j6 --locked --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 267 passed, 0 failed, 4 ignored, including all 16 native probes. Confirmed the probe executable is x86_64 Mach-O.
  • Windows-target workspace Clippy with --all-targets --locked -- -D warnings, both default and --all-features: passed.
  • Native macOS GPU-test Clippy: passed with existing warnings elsewhere; no diagnostics in the new test module.
  • Final focused GPU rerun after lint cleanup: 2 passed, including the exhaustive readbacks and rectangle comparisons.
  • cargo xtask policy: 366 files OK; new test-file formatting and git diff --check: passed.

The GPU tests follow the repository convention of skipping when Metal Shader Converter is absent. Windows CI covers shared translator tests, not Metal execution. No game content or SDK binaries are included; no depth/stencil or setup/launcher changes.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5509236707 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49). Originally posted by [shabouwcaw](https://github.com/shabouwcaw) on 2026-11-26T11:30:54Z. --- GFX10 vertex fetches using 8-bit USCALED/SSCALED formats currently stop translation with `a vertex fetch format the host's vertex layout lacks`. This supports the one-, two-, and four-channel byte formats, including partial loads, through the existing integer vertex layouts and explicit unsigned/signed integer-to-float conversion. For example, unsigned 255 becomes 255.0 and signed byte 0x80 becomes -128.0. Conversion happens before rectangle reconstruction so the missing corner is computed as floating-point data. Integer and normalized fetches retain their existing paths. Wider and packed scaled formats remain refused. The instruction encodings were independently checked with LLVM's gfx1030 assembler; numeric conversion follows the existing scaled buffer decoder. Related to #4. This fixes a demonstrated translator gap, but no game shaders were inspected or run, so it does not establish that any of the seven reported title shaders are fixed and does not close the issue. ### Regression evidence - Before the implementation, a synthetic shader through the native graphics translator failed at the scaled tbuffer load (`GFX10 code at 0x48`). The original unsigned/signed unit reproducers also failed with the format refusal. - After: **3,584 actual Metal draws** exercise all 256 byte values in every loaded channel of all six supported formats and every valid partial-load width. RGBA32_FLOAT readback is checked bit-for-bit, including sentinel values in untouched registers. The path includes translation, host input-layout mapping, Metal Shader Converter, vertex fetch, pixel output, and readback. - Signed and unsigned rectangle rendering matches an independent explicit four-corner float quad across every output pixel. Clear sentinels are checked to exclude undrawn results. - Translation tests cover wave32/wave64, normal/rectangle paths, integer input signatures, excessive channel counts, and retained refusals. Existing 42-format/partial-load tests still pass. - Temporary mutation checks: unsigned conversion substituted for signed fails at byte 128; treating scaled attributes as integers during rectangle reconstruction fails the pixel comparison. Both mutations were removed. ### Local validation All builds used `nice` and at most six jobs, with the configured Metal Shader Converter. The new GPU tests executed on Apple Silicon; they were not skipped. - `cargo test -j6 --locked -p victory-shader -p victory-hle -p victory -p victory-gpu -p xtask`: **506 passed, 0 failed, 4 ignored**. - `cargo test -j6 --locked --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: **267 passed, 0 failed, 4 ignored**, including all 16 native probes. Confirmed the probe executable is x86_64 Mach-O. - Windows-target workspace Clippy with `--all-targets --locked -- -D warnings`, both default and `--all-features`: passed. - Native macOS GPU-test Clippy: passed with existing warnings elsewhere; no diagnostics in the new test module. - Final focused GPU rerun after lint cleanup: **2 passed**, including the exhaustive readbacks and rectangle comparisons. - `cargo xtask policy`: **366 files OK**; new test-file formatting and `git diff --check`: passed. The GPU tests follow the repository convention of skipping when Metal Shader Converter is absent. Windows CI covers shared translator tests, not Metal execution. No game content or SDK binaries are included; no depth/stencil or setup/launcher changes.
LakshanSivakumar commented 2026-11-26 11:42:48 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:42:48Z.

Review: CHANGES_REQUESTED


Thanks for the synthetic readback tests. Two things:

  1. Rectangle reconstruction. A scaled attribute fetched before position can now pick the rectangle's right-angle corner (lower.rs:~11101). For example: positions (-1,-1), (1,-1), (-1,1) with an earlier scaled attribute of (10,0), (0,0), (0,10) reconstructs (-3,1) instead of (1,1). Please add a rectangle case that fetches scaled colour or UV before position, with the two implying different corners.
  2. Narrow formats. Please say whether wider opcodes on narrow scaled formats are refused on purpose, or pin their typed-load fill in a test. The RDNA ISA uses zero fill (X000/XY00) for typed loads, not the raw-buffer 0,0,0,1.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073547104 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#pullrequestreview-6073547104). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:42:48Z. **Review:** CHANGES_REQUESTED --- Thanks for the synthetic readback tests. Two things: 1. **Rectangle reconstruction.** A scaled attribute fetched *before* position can now pick the rectangle's right-angle corner (`lower.rs:~11101`). For example: positions `(-1,-1), (1,-1), (-1,1)` with an earlier scaled attribute of `(10,0), (0,0), (0,10)` reconstructs `(-3,1)` instead of `(1,1)`. Please add a rectangle case that fetches scaled colour or UV before position, with the two implying different corners. 2. **Narrow formats.** Please say whether wider opcodes on narrow scaled formats are refused on purpose, or pin their typed-load fill in a test. The RDNA ISA uses zero fill (`X000`/`XY00`) for typed loads, not the raw-buffer `0,0,0,1`.
LakshanSivakumar commented 2026-11-26 13:26:57 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T13:26:57Z.


Quick status ping: this PR now has merge conflicts with main, in addition to the two open items from the previous review (a rectangle test fetching a scaled attribute before position with distinct corners, and clarifying/pinning wider opcodes on narrow scaled formats). Please rebase on main and update when ready.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193366419 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#issuecomment-7193366419). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T13:26:57Z. --- Quick status ping: this PR now has merge conflicts with `main`, in addition to the two open items from the previous review (a rectangle test fetching a scaled attribute before position with distinct corners, and clarifying/pinning wider opcodes on narrow scaled formats). Please rebase on `main` and update when ready.
LakshanSivakumar commented 2026-11-26 16:31:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:31:12Z.

Review: CHANGES_REQUESTED


This no longer merges cleanly with main (conflicts, mainly in crates/victory-shader/src/emit/lower.rs and docs/native-host.md). Please merge main and re-run the tests. The two points from my earlier review still need an answer: a rectangle test that fetches a scaled attribute before position with the two implying different corners, and whether wider opcodes on narrow scaled formats are refused on purpose or pinned to zero fill (X000/XY00) in a test. I could not find either in the current head, so please point me at them if they are there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6077589826 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#pullrequestreview-6077589826). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:31:12Z. **Review:** CHANGES_REQUESTED --- This no longer merges cleanly with main (conflicts, mainly in crates/victory-shader/src/emit/lower.rs and docs/native-host.md). Please merge main and re-run the tests. The two points from my earlier review still need an answer: a rectangle test that fetches a scaled attribute before position with the two implying different corners, and whether wider opcodes on narrow scaled formats are refused on purpose or pinned to zero fill (X000/XY00) in a test. I could not find either in the current head, so please point me at them if they are there.
LakshanSivakumar commented 2026-11-26 16:31:22 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T16:31:22Z.


Correction: the conflicts are in crates/victory-shader/src/emit/gfx_refusal_tests.rs and docs/native-host.md (lower.rs merges automatically).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7197755223 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#issuecomment-7197755223). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T16:31:22Z. --- Correction: the conflicts are in crates/victory-shader/src/emit/gfx_refusal_tests.rs and docs/native-host.md (lower.rs merges automatically).
LakshanSivakumar commented 2026-11-26 17:08:47 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:08:47Z.


This conflicts with main in gfx_refusal_tests.rs and docs/native-host.md. Could you rebase it? The two earlier review points are also still open: the rectangle test with a scaled attribute fetched before position, and the narrow-format zero-fill question.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198565052 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#issuecomment-7198565052). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:08:47Z. --- This conflicts with main in `gfx_refusal_tests.rs` and `docs/native-host.md`. Could you rebase it? The two earlier review points are also still open: the rectangle test with a scaled attribute fetched before position, and the narrow-format zero-fill question.
LakshanSivakumar commented 2026-11-27 05:41:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T05:41:14Z.


This still needs a rebase on main (conflicts in gfx_refusal_tests.rs and docs/native-host.md) and the two review points: a rectangle test where a scaled attribute is fetched before position and the two imply different corners, and whether wider opcodes on narrow scaled formats are refused on purpose or pinned to zero fill. The numerics and the readback test look solid, so it is close.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7210851237 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/49#issuecomment-7210851237). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T05:41:14Z. --- This still needs a rebase on main (conflicts in gfx_refusal_tests.rs and docs/native-host.md) and the two review points: a rectangle test where a scaled attribute is fetched before position and the two imply different corners, and whether wider opcodes on narrow scaled formats are refused on purpose or pinned to zero fill. The numerics and the readback test look solid, so it is close.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
LakshanSivakumar/Native-Victory-macOS!49
No description provided.