Skip to content

d3d12: give an empty pipeline library a null blob (D3D12-VKD3D-EMPTY-PIPELINE-LIBRARY) - #2654

Open
kuzeyc wants to merge 2 commits into
ProjectLeonida:mainfrom
kuzeyc:fix/vkd3d-empty-pipeline-library
Open

kuzeyc wants to merge 2 commits into
ProjectLeonida:mainfrom
kuzeyc:fix/vkd3d-empty-pipeline-library

Conversation

@kuzeyc

@kuzeyc kuzeyc commented Nov 29, 2026

Copy link
Copy Markdown

Item: D3D12-VKD3D-EMPTY-PIPELINE-LIBRARY (claim: #2570 (comment))

What is wrong

pipeline/library.rs (open) makes the empty host pipeline library with CreatePipelineLibrary(&[]). The windows crate passes an empty slice's pointer, which is dangling, not null, with a length of 0. Microsoft's D3D12 takes that. VKD3D-Proton answers E_INVALIDARG (0x80070057), and make(&[]).ok()? dropped the error, so under Wine and Proton the run keeps no library:

INFO no host pipeline library yet; starting an empty one
WARN no host pipeline library: pipelines are not kept

Nothing is stored or saved (cache/pipelines/host-pipelines.bin never appears), and every start makes every pipeline again.

The change

  • The blob goes to CreatePipelineLibrary through blob_pointer(), which gives a null pointer for an empty blob.
  • A refused empty library is logged (the host refused an empty pipeline library, with the error) instead of dropped.
  • New unit test an_empty_blob_is_given_as_a_null_pointer.

One file, d3d12/crates/leonida-gpu/src/pipeline/library.rs.

Tested

  • cargo xwin test --target x86_64-pc-windows-msvc -p leonida-gpu --features diagnostics -- pipeline::library, run under Wine 11.23: 7 passed, 0 failed (the new test and the six that were there).
  • On hardware: RTX 3070 8 GB, NVIDIA 610.57.04, Arch Linux, Proton Hotfix (hotfix-20261110) and its VKD3D-Proton (vkd3d-1.1-5729-g00b6ef057), started with the play-linux.sh of Linux: build leonida.exe and run it under Proton or Wine #2577.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/pipeline/library.rs: clean.

The new unit test checks the pointer, not the host: it passes on main too as far as the D3D12 call is concerned, since Microsoft's runtime accepts the dangling pointer. The failure only shows under VKD3D-Proton, which is what the hardware runs above are for.

Related

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…PIPELINE-LIBRARY)

The empty host pipeline library was made with CreatePipelineLibrary(&[]),
which the windows crate passes as an empty slice's dangling, non-null
pointer with a length of 0. Microsoft's D3D12 takes that; VKD3D-Proton
answers E_INVALIDARG (0x80070057), and make(&[]).ok()? dropped the error,
so under Wine and Proton the run kept no library and every start made
every pipeline again.

The blob now goes through blob_pointer(), null when it is empty, and a
refused empty library is logged instead of dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 29, 2026 22:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent synthetic A/B of f1794125 (GitHub merge 71250d7b onto 452d1d1b). Win64 MSVC-target Rust 1.98.1, Wine 11.22, VKD3D-Proton 71cae091, DXC 1.8.2505.32, RTX 4070 SUPER (620.73.04) and Radeon Raphael (RADV 26.3.1).

  • MEASURED, unchanged GPU fixtures. On both GPUs, main failed 3/3 at the library reload assertion in each of depth_bounds_pipeline_loads_and_filters_draws and a_mesh_pipeline_loads_from_the_library. With this PR each passed 3/3, including both depth readbacks. The library unit group went from 5 passed and the rejected-blob test failing to 7/7 on each GPU. An initial blank NVIDIA process timeout was outside the completed baseline sample.
  • MEASURED, save and reopen. A test-only probe gave the existing depth fixture a scratch library path and recorded the first PSO and save counters. The direct CreatePipelineLibrary(&[]) call returned 0x80070057. The PR path created one PSO and serialized the library, 15,664 bytes on NVIDIA and 3,136 bytes on RADV. A new process loaded the first PSO (loaded=1, made=0) and left the file size unchanged. It also rebuilt and saved successfully after I substituted a malformed blob. Each case passed 3/3 per GPU.
  • MEASURED, interaction with runtime, d3d12: memory leak fixes from one sweep (RT-LEAK-SWEEP) #2569. 8f5f02d80 combined cleanly with this PR (local tree 1b933a60). Cold and warm behavior matched the standalone PR. Replacing only host-pipelines.fingerprint with a stale value forced a rebuild and a fresh save, in 3/3 per GPU. All 36 instrumented invocations passed the depth fixture.

This resolves the local Wine library assertion I reported in #2648. The hosted native Windows pixel failure there remains open. Small build note: the !empty.as_ptr().is_null() assertion at library.rs:906 emits useless_ptr_null_checks. The test already checks the converted pointer immediately above.

Synthetic fixtures only. AI-assisted with OpenAI Codex.

An empty slice's pointer is never null, so the assertion could not fail
(useless_ptr_null_checks); the converted pointer is checked just above.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kuzeyc

kuzeyc commented Nov 29, 2026

Copy link
Copy Markdown
Author

Thanks for the A/B on both GPUs, and for checking it together with #2569.

  • Pushed 55ac5d337: drops the !empty.as_ptr().is_null() assertion that useless_ptr_null_checks flags. The converted pointer is still checked just above. pipeline::library is 7/7 under Wine 11.23, and clippy has no warnings in library.rs.
  • Your runs also answer the "a test that fails on main" question better than my new unit test does. Under VKD3D-Proton, a_rejected_blob_gives_an_empty_library, depth_bounds_pipeline_loads_and_filters_draws and a_mesh_pipeline_loads_from_the_library fail on main and pass with this PR, on both your RTX 4070 SUPER and RADV.

AI-assisted (Claude Code).

@z3r0rc

z3r0rc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

We independently landed exactly this on our tree and can confirm it end-to-end under Wine. Before the null-pointer fix, with CreatePipelineLibrary receiving the dangling non-null + 0, the library was dead here under Wine + VKD3D-Proton master (RTX 4090, NVIDIA 620.73.04): every start logged "no host pipeline library: pipelines are not kept", nothing was written at clean exit, and the entry backlog peaked ~1038 every run. With this shape — vtable call, null for the empty blob — the loop closes: saved bytes=448760 made=2347 at a clean close, loaded mapped=true at the next start, compounding 605,624 → 641,336 bytes over the next three windows with the entry backlog shrinking each time. Your blob_pointer helper is the cleaner way to state the rule; we inlined the same thing. Happy to test this PR as-is on our machine if useful. AI-assisted; measured logs on the setup above.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not superseded, and the fix is correct: main still has device.CreatePipelineLibrary::<ID3D12PipelineLibrary>(bytes)?.cast() (library.rs:522) with make(&[]).ok()? (:551), and windows-rs 0.62.2 does transmute(plibraryblob.as_ptr()) on an empty slice (Windows/Win32/Graphics/Direct3D12/mod.rs:9959) — a dangling non-null pointer. The manual vtable call with null + 0 is the right fix, and the rejected-blob test exercises that path against native D3D12 here (7/7 pass, clippy clean in library.rs).

One test gap: replacing blob_pointer(bytes) at the call site with bytes.as_ptr().cast() leaves all 7 tests green — only the helper is asserted, not that open uses it. A small seam (or the replay vtable) that checks the pointer open passes would close it, since the bug is only observable under VKD3D.

Also d3d12/crates/leonida-gpu/tests/replay.rs:193 still calls CreatePipelineLibrary(&[]) through windows-rs, so the replay test keeps the same dangling pointer under Wine — worth switching too.

Branch is 1068 commits behind main; merge-tree is clean (0b142434a), but the head predates #2648's d3d12 cargo-test CI, so no checks have run. A rebase is needed for CI; otherwise this is good to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants