Skip to content

[upstream #1789] D3D12.X: read the late-release setting at adoption, not at first release - #345

Open
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1789
Open

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1789

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

On a Mac (CrossOver, D3DMetal), D3DMetal releases the resources of an executed command list from a native thread of its own, which has no Wine TEB. The first Release there calls late_release::enabled(), whose OnceLock reads XCL_LATE_RELEASE from the environment for the first time, and that read never returns on that thread. This reads the setting in real::adopt, on the Wine thread that creates the object, so the OnceLock is set before the host's thread can reach it. Nothing changes on Windows: the same value is read once, only earlier.

Part of #258. It is the first commit of the series Ahmet-Dedeler reviewed in xcl-dev#258 (comment); the rest (deferring a Release that arrives on a host thread) stays a separate PR, since no test here needs it yet (xcl-dev#258 (comment)).

What is in it

  • crates/xcl/src/hle/d3d12x/late_release.rs: init(), which forces the one-time read.
  • crates/xcl/src/hle/d3d12x/real.rs: adopt calls it for every adopted object.

Tested

  • MacBook Pro M5 Pro (20-core GPU), 48 GB, macOS 27.2.1, CrossOver 26.3.0.39832 with D3DMetal 3.0, Rosetta 2. Rust 1.100.0, x86_64-pc-windows-gnu (mingw-w64 GCC 16.2.0), debug, DXC 1.9.2609. Each test in its own process (<test exe> --exact <test> --test-threads=1 --nocapture, 90 to 120 s timeout).
  • console_wave64_compute_through_the_pso_hook_dispatch_and_read_back (tests/gpu_compute_e2e.rs) and hle::d3d12x::title_textures::tests::gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes:
  • late_release unit tests (a_held_resource_goes_when_the_queue_is_past_its_batch, without_queues_a_batch_goes_at_once): pass.

Regression run

This changes runtime files, so it needs an xcl-smoke pair from someone with a title; I have none.

Not tested

  • Windows and the whole suite: I can't build for MSVC here. On Windows the change only moves the first read of XCL_LATE_RELEASE earlier.
  • A retail title, a release build, Linux Wine.
  • No new test: the failure is a hang on a D3DMetal thread, which the two tests above show on a Mac and which can't happen on Windows.

AI use

  • Claude Code. Claude Opus 4.6 wrote the change; Claude Opus 5.5 reviewed it, ran the tests above on this machine and wrote this description.

Mirror of xcl-dev#1789 (auto-synced, do not edit).

D3DMetal calls Release on adopted resources from a native thread of its
own at submit time.  That thread has no Wine TEB, so the first-time
std::env::var read inside the OnceLock in late_release::enabled() enters
Wine's ntdll and never returns.

Reading the setting once in adopt(), on the Wine thread that creates the
object, makes sure the OnceLock is already set before the host's thread
can reach it.

Part of #258.

Assisted-by: Claude Code (Claude Opus 4.6 (1M context))
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.

2 participants