[pr-tests] Shaders: the test host keeps its last device, so each case does not make one again #384

Open
ntsthay wants to merge 2 commits from ntsthay/shader-host-keeps-device into main AGit
First-time contributor

Tests only. Nothing here runs in the game.

Contributor role (optional)

  • Fluxer ID:

What it changes

Host::new in the shader test host made a new D3D12 device every time, and each host was dropped at the end of its case. The GPU tests make a host for every shader they check, so a device was made and destroyed again and again. D3D12 gives one device per adapter while one is alive, and vkd3d-proton does the same (d3d12_find_device_singleton). Host::new now keeps the last device of each kind (card and WARP) for the life of the process, so the next D3D12CreateDevice on that adapter gets the same device back. A kept device that was removed is dropped first, so a removed device is never handed out again.

Measured under vkd3d-proton (Proton on Linux, RTX 4080), on f3840d7:

  • cost_checks::the_median_of_a_value_and_two_constants_is_a_clamp made 56 hosts at 256 ms each. That is 14.3 s of its 25.4 s. Its thread spent three quarters of its time in the kernel.
  • With 16 test processes at once, those device creations wait on each other in the driver. Eight of the slowest tests took 93 s one after another and 84 s with eight processes, so the processes gained almost nothing over running one at a time.
  • The 61 GPU tests that went over 15 s in a 16-process run: their times added up to 2,837 s before and 936 s with this change. Alone, the test above takes about 15 s and v_mad_u64_u32_matches_its_definition takes 7.7 s, down from 9 s.
  • The whole darner-shader crate with 16 processes: 61 tests over 15 s before, 11 now, in 68 s of wall time.

Statics are not dropped, so the kept device is still alive when the process ends. Holding the device in a thread-local instead made the test process hang on exit under vkd3d-proton.

How it was tested

  • Tested revision: 79f3c9f, this branch on f3840d7.
  • Commands and results: cargo nextest run -p darner-shader under Proton with 16 processes. Every test that passed on f3840d7 still passes, and the ones over 15 s went from 61 to 11. The 4 failures are the same as on f3840d7 and are fixed by #347 and #349.
  • Gates 1 and 2 (cargo clippy -p darner-shader -p darner-gpu --all-targets, with and without --all-features, -D warnings) are clean. Gate 3 ran under Wine, not on Windows.
  • Coverage gaps: not measured on Windows, where D3D12 also keeps one device per adapter, so it should save the same device creations there.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #349 adds a test-only on_wine() to the same file, in a different place.
  • Replaces or overlaps: none found
Tests only. Nothing here runs in the game. ## Contributor role (optional) - Fluxer ID: ## What it changes `Host::new` in the shader test host made a new D3D12 device every time, and each host was dropped at the end of its case. The GPU tests make a host for every shader they check, so a device was made and destroyed again and again. D3D12 gives one device per adapter while one is alive, and vkd3d-proton does the same (`d3d12_find_device_singleton`). `Host::new` now keeps the last device of each kind (card and WARP) for the life of the process, so the next `D3D12CreateDevice` on that adapter gets the same device back. A kept device that was removed is dropped first, so a removed device is never handed out again. Measured under vkd3d-proton (Proton on Linux, RTX 4080), on `f3840d7`: - `cost_checks::the_median_of_a_value_and_two_constants_is_a_clamp` made 56 hosts at 256 ms each. That is 14.3 s of its 25.4 s. Its thread spent three quarters of its time in the kernel. - With 16 test processes at once, those device creations wait on each other in the driver. Eight of the slowest tests took 93 s one after another and 84 s with eight processes, so the processes gained almost nothing over running one at a time. - The 61 GPU tests that went over 15 s in a 16-process run: their times added up to 2,837 s before and 936 s with this change. Alone, the test above takes about 15 s and `v_mad_u64_u32_matches_its_definition` takes 7.7 s, down from 9 s. - The whole `darner-shader` crate with 16 processes: 61 tests over 15 s before, 11 now, in 68 s of wall time. Statics are not dropped, so the kept device is still alive when the process ends. Holding the device in a thread-local instead made the test process hang on exit under vkd3d-proton. ## How it was tested - Tested revision: `79f3c9f`, this branch on `f3840d7`. - Commands and results: `cargo nextest run -p darner-shader` under Proton with 16 processes. Every test that passed on `f3840d7` still passes, and the ones over 15 s went from 61 to 11. The 4 failures are the same as on `f3840d7` and are fixed by #347 and #349. - Gates 1 and 2 (`cargo clippy -p darner-shader -p darner-gpu --all-targets`, with and without `--all-features`, `-D warnings`) are clean. Gate 3 ran under Wine, not on Windows. - Coverage gaps: not measured on Windows, where D3D12 also keeps one device per adapter, so it should save the same device creations there. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #349 adds a test-only `on_wine()` to the same file, in a different place. - Replaces or overlaps: none found
First-time contributor

One issue with keeping the device at 79f3c9f: the next Host::make can call EnableDebugLayer while that device is still alive. Microsoft documents that enabling the layer after device creation removes the device. This also matters for darner translate --check, which uses the same host. D3D12 debug layer documentation

752f312 initializes the layer once, before either host creation or test adapter enumeration. It keeps the existing opt-in and leaves the device cache in place. The scoped shader test type-check, asset policy and diff check passed. This machine returned 0x887A002D for D3D12GetDebugInterface, so the debug-enabled path still needs a Windows run with the graphics debug layer installed.

If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg <[email protected]>

One issue with keeping the device at `79f3c9f`: the next `Host::make` can call `EnableDebugLayer` while that device is still alive. Microsoft documents that enabling the layer after device creation removes the device. This also matters for `darner translate --check`, which uses the same host. [D3D12 debug layer documentation](https://learn.microsoft.com/en-us/windows/win32/api/d3d12sdklayers/nf-d3d12sdklayers-id3d12debug-enabledebuglayer) [752f312](https://git.gtahub.st/andrewpozdnakov7-jpg/Darner/commit/752f312669b66814185993b036ac5a121ba5c5dc) initializes the layer once, before either host creation or test adapter enumeration. It keeps the existing opt-in and leaves the device cache in place. The scoped shader test type-check, asset policy and diff check passed. This machine returned `0x887A002D` for `D3D12GetDebugInterface`, so the debug-enabled path still needs a Windows run with the graphics debug layer installed. If you cherry-pick or rebase this commit, please keep the Git author. If you fold it into another commit, please add this trailer. `Co-authored-by: andrewpozdnakov7-jpg <296776509+[email protected]>`
Author
First-time contributor

Thanks, good catch. With the device kept alive, a second Host::make would have enabled the debug layer on a live device and removed it. I cherry-picked 752f312 with your authorship kept (now 6b79d2d on this PR). Clippy is clean, and darner-shader under Proton has the same 4 failures as main (fixed by #347 and #349).

The debug-layer path is still untested on both sides: your machine has no graphics debug layer (0x887A002D), and Wine has none either. If someone with Windows and the Graphics Tools installed can run a shader test with DARNER_D3D12_DEBUG=1, that would cover it. Without the variable nothing changes.

Thanks, good catch. With the device kept alive, a second `Host::make` would have enabled the debug layer on a live device and removed it. I cherry-picked 752f312 with your authorship kept (now 6b79d2d on this PR). Clippy is clean, and `darner-shader` under Proton has the same 4 failures as `main` (fixed by #347 and #349). The debug-layer path is still untested on both sides: your machine has no graphics debug layer (`0x887A002D`), and Wine has none either. If someone with Windows and the Graphics Tools installed can run a shader test with `DARNER_D3D12_DEBUG=1`, that would cover it. Without the variable nothing changes.
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/384/head:ntsthay/shader-host-keeps-device'
git switch 'ntsthay/shader-host-keeps-device'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'ntsthay/shader-host-keeps-device'
git switch 'ntsthay/shader-host-keeps-device'
git rebase 'main'
git switch 'main'
git merge --ff-only 'ntsthay/shader-host-keeps-device'
git switch 'ntsthay/shader-host-keeps-device'
git rebase 'main'
git switch 'main'
git merge --no-ff 'ntsthay/shader-host-keeps-device'
git switch 'main'
git merge --squash 'ntsthay/shader-host-keeps-device'
git switch 'main'
git merge --ff-only 'ntsthay/shader-host-keeps-device'
git switch 'main'
git merge 'ntsthay/shader-host-keeps-device'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!384
No description provided.