Shader: LDS bytes and halves, constant sample offsets, descriptor-data reasons #383

Closed
xmvo wants to merge 2 commits from upstream-pr/383 into main
xmvo commented 2026-11-24 02:49:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by xmvo on 2026-11-24T02:49:04Z.


Builds on #318 (its commit is the first of the two here); merge that first, or this one instead of it.

What

LDS bytes and halves. ds_read_{u,i}{8,16}, ds_write_b{8,16} and their _d16 / _d16_hi forms now lower within their dword:

  • reads load the dword, shift by the byte offset and zero- or sign-extend; d16 forms keep the VGPR's other half,
  • writes clear then set their bits with two atomics (and, then or), so lanes writing other bytes of the same dword keep theirs.

Constant sample offsets. image_sample_o, image_sample_lz_o and image_sample_l_o pass a constant offset word as the sample's immediate offsets. A computed word, or an offset outside -8..7, stops the program with its own reason. image_sample_l(_o) now reads its level after the extra words (it assumed none).

Descriptor data. A buffer descriptor read as data and by s_buffer_load is now sized from its raw SRV, as buffer-instruction uses already were. The other paths that returned "a scalar memory read as data" now each have their own reason. The title's census stopped 573 programs with that message, and this tells the causes apart.

Adds BitcodeModule::int_value (an integer constant's value).

Census buckets addressed

Reason Programs
an LDS write of bytes or halves 9
an LDS read of bytes or halves 7
image_sample_o 4
a scalar memory read as data 573 (split into specific reasons; the s_buffer_load + raw SRV case translates)

Testing

  • lds_byte_and_half_writes_keep_the_rest_of_the_dword / lds_byte_and_half_reads_extend_as_the_console (valu_tests): validated by dxil.dll and run on the hardware device. They need a one-wave group with LDS, which takes the console's wave size, and WARP can't run that, so run_cases_on lets these choose backends.
  • New image_tests module: a synthetic program loads a UAV, a 4×4 texture and a sampler from tables and samples it. Validated, then run on hardware and WARP:
    • image_sample_lz_o with a constant offset,
    • image_sample_l_o (level after the offset word),
    • image_sample_l_o with a16: coordinates in the VGPR after the offset word (the #318 layout; the old k / 2 read the offset word as u, v),
    • image_sample_d_cl (coordinates after the gradients, then the clamp).
  • cargo test -p victory-shader: 76 pass (hardware: RTX 3060). cargo clippy -p victory-shader and rustfmt clean.
  • Not yet re-run against the title's census.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573491684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383). Originally posted by [xmvo](https://github.com/xmvo) on 2026-11-24T02:49:04Z. --- Builds on #318 (its commit is the first of the two here); merge that first, or this one instead of it. ## What **LDS bytes and halves.** `ds_read_{u,i}{8,16}`, `ds_write_b{8,16}` and their `_d16` / `_d16_hi` forms now lower within their dword: - reads load the dword, shift by the byte offset and zero- or sign-extend; d16 forms keep the VGPR's other half, - writes clear then set their bits with two atomics (`and`, then `or`), so lanes writing other bytes of the same dword keep theirs. **Constant sample offsets.** `image_sample_o`, `image_sample_lz_o` and `image_sample_l_o` pass a constant offset word as the sample's immediate offsets. A computed word, or an offset outside -8..7, stops the program with its own reason. `image_sample_l(_o)` now reads its level after the extra words (it assumed none). **Descriptor data.** A buffer descriptor read as data *and* by `s_buffer_load` is now sized from its raw SRV, as buffer-instruction uses already were. The other paths that returned "a scalar memory read as data" now each have their own reason. The title's census stopped 573 programs with that message, and this tells the causes apart. Adds `BitcodeModule::int_value` (an integer constant's value). ## Census buckets addressed | Reason | Programs | |---|---| | an LDS write of bytes or halves | 9 | | an LDS read of bytes or halves | 7 | | image_sample_o | 4 | | a scalar memory read as data | 573 (split into specific reasons; the `s_buffer_load` + raw SRV case translates) | ## Testing - `lds_byte_and_half_writes_keep_the_rest_of_the_dword` / `lds_byte_and_half_reads_extend_as_the_console` (valu_tests): validated by dxil.dll and run on the hardware device. They need a one-wave group with LDS, which takes the console's wave size, and WARP can't run that, so `run_cases_on` lets these choose backends. - New `image_tests` module: a synthetic program loads a UAV, a 4×4 texture and a sampler from tables and samples it. Validated, then run on hardware and WARP: - `image_sample_lz_o` with a constant offset, - `image_sample_l_o` (level after the offset word), - `image_sample_l_o` with **a16**: coordinates in the VGPR after the offset word (the #318 layout; the old `k / 2` read the offset word as u, v), - `image_sample_d_cl` (coordinates after the gradients, then the clamp). - `cargo test -p victory-shader`: 76 pass (hardware: RTX 3060). `cargo clippy -p victory-shader` and rustfmt clean. - Not yet re-run against the title's census.
SpaghettiMaster545 commented 2026-11-24 06:55:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SpaghettiMaster545 on 2026-11-24T03:48:32Z.


Tested with the title at b6af8b1. The branch also carries #318's commit 1d7bf9b, so this measures both together.

  • NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build of the branch merged onto main d2a4bae (clean), its own empty VICTORY_CACHE_DIR, VICTORY_KEYS into story mode, until the host GPU failure (#71, unrelated); compared program by program with a main run made the same way (#400 has the setup).
  • 5 programs that stop on main translate and run. 0 programs that ran on main stop. This run ended earlier (63 s) than the main one, so it reached fewer programs and the count is a lower bound.
  • The world hang is unchanged.

Not tested: this PR without #318, AMD GPUs, a release build, image results.

(Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121442572 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7121442572). Originally posted by [SpaghettiMaster545](https://github.com/SpaghettiMaster545) on 2026-11-24T03:48:32Z. --- **Tested with the title** at `b6af8b1`. The branch also carries #318's commit `1d7bf9b`, so this measures both together. - NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9800X3D; Windows 11 10.0.26100; Rust 1.98.1. Diag build of the branch merged onto `main` `d2a4bae` (clean), its own empty `VICTORY_CACHE_DIR`, `VICTORY_KEYS` into story mode, until the host GPU failure (#71, unrelated); compared program by program with a `main` run made the same way (#400 has the setup). - 5 programs that stop on `main` translate and run. 0 programs that ran on `main` stop. This run ended earlier (63 s) than the `main` one, so it reached fewer programs and the count is a lower bound. - The world hang is unchanged. **Not tested**: this PR without #318, AMD GPUs, a release build, image results. (Claude Code, Claude Opus 5.5: ran the title on both builds and compared the logs program by program.)
jeremygold02 commented 2026-11-24 06:55:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:21:42Z.


I ran the shader crate’s unit suite at head b6af8b177e46e14b0ac9e372c287a8db63c83630:

cargo test --locked -p victory-shader --lib -- --test-threads=1

Result: 76 passed, 0 failed, 0 ignored. Relevant checks include lds_byte_and_half_reads_extend_as_the_console, lds_byte_and_half_writes_keep_the_rest_of_the_dword, the image sampling offset tests, and the shader lowering/bitcode tests. These are synthetic unit checks; this run does not validate rendered image output or title behavior.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121947291 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7121947291). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:21:42Z. --- I ran the shader crate’s unit suite at head `b6af8b177e46e14b0ac9e372c287a8db63c83630`: ``` cargo test --locked -p victory-shader --lib -- --test-threads=1 ``` Result: 76 passed, 0 failed, 0 ignored. Relevant checks include `lds_byte_and_half_reads_extend_as_the_console`, `lds_byte_and_half_writes_keep_the_rest_of_the_dword`, the image sampling offset tests, and the shader lowering/bitcode tests. These are synthetic unit checks; this run does not validate rendered image output or title behavior.
TrashTalker3460 commented 2026-11-24 06:56:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TrashTalker3460 on 2026-11-24T05:50:52Z.


Review note on head b6af8b1: for ds_read_*_d16 / _d16_hi, crates/victory-shader/src/emit/lower.rs:2138 keeps the destination's other half by reading its old value with inst.read(Reg::V(reg)), and falls back to 0 when that is None.

On main, ir.rs effects() (the Fields::Ds arm, around line 842) adds a ds_read destination only to the written registers, and Inst::read only searches the read list. So for these reads inst.read is always None and the kept half is always zeroed: a _d16 read clears the high 16 bits, a _d16_hi read clears the low 16.

#116 fixes this in effects():

if name.starts_with("ds_read") && name.contains("_d16") {
    regs(d, &mut r)?;
}

This PR would need the same, plus a test that writes a known value to the destination first and checks the other half survives.

Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and main at d2a4bae. Context: the triage in #366.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123330971 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7123330971). Originally posted by [TrashTalker3460](https://github.com/TrashTalker3460) on 2026-11-24T05:50:52Z. --- Review note on head `b6af8b1`: for `ds_read_*_d16` / `_d16_hi`, `crates/victory-shader/src/emit/lower.rs:2138` keeps the destination's other half by reading its old value with `inst.read(Reg::V(reg))`, and falls back to 0 when that is `None`. On `main`, `ir.rs` `effects()` (the `Fields::Ds` arm, around line 842) adds a `ds_read` destination only to the written registers, and `Inst::read` only searches the read list. So for these reads `inst.read` is always `None` and the kept half is always zeroed: a `_d16` read clears the high 16 bits, a `_d16_hi` read clears the low 16. #116 fixes this in `effects()`: ```rust if name.starts_with("ds_read") && name.contains("_d16") { regs(d, &mut r)?; } ``` This PR would need the same, plus a test that writes a known value to the destination first and checks the other half survives. _Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and `main` at `d2a4bae`. Context: the triage in #366._
iurysf commented 2026-11-24 08:02:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by iurysf on 2026-11-24T07:21:35Z.


Measured offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17: failures 3,733 -> 3,588 (−145), with no regressions (194 rejected by the validator, against 185). Most of the change is reclassification. "a scalar memory read as data" (573) goes to 0 here, but mostly by splitting into "descriptor address/format" (71 -> 595) rather than by translating. For comparison, #136 + #180 together take failures to 3,080 and clear both categories (details on #136).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7124901767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7124901767). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-24T07:21:35Z. --- Measured offline against main `d2a4bae` with `victory translate --list --validate` over the title's `shaders.rpf` + executable (26,096 programs), dxil.dll 1.9.2602.17: failures 3,733 -> 3,588 (−145), with no regressions (194 rejected by the validator, against 185). Most of the change is reclassification. "a scalar memory read as data" (573) goes to 0 here, but mostly by splitting into "descriptor address/format" (71 -> 595) rather than by translating. For comparison, #136 + #180 together take failures to 3,080 and clear both categories (details on #136). AI-assisted.
slint6614-dev commented 2026-11-24 08:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slint6614-dev on 2026-11-24T07:47:22Z.


Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.

VS/PS CS MS sub-dword LDS refusals (7 reads, 9 writes on main) tests
main 12272 / 12172 1693 / 1670 8191 / 8129 16 ok
#101 same 1709 / 1686 same 0 ok
#632 same 1707 / 1684 same 0, but 2 new "an LDS read into half a register" ok
#383 12361 / 12252 1720 / 1697 8220 / 8158 0 see below
  • #101 turns all 16 into validated compute programs; #632 gets 14 of them.
  • #383 (wider PR) also clears image_sample_o, image_sample_d_cl, the 108 biased 16-bit samples and the 573 "scalar memory read as data", but those mostly move to other reasons ("a descriptor's address or format read as data" 71 → 595, "an image address" 2 → 27), and the signature mismatches go 21 → 29 (input) and 25 → 26 (output).
  • #383: cargo test -p victory-shader --release crashed with STATUS_ACCESS_VIOLATION in 2 of 6 parallel runs (0 of 6 on main; --test-threads=1 always passes, 76 tests). Possibly a race in one of the new tests.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7125372650 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7125372650). Originally posted by [slint6614-dev](https://github.com/slint6614-dev) on 2026-11-24T07:47:22Z. --- Measured on the full retail shader pack (26,503 containers) with `victory translate --validate`, against main d2a4bae (emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100. | | VS/PS | CS | MS | sub-dword LDS refusals (7 reads, 9 writes on main) | tests | |---|---|---|---|---|---| | main | 12272 / 12172 | 1693 / 1670 | 8191 / 8129 | 16 | ok | | #101 | same | 1709 / 1686 | same | 0 | ok | | #632 | same | 1707 / 1684 | same | 0, but 2 new "an LDS read into half a register" | ok | | #383 | 12361 / 12252 | 1720 / 1697 | 8220 / 8158 | 0 | see below | - #101 turns all 16 into validated compute programs; #632 gets 14 of them. - #383 (wider PR) also clears `image_sample_o`, `image_sample_d_cl`, the 108 biased 16-bit samples and the 573 "scalar memory read as data", but those mostly move to other reasons ("a descriptor's address or format read as data" 71 → 595, "an image address" 2 → 27), and the signature mismatches go 21 → 29 (input) and 25 → 26 (output). - #383: `cargo test -p victory-shader --release` crashed with `STATUS_ACCESS_VIOLATION` in 2 of 6 parallel runs (0 of 6 on main; `--test-threads=1` always passes, 76 tests). Possibly a race in one of the new tests.
catminou4 commented 2026-11-24 14:03:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:19:36Z.

Review: COMMENTED


Test-merge with current main (ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touched lower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039898621 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#pullrequestreview-6039898621). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T13:19:36Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) **conflicts** — needs a rebase. Main moved recently (PR #566 waterfall loops touched `lower.rs`/`resource.rs`/`valu_tests.rs`), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.
adamdotpy commented 2026-11-24 16:05:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T15:55:08Z.


Reviewed b6af8b1. Two things first, then what I found in each part.

It no longer applies to main. The branch is based on d2a4bae; git merge-tree against ffe310e conflicts in crates/victory-shader/src/emit/lower.rs and .../valu_tests.rs, which is why the PR reads as dirty. @SpaghettiMaster545's title test merged onto d2a4bae cleanly, so the conflict came in with the commits after that; a rebase is needed before anyone can judge the merge or re-run a census.

Run here (Windows 11, Rust 1.98.1): cargo test -p victory-shader — 76 passed, 0 failed, matching @jeremygold02.

_d16 / _d16_hi kept half: the source is the wrong one, and this test cannot see it

@TrashTalker3460 is right that the kept half is unreliable, but the mechanism is worth stating precisely, because it explains why lds_byte_and_half_reads_extend_as_the_console passes on hardware:

  • ir.rs's effects() puts a ds destination only in the write list, and chains data into the read list (Fields::Ds, addr.iter().chain(data)).
  • So inst.read(Reg::V(vdst)) returns something only because the encoding's data0 field is parsed as an operand and names that register. In the test ds(op, 0, 5, 0, offset) has data0 = 0, i.e. v0, and vdst is also v0, preloaded with the LDS content — so the "kept" half happens to be the value the test expects. In a title shader whose data0 names another register (hardware ignores that field on a read), the kept half comes from that register instead.
  • The robust source is the destination register's previous SSA definition, not an operand of this instruction. If #116 does that, it fixes both _d16 and _d16_hi.

A test that would catch it: same program, but vdst = 2 with the address in v5 and data0 naming a third register (or 0 while vdst != 0), so the kept half can only come from v2's own previous value.

LDS bytes and halves

The part I expected to be wrong is right. hole = mask << shift, keep = ~hole, value masked into hole: mask and value are disjoint per write, so the and then or pair commutes and lanes writing different bytes of one dword cannot lose each other's bits. Two notes:

  • A lane reading that dword between the two atomics sees the hole zeroed. The console program has the same race unlocked, but "two atomics" reads as if the pair were atomic; a sentence saying it is not would stop someone relying on it.
  • The byte-3 half shortcut is documented; the read at byte 3 (the high half coming from the next dword) is where this differs from hardware, so it is the case to name in the shortcut comment.

image_address_place

per = grads / 2 is safe only because the caller computes grads = 2 * spatial, so it is never 1. Nothing in the function says that, and the comment right above talks about odd gradient counts being padded — a debug_assert!(per > 0 || grads == 0) or a sentence would keep the next edit from dividing by zero inside the translator rather than failing a shader.

Descriptor data — three PRs, one case

Your Fields::Smem arm is the same fix as #953 (a buffer descriptor also read by s_buffer_load becomes a raw SRV, (11 | u, 0)), reached independently, and the reason split around it is what #1083 does. Whichever lands first, the other two rebase:

  • if #953 goes in first, this keeps the reclassification (Fields::Flat, the other arms) and drops the Fields::Smem translation;
  • @iurysf's census says the split accounts for most of the change here anyway ("descriptor address/format" 71 → 595 rather than new translations), so the two PRs are complementary once one carries the arm.

One shared open question: both use (11 | u, 0) regardless of used.stride, so getDimensions().x on that raw view is bytes/4 while a console structured descriptor's dword 2 is bytes/stride — 4× at stride 16, and it is the record count. I raised it on #953; if it turns out to matter, it matters identically here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136829679 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7136829679). Originally posted by [adamdotpy](https://github.com/adamdotpy) on 2026-11-24T15:55:08Z. --- Reviewed `b6af8b1`. Two things first, then what I found in each part. **It no longer applies to `main`.** The branch is based on `d2a4bae`; `git merge-tree` against `ffe310e` conflicts in `crates/victory-shader/src/emit/lower.rs` and `.../valu_tests.rs`, which is why the PR reads as `dirty`. @SpaghettiMaster545's title test merged onto `d2a4bae` cleanly, so the conflict came in with the commits after that; a rebase is needed before anyone can judge the merge or re-run a census. **Run here** (Windows 11, Rust 1.98.1): `cargo test -p victory-shader` — 76 passed, 0 failed, matching @jeremygold02. ### `_d16` / `_d16_hi` kept half: the source is the wrong one, and this test cannot see it @TrashTalker3460 is right that the kept half is unreliable, but the mechanism is worth stating precisely, because it explains why `lds_byte_and_half_reads_extend_as_the_console` passes on hardware: - `ir.rs`'s `effects()` puts a `ds` destination only in the write list, and chains `data` into the read list (`Fields::Ds`, `addr.iter().chain(data)`). - So `inst.read(Reg::V(vdst))` returns something only because the *encoding's* `data0` field is parsed as an operand and names that register. In the test `ds(op, 0, 5, 0, offset)` has `data0 = 0`, i.e. v0, and `vdst` is also v0, preloaded with the LDS content — so the "kept" half happens to be the value the test expects. In a title shader whose `data0` names another register (hardware ignores that field on a read), the kept half comes from that register instead. - The robust source is the destination register's previous SSA definition, not an operand of this instruction. If #116 does that, it fixes both `_d16` and `_d16_hi`. A test that would catch it: same program, but `vdst = 2` with the address in `v5` and `data0` naming a third register (or 0 while `vdst != 0`), so the kept half can only come from v2's own previous value. ### LDS bytes and halves The part I expected to be wrong is right. `hole = mask << shift`, `keep = ~hole`, value masked into `hole`: mask and value are disjoint per write, so the `and` then `or` pair commutes and lanes writing different bytes of one dword cannot lose each other's bits. Two notes: - A lane reading that dword *between* the two atomics sees the hole zeroed. The console program has the same race unlocked, but "two atomics" reads as if the pair were atomic; a sentence saying it is not would stop someone relying on it. - The byte-3 half shortcut is documented; the read at byte 3 (the high half coming from the next dword) is where this differs from hardware, so it is the case to name in the shortcut comment. ### `image_address_place` `per = grads / 2` is safe only because the caller computes `grads = 2 * spatial`, so it is never 1. Nothing in the function says that, and the comment right above talks about odd gradient counts being padded — a `debug_assert!(per > 0 || grads == 0)` or a sentence would keep the next edit from dividing by zero inside the translator rather than failing a shader. ### Descriptor data — three PRs, one case Your `Fields::Smem` arm is the same fix as #953 (a buffer descriptor also read by `s_buffer_load` becomes a raw SRV, `(11 | u, 0)`), reached independently, and the reason split around it is what #1083 does. Whichever lands first, the other two rebase: - if #953 goes in first, this keeps the reclassification (`Fields::Flat`, the other arms) and drops the `Fields::Smem` translation; - @iurysf's census says the split accounts for most of the change here anyway ("descriptor address/format" 71 → 595 rather than new translations), so the two PRs are complementary once one carries the arm. One shared open question: both use `(11 | u, 0)` regardless of `used.stride`, so `getDimensions().x` on that raw view is bytes/4 while a console structured descriptor's dword 2 is bytes/stride — 4× at stride 16, and it is the record count. I raised it on #953; if it turns out to matter, it matters identically here.
adamdotpy commented 2026-11-24 16:05:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T15:58:08Z.


For the LDS half of this PR, #571 is the better implementation of the same ground: it handles the halfword at byte 3 by straddling into the next dword (64-bit shift on read, 64-bit mask/data on write, past-the-end clamped with reads seeing 0), where this PR documents the straddle as a shortcut that loses the spilling byte. I would land #571 for LDS and rebase this one to keep only the image_sample_o and descriptor-data work, which nothing else covers.

Both PRs share the same question about the _d16 kept half — the destination register is read via inst.read(Reg::V(dst)) while ir.rs::effects() only declares dst as written, and the tests cannot see it because vdst and the data field coincide. I left the details with an experiment on #571. One fix upstream would close both.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136909413 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7136909413). Originally posted by [adamdotpy](https://github.com/adamdotpy) on 2026-11-24T15:58:08Z. --- For the LDS half of this PR, #571 is the better implementation of the same ground: it handles the halfword at byte 3 by straddling into the next dword (64-bit shift on read, 64-bit mask/data on write, past-the-end clamped with reads seeing 0), where this PR documents the straddle as a shortcut that loses the spilling byte. I would land #571 for LDS and rebase this one to keep only the `image_sample_o` and descriptor-data work, which nothing else covers. Both PRs share the same question about the `_d16` kept half — the destination register is read via `inst.read(Reg::V(dst))` while `ir.rs::effects()` only declares `dst` as written, and the tests cannot see it because `vdst` and the data field coincide. I left the details with an experiment on #571. One fix upstream would close both.
pablogonz12 commented 2026-11-24 17:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-24T16:20:50Z.


I ran the CI clippy on head b6af8b1 (the branch has no checks): cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings fails on two points, both the first error in their crate:

  • crates/victory-shader/src/emit/valu_tests.rs:757: type_complexity on the [(u8, u16, fn(u32) -> u32); 6] table in lds_byte_and_half_reads_extend_as_the_console — a type alias (or #[allow(clippy::type_complexity)]) clears it.
  • crates/victory-gpu/src/host.rs:267: undocumented_unsafe_blocks, which is not from this PR: current main has since added a // SAFETY: comment above that raw.cast::<IDXGIAdapter1>() line, so rebasing on main fixes it.
    Also, when this meets current main: image_tests.rs needs emit(..., Target::ANY) and raw_view_tests.rs needs the extra lanes argument of resource::track (I hit both in my tree).
    No game data, just the two compiler messages.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7137518212 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7137518212). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-24T16:20:50Z. --- I ran the CI clippy on head b6af8b1 (the branch has no checks): `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` fails on two points, both the first error in their crate: - `crates/victory-shader/src/emit/valu_tests.rs:757`: `type_complexity` on the `[(u8, u16, fn(u32) -> u32); 6]` table in `lds_byte_and_half_reads_extend_as_the_console` — a `type` alias (or `#[allow(clippy::type_complexity)]`) clears it. - `crates/victory-gpu/src/host.rs:267`: `undocumented_unsafe_blocks`, which is not from this PR: current main has since added a `// SAFETY:` comment above that `raw.cast::<IDXGIAdapter1>()` line, so rebasing on main fixes it. Also, when this meets current main: `image_tests.rs` needs `emit(..., Target::ANY)` and `raw_view_tests.rs` needs the extra `lanes` argument of `resource::track` (I hit both in my tree). No game data, just the two compiler messages.
adamdotpy commented 2026-11-24 17:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T16:29:46Z.


Reproduced the flaky release-test crash on b6af8b1, and found the cause. Windows 11, Rust 1.98.1, the branch's release test binary run 6 times with default (parallel) threads:

run 1 exit=139 (segfault)     run 4 exit=139 (segfault)
runs 2, 3, 5, 6 exit=0, "test result: ok"

That is 2 of 6, same as your report, and --test-threads=1 passes every time. So it is a parallel-run race, not a broken assertion.

The cause is that this branch's base predates the GPU-test serialization. Current main's valu_tests.rs has:

/// … two GPU tests at once on WARP can end the test process with an
/// access violation. Other GPU test modules take this lock too.
pub(super) static ONE_AT_A_TIME: std::sync::Mutex<()> = …

and run_cases takes it before touching a device. Your merge base's valu_tests.rs has no ONE_AT_A_TIME at all (git show <merge-base>:…valu_tests.rs | grep -c ONE_AT_A_TIME → 0), and the new run_cases_on in this branch — called from the two new LDS tests and from image_tests.rs — creates Host::new and dispatches without taking any lock. Two of those on the same device (hardware or WARP) at once is precisely the access violation main's comment names. I could not make the LDS tests alone crash in 10 parallel runs, so the full suite's contention is what tips it over; the missing lock is still the defect.

The fix is one line after the rebase: have run_cases_on take ONE_AT_A_TIME like run_cases does on current main (it will be in scope after rebasing, since it is pub(super) in the same module). Until then, --test-threads=1 is the honest way to run it, as you found.

On @pablogonz12's two clippy points: the type_complexity on the [(u8, u16, fn(u32) -> u32); 6] table at valu_tests.rs:757 is yours — an alias or #[allow] clears it. The undocumented_unsafe_blocks at host.rs:267 is a rebase artifact, confirmed: current main has the // SAFETY: EnumWarpAdapter returns a DXGI adapter… comment on exactly that raw.cast::<IDXGIAdapter1>() line, so merging main in clears it. Your other two notes (the Target::ANY and lanes signature changes) are the same class — they come from meeting current main, not from this diff.

Nothing changed on your branch from me; this is evidence only. The shader-side substance (LDS sub-dword handling, sample offsets, descriptor-data reasons) I reviewed earlier still stands, and the #571 comparison note from before is unchanged: for the LDS half, #571 is the stronger implementation.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7137754530 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/383#issuecomment-7137754530). Originally posted by [adamdotpy](https://github.com/adamdotpy) on 2026-11-24T16:29:46Z. --- Reproduced the flaky release-test crash on `b6af8b1`, and found the cause. Windows 11, Rust 1.98.1, the branch's release test binary run 6 times with default (parallel) threads: ``` run 1 exit=139 (segfault) run 4 exit=139 (segfault) runs 2, 3, 5, 6 exit=0, "test result: ok" ``` That is 2 of 6, same as your report, and `--test-threads=1` passes every time. So it is a parallel-run race, not a broken assertion. **The cause is that this branch's base predates the GPU-test serialization.** Current `main`'s `valu_tests.rs` has: ```rust /// … two GPU tests at once on WARP can end the test process with an /// access violation. Other GPU test modules take this lock too. pub(super) static ONE_AT_A_TIME: std::sync::Mutex<()> = … ``` and `run_cases` takes it before touching a device. Your merge base's `valu_tests.rs` has no `ONE_AT_A_TIME` at all (`git show <merge-base>:…valu_tests.rs | grep -c ONE_AT_A_TIME` → 0), and the new `run_cases_on` in this branch — called from the two new LDS tests and from `image_tests.rs` — creates `Host::new` and dispatches without taking any lock. Two of those on the same device (hardware or WARP) at once is precisely the access violation `main`'s comment names. I could not make the LDS tests alone crash in 10 parallel runs, so the full suite's contention is what tips it over; the missing lock is still the defect. **The fix is one line after the rebase:** have `run_cases_on` take `ONE_AT_A_TIME` like `run_cases` does on current main (it will be in scope after rebasing, since it is `pub(super)` in the same module). Until then, `--test-threads=1` is the honest way to run it, as you found. On @pablogonz12's two clippy points: the `type_complexity` on the `[(u8, u16, fn(u32) -> u32); 6]` table at `valu_tests.rs:757` is yours — an alias or `#[allow]` clears it. The `undocumented_unsafe_blocks` at `host.rs:267` is a rebase artifact, confirmed: current `main` has the `// SAFETY: EnumWarpAdapter returns a DXGI adapter…` comment on exactly that `raw.cast::<IDXGIAdapter1>()` line, so merging `main` in clears it. Your other two notes (the `Target::ANY` and `lanes` signature changes) are the same class — they come from meeting current `main`, not from this diff. Nothing changed on your branch from me; this is evidence only. The shader-side substance (LDS sub-dword handling, sample offsets, descriptor-data reasons) I reviewed earlier still stands, and the #571 comparison note from before is unchanged: for the LDS half, #571 is the stronger implementation.
upstream-sync closed this pull request 2026-11-24 23:04:06 +00:00

Pull request closed

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
Marvisak/VIctory!383
No description provided.