Shader tests: snapshot of which ALU instructions lower (catches lowerings lost in a merge) #81

Closed
lcg007xd-c wants to merge 0 commits from upstream-pr/81 into main
lcg007xd-c commented 2026-11-25 22:04:35 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T22:04:35Z.


What

A tripwire against losing lowerings. Issue #4 records lowerings that went missing in a merge (image_sample_b_o, the LDS bounds checks). Nothing noticed until a title broke.

The new test lowering_coverage_matches_the_snapshot (emit/coverage_tests.rs) works like this:

  • Each opcode on its own. Every VOP1, VOP2, VOP3, VOP3P, SOP1 and SOP2 opcode the decoder has a name for goes alone into a one-thread compute program and is lowered. Sources come from root constants, and the result is stored to a buffer. Scalar results go through s20, which stays clear of the buffer descriptor in s[8:11].
  • Compared with a list. Each opcode either lowers, is refused, or panics. That status is compared with the checked-in emit/lowering-coverage.txt (743 lines, 24 KB).
  • On a change, the test names each changed opcode, e.g. vop1 0x02a v_rcp_f32: lowers -> refused. By default it only prints that as a warning and passes, so no one else's PR goes red over it. With VICTORY_STRICT_TESTS=1 (the switch #43's skips already use) it fails.
  • A deliberate change (a new lowering) is recorded with VICTORY_BLESS=1 cargo test -p victory-shader coverage, and the updated list is committed with it.

The whole sweep takes about 0.6 s.

Today, 544 of the 743 named opcodes lower, 197 are refused, and 2 panic. The 2 are v_permlane16_b32 and v_permlanex16_b32, and #79 fixes them. Once #79 merges, they show up as a warning until the list is re-blessed.

Tests

  • The test passes on this branch.
  • I removed the v_rcp_f32 arm from lower.rs locally. The test then named both encodings (vop1 0x02a and vop3 0x1aa, lowers -> refused). In the sandbox, a stale list passes with a warning by default and fails with VICTORY_STRICT_TESTS=1.
  • The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally. The asset-policy test accepts the new .txt.

Open lowering PRs (#56, #57, #71, #73) keep passing after this merges. Their new lowerings show up as warnings until someone re-blesses the list.

Not covered: instructions that need more than this template (VOPC, memory, images, branches). The test only shows that an opcode lowers or is refused, not that the result is numerically right.

🤖 Generated with Claude Code

<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:5499961490 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VitoriaBr2.0/pull/81). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T22:04:35Z. --- ## What A tripwire against losing lowerings. Issue #4 records lowerings that went missing in a merge (`image_sample_b_o`, the LDS bounds checks). Nothing noticed until a title broke. The new test `lowering_coverage_matches_the_snapshot` (`emit/coverage_tests.rs`) works like this: - **Each opcode on its own.** Every VOP1, VOP2, VOP3, VOP3P, SOP1 and SOP2 opcode the decoder has a name for goes alone into a one-thread compute program and is lowered. Sources come from root constants, and the result is stored to a buffer. Scalar results go through `s20`, which stays clear of the buffer descriptor in `s[8:11]`. - **Compared with a list.** Each opcode either lowers, is refused, or panics. That status is compared with the checked-in `emit/lowering-coverage.txt` (743 lines, 24 KB). - **On a change**, the test names each changed opcode, e.g. `vop1 0x02a v_rcp_f32: lowers -> refused`. By default it only prints that as a warning and passes, so no one else's PR goes red over it. With `VICTORY_STRICT_TESTS=1` (the switch #43's skips already use) it fails. - **A deliberate change** (a new lowering) is recorded with `VICTORY_BLESS=1 cargo test -p victory-shader coverage`, and the updated list is committed with it. The whole sweep takes about 0.6 s. Today, 544 of the 743 named opcodes lower, 197 are refused, and 2 panic. The 2 are `v_permlane16_b32` and `v_permlanex16_b32`, and #79 fixes them. Once #79 merges, they show up as a warning until the list is re-blessed. ## Tests - The test passes on this branch. - I removed the `v_rcp_f32` arm from `lower.rs` locally. The test then named both encodings (`vop1 0x02a` and `vop3 0x1aa`, `lowers -> refused`). In the sandbox, a stale list passes with a warning by default and fails with `VICTORY_STRICT_TESTS=1`. - The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. The asset-policy test accepts the new `.txt`. Open lowering PRs (#56, #57, #71, #73) keep passing after this merges. Their new lowerings show up as warnings until someone re-blesses the list. Not covered: instructions that need more than this template (VOPC, memory, images, branches). The test only shows that an opcode lowers or is refused, not that the result is numerically right. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lmouz823-lang commented 2026-11-28 08:05:47 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:05:47Z.


I can take native Windows snapshot validation at exact head ef660b0b012273a15d7b5682e9b6aeb3170a93c1. I will run the ALU sweep, audit the recorded lowers/refused/panic counts and the ordinary/strict/bless paths, then propose a minimal justified regression or fix for any uncovered integrity gap. Negative controls and restored-source verification will accompany the result, with explicit panic allowances, skipped tests and numerical/GPU/game limits. AI-assisted with Codex.

<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7236359813 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/81#issuecomment-7236359813). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T08:05:47Z. --- I can take native Windows snapshot validation at exact head `ef660b0b012273a15d7b5682e9b6aeb3170a93c1`. I will run the ALU sweep, audit the recorded lowers/refused/panic counts and the ordinary/strict/bless paths, then propose a minimal justified regression or fix for any uncovered integrity gap. Negative controls and restored-source verification will accompany the result, with explicit panic allowances, skipped tests and numerical/GPU/game limits. AI-assisted with Codex.
lmouz823-lang commented 2026-11-28 08:18:47 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T08:18:47Z.


Native Windows validation and snapshot-parser repair completed for exact head ef660b0b012273a15d7b5682e9b6aeb3170a93c1. The original strict exact test executes one test and passes. The generated snapshot agrees byte-for-byte with the committed 743-row file on this machine.

The 743 outcomes consist of 544 lowers, 197 refused, and 2 caught panics. The panic rows are vop3 0x377 v_permlane16_b32 and vop3 0x378 v_permlanex16_b32. They are part of the recorded classification. The probe generates 1,728 templates from VOP1/2/3/3P and SOP1/2, and its name() path produces the 743 snapshot rows.

I found a snapshot parsing gap through the existing test entry point. filter_map(rsplit_once) silently drops a line without a separator, and BTreeMap::collect silently replaces an earlier duplicate case. Appending either kind of corruption leaves the original strict test passing. Missing cases and ordinary status changes already produce comparison diagnostics.

The attached +10/-4 test-harness patch parses each row explicitly and appends malformed-row or duplicate-case diagnostics to the existing changes list. The existing warning/strict policy then handles those diagnostics.

Snapshot / environment Original head With patch
Valid committed snapshot, strict 1 passed 1 passed
Append malformed_snapshot_entry, strict 1 passed, silently ignored 1 failed, exit 101, explicit invalid-entry diagnostic
Append a duplicate first case, strict 1 passed, silently overwritten 1 failed, exit 101, explicit duplicate-entry diagnostic
Either corruption, ordinary mode Not separately run Warns and passes
Change a real status, ordinary / strict Warns and passes / fails 101 Warns and passes / fails 101
Either corruption with VICTORY_BLESS=1, then rerun strict Status-change blessing tested Regenerates, then freshly compiled strict run passes

I also checked the existing environment interaction. Blessing runs before comparison, including with strict mode enabled. The flag is presence-based, so VICTORY_BLESS=0 also rewrites the snapshot. Both behaviors were exercised through fresh child processes. The generated file was byte-identical to the original snapshot in the tested cases.

After restoring the original snapshot bytes, I cleaned only the isolated shader-package target and confirmed a fresh 13.06-second compilation. The final strict and ordinary selections each execute one test and pass, with zero ignored tests or runtime skip diagnostics. The snapshot SHA256 is 0899c7580e081424aac104db080bfd6fb199b2d3eb41b5224ebb1dfd6404f8f5.

Package Clippy with --all-targets -- -D warnings, whole-file rustfmt on original and final source, git diff --check, and asset policy (198 files) pass. Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated target.

Scope is the synthetic lowering-outcome snapshot and its parser/mode behavior. Each opcode uses one operand template. The scalar template stores one result dword. Alternative encodings, full-width results, SCC semantics, numerical results, DXIL/GPU execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified. The two recorded panic outcomes were observed as part of snapshot agreement.

Reproduce the final exact test after applying the attached patch, with blessing cleared for comparison.

Remove-Item Env:VICTORY_BLESS -ErrorAction SilentlyContinue
$env:VICTORY_STRICT_TESTS = '1'
cargo test --locked -p victory-shader --lib emit::coverage_tests::lowering_coverage_matches_the_snapshot -- --exact --nocapture --test-threads=1

AI assistance from Codex covered the audit, patch, execution and this report.

Snapshot-parser diagnostics patch against this head
diff --git a/crates/victory-shader/src/emit/coverage_tests.rs b/crates/victory-shader/src/emit/coverage_tests.rs
index 4f42e4c..c9327b7 100644
--- a/crates/victory-shader/src/emit/coverage_tests.rs
+++ b/crates/victory-shader/src/emit/coverage_tests.rs
@@ -172,11 +172,17 @@ fn lowering_coverage_matches_the_snapshot() {
         std::fs::write(path, &now).expect("writing the snapshot");
         return;
     }
-    let was: std::collections::BTreeMap<_, _> = SNAPSHOT
-        .lines()
-        .filter_map(|l| l.rsplit_once(' '))
-        .collect();
     let mut changes = Vec::new();
+    let mut was = std::collections::BTreeMap::new();
+    for line in SNAPSHOT.lines() {
+        let Some((case, status)) = line.rsplit_once(' ') else {
+            changes.push(format!("invalid snapshot entry: {line}"));
+            continue;
+        };
+        if was.insert(case, status).is_some() {
+            changes.push(format!("{case}: duplicate snapshot entry"));
+        }
+    }
     for line in now.lines() {
         let (case, status) = line.rsplit_once(' ').expect("case and status");
         match was.get(case) {
<!-- greyfinch-sync:uiliannn/VItoriaBr:comment:7236501207 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VItoriaBr/pull/81#issuecomment-7236501207). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-28T08:18:47Z. --- Native Windows validation and snapshot-parser repair completed for exact head `ef660b0b012273a15d7b5682e9b6aeb3170a93c1`. The original strict exact test executes one test and passes. The generated snapshot agrees byte-for-byte with the committed 743-row file on this machine. The 743 outcomes consist of **544 `lowers`, 197 `refused`, and 2 caught `panics`**. The panic rows are `vop3 0x377 v_permlane16_b32` and `vop3 0x378 v_permlanex16_b32`. They are part of the recorded classification. The probe generates 1,728 templates from VOP1/2/3/3P and SOP1/2, and its `name()` path produces the 743 snapshot rows. I found a snapshot parsing gap through the existing test entry point. `filter_map(rsplit_once)` silently drops a line without a separator, and `BTreeMap::collect` silently replaces an earlier duplicate case. Appending either kind of corruption leaves the original strict test passing. Missing cases and ordinary status changes already produce comparison diagnostics. The attached **+10/-4 test-harness patch** parses each row explicitly and appends malformed-row or duplicate-case diagnostics to the existing `changes` list. The existing warning/strict policy then handles those diagnostics. | Snapshot / environment | Original head | With patch | | --- | --- | --- | | Valid committed snapshot, strict | 1 passed | 1 passed | | Append `malformed_snapshot_entry`, strict | 1 passed, silently ignored | 1 failed, exit 101, explicit invalid-entry diagnostic | | Append a duplicate first case, strict | 1 passed, silently overwritten | 1 failed, exit 101, explicit duplicate-entry diagnostic | | Either corruption, ordinary mode | Not separately run | Warns and passes | | Change a real status, ordinary / strict | Warns and passes / fails 101 | Warns and passes / fails 101 | | Either corruption with `VICTORY_BLESS=1`, then rerun strict | Status-change blessing tested | Regenerates, then freshly compiled strict run passes | I also checked the existing environment interaction. Blessing runs before comparison, including with strict mode enabled. The flag is presence-based, so `VICTORY_BLESS=0` also rewrites the snapshot. Both behaviors were exercised through fresh child processes. The generated file was byte-identical to the original snapshot in the tested cases. After restoring the original snapshot bytes, I cleaned only the isolated shader-package target and confirmed a fresh **13.06-second compilation**. The final strict and ordinary selections each execute one test and pass, with zero ignored tests or runtime skip diagnostics. The snapshot SHA256 is `0899c7580e081424aac104db080bfd6fb199b2d3eb41b5224ebb1dfd6404f8f5`. Package Clippy with `--all-targets -- -D warnings`, whole-file rustfmt on original and final source, `git diff --check`, and asset policy (**198 files**) pass. Environment was Windows 11 build 26200, Rust 1.98.1 MSVC, default test profile and an isolated target. Scope is the synthetic lowering-outcome snapshot and its parser/mode behavior. Each opcode uses one operand template. The scalar template stores one result dword. Alternative encodings, full-width results, SCC semantics, numerical results, DXIL/GPU execution, game behavior, other platforms and the remaining shader/workspace suites remain unverified. The two recorded panic outcomes were observed as part of snapshot agreement. Reproduce the final exact test after applying the attached patch, with blessing cleared for comparison. ```powershell Remove-Item Env:VICTORY_BLESS -ErrorAction SilentlyContinue $env:VICTORY_STRICT_TESTS = '1' cargo test --locked -p victory-shader --lib emit::coverage_tests::lowering_coverage_matches_the_snapshot -- --exact --nocapture --test-threads=1 ``` AI assistance from Codex covered the audit, patch, execution and this report. <details> <summary>Snapshot-parser diagnostics patch against this head</summary> ```diff diff --git a/crates/victory-shader/src/emit/coverage_tests.rs b/crates/victory-shader/src/emit/coverage_tests.rs index 4f42e4c..c9327b7 100644 --- a/crates/victory-shader/src/emit/coverage_tests.rs +++ b/crates/victory-shader/src/emit/coverage_tests.rs @@ -172,11 +172,17 @@ fn lowering_coverage_matches_the_snapshot() { std::fs::write(path, &now).expect("writing the snapshot"); return; } - let was: std::collections::BTreeMap<_, _> = SNAPSHOT - .lines() - .filter_map(|l| l.rsplit_once(' ')) - .collect(); let mut changes = Vec::new(); + let mut was = std::collections::BTreeMap::new(); + for line in SNAPSHOT.lines() { + let Some((case, status)) = line.rsplit_once(' ') else { + changes.push(format!("invalid snapshot entry: {line}")); + continue; + }; + if was.insert(case, status).is_some() { + changes.push(format!("{case}: duplicate snapshot entry")); + } + } for line in now.lines() { let (case, status) = line.rsplit_once(' ').expect("case and status"); match was.get(case) { ``` </details>

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
uiliannn/VItoriaBr!81
No description provided.