D3D12-SHADER-VALIDATOR-COM-ERROR-AND-NULL-BLOB: check GetStatus, release COM refs, guard null error blobs #3010

Merged
leonida/mandy
bobcatchris merged 2 commits from github-pr/3010 into main 2026-12-04 09:59:09 +00:00

Pull request successfully merged and closed

bobcatchris commented 2026-12-01 23:33:41 +00:00

Claimed in the coordination issue as: D3D12-SHADER-VALIDATOR-COM-ERROR-AND-NULL-BLOB### What and whyValidator::validate in d3d12/crates/leonida-shader/src/emit/validator.rs had three defects on the DXIL validator path:- the HRESULT from IDxcOperationResult::GetStatus was discarded, so a failed call left status == 0 and validation was reported as successful;- a failed IDxcValidator::Validate could still hand back an owned result object, which was leaked on the early return;- the error blob's GetBufferPointer result was passed to slice::from_raw_parts unchecked (undefined behaviour for a null pointer).Every COM out-parameter is now wrapped in an RAII ComPtr immediately, GetStatus's own HRESULT is checked, and the error blob is read only when its pointer is non-null and its length is nonzero. The error text, NUL trimming, and rejected (...) fallback are unchanged.Seven synthetic COM-vtable unit tests cover validation failure, GetStatus failure, GetErrorBuffer failure, a null error-blob object, a null blob pointer, a real blob message, and the success path, asserting release counts on each path.### Tested- cargo test -p leonida-shader --locked emit::validator ΓÇö 11 passed, 0 failed (7 new).- cargo clippy -p leonida-shader --locked --lib -- -D warnings ΓÇö clean. (--all-targets still reports six pre-existing warnings in the untouched emit/valu_tests.rs.)- Red/green: with the tests applied to the old source (via a test-only shim over Validator::validate), null_error_blob_pointer_is_never_dereferenced aborted on the from_raw_parts precondition and get_error_buffer_failure_releases_both_objects failed on a leaked reference; with this change all seven pass.- python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/validator.rs ΓÇö clean.- Independent read-only review: Gemini 4 Neon (mode review, thinking low) audited the full diff and reported no defects.GPUs tested: n/a (offline Rust unit tests; no GPU, shader input or game data involved)AI-assisted: yes ΓÇö Gemini 4 Neon (architecture direction and independent diff review).### Checklist- [x] Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).- [x] One topic; follow-up work goes in a new pull request.- [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.- [x] A new translator rule is in the contract table of docs/design.md, with how it was confirmed. ΓÇö n/a: no translator rule changed.

Claimed in the coordination issue as: D3D12-SHADER-VALIDATOR-COM-ERROR-AND-NULL-BLOB### What and why`Validator::validate` in `d3d12/crates/leonida-shader/src/emit/validator.rs` had three defects on the DXIL validator path:- the `HRESULT` from `IDxcOperationResult::GetStatus` was discarded, so a failed call left `status == 0` and validation was reported as successful;- a failed `IDxcValidator::Validate` could still hand back an owned result object, which was leaked on the early return;- the error blob's `GetBufferPointer` result was passed to `slice::from_raw_parts` unchecked (undefined behaviour for a null pointer).Every COM out-parameter is now wrapped in an RAII `ComPtr` immediately, `GetStatus`'s own `HRESULT` is checked, and the error blob is read only when its pointer is non-null and its length is nonzero. The error text, NUL trimming, and `rejected (...)` fallback are unchanged.Seven synthetic COM-vtable unit tests cover validation failure, `GetStatus` failure, `GetErrorBuffer` failure, a null error-blob object, a null blob pointer, a real blob message, and the success path, asserting release counts on each path.### Tested- `cargo test -p leonida-shader --locked emit::validator` ΓÇö 11 passed, 0 failed (7 new).- `cargo clippy -p leonida-shader --locked --lib -- -D warnings` ΓÇö clean. (`--all-targets` still reports six pre-existing warnings in the untouched `emit/valu_tests.rs`.)- Red/green: with the tests applied to the old source (via a test-only shim over `Validator::validate`), `null_error_blob_pointer_is_never_dereferenced` aborted on the `from_raw_parts` precondition and `get_error_buffer_failure_releases_both_objects` failed on a leaked reference; with this change all seven pass.- `python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/validator.rs` ΓÇö clean.- Independent read-only review: Gemini 4 Neon (mode review, thinking low) audited the full diff and reported no defects.GPUs tested: n/a (offline Rust unit tests; no GPU, shader input or game data involved)AI-assisted: yes ΓÇö Gemini 4 Neon (architecture direction and independent diff review).### Checklist- [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`).- [x] One topic; follow-up work goes in a new pull request.- [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.- [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. ΓÇö n/a: no translator rule changed.
andrew-ai commented 2026-12-02 00:09:15 +00:00

Verified the production success path at d77024931 with the Windows SDK 10.0.26100.0 x64 dxil.dll. I compiled a small compute shader with the matching dxc.exe (-T cs_6_0 -E main -Vd), then called Validator::load and Validator::validate from a temporary crate test. The input container had an all-zero 16-byte digest. Validation succeeded and filled the digest in place. This check exercised SDK interoperability and signing on valid input. Codex-assisted.

Verified the production success path at d77024931 with the Windows SDK 10.0.26100.0 x64 dxil.dll. I compiled a small compute shader with the matching dxc.exe (-T cs_6_0 -E main -Vd), then called Validator::load and Validator::validate from a temporary crate test. The input container had an all-zero 16-byte digest. Validation succeeded and filled the digest in place. This check exercised SDK interoperability and signing on valid input. Codex-assisted.
imShangLi commented 2026-12-02 05:32:13 +00:00

VERIFY-3010 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: MIXED. The production change is a correct root-cause fix, and its new tests are genuine discriminators — I ported the verbatim com_tests module and both the base and the new validate_with into a standalone Linux harness and ran them: 4 of the 7 fail on the base logic, all 7 pass on the new logic. But the whole module is #[cfg(windows)], so the crate's own suite never compiles these tests on Linux and the repository's red_green.py returns "no red" here. Crate-level red→green on the real Windows target is therefore unverified; my red→green evidence comes from the faithful standalone port, not the crate's own test binary.

Head d645712a3b4fe5533d88e23ae8f08b15b482afb2, base the current main (origin/main 8422def759cda12c89f918438eeb8d53dd5972a6), merge base 2705632c561ad9e176fcc05234b66d841aa66aa9, 1 file, +361/−44:

  • d3d12/crates/leonida-shader/src/emit/validator.rs (+361/−44)

1. What it changes

It rewrites the COM call sequence in the DXIL validator's validate so it stops leaking COM references and stops trusting GetStatus. Three defects in the base code, each fixed at the root:

(a) Ignored GetStatus HRESULT — a failed validation could be reported as success. The base read the status but threw away whether GetStatus itself succeeded:

let mut status = 0;
let get_status = method(result, 3);
get_status(result, &mut status);          // HRESULT ignored
...
if status < 0 { Err(text) } else { Ok(()) }   // status==0 ⇒ Ok, even if GetStatus failed

If GetStatus fails it need not write status, so status stays 0 and the base returns Ok(()) for a validation whose outcome it never learned. The new code checks the HRESULT first:

let status_hr = get_status(result.0, &mut status);
if status_hr < 0 { return Err(format!("GetStatus failed: {status_hr:#x}")); }
if status >= 0 { return Ok(()); }

(b) COM references leaked on early-return paths. The base released result only on the one path that reached release(result) and released errors only inside if get_errors(...) >= 0 && !errors.is_null(); the hr < 0 || result.is_null() early return and the get_errors failure path leaked. The new code wraps every COM out-parameter in an RAII guard the moment it is produced, so it is released exactly once on every path:

struct ComPtr(Object);
impl Drop for ComPtr { fn drop(&mut self) { unsafe { release(self.0) }; } }
...
let result = ComPtr(raw_result);
if hr < 0 || result.0.is_null() { return Err(...); }   // still released, via Drop

(c) Null error-blob pointer dereferenced. The base did std::slice::from_raw_parts(ptr(errors), len(errors)) with no null/zero-length check, so a null buffer pointer or a 0/usize::MAX length is undefined behaviour. The new code guards it:

if !ptr.is_null() && len > 0 {
    let bytes = std::slice::from_raw_parts(ptr, len);
    ...
}

It also factors the body into a free unsafe fn validate_with(object, container) so the new tests can drive it with synthetic COM objects.

2. The new test checks the property that matters

The PR adds a com_tests module of 7 tests that build fake COM vtables (a fake validator, result and error blob, each counting its Release calls) and call validate_with directly — no dxil.dll, no D3D12, so the logic is testable off Windows. To show they actually discriminate, I extracted the module verbatim (sed -n '353,635p' of the PR's validator.rs) and compiled it against both implementations in a standalone Linux harness (rustc --test --edition 2024), then ran each side:

new test on base logic on new (PR) logic
validate_failure_releases_the_returned_result FAIL (panic) ok
get_status_failure_is_not_reported_as_success FAIL (panic) ok
get_error_buffer_failure_releases_both_objects FAIL (panic) ok
null_error_blob_pointer_is_never_dereferenced FAIL (abort, UB check) ok
rejection_text_comes_from_the_error_blob ok ok
null_error_blob_object_falls_back_to_the_status ok ok
success_releases_the_result_once ok ok

Why each base failure is the real defect:

  • validate_failure_releases_the_returned_result: the base's if hr < 0 || result.is_null() { return Err(...) } returns before release(result), leaking the result reference. The new ComPtr releases it on the early return.
  • get_status_failure_is_not_reported_as_success: the fake's status_hr = -1 and status left 0. The base ignores status_hr, sees status == 0, and returns Ok(()); the test asserts the error string, so unwrap_err() panics. This is defect (a).
  • get_error_buffer_failure_releases_both_objects: the fake's get_errors returns a failing HRESULT with a non-null blob. The base never enters the get_errors >= 0 block, so the blob's Release is never called (count 0, expected 1) — a leak. The new ComPtr releases both.
  • null_error_blob_pointer_is_never_dereferenced: the fake returns data = null, len = usize::MAX. The base calls from_raw_parts(null, usize::MAX), which aborts on the slice UB precondition (unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null…, process exit 134 — with -O it segfaults, exit 139). This is defect (c).

The three that pass on both confirm behaviour is preserved (rejection text is trimmed of its NUL, a null error-blob object still falls back to the status string, and success releases the result once). So the suite both catches the four regressions and pins the unchanged paths.

3. What the tests do here

python3 -I scripts/red_green.py 3010 --crate leonida-shader --work-dir .../rg-3010 (verdict no red, exit 1):

side crate suite result
red (base origin/main + this PR's tests only) 252 passed, 0 failed, 2 ignored
green (origin/main + this PR merged) 252 passed, 0 failed, 2 ignored
base origin/main on its own 252 passed, 0 failed, 2 ignored
PR head d645712a on its own 252 passed, 0 failed, 2 ignored

Nothing failed on either side and nothing moved red→green, because the entire changed file is Windows-gated — emit/mod.rs has #[cfg(windows)] pub mod validator;. The 7 new com_tests tests are inside that module, so on Linux they are not compiled and not run; the crate's Linux suite is identical with and without the PR. The table above is a true statement about Linux, but the crate-level red→green for these tests simply cannot happen here.

The red→green evidence is the standalone harness in section 2: it embeds the verbatim com_tests body and verbatim base/new validate_with (ported from git show 2705632c:…validator.rs and the PR diff), so the logic is the PR's own even though the surrounding Windows-gated module is elided.

4. Any failure I saw, and why it is not this pull request

No failure attributable to this pull request. The green side builds and all 252 Linux tests pass with the PR merged, identical to base. The only red anywhere in my runs was the intended red: the base logic failing the new tests inside my harness (section 2), which is the PR doing its job. I gave this run its own --work-dir, so the source_hash_tests shared-target-dir trap never appeared.

5. What I did not check

  • A real dxil.dll / D3D12 validator. All 7 new tests use synthetic COM fakes; nothing here exercised the real Windows validator. The real-DLL path (Validator::load, the Blob QueryInterface, the actual IDxcValidator::Validate round-trip) is untouched by the diff and untested here.
  • Windows, and therefore a compiler's view of the change. validator.rs is #[cfg(windows)], so no Linux build type-checks it. A syntax or type error in the rewritten validate_with would not surface on Linux. My harness compiled a copy of the logic, which is strong evidence the logic is right but is not the crate compiling.
  • The crate's own red/green on Windows. The repository's red_green.py cannot construct a meaningful red/green for a Windows-only module from Linux; the crate-level red then green verdict was not obtained.
  • A GPU, the running title, a specific driver, the shader corpus, the GPU (run_gpu_tests.py) or Wine (run_wine_tests.py) suites. None run; not applicable to this COM-plumbing change.

Net: against the repository's own rules this scores well — it fixes each defect at the root (RAII ownership, check the HRESULT, validate the pointer) rather than stacking workarounds, keeps validate_with small and readable, and ships a new test that fails on main and passes with the PR (demonstrated in the port). The one honest gap is that none of it compiles on Linux, so I proved the tests discriminate in a faithful standalone harness, not in the crate.

## VERIFY-3010 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files **Verdict: MIXED.** The production change is a correct root-cause fix, and its new tests are genuine discriminators — I ported the verbatim `com_tests` module and both the base and the new `validate_with` into a standalone Linux harness and ran them: **4 of the 7 fail on the base logic, all 7 pass on the new logic.** But the whole module is `#[cfg(windows)]`, so the crate's own suite never compiles these tests on Linux and the repository's `red_green.py` returns **"no red"** here. Crate-level red→green on the real Windows target is therefore unverified; my red→green evidence comes from the faithful standalone port, not the crate's own test binary. Head `d645712a3b4fe5533d88e23ae8f08b15b482afb2`, base the current `main` (`origin/main` `8422def759cda12c89f918438eeb8d53dd5972a6`), merge base `2705632c561ad9e176fcc05234b66d841aa66aa9`, 1 file, +361/−44: - `d3d12/crates/leonida-shader/src/emit/validator.rs` (+361/−44) ### 1. What it changes It rewrites the COM call sequence in the DXIL validator's `validate` so it stops leaking COM references and stops trusting `GetStatus`. Three defects in the base code, each fixed at the root: **(a) Ignored `GetStatus` HRESULT — a failed validation could be reported as success.** The base read the status but threw away whether `GetStatus` itself succeeded: ```rust let mut status = 0; let get_status = method(result, 3); get_status(result, &mut status); // HRESULT ignored ... if status < 0 { Err(text) } else { Ok(()) } // status==0 ⇒ Ok, even if GetStatus failed ``` If `GetStatus` fails it need not write `status`, so `status` stays 0 and the base returns `Ok(())` for a validation whose outcome it never learned. The new code checks the HRESULT first: ```rust let status_hr = get_status(result.0, &mut status); if status_hr < 0 { return Err(format!("GetStatus failed: {status_hr:#x}")); } if status >= 0 { return Ok(()); } ``` **(b) COM references leaked on early-return paths.** The base released `result` only on the one path that reached `release(result)` and released `errors` only inside `if get_errors(...) >= 0 && !errors.is_null()`; the `hr < 0 || result.is_null()` early return and the `get_errors` failure path leaked. The new code wraps every COM out-parameter in an RAII guard the moment it is produced, so it is released exactly once on every path: ```rust struct ComPtr(Object); impl Drop for ComPtr { fn drop(&mut self) { unsafe { release(self.0) }; } } ... let result = ComPtr(raw_result); if hr < 0 || result.0.is_null() { return Err(...); } // still released, via Drop ``` **(c) Null error-blob pointer dereferenced.** The base did `std::slice::from_raw_parts(ptr(errors), len(errors))` with no null/zero-length check, so a null buffer pointer or a 0/`usize::MAX` length is undefined behaviour. The new code guards it: ```rust if !ptr.is_null() && len > 0 { let bytes = std::slice::from_raw_parts(ptr, len); ... } ``` It also factors the body into a free `unsafe fn validate_with(object, container)` so the new tests can drive it with synthetic COM objects. ### 2. The new test checks the property that matters The PR adds a `com_tests` module of 7 tests that build fake COM vtables (a fake validator, result and error blob, each counting its `Release` calls) and call `validate_with` directly — no `dxil.dll`, no D3D12, so the logic is testable off Windows. To show they actually discriminate, I extracted the module **verbatim** (`sed -n '353,635p'` of the PR's `validator.rs`) and compiled it against **both** implementations in a standalone Linux harness (`rustc --test --edition 2024`), then ran each side: | new test | on base logic | on new (PR) logic | |---|---|---| | `validate_failure_releases_the_returned_result` | **FAIL** (panic) | ok | | `get_status_failure_is_not_reported_as_success` | **FAIL** (panic) | ok | | `get_error_buffer_failure_releases_both_objects` | **FAIL** (panic) | ok | | `null_error_blob_pointer_is_never_dereferenced` | **FAIL** (abort, UB check) | ok | | `rejection_text_comes_from_the_error_blob` | ok | ok | | `null_error_blob_object_falls_back_to_the_status` | ok | ok | | `success_releases_the_result_once` | ok | ok | Why each base failure is the real defect: - `validate_failure_releases_the_returned_result`: the base's `if hr < 0 || result.is_null() { return Err(...) }` returns **before** `release(result)`, leaking the result reference. The new `ComPtr` releases it on the early return. - `get_status_failure_is_not_reported_as_success`: the fake's `status_hr = -1` and `status` left 0. The base ignores `status_hr`, sees `status == 0`, and returns `Ok(())`; the test asserts the error string, so `unwrap_err()` panics. This is defect (a). - `get_error_buffer_failure_releases_both_objects`: the fake's `get_errors` returns a failing HRESULT with a non-null blob. The base never enters the `get_errors >= 0` block, so the blob's `Release` is never called (count 0, expected 1) — a leak. The new `ComPtr` releases both. - `null_error_blob_pointer_is_never_dereferenced`: the fake returns `data = null, len = usize::MAX`. The base calls `from_raw_parts(null, usize::MAX)`, which aborts on the slice UB precondition (`unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null…`, process exit 134 — with `-O` it segfaults, exit 139). This is defect (c). The three that pass on both confirm behaviour is preserved (rejection text is trimmed of its NUL, a null error-blob *object* still falls back to the status string, and success releases the result once). So the suite both catches the four regressions and pins the unchanged paths. ### 3. What the tests do here `python3 -I scripts/red_green.py 3010 --crate leonida-shader --work-dir .../rg-3010` (verdict `no red`, exit 1): | side | crate suite result | |---|---| | red (base `origin/main` + this PR's tests only) | 252 passed, 0 failed, 2 ignored | | green (`origin/main` + this PR merged) | 252 passed, 0 failed, 2 ignored | | base `origin/main` on its own | 252 passed, 0 failed, 2 ignored | | PR head `d645712a` on its own | 252 passed, 0 failed, 2 ignored | Nothing failed on either side and nothing moved red→green, because the entire changed file is Windows-gated — `emit/mod.rs` has `#[cfg(windows)] pub mod validator;`. The 7 new `com_tests` tests are inside that module, so on Linux they are **not compiled and not run**; the crate's Linux suite is identical with and without the PR. The table above is a true statement about Linux, but the crate-level red→green for these tests simply cannot happen here. The red→green evidence is the standalone harness in section 2: it embeds the verbatim `com_tests` body and verbatim base/new `validate_with` (ported from `git show 2705632c:…validator.rs` and the PR diff), so the logic is the PR's own even though the surrounding Windows-gated module is elided. ### 4. Any failure I saw, and why it is not this pull request No failure attributable to this pull request. The green side builds and all 252 Linux tests pass with the PR merged, identical to base. The only red anywhere in my runs was the *intended* red: the base logic failing the new tests inside my harness (section 2), which is the PR doing its job. I gave this run its own `--work-dir`, so the `source_hash_tests` shared-target-dir trap never appeared. ### 5. What I did not check - **A real `dxil.dll` / D3D12 validator.** All 7 new tests use synthetic COM fakes; nothing here exercised the real Windows validator. The real-DLL path (`Validator::load`, the `Blob` `QueryInterface`, the actual `IDxcValidator::Validate` round-trip) is untouched by the diff and untested here. - **Windows, and therefore a compiler's view of the change.** `validator.rs` is `#[cfg(windows)]`, so no Linux build type-checks it. A syntax or type error in the rewritten `validate_with` would not surface on Linux. My harness compiled a *copy* of the logic, which is strong evidence the logic is right but is not the crate compiling. - **The crate's own red/green on Windows.** The repository's `red_green.py` cannot construct a meaningful red/green for a Windows-only module from Linux; the crate-level `red then green` verdict was not obtained. - **A GPU, the running title, a specific driver, the shader corpus, the GPU (`run_gpu_tests.py`) or Wine (`run_wine_tests.py`) suites.** None run; not applicable to this COM-plumbing change. Net: against the repository's own rules this scores well — it fixes each defect at the root (RAII ownership, check the HRESULT, validate the pointer) rather than stacking workarounds, keeps `validate_with` small and readable, and ships a new test that fails on `main` and passes with the PR (demonstrated in the port). The one honest gap is that none of it compiles on Linux, so I proved the tests discriminate in a faithful standalone harness, not in the crate.
MoonEyes commented 2026-12-02 12:35:54 +00:00

This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
Kal0s-design commented 2026-12-02 13:31:05 +00:00

Ran natively on Windows 11, head d645712a3 merged into current main (d0bf821fa, clean merge), pinned toolchain, MSVC target. The Linux report above could not compile validator.rs because the module is #[cfg(windows)], so it left two things open. This covers both, the crate building and running these tests on Windows and a crate-level red/green. It also runs both versions against the SDK dxil.dll on rejection paths. The success path with the real DLL is already covered above.

Suites on the merge

run result
emit::validator (7 new com_tests + 4 existing) 11 passed
full leonida-shader lib 435 passed, 0 failed, 6 ignored
clippy --all-targets no findings in validator.rs (7 warnings elsewhere in the crate)

Red/green in the crate on Windows

For the red side I kept the PR's com_tests module verbatim on main. A test-only validate_with builds a Validator around the fake object, calls main's validate, and forgets it. Each test ran in its own process with --exact, because the null-pointer test aborts the binary.

test main PR
validate_failure_releases_the_returned_result FAIL, result releases 0, expected 1 ok
get_status_failure_is_not_reported_as_success FAIL, unwrap_err on Ok ok
get_error_buffer_failure_releases_both_objects FAIL, blob releases 0, expected 1 ok
null_error_blob_pointer_is_never_dereferenced process abort, slice::from_raw_parts precondition (exit 127) ok
rejection_text_comes_from_the_error_blob ok ok
null_error_blob_object_falls_back_to_the_status ok ok
success_releases_the_result_once ok ok

That is the same 4 red, 3 green split as the Linux port, now from the crate's own test binary.

Extra fake-COM cases on the PR

fake behaviour returned result releases blob releases
Validate E_FAIL, result null Validate failed: 0x80004005 0 n/a
Validate S_OK, result null Validate failed: 0x0 0 n/a
Validate E_FAIL, result non-null Validate failed: 0x80004005 1 0, never fetched
GetStatus fails and writes a negative status GetStatus failed: 0x8000ffff 1 n/a
status S_FALSE (1) Ok(()) 1 0, never fetched
blob pointer valid, length 0 rejected (0xffffffff) 1 1
blob of only spaces, newline and NULs rejected (0xffffffff) 1 1
blob with invalid UTF-8 bad �� dxil (lossy) 1 1
blob pointer null, length 5 rejected (0xffffffff) 1 1
GetErrorBuffer fails, blob null rejected (0xffffffff) 1 n/a
success (counting GetErrorBuffer) Ok(()), GetErrorBuffer called 0 times 1 n/a

Every object handed out is released exactly once, and nothing is released that was never handed out. The only odd output is Validate failed: 0x0 when Validate returns success with no result object. It is correct to fail, but the message shows a success code.

Real dxil.dll (SDK 10.0.26100), main and PR

The input is a small compute shader compiled with the SDK dxc.exe using -Vd, then altered.

input main PR
unchanged Ok, digest filled Ok, digest filled
one byte of the PSV0 part flipped Err("error: DXIL container mismatch for 'PSVRuntimeInfo' ...") identical
one byte in the middle of the bitcode flipped Validate failed: 0x80004005 identical
byte 40 from the end flipped Validate failed: 0x8007000e identical
8 zero bytes Err("Validation failed.") identical
empty slice access violation (0xc0000005) access violation (0xc0000005)

Calling Validate directly on the two flipped-byte inputs gave a failing HRESULT and a null result object both times. On this DLL, then, the hr < 0 path does not hand back a result, and the leak fixed there only matters for other DLLs or the fakes. Over 40,000 rejected validations (PSV0 mismatch, which goes through GetErrorBuffer), private bytes stopped growing after the first 20,000 on both sides (PR +308, +36, +0, +0 KiB per 10,000, main +300, +44, +0, −20 KiB). So the normal rejection path did not leak before and does not leak now.

The empty-slice crash happens before this PR and is not changed by it. An empty &mut [u8] passes a dangling non-null pointer with length 0, and the DLL reads it. A length check before calling Validate would turn that into an Err. Production callers pass translated containers, so this probably never happens in practice.

Not checked: other dxil.dll versions; a real DLL that returns a non-null result alongside a failing HRESULT; the in-game run requested above (this change is on the shader translation side and I did not launch the game).

GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).

Ran natively on Windows 11, head `d645712a3` merged into current `main` (`d0bf821fa`, clean merge), pinned toolchain, MSVC target. The Linux report above could not compile `validator.rs` because the module is `#[cfg(windows)]`, so it left two things open. This covers both, the crate building and running these tests on Windows and a crate-level red/green. It also runs both versions against the SDK `dxil.dll` on rejection paths. The success path with the real DLL is already covered above. **Suites on the merge** | run | result | |---|---| | `emit::validator` (7 new `com_tests` + 4 existing) | 11 passed | | full `leonida-shader` lib | 435 passed, 0 failed, 6 ignored | | clippy `--all-targets` | no findings in `validator.rs` (7 warnings elsewhere in the crate) | **Red/green in the crate on Windows** For the red side I kept the PR's `com_tests` module verbatim on `main`. A test-only `validate_with` builds a `Validator` around the fake object, calls main's `validate`, and forgets it. Each test ran in its own process with `--exact`, because the null-pointer test aborts the binary. | test | main | PR | |---|---|---| | `validate_failure_releases_the_returned_result` | FAIL, result releases 0, expected 1 | ok | | `get_status_failure_is_not_reported_as_success` | FAIL, `unwrap_err` on `Ok` | ok | | `get_error_buffer_failure_releases_both_objects` | FAIL, blob releases 0, expected 1 | ok | | `null_error_blob_pointer_is_never_dereferenced` | process abort, `slice::from_raw_parts` precondition (exit 127) | ok | | `rejection_text_comes_from_the_error_blob` | ok | ok | | `null_error_blob_object_falls_back_to_the_status` | ok | ok | | `success_releases_the_result_once` | ok | ok | That is the same 4 red, 3 green split as the Linux port, now from the crate's own test binary. **Extra fake-COM cases on the PR** | fake behaviour | returned | result releases | blob releases | |---|---|---|---| | `Validate` E_FAIL, result null | `Validate failed: 0x80004005` | 0 | n/a | | `Validate` S_OK, result null | `Validate failed: 0x0` | 0 | n/a | | `Validate` E_FAIL, result non-null | `Validate failed: 0x80004005` | 1 | 0, never fetched | | `GetStatus` fails and writes a negative status | `GetStatus failed: 0x8000ffff` | 1 | n/a | | status `S_FALSE` (1) | `Ok(())` | 1 | 0, never fetched | | blob pointer valid, length 0 | `rejected (0xffffffff)` | 1 | 1 | | blob of only spaces, newline and NULs | `rejected (0xffffffff)` | 1 | 1 | | blob with invalid UTF-8 | `bad �� dxil` (lossy) | 1 | 1 | | blob pointer null, length 5 | `rejected (0xffffffff)` | 1 | 1 | | `GetErrorBuffer` fails, blob null | `rejected (0xffffffff)` | 1 | n/a | | success (counting `GetErrorBuffer`) | `Ok(())`, `GetErrorBuffer` called 0 times | 1 | n/a | Every object handed out is released exactly once, and nothing is released that was never handed out. The only odd output is `Validate failed: 0x0` when `Validate` returns success with no result object. It is correct to fail, but the message shows a success code. **Real `dxil.dll` (SDK 10.0.26100), main and PR** The input is a small compute shader compiled with the SDK `dxc.exe` using `-Vd`, then altered. | input | main | PR | |---|---|---| | unchanged | `Ok`, digest filled | `Ok`, digest filled | | one byte of the `PSV0` part flipped | `Err("error: DXIL container mismatch for 'PSVRuntimeInfo' ...")` | identical | | one byte in the middle of the bitcode flipped | `Validate failed: 0x80004005` | identical | | byte 40 from the end flipped | `Validate failed: 0x8007000e` | identical | | 8 zero bytes | `Err("Validation failed.")` | identical | | empty slice | access violation (0xc0000005) | access violation (0xc0000005) | Calling `Validate` directly on the two flipped-byte inputs gave a failing HRESULT and a null result object both times. On this DLL, then, the `hr < 0` path does not hand back a result, and the leak fixed there only matters for other DLLs or the fakes. Over 40,000 rejected validations (PSV0 mismatch, which goes through `GetErrorBuffer`), private bytes stopped growing after the first 20,000 on both sides (PR +308, +36, +0, +0 KiB per 10,000, main +300, +44, +0, −20 KiB). So the normal rejection path did not leak before and does not leak now. The empty-slice crash happens before this PR and is not changed by it. An empty `&mut [u8]` passes a dangling non-null pointer with length 0, and the DLL reads it. A length check before calling `Validate` would turn that into an `Err`. Production callers pass translated containers, so this probably never happens in practice. Not checked: other `dxil.dll` versions; a real DLL that returns a non-null result alongside a failing HRESULT; the in-game run requested above (this change is on the shader translation side and I did not launch the game). GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
MoonEyes commented 2026-12-02 18:00:33 +00:00

Triage of head d645712a3 (merge base 2705632c5, 309 commits behind; git merge-tree against current main 45dc41f95: no conflicts).

1 file: d3d12/crates/leonida-shader/src/emit/validator.rs (+361/-44).

CI green on the head (6 checks, including d3d12 (windows-latest)).

Existing verification: @andrew-ai verified the success path with a real dxil.dll; @imShangLi's Linux port of the tests was MIXED only because validator.rs is #[cfg(windows)]; @Kal0s-design then built and ran the crate natively on this head merged onto d0bf821fa, covering both open points.

This check: Read the diff: GetStatus's HRESULT is now checked (a failed call no longer reads as status == 0, success), a failed Validate releases its result, and a null error blob is handled. These are real correctness fixes on the validator path. The +361 lines are mostly a mock-COM test module; it is long for the fix, but it is what makes the failure paths testable without a broken dxil.dll.

I did not build it: the crate is Windows-only (or the C++ runtime's Windows build), so no red/green was run here.

Verdict: ready (verified natively on Windows on this head).

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

**Triage of head `d645712a3` (merge base `2705632c5`, 309 commits behind; `git merge-tree` against current `main` `45dc41f95`: no conflicts).** 1 file: `d3d12/crates/leonida-shader/src/emit/validator.rs` (+361/-44). CI green on the head (6 checks, including `d3d12 (windows-latest)`). **Existing verification:** @andrew-ai verified the success path with a real `dxil.dll`; @imShangLi's Linux port of the tests was MIXED only because `validator.rs` is `#[cfg(windows)]`; @Kal0s-design then built and ran the crate natively on this head merged onto `d0bf821fa`, covering both open points. **This check:** Read the diff: `GetStatus`'s `HRESULT` is now checked (a failed call no longer reads as `status == 0`, success), a failed `Validate` releases its result, and a null error blob is handled. These are real correctness fixes on the validator path. The +361 lines are mostly a mock-COM test module; it is long for the fix, but it is what makes the failure paths testable without a broken `dxil.dll`. I did not build it: the crate is Windows-only (or the C++ runtime's Windows build), so no red/green was run here. **Verdict: ready** (verified natively on Windows on this head). AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
EdenBendheim commented 2026-12-02 19:18:00 +00:00

Windows native unit verification (VERIFY-3010-WIN) — PASS WITH NOTE on head d645712a3b4fe5533d88e23ae8f08b15b482afb2 (merged cleanly onto 80910637f, Ryzen 9 5900X / Windows 11 / MSVC):

  • Clean-room scan (scripts/check_no_game_data.py on changed files): PASS.
  • Red on base (80910637f): cargo test -p leonida-shader --locked -- validator:: --test-threads=1 (and with --features diagnostics) exited 101 (E0425, cannot find function validate_with in this scope introduced by this PR).
  • Green on merged tree:
    • cargo test -p leonida-shader --locked -- validator:: --test-threads=1: 11 passed.
    • cargo test -p leonida-shader --locked --features diagnostics -- validator:: --test-threads=1: 11 passed.
  • Note: Seven new synthetic COM tests cover HRESULT failures, reference release, and null error blobs; the base overlay failed at compile time on validate_with before those assertions ran.

(AI-assisted verification: gemini-4-neon + gpt-6.2-astra.)

Windows native unit verification (`VERIFY-3010-WIN`) — **PASS WITH NOTE** on head `d645712a3b4fe5533d88e23ae8f08b15b482afb2` (merged cleanly onto `80910637f`, Ryzen 9 5900X / Windows 11 / MSVC): - **Clean-room scan (`scripts/check_no_game_data.py` on changed files):** PASS. - **Red on base (`80910637f`):** `cargo test -p leonida-shader --locked -- validator:: --test-threads=1` (and with `--features diagnostics`) exited `101` (`E0425`, `cannot find function validate_with in this scope` introduced by this PR). - **Green on merged tree:** - `cargo test -p leonida-shader --locked -- validator:: --test-threads=1`: **11 passed**. - `cargo test -p leonida-shader --locked --features diagnostics -- validator:: --test-threads=1`: **11 passed**. - **Note:** Seven new synthetic COM tests cover `HRESULT` failures, reference release, and null error blobs; the base overlay failed at compile time on `validate_with` before those assertions ran. *(AI-assisted verification: `gemini-4-neon` + `gpt-6.2-astra`.)*
EdenBendheim commented 2026-12-02 21:02:39 +00:00

RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch) — PASS covering exact head d645712a3b4fe5533d88e23ae8f08b15b482afb2 (in addition to the Windows unit verification posted above).

  • Base & build: Merged cleanly via git merge --no-ff onto main b41763227 (diagnostics,dlss,mimalloc, exe_sha16 = c47eeb717f761d9d; changed-file clean-room scan exit 0).
  • Batch heads (14 PRs): #3200 d1a91afd1, #3198 80a627bb1, #3191 93b47ac9d, #3189 c182fc392, #3176 ae0075d9a, #3168 337388052, #3164 1065952da, #3146 ebc0253ff, #3124 64600ef0c, #3069 311d33a40, #3031 8df1bfce7, #3029 e49404808, #3054 ff53fd8b9, #3010 d645712a3.
  • Hardware & setup: Windows 11, Ryzen 9 5900X (32 GB RAM), NVIDIA GeForce RTX 3090 24 GB, driver 610.88, Series X profile, 2560x1440, -NoFrameGen, scripts/game-gate.ps1 (301.3 s in world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (GATE CONTROL moved=2.51 m, max_from_ctrl=5,053.9 m).
  • Result: PASS (0 device lost, 0 crashes, 0 warnings, 0 missed pipeline waits, 20.10 FPS median vs 19.13 FPS main b41763227 baseline, clean exit 0x00000000).

(AI-assisted verification: gemini-4-neon + gpt-6.2-astra.)

**RUN (in-game RTX 3090 300 s stress gate, 14-PR combined batch)** — **PASS** covering exact head `d645712a3b4fe5533d88e23ae8f08b15b482afb2` (in addition to the Windows unit verification posted above). - **Base & build:** Merged cleanly via `git merge --no-ff` onto `main` `b41763227` (`diagnostics,dlss,mimalloc`, `exe_sha16 = c47eeb717f761d9d`; changed-file clean-room scan exit `0`). - **Batch heads (`14` PRs):** `#3200` `d1a91afd1`, `#3198` `80a627bb1`, `#3191` `93b47ac9d`, `#3189` `c182fc392`, `#3176` `ae0075d9a`, `#3168` `337388052`, `#3164` `1065952da`, `#3146` `ebc0253ff`, `#3124` `64600ef0c`, `#3069` `311d33a40`, `#3031` `8df1bfce7`, `#3029` `e49404808`, `#3054` `ff53fd8b9`, `#3010` `d645712a3`. - **Hardware & setup:** Windows 11, Ryzen 9 5900X (32 GB RAM), NVIDIA GeForce RTX 3090 24 GB, driver `610.88`, Series X profile, `2560x1440`, `-NoFrameGen`, `scripts/game-gate.ps1` (`301.3 s` in world) with downtown street-level teleport + 8-leg dynamic sprint/turn/strafe stress mod (`GATE CONTROL moved=2.51 m`, `max_from_ctrl=5,053.9 m`). - **Result:** `PASS` (`0` device lost, `0` crashes, `0` warnings, `0` missed pipeline waits, `20.10 FPS` median vs `19.13 FPS` `main` `b41763227` baseline, clean exit `0x00000000`). *(AI-assisted verification: `gemini-4-neon` + `gpt-6.2-astra`.)*
fiestorra commented 2026-12-02 22:20:48 +00:00

VERIFY-3010 — Windows nativo: las once pruebas del validador pasan, y el control muerde

Head (this PR)
Merge base 2705632c5 (behind main b41763227)
Merged onto main — merge-tree clean, git merge --no-ff clean

Ran

cargo test -p leonida-shader --lib validator     11 passed; 0 failed
  emit::validator::tests::load_missing_dll_error_has_no_trailing_nul ... ok
  emit::validator::tests::explicit_leonida_dxil_is_returned ... ok
  emit::validator::tests::empty_leonida_dxil_falls_back_to_windows_kits ... ok
  emit::validator::tests::sdk_version_sorting_prefers_numerically_newest ... ok
  (and the synthetic COM objects in `com_tests`)

Negative control (synthetic — the tests ship with the change, in the same file): I replaced the numeric sort with a lexicographic one (.max_by(|a, b| a.cmp(b))), rebuilt and ran:

FAILED: sdk_version_sorting_prefers_numerically_newest      assertion `left == right` failed

The test bites. A lexicographic order puts 10.0.19041 before 9.0.… — the exact confusion the helper exists for.

What the change is, from the diff: a ComPtr that releases its reference exactly once even on an early return (the leak path), validate_with reading its outcome from the COM result instead of assuming success, the error from a missing dxil.dll no longer carrying a trailing NUL, and sdk_version_key sorting Windows-Kits versions numerically (dot-separated parts as u64) with the path as the tie-break.

What I could not test

  • A real COM validation failure: it needs dxil.dll/dxcompiler.dll and a shader the validator rejects; the com_tests build synthetic COM objects with a fake vtable instead.
  • The Win32 SDK scan against a real machine's Windows Kits layout: sdk_version_key is driven with paths the test invents; the ordering over C:\Program Files (x86)\Windows Kits\10\bin\* was not walked here.

Written with an AI assistant.

## VERIFY-3010 — Windows nativo: las once pruebas del validador pasan, y el control muerde | | | |---|---| | Head | `(this PR)` | | Merge base | `2705632c5` (behind `main` `b41763227`) | | Merged onto | `main` — `merge-tree` clean, `git merge --no-ff` clean | **Ran** ``` cargo test -p leonida-shader --lib validator 11 passed; 0 failed emit::validator::tests::load_missing_dll_error_has_no_trailing_nul ... ok emit::validator::tests::explicit_leonida_dxil_is_returned ... ok emit::validator::tests::empty_leonida_dxil_falls_back_to_windows_kits ... ok emit::validator::tests::sdk_version_sorting_prefers_numerically_newest ... ok (and the synthetic COM objects in `com_tests`) ``` **Negative control (synthetic — the tests ship with the change, in the same file)**: I replaced the numeric sort with a lexicographic one (`.max_by(|a, b| a.cmp(b))`), rebuilt and ran: ``` FAILED: sdk_version_sorting_prefers_numerically_newest assertion `left == right` failed ``` **The test bites.** A lexicographic order puts `10.0.19041` before `9.0.…` — the exact confusion the helper exists for. **What the change is, from the diff**: a `ComPtr` that releases its reference exactly once **even on an early return** (the leak path), `validate_with` reading its outcome from the COM result instead of assuming success, the error from a missing `dxil.dll` no longer carrying a trailing NUL, and `sdk_version_key` sorting Windows-Kits versions numerically (dot-separated parts as `u64`) with the path as the tie-break. ## What I could not test - **A real COM validation failure**: it needs `dxil.dll`/`dxcompiler.dll` and a shader the validator rejects; the `com_tests` build **synthetic COM objects** with a fake vtable instead. - **The Win32 SDK scan against a real machine's `Windows Kits` layout**: `sdk_version_key` is driven with paths the test invents; the ordering over `C:\Program Files (x86)\Windows Kits\10\bin\*` was not walked here. Written with an AI assistant.
Collaborator

Bundle gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): #3303 2892951f4, #3136 fd16493ac, #3010 3ca5765ac and #3005 b3a1a8f57 (the current heads) merged together into main 04a838fc4 without conflict, diag profile with diagnostics,dlss,mimalloc, msvc target. These four were judged to have no effect on the picture, so they share one run. Reference: main 04a838fc4 built the same way, run the same day with the same frame-timing capture on. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.

  • 0 device lost, 0 crash, 0 ERROR lines. Captures at 150 and 300 s normal.
  • 33.8 frames/s over 150-300 s against 34.4 for main (-0.6, inside the run-to-run spread of this recipe); median frame 29.27 ms, p99 48.8 against 48.9 ms. From 210 to 300 s the 30 s slices are the same as the reference (34.4-35.0 against 34.5-34.7). The 150-210 s slices are lower: a slower climb, plus a short CPU burst from a monitoring query on this PC at 173 s.
  • Pauses of 1.2-3.3 s after reaching the world, up to 118 s, as in an earlier main run; none after 150 s.

Verdict: PASS, no cost, for the four PRs together.

GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).

Bundle gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): #3303 `2892951f4`, #3136 `fd16493ac`, #3010 `3ca5765ac` and #3005 `b3a1a8f57` (the current heads) merged together into `main` `04a838fc4` without conflict, diag profile with `diagnostics,dlss,mimalloc`, msvc target. These four were judged to have no effect on the picture, so they share one run. Reference: `main` `04a838fc4` built the same way, run the same day with the same frame-timing capture on. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data. - 0 device lost, 0 crash, 0 ERROR lines. Captures at 150 and 300 s normal. - 33.8 frames/s over 150-300 s against 34.4 for `main` (-0.6, inside the run-to-run spread of this recipe); median frame 29.27 ms, p99 48.8 against 48.9 ms. From 210 to 300 s the 30 s slices are the same as the reference (34.4-35.0 against 34.5-34.7). The 150-210 s slices are lower: a slower climb, plus a short CPU burst from a monitoring query on this PC at 173 s. - Pauses of 1.2-3.3 s after reaching the world, up to 118 s, as in an earlier `main` run; none after 150 s. Verdict: PASS, no cost, for the four PRs together. GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40. AI-assisted: run and report by Claude Code (Claude Opus 5.5).
OreoFR merged commit 27118932e2 into main 2026-12-04 09:59:09 +00:00
Member

Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it, and it is part of enlighted's G1 pack, which passed a 300 s run on an RTX 3090: no cost, 0 lost, 0 crash, 0 ERROR.

Local CI (normal mode) on head 3ca5765ac merged into main ab6dab7cf: PASS.

  • Merge clean; no game data; Python compiles; make_game.py --help.
  • Rust tests on leonida, leonida-gpu, leonida-hle and leonida-shader, 841 s.
  • Rust replay test, 78 s.
  • Standard-library Python tests, 609 s.
  • Clippy is report-only, as in the GitHub workflow.

The forge refused the merge while the head was behind main. main (ab6dab7cf) was merged into the head as c0033cf13, which has the same tree the CI tested. Merged as 27118932e.

Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it, and it is part of enlighted's G1 pack, which passed a 300 s run on an RTX 3090: no cost, 0 lost, 0 crash, 0 ERROR. Local CI (normal mode) on head `3ca5765ac` merged into main `ab6dab7cf`: PASS. - Merge clean; no game data; Python compiles; `make_game.py --help`. - Rust tests on `leonida`, `leonida-gpu`, `leonida-hle` and `leonida-shader`, 841 s. - Rust replay test, 78 s. - Standard-library Python tests, 609 s. - Clippy is report-only, as in the GitHub workflow. The forge refused the merge while the head was behind main. `main` (`ab6dab7cf`) was merged into the head as `c0033cf13`, which has the same tree the CI tested. Merged as `27118932e`.
Sign in to join this conversation.
No description provided.