dlss: fix 2-arg NVSDK_NGX_D3D12_Shutdown1 core ABI and full teardown … #227

Open
github-bot wants to merge 1 commit from github-bot/gh-227 into main AGit
Owner

@⁠mint17 on GitHub · 2026-11-27 11:17 UTC · original
mint17:fix/dlss-shutdown1-abi-teardown → main · +750 −93 · 2 files · 1 commits · open

Fixes #176 and #183 (and resolves the root cause behind #217 / #219 so Shutdown1 does not need to be skipped).

Root cause

dlss.rs loads _nvngx.dll directly via GetProcAddress without linking NVIDIA's static wrapper nvsdk_ngx_s.lib, and declared NVSDK_NGX_D3D12_Shutdown1 with 1 argument (fn(*mut c_void) -> u32, matching nvsdk_ngx.h). However, _nvngx.dll's internal core export takes 2 arguments:

NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown1(ID3D12Device *InDevice, unsigned int *OutRemaining);

Calling it with 1 argument left Win64 RDX (OutRemaining) uninitialized, causing _nvngx.dll to write *OutRemaining to 0x0 (0xC0000005) or corrupt 4 bytes of memory on both dlss::shut_down() and dlss::start()'s failure cleanup path (explaining why both startup-failure and exit crashes hit the exact same offset in _nvngx.dll).

Changes

  • Fix Shutdown signature to unsafe extern "C" fn(*mut c_void, *mut u32) -> u32 and pass &mut remaining in both dlss::start() failure cleanup and dlss::shut_down().
  • Load optional NVSDK_NGX_D3D12_DestroyParameters and destroy capability parameters before Shutdown1 on both failure and exit paths.
  • Store live feature handles in AtomicPtr + leaf-locked LIVE_HANDLES: Mutex<Vec<Weak<Handle>>> and lock PENDING before atomic take() in Handle::enqueue_drop, ensuring all live and bury_lag-retained features are released exactly once before DestroyParameters and Shutdown1.
  • Serialize concurrent shut_down() calls via Once (preserving PR #214's exact shutdown stage trace logs) and guard duplicate dlss::start() calls cleanly.
  • Add mock-ABI unit tests for teardown ordering, detached bury_lag handles, concurrent idempotency, and start-failure cleanup, plus repeated shut_down() at the end of tests/dlss.rs.

Verification

  • cargo test --locked -p victory-hle dlss -- --test-threads=1 (21 unit tests passed)
  • Live hardware DLSS test on RTX 4090 (NVIDIA driver 617.42, _nvngx.dll 32.0.16.1742, nvngx_dlss.dll 310.6.0): VICTORY_DLSS_TEST=1 cargo test --locked -p victory-hle --test dlss -- --nocapture --test-threads=1 — PASS (1440p -> 4K Super Resolution, 0 D3D12 debug-layer errors, clean repeated shut_down() including Shutdown1).
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings (default + --all-features) and cargo test --locked -p xtask passed.
  • Not yet tested in-game (no title files locally).
**@⁠mint17** on GitHub · 2026-11-27 11:17 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/227) `mint17:fix/dlss-shutdown1-abi-teardown` → `main` · +750 −93 · 2 files · 1 commits · open Fixes #176 and #183 (and resolves the root cause behind #217 / #219 so `Shutdown1` does not need to be skipped). ### Root cause `dlss.rs` loads `_nvngx.dll` directly via `GetProcAddress` without linking NVIDIA's static wrapper `nvsdk_ngx_s.lib`, and declared `NVSDK_NGX_D3D12_Shutdown1` with 1 argument (`fn(*mut c_void) -> u32`, matching `nvsdk_ngx.h`). However, `_nvngx.dll`'s internal core export takes **2 arguments**: ```c NVSDK_NGX_Result NVSDK_NGX_D3D12_Shutdown1(ID3D12Device *InDevice, unsigned int *OutRemaining); ``` Calling it with 1 argument left Win64 `RDX` (`OutRemaining`) uninitialized, causing `_nvngx.dll` to write `*OutRemaining` to `0x0` (`0xC0000005`) or corrupt 4 bytes of memory on both `dlss::shut_down()` and `dlss::start()`'s failure cleanup path (explaining why both startup-failure and exit crashes hit the exact same offset in `_nvngx.dll`). ### Changes - Fix `Shutdown` signature to `unsafe extern "C" fn(*mut c_void, *mut u32) -> u32` and pass `&mut remaining` in both `dlss::start()` failure cleanup and `dlss::shut_down()`. - Load optional `NVSDK_NGX_D3D12_DestroyParameters` and destroy capability parameters before `Shutdown1` on both failure and exit paths. - Store live feature handles in `AtomicPtr` + leaf-locked `LIVE_HANDLES: Mutex<Vec<Weak<Handle>>>` and lock `PENDING` before atomic `take()` in `Handle::enqueue_drop`, ensuring all live and `bury_lag`-retained features are released exactly once before `DestroyParameters` and `Shutdown1`. - Serialize concurrent `shut_down()` calls via `Once` (preserving PR #214's exact shutdown stage trace logs) and guard duplicate `dlss::start()` calls cleanly. - Add mock-ABI unit tests for teardown ordering, detached `bury_lag` handles, concurrent idempotency, and start-failure cleanup, plus repeated `shut_down()` at the end of `tests/dlss.rs`. ### Verification - `cargo test --locked -p victory-hle dlss -- --test-threads=1` (21 unit tests passed) - Live hardware DLSS test on **RTX 4090** (NVIDIA driver `617.42`, `_nvngx.dll` `32.0.16.1742`, `nvngx_dlss.dll` `310.6.0`): `VICTORY_DLSS_TEST=1 cargo test --locked -p victory-hle --test dlss -- --nocapture --test-threads=1` — **PASS** (1440p -> 4K Super Resolution, 0 D3D12 debug-layer errors, clean repeated `shut_down()` including `Shutdown1`). - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (default + `--all-features`) and `cargo test --locked -p xtask` passed. - Not yet tested in-game (no title files locally).
Fixes #176, #183 (and supersedes the Shutdown1 skip workaround in #219):

- Fix NVSDK_NGX_D3D12_Shutdown1 signature to the core _nvngx.dll 2-argument
  ABI (ID3D12Device*, *mut u32 OutRemaining). Passing 1 argument left RDX
  uninitialized, causing _nvngx.dll to dereference null (0xC0000005 write to
  0x0) or silently corrupt 4 bytes on both dlss::shut_down() and dlss::start()
  failure cleanup.
- Load optional NVSDK_NGX_D3D12_DestroyParameters and destroy capability
  parameters before Shutdown1 on both start-failure and shutdown paths.
- Track live feature handles via AtomicPtr + LIVE_HANDLES (Weak<Handle>) and
  lock PENDING before atomic take() in Handle::enqueue_drop so all live and
  bury_lag-retained features are released exactly once before DestroyParameters
  and Shutdown1.
- Serialize concurrent shut_down() callers via Once while preserving PR #214's
  shutdown stage trace logs, and reject duplicate dlss::start() calls cleanly.
- Add mock-ABI unit tests for teardown ordering, detached bury_lag handles,
  concurrent idempotency, and start-failure cleanup, and exercise repeated
  shut_down() at the end of tests/dlss.rs (verified live on RTX 4090).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:20:13 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 11:19 UTC · original

@⁠mint17 The public NGX header describes the SDK wrapper, and this code resolves the core export directly. Which driver and NGX core version were used for the live RTX 4090 teardown check? That will let us tie the ABI evidence to the tested runtime. The mock tests cover release order and concurrent calls. The live run is what establishes the full teardown path for that core version.

**@⁠TaynanGT** on GitHub · 2026-11-27 11:19 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/227#issuecomment-7216945526) @⁠mint17 The public NGX header describes the SDK wrapper, and this code resolves the core export directly. Which driver and NGX core version were used for the live RTX 4090 teardown check? That will let us tie the ABI evidence to the tested runtime. The mock tests cover release order and concurrent calls. The live run is what establishes the full teardown path for that core version.
github-bot force-pushed github-bot/gh-227 from 62568895ab to 51220d96f3 2026-11-27 11:32:47 +00:00 Compare
Author
Owner

@⁠mint17 on GitHub · 2026-11-27 11:26 UTC · original

The live RTX 4090 run (VICTORY_DLSS_TEST=1 cargo test --locked -p victory-hle --test dlss -- --nocapture --test-threads=1) ran on:

  • GPU: NVIDIA GeForce RTX 4090
  • NVIDIA driver: 617.42
  • NGX core (_nvngx.dll): 32.0.16.1742 (from the driver store)
  • DLSS snippet (nvngx_dlss.dll): 310.6.0 (Presets M / L)

In addition, disassembling NVIDIA's official static wrapper nvsdk_ngx_s.lib (NVSDK_NGX_D3D12_Shutdown1) shows the SDK wrapper itself always allocates a local unsigned int remaining = 0 and passes lea rdx, [remaining] as the 2nd argument to _nvngx.dll!NVSDK_NGX_D3D12_Shutdown1(InDevice, &remaining).

Rebasing this branch cleanly on top of 63e2c98 now so there are no merge conflicts.

**@⁠mint17** on GitHub · 2026-11-27 11:26 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/227#issuecomment-7217079712) The live RTX 4090 run (`VICTORY_DLSS_TEST=1 cargo test --locked -p victory-hle --test dlss -- --nocapture --test-threads=1`) ran on: - **GPU:** NVIDIA GeForce RTX 4090 - **NVIDIA driver:** `617.42` - **NGX core (`_nvngx.dll`):** `32.0.16.1742` (from the driver store) - **DLSS snippet (`nvngx_dlss.dll`):** `310.6.0` (Presets M / L) In addition, disassembling NVIDIA's official static wrapper `nvsdk_ngx_s.lib` (`NVSDK_NGX_D3D12_Shutdown1`) shows the SDK wrapper itself always allocates a local `unsigned int remaining = 0` and passes `lea rdx, [remaining]` as the 2nd argument to `_nvngx.dll!NVSDK_NGX_D3D12_Shutdown1(InDevice, &remaining)`. Rebasing this branch cleanly on top of `63e2c98` now so there are no merge conflicts.
Author
Owner

@⁠mint17 on GitHub · 2026-11-27 11:31 UTC · original

Rebased cleanly onto 63e2c98 (51220d9) — removed the VICTORY_DLSS_SHUTDOWN skip gate while keeping the releasing NGX capability parameters trace log, and re-verified all 21 unit tests, Clippy, xtask, and the live RTX 4090 VICTORY_DLSS_TEST=1 teardown run (driver 617.42, _nvngx.dll 32.0.16.1742, nvngx_dlss.dll 310.6.0.0 — passed in 5.58s with 0 D3D12 errors).

**@⁠mint17** on GitHub · 2026-11-27 11:31 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/227#issuecomment-7217166863) Rebased cleanly onto `63e2c98` (`51220d9`) — removed the `VICTORY_DLSS_SHUTDOWN` skip gate while keeping the `releasing NGX capability parameters` trace log, and re-verified all 21 unit tests, Clippy, `xtask`, and the live RTX 4090 `VICTORY_DLSS_TEST=1` teardown run (driver `617.42`, `_nvngx.dll` `32.0.16.1742`, `nvngx_dlss.dll` `310.6.0.0` — passed in 5.58s with 0 D3D12 errors).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 11:42 UTC · original

@⁠mint17 The exact driver and core versions help. 51220d9 covers full teardown on _nvngx.dll 32.0.16.1742 with driver 617.42. Our installed core is 32.0.16.2140 on 621.40, so I’ll use that as the next compatibility check once the active run is done. I’m keeping the process-exit fallback available until that check covers the new default.

**@⁠TaynanGT** on GitHub · 2026-11-27 11:42 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/227#issuecomment-7217375836) @⁠mint17 The exact driver and core versions help. `51220d9` covers full teardown on `_nvngx.dll` `32.0.16.1742` with driver `617.42`. Our installed core is `32.0.16.2140` on `621.40`, so I’ll use that as the next compatibility check once the active run is done. I’m keeping the process-exit fallback available until that check covers the new default.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/227/head:github-bot/gh-227'
git switch 'github-bot/gh-227'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-227'
git switch 'github-bot/gh-227'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-227'
git switch 'github-bot/gh-227'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-227'
git switch 'main'
git merge --squash 'github-bot/gh-227'
git switch 'main'
git merge --ff-only 'github-bot/gh-227'
git switch 'main'
git merge 'github-bot/gh-227'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.