Shader resource tracking: redundant masked write after a per-lane descriptor join is refused (synthetic repro on #566) #750

Open
opened 2026-11-26 04:13:55 +00:00 by github-bot · 7 comments
Owner

@⁠YouKnowWh on GitHub · 2026-11-24 09:28 UTC · original

On #566 head e09dbb6, a four-word descriptor selected across an if/else can drive the correct sampler. A subsequent masked write of one word, even when it writes exactly what those active lanes already held, stops resource tracking. This documents a reproducible coverage limit of the conservative refusal discussed in #566.

Small repro without a game or GPU. Add the following test inside the existing tests module of crates/victory-shader/src/resource.rs on that head. It reuses the existing image-descriptor fixture so the reproducer is just four extra instructions.

#[test]
fn joined_descriptor_redundant_partial_write() {
    let mut words = WATERFALL_JOINED_WAVE32.to_vec();
    let at = words.iter().position(|w| *w == 0x887e147e).unwrap() + 1;
    words.splice(at..at, [
        0x7d880090, // compare lane ID < 16
        0xbe923c6a, // save EXEC to s18 and enable the lower 16 lanes
        0x7e080218, // v4 = s24, the original value from their then arm
        0xbefe0312, // restore EXEC
    ]);
    waterfall(&words, false).unwrap();
}

Observed: resource tracking refuses at 0x108 with a per-lane descriptor written where some lanes may keep the old one. Expected: the same two per-lane resources as the unmodified fixture. Upper lanes preserve the else-arm word. Simply skipping the guard check would be wrong for a write that changes the active lanes' value.

Independent sampler control: a 32-thread synthetic compute shader uses the same 2×1 texture for all lanes and selects a point WRAP or CLAMP sampler through four joined dwords. At U=2.0 the expected red values are 1 and 2. The RTX 5070 Ti and WARP both returned the expected value for every lane, including with the two sampler slots swapped. Adding the analogous masked identity write to the first sampler word (v4 = s32 in this fixture) instead fails at 0xc0 before DXIL generation.

Retail scope: on the same head, mesh shaders 89a622617919c92a and fe660f2d6d57de76 still stop at image_sample_lz (0x5fe8, computed first-lane VGPRs; 0x5d90, partial control-flow join). Both read four sampler words with v_readfirstlane_b32. Their errors differ from the synthetic refusal. We have not established that supporting the synthetic case would fix either retail shader or the black scene.

AI disclosure: Codex authored and ran the synthetic tests locally, checked the results and wrote this report at my request.

**@⁠YouKnowWh** on GitHub · 2026-11-24 09:28 UTC · [original](https://github.com/Marvisak/VIctory/issues/750) On #566 head e09dbb6, a four-word descriptor selected across an if/else can drive the correct sampler. A subsequent masked write of one word, even when it writes exactly what those active lanes already held, stops resource tracking. This documents a reproducible coverage limit of the conservative refusal discussed in #566. **Small repro without a game or GPU**. Add the following test inside the existing tests module of `crates/victory-shader/src/resource.rs` on that head. It reuses the existing image-descriptor fixture so the reproducer is just four extra instructions. ```rust #[test] fn joined_descriptor_redundant_partial_write() { let mut words = WATERFALL_JOINED_WAVE32.to_vec(); let at = words.iter().position(|w| *w == 0x887e147e).unwrap() + 1; words.splice(at..at, [ 0x7d880090, // compare lane ID < 16 0xbe923c6a, // save EXEC to s18 and enable the lower 16 lanes 0x7e080218, // v4 = s24, the original value from their then arm 0xbefe0312, // restore EXEC ]); waterfall(&words, false).unwrap(); } ``` Observed: resource tracking refuses at 0x108 with `a per-lane descriptor written where some lanes may keep the old one`. Expected: the same two per-lane resources as the unmodified fixture. Upper lanes preserve the else-arm word. Simply skipping the guard check would be wrong for a write that changes the active lanes' value. **Independent sampler control**: a 32-thread synthetic compute shader uses the same 2×1 texture for all lanes and selects a point WRAP or CLAMP sampler through four joined dwords. At U=2.0 the expected red values are 1 and 2. The RTX 5070 Ti and WARP both returned the expected value for every lane, including with the two sampler slots swapped. Adding the analogous masked identity write to the first sampler word (v4 = s32 in this fixture) instead fails at 0xc0 before DXIL generation. **Retail scope**: on the same head, mesh shaders 89a622617919c92a and fe660f2d6d57de76 still stop at image_sample_lz (0x5fe8, computed first-lane VGPRs; 0x5d90, partial control-flow join). Both read four sampler words with v_readfirstlane_b32. Their errors differ from the synthetic refusal. We have not established that supporting the synthetic case would fix either retail shader or the black scene. AI disclosure: Codex authored and ran the synthetic tests locally, checked the results and wrote this report at my request.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:55 +00:00
Author
Owner

@⁠YouKnowWh on GitHub · 2026-11-24 09:35 UTC · original

Follow-up on e09dbb6: the synthetic case is now fixed in a local prototype. For a plain predicated VGPR copy we keep the previous descriptor word only if the forward phi inputs on every feasible active path prove it already equals the replacement. The prototype recognizes repeated v_cmp_gt_u32 comparisons of identical entry VGPRs/constants. Changing the source word to the other arm's word is still refused.

With the masked rewrite present, the 32 lanes select the expected wrap/clamp samples on RTX 5070 Ti and WARP, and swapping the two sampler slots reverses the expected result correctly on both devices (32/32 per run). The short image-descriptor repro passes as well. Windows victory-shader test run: 122 passed, 0 failed, 1 ignored.

Retail check on the same build: 89a622617919c92a still stops at 0x5fe8 (computed first-lane VGPRs) and fe660f2d6d57de76 at 0x5d90 (partial control-flow join). Two unrelated mesh controls still validate and create hardware PSOs. This narrows #750 to a confirmed synthetic improvement; it does not resolve the two world draws. The prototype is local; no change to upstream or game-frame result is claimed.

AI disclosure: Codex implemented and tested the local change and prepared this update.

**@⁠YouKnowWh** on GitHub · 2026-11-24 09:35 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7127613545) Follow-up on e09dbb6: the synthetic case is now fixed in a local prototype. For a plain predicated VGPR copy we keep the previous descriptor word only if the forward phi inputs on every feasible active path prove it already equals the replacement. The prototype recognizes repeated v_cmp_gt_u32 comparisons of identical entry VGPRs/constants. Changing the source word to the other arm's word is still refused. With the masked rewrite present, the 32 lanes select the expected wrap/clamp samples on RTX 5070 Ti and WARP, and swapping the two sampler slots reverses the expected result correctly on both devices (32/32 per run). The short image-descriptor repro passes as well. Windows victory-shader test run: 122 passed, 0 failed, 1 ignored. Retail check on the same build: 89a622617919c92a still stops at 0x5fe8 (computed first-lane VGPRs) and fe660f2d6d57de76 at 0x5d90 (partial control-flow join). Two unrelated mesh controls still validate and create hardware PSOs. This narrows #750 to a confirmed synthetic improvement; it does not resolve the two world draws. The prototype is local; no change to upstream or game-frame result is claimed. AI disclosure: Codex implemented and tested the local change and prepared this update.
Author
Owner

@⁠YouKnowWh on GitHub · 2026-11-24 09:45 UTC · original

Retail follow-up to the previous local experiment on e09dbb6. A separate change to the lane-condition satisfiability check now gets the two reported mesh shaders past resource tracking.

For fe660f2d6d57de76 at 0x5d90, the image resolves to a load from root parameter 210 + 0x180. The sampler uses v97..v100 via s28..s31. Two incoming paths load four consecutive sampler words at 0x5404 and 0x5b7c; the tracker resolves both loads to root parameter 229 + 0x410 with no dynamic term. The original search also pursued an earlier path containing floating-point temporaries for the first two words and phi inputs for the other two.

On the previous #750 prototype I changed Bools::meet only: when the full search exhausts its budget, retry a bounded subset of small conditions. If even that subset is unsatisfiable, the full path is impossible. An inconclusive retry retains the original conservative result. No descriptor is substituted. A synthetic test checks both a contradiction behind a large reach condition and a nearby satisfiable case.

Five retail mesh samples now complete resource tracking. The two positive controls still validate and create hardware PSOs. The three previously refused samples now stop in DXIL emission with "a scalar memory read as data": 89a622617919c92a at 0x13b8, fe660f2d6d57de76 at 0x1254 and 903776ba469c8bac at 0x0f34. Windows victory-shader suite: 123 passed, 0 failed, 1 ignored. No new scene-rendering or crash claim. AI-assisted local investigation and testing.

**@⁠YouKnowWh** on GitHub · 2026-11-24 09:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7127856668) Retail follow-up to the previous local experiment on e09dbb6. A separate change to the lane-condition satisfiability check now gets the two reported mesh shaders past resource tracking. For fe660f2d6d57de76 at 0x5d90, the image resolves to a load from root parameter 210 + 0x180. The sampler uses v97..v100 via s28..s31. Two incoming paths load four consecutive sampler words at 0x5404 and 0x5b7c; the tracker resolves both loads to root parameter 229 + 0x410 with no dynamic term. The original search also pursued an earlier path containing floating-point temporaries for the first two words and phi inputs for the other two. On the previous #750 prototype I changed Bools::meet only: when the full search exhausts its budget, retry a bounded subset of small conditions. If even that subset is unsatisfiable, the full path is impossible. An inconclusive retry retains the original conservative result. No descriptor is substituted. A synthetic test checks both a contradiction behind a large reach condition and a nearby satisfiable case. Five retail mesh samples now complete resource tracking. The two positive controls still validate and create hardware PSOs. The three previously refused samples now stop in DXIL emission with "a scalar memory read as data": 89a622617919c92a at 0x13b8, fe660f2d6d57de76 at 0x1254 and 903776ba469c8bac at 0x0f34. Windows victory-shader suite: 123 passed, 0 failed, 1 ignored. No new scene-rendering or crash claim. AI-assisted local investigation and testing.
Author
Owner

@⁠YouKnowWh on GitHub · 2026-11-24 09:54 UTC · original

Follow-up on the new emission blocker (local #566 + the previous resource-tracking change). In fe660f2d6d57de76, 0x1254 is the conditional branch where the missing value surfaces. At 0x10b0 the title loads an SRV descriptor (table param 210, offset 0, used-resource stride 80). It uses dword 2 in (count - 1) * 80, then s_buffer_load_dword reads at that byte offset (0x10ec).

Recognizing scalar buffer uses with the raw-handle descriptor-data case from #437 made all five mesh samples emit, validate, and create hardware PSOs locally. This alone can produce incorrect data. A synthetic three-record buffer (240 bytes, with dwords 1000..1059) should return [3,1040] for [count, first dword of last record]. On RTX 5070 Ti it returned [240,0] with a raw SRV and [60,0] with a structured SRV when the DXIL handle was annotated raw. WARP returned [240,0] in both cases.

With the host view explicitly controlled, two separate experiments returned [3,1040] on both adapters: a verified raw SRV using byte length / 80 and byte addressing, and a matching structured SRV using element count and record-relative addressing. The actual view bound by this title at this draw has not been measured. This is a numerical regression case and not a validated retail fix; no game pixels or performance change claimed. The behavior concerns the descriptor count used as data, beyond the fixed byte-offset load tested in #437. AI-assisted local tests.

**@⁠YouKnowWh** on GitHub · 2026-11-24 09:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7128046200) Follow-up on the new emission blocker (local #566 + the previous resource-tracking change). In fe660f2d6d57de76, 0x1254 is the conditional branch where the missing value surfaces. At 0x10b0 the title loads an SRV descriptor (table param 210, offset 0, used-resource stride 80). It uses dword 2 in (count - 1) * 80, then s_buffer_load_dword reads at that byte offset (0x10ec). Recognizing scalar buffer uses with the raw-handle descriptor-data case from #437 made all five mesh samples emit, validate, and create hardware PSOs locally. This alone can produce incorrect data. A synthetic three-record buffer (240 bytes, with dwords 1000..1059) should return [3,1040] for [count, first dword of last record]. On RTX 5070 Ti it returned [240,0] with a raw SRV and [60,0] with a structured SRV when the DXIL handle was annotated raw. WARP returned [240,0] in both cases. With the host view explicitly controlled, two separate experiments returned [3,1040] on both adapters: a verified raw SRV using byte length / 80 and byte addressing, and a matching structured SRV using element count and record-relative addressing. The actual view bound by this title at this draw has not been measured. This is a numerical regression case and not a validated retail fix; no game pixels or performance change claimed. The behavior concerns the descriptor count used as data, beyond the fixed byte-offset load tested in #437. AI-assisted local tests.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 10:58 UTC · original

For the stride-80 scalar read in fe660f2d6d57de76, Derek put together a comparison branch with both GPU controls. It reuses #329’s original PSV0 resource declaration for an exact static table binding. Stride alone cannot distinguish the two cases.

On an RTX 4090 with Wine/vkd3d-proton 3.2, both synthetic shaders carried stride 80. With a raw declaration and matching raw view, the fixed byte-offset read at 20 returned 1005. With a structured declaration and matching view, the shader computed (record_count - 1) * 80 + 4 and returned 1041, the second dword of the third record. On a separate stride-16 control, the #329-only parent kept the raw result but refused the structured scalar read; the follow-up passed both.

The remaining question for this hash is whether its original PSV0 identifies the SRV at table parameter 210, offset 0 unambiguously, and whether the actual view matches. If your existing local sample can answer the declaration half, just the resource kind and whether the register/space match is unique would be enough. This branch doesn't implement the raw byte-length-to-record-count experiment from your comment.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 10:58 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7129486331) For the stride-80 scalar read in `fe660f2d6d57de76`, Derek put together a [comparison branch with both GPU controls](https://github.com/MichaelSmithAI/VIctory/tree/test/scalar-srv-declaration). It reuses #329’s original PSV0 resource declaration for an exact static table binding. Stride alone cannot distinguish the two cases. On an RTX 4090 with Wine/vkd3d-proton 3.2, both synthetic shaders carried stride 80. With a raw declaration and matching raw view, the fixed byte-offset read at 20 returned 1005. With a structured declaration and matching view, the shader computed `(record_count - 1) * 80 + 4` and returned 1041, the second dword of the third record. On a separate stride-16 control, the #329-only parent kept the raw result but refused the structured scalar read; the follow-up passed both. The remaining question for this hash is whether its original PSV0 identifies the SRV at table parameter 210, offset 0 unambiguously, and whether the actual view matches. If your existing local sample can answer the declaration half, just the resource kind and whether the register/space match is unique would be enough. This branch doesn't implement the raw byte-length-to-record-count experiment from your comment.
Author
Owner

@⁠R0D4X on GitHub · 2026-11-24 15:55 UTC · original

Looking into this — I have a repro and test setup on RTX 5080 (Wave32) and will put together a PR.

**@⁠R0D4X** on GitHub · 2026-11-24 15:55 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7136851319) Looking into this — I have a repro and test setup on RTX 5080 (Wave32) and will put together a PR.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:02 UTC · original

Verified redundant masked v_mov_b32 preservation across per-lane descriptor joins on RTX 5090 and WARP (dxil.dll validated), covering:

  • Repeated and complementary integer lane compares (v_cmp_gt_u32 16, v0 and v_cmp_le_u32 16, v0) across 8-dword image, 4-dword buffer, and 4-dword per-lane sampler (WRAP vs CLAMP) waterfall loops;
  • Negative safety cases ensuring cross-arm dwords (v4 = s32 under lane < 16), constant overwrites (v4 = 0), and widened masks (lane < 24 crossing into the other arm's lanes) are still rejected.

Reference branch with the end-to-end GPU image & sampler waterfall readback tests in case useful while reviewing #1182 / #1229: github.com/fuzeofficlal/VIctory@536daa9516

**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:02 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7138584532) Verified redundant masked `v_mov_b32` preservation across per-lane descriptor joins on RTX 5090 and WARP (`dxil.dll` validated), covering: - Repeated and complementary integer lane compares (`v_cmp_gt_u32 16, v0` and `v_cmp_le_u32 16, v0`) across 8-dword image, 4-dword buffer, and 4-dword per-lane sampler (`WRAP` vs `CLAMP`) waterfall loops; - Negative safety cases ensuring cross-arm dwords (`v4 = s32` under `lane < 16`), constant overwrites (`v4 = 0`), and widened masks (`lane < 24` crossing into the other arm's lanes) are still rejected. Reference branch with the end-to-end GPU image & sampler waterfall readback tests in case useful while reviewing #1182 / #1229: https://github.com/fuzeofficlal/VIctory/commit/536daa9516871601fc52e6978bf5d5d0bc8b6bf5
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:50 UTC · original

Automated triage for the maintainers.

Confirmed on current main (#566 is merged; the WATERFALL_JOINED_WAVE32 fixture is in crates/victory-shader/src/resource.rs). Tracer::runs returns "a per-lane descriptor written where some lanes may keep the old one" whenever some lanes that reach a guarded descriptor write could skip it. It does not check whether the write leaves the value unchanged, so the redundant masked write in the repro is refused. This is a known conservative limit, not a miscompile. As the thread notes, lifting it has not been shown to fix the two retail mesh shaders. With the local tracking changes they stop later, at "a scalar memory read as data".

The prototype and the reference tests (YouKnowWh, fuzeofficlal's commit) are only on forks so far, and R0D4X said a PR is coming. Pull requests are open to everyone. Please open one against current main with the synthetic repro and the negative cases (cross-arm word, constant overwrite, widened mask) as tests.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/750#issuecomment-7152287544) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T17:02:08Z at=2026-11-25T03:50:18Z --> Automated triage for the maintainers. Confirmed on current `main` (#566 is merged; the `WATERFALL_JOINED_WAVE32` fixture is in `crates/victory-shader/src/resource.rs`). `Tracer::runs` returns "a per-lane descriptor written where some lanes may keep the old one" whenever some lanes that reach a guarded descriptor write could skip it. It does not check whether the write leaves the value unchanged, so the redundant masked write in the repro is refused. This is a known conservative limit, not a miscompile. As the thread notes, lifting it has not been shown to fix the two retail mesh shaders. With the local tracking changes they stop later, at "a scalar memory read as data". The prototype and the reference tests (YouKnowWh, fuzeofficlal's commit) are only on forks so far, and R0D4X said a PR is coming. Pull requests are open to everyone. Please open one against current `main` with the synthetic repro and the negative cases (cross-arm word, constant overwrite, widened mask) as tests. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#750
No description provided.