d3d12-shader: fix validator SDK version sort, empty env fallback, and error cleanup #2875

Merged
kirigayakazima merged 1 commit from upstream-pr/2875 into main 2026-12-01 15:04:12 +00:00
kirigayakazima commented 2026-12-01 13:06:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-12-01T13:06:07Z.


Claimed in the coordination issue as: D3D12-VALIDATOR-SDK-VERSION-AND-CLEANUP (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7312055346)

What and why

Fixes four small defects in d3d12/crates/leonida-shader/src/emit/validator.rs:

  1. Numeric SDK version sorting (Validator::default_path): previously versions.sort(); versions.pop() sorted paths lexicographically, so e.g. 10.0.9999.0 sorted after 10.0.26100.0. Extracted sdk_version_key and default_path_from to select the numerically newest dotted SDK version.
  2. Empty LEONIDA_DXIL="" fallback: filtered out empty LEONIDA_DXIL values so setting LEONIDA_DXIL="" falls back to scanning Windows Kits (matching leonida-core/src/config.rs), instead of returning Some("").
  3. Clean error string in Validator::load: sliced off the trailing UTF-16 NUL terminator when formatting "cannot load ...", avoiding an embedded \0 in error text.
  4. Release HMODULE on load failure: called FreeLibrary(module) before returning Err if GetProcAddress or DxcCreateInstance fails in Validator::load.

Tested

Verified locally (Windows 11, Rust 1.98.1, no game data):

  • Red before fix: cargo test --locked -p leonida-shader --lib emit::validator failed 3 of 4 tests (sdk_version_sorting_prefers_numerically_newest, empty_leonida_dxil_falls_back_to_windows_kits, load_missing_dll_error_has_no_trailing_nul).
  • Green after fix:
    • cargo test --locked -p leonida-shader --lib emit::validator: 4 passed; 0 failed
    • cargo clippy --locked -p leonida-shader -- -D warnings: 0 warnings, exit 0
    • python -I scripts/check_no_game_data.py & git diff --check: clean

GPUs tested: n/a (unit tests only)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5586297291 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2875). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-12-01T13:06:07Z. --- Claimed in the coordination issue as: D3D12-VALIDATOR-SDK-VERSION-AND-CLEANUP (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7312055346) ### What and why Fixes four small defects in `d3d12/crates/leonida-shader/src/emit/validator.rs`: 1. **Numeric SDK version sorting (`Validator::default_path`)**: previously `versions.sort(); versions.pop()` sorted paths lexicographically, so e.g. `10.0.9999.0` sorted after `10.0.26100.0`. Extracted `sdk_version_key` and `default_path_from` to select the numerically newest dotted SDK version. 2. **Empty `LEONIDA_DXIL=""` fallback**: filtered out empty `LEONIDA_DXIL` values so setting `LEONIDA_DXIL=""` falls back to scanning Windows Kits (matching `leonida-core/src/config.rs`), instead of returning `Some("")`. 3. **Clean error string in `Validator::load`**: sliced off the trailing UTF-16 NUL terminator when formatting `"cannot load ..."`, avoiding an embedded `\0` in error text. 4. **Release `HMODULE` on load failure**: called `FreeLibrary(module)` before returning `Err` if `GetProcAddress` or `DxcCreateInstance` fails in `Validator::load`. ### Tested Verified locally (Windows 11, Rust 1.98.1, no game data): - Red before fix: `cargo test --locked -p leonida-shader --lib emit::validator` failed 3 of 4 tests (`sdk_version_sorting_prefers_numerically_newest`, `empty_leonida_dxil_falls_back_to_windows_kits`, `load_missing_dll_error_has_no_trailing_nul`). - Green after fix: - `cargo test --locked -p leonida-shader --lib emit::validator`: `4 passed; 0 failed` - `cargo clippy --locked -p leonida-shader -- -D warnings`: 0 warnings, exit 0 - `python -I scripts/check_no_game_data.py` & `git diff --check`: clean GPUs tested: n/a (unit tests only) AI-assisted: yes ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
merzleckeier commented 2026-12-01 13:16:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T13:16:57Z.


Checked both failed validator loads with real Win32 module handles under Wine 11.22, using 02f0a8c6e + ed867d7b2. I used two benign DLL fixtures: one without DxcCreateInstance, and one whose factory returns E_FAIL. The same test called GetModuleHandleW before and after each refusal. On main both modules remained loaded. With this PR both were unloaded, and the installed SDK dxil.dll still loaded successfully. The validator filter passed 7/7 checks, including the numeric SDK ordering and empty override tests.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7312377733 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2875#issuecomment-7312377733). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T13:16:57Z. --- Checked both failed validator loads with real Win32 module handles under Wine 11.22, using `02f0a8c6e` + `ed867d7b2`. I used two benign DLL fixtures: one without `DxcCreateInstance`, and one whose factory returns `E_FAIL`. The same test called `GetModuleHandleW` before and after each refusal. On main both modules remained loaded. With this PR both were unloaded, and the installed SDK `dxil.dll` still loaded successfully. The validator filter passed 7/7 checks, including the numeric SDK ordering and empty override tests. AI-assisted with OpenAI Codex.
KelboLive commented 2026-12-01 13:53:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T13:53:30Z.

Review: COMMENTED


The sort fix is correct: sdk_version_key compares numeric components ((1, Vec<u64>)), so max_by picks 10.0.26100.0 over 10.0.9999.0; unparseable directory names get (0, []) and lose to any numeric version, and the path tie-break makes odd component counts deterministic. The mutation proves the test bites: with the old lexicographic comparator it fails on exactly that pair (left: …\10.0.9999.0\…, right: …\10.0.26100.0\…).

The empty LEONIDA_DXIL filter matches leonida-core's Config convention, and the NUL strip is safe because exactly one terminator is appended (validator.rs:160-165, saturating_sub(1) handles the empty case). FreeLibrary placement is right — released on both failure paths, correctly left loaded on success because the COM vtable lives in the module. leonida-shader 414/0/5, clippy clean, merge-tree clean.

Two micro-notes, neither blocking: an object returned with a failing HRESULT from DxcCreateInstance would leak (against COM's contract, so harmless in practice), and no trim means LEONIDA_DXIL=" " is not treated as empty — consistent with core's rule, inconsistent with the logging trim in #2874. The tests do not cover mixed-length version names; the sort is still deterministic there, so it is coverage rather than behaviour.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6132638709 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2875#pullrequestreview-6132638709). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T13:53:30Z. **Review:** COMMENTED --- The sort fix is correct: `sdk_version_key` compares numeric components (`(1, Vec<u64>)`), so `max_by` picks `10.0.26100.0` over `10.0.9999.0`; unparseable directory names get `(0, [])` and lose to any numeric version, and the path tie-break makes odd component counts deterministic. The mutation proves the test bites: with the old lexicographic comparator it fails on exactly that pair (`left: …\10.0.9999.0\…`, `right: …\10.0.26100.0\…`). The empty `LEONIDA_DXIL` filter matches `leonida-core`'s `Config` convention, and the NUL strip is safe because exactly one terminator is appended (`validator.rs:160-165`, `saturating_sub(1)` handles the empty case). `FreeLibrary` placement is right — released on both failure paths, correctly left loaded on success because the COM vtable lives in the module. `leonida-shader` 414/0/5, clippy clean, merge-tree clean. Two micro-notes, neither blocking: an `object` returned with a failing `HRESULT` from `DxcCreateInstance` would leak (against COM's contract, so harmless in practice), and no trim means `LEONIDA_DXIL=" "` is not treated as empty — consistent with core's rule, inconsistent with the logging trim in #2874. The tests do not cover mixed-length version names; the sort is still deterministic there, so it is coverage rather than behaviour.
aslan2142 commented 2026-12-01 15:03:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T15:03:25Z.

Review: APPROVED


Second-maintainer review: looks clean and safe to merge.

  • Does not widen dxil.dll search paths; keeps LEONIDA_DXIL override (now falling back cleanly to C:\Program Files (x86)\Windows Kits\10\bin when LEONIDA_DXIL=""), fixes lexicographic vs numeric SDK version sorting (10.0.26100.0 > 10.0.9999.0), strips the trailing UTF-16 NUL from load error strings, and properly calls FreeLibrary on both GetProcAddress and DxcCreateInstance failure paths.
  • All 6 CI checks are green and failure-path module unloading was independently verified. Merging.
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6133920504 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2875#pullrequestreview-6133920504). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T15:03:25Z. **Review:** APPROVED --- Second-maintainer review: looks clean and safe to merge. - Does not widen `dxil.dll` search paths; keeps `LEONIDA_DXIL` override (now falling back cleanly to `C:\Program Files (x86)\Windows Kits\10\bin` when `LEONIDA_DXIL=""`), fixes lexicographic vs numeric SDK version sorting (`10.0.26100.0` > `10.0.9999.0`), strips the trailing UTF-16 NUL from load error strings, and properly calls `FreeLibrary` on both `GetProcAddress` and `DxcCreateInstance` failure paths. - All 6 CI checks are green and failure-path module unloading was independently verified. Merging.
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
ProjectLeonida/mandy!2875
No description provided.