Skip to content

D3D12.X: serialize real::init against concurrent device creation - #1

Draft
RandomGithub12309 wants to merge 1 commit into
mainfrom
d3d12x/serialize-real-init
Draft

RandomGithub12309 wants to merge 1 commit into
mainfrom
d3d12x/serialize-real-init

Conversation

@RandomGithub12309

Copy link
Copy Markdown
Owner

Serialize real::init() with double-checked locking so concurrent threads calling real::init() cannot race past device_raw().is_null(), create competing D3D12 devices, and re-run open_uma / sparse::init simultaneously.

(Parked as a draft PR on RandomGithub12309/xcl while #667 and #674 are in review upstream; rebase onto ivall/xcl:main and run the full workspace test suite + scripts/smoke.ps1 before opening upstream.)

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: add a static INIT: Mutex<()> guard inside real::init() and re-check device_raw().is_null() under the lock; add unit test hle::d3d12x::real::init_tests::concurrent_init_returns_consistent_adapter spawning 4 synchronized threads calling init().

Tested

  • Hardware: NVIDIA GeForce RTX 5050 Laptop GPU (driver 32.0.16.2114), Intel Core Ultra 7 255HX (20 cores), Windows 11 Build 26300, rustc 1.100.0 (0ef1bc386 2026-11-09) stable-x86_64-pc-windows-msvc (debug).
  • cargo test -p xcl --lib hle::d3d12x::real::init_tests -- --nocapture: 1 passed, 0 failed, 0 ignored (0 skipped; UMA import check ran once across all 4 threads).

Regression run

  • Pending: parked on fork branch (main baseline dd2ae9a already captured on this machine; run cargo test --workspace -- --test-threads=4 and scripts/smoke.ps1 before submitting upstream to ivall/xcl).

Not tested

  • Full cargo test --workspace and scripts/smoke.ps1 on this standalone branch (deferred until ready to open upstream), AMD/Intel GPUs, Wine/Linux.

AI use

  • Antigravity with Gemini 4 Neon — wrote the change and unit test; test command executed on the hardware listed above.

real::init previously checked device_raw().is_null() without a lock, allowing concurrent threads (such as parallel GPU tests) to enter device creation and open_uma/sparse::init simultaneously before DEVICE was published.

Add a double-checked static Mutex guard around initialization in real::init() and a 4-thread concurrent_init_returns_consistent_adapter test.

Assisted-by: Antigravity (Gemini 4 Neon)
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.

1 participant