Skip to content

Merge main into amd-dev - #3444

Merged
raylitebull merged 650 commits into
xcl-dev:amd-devfrom
lucsoft:merge/main-into-amd-dev
Nov 30, 2026
Merged

raylitebull merged 650 commits into
xcl-dev:amd-devfrom
lucsoft:merge/main-into-amd-dev

Conversation

@lucsoft

@lucsoft lucsoft commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR merges main into amd-dev, so the two branches stop drifting apart, the same way #3203 did for nvidia-dev. amd-dev branched from main at 2c717a04 (2026-11-27) and has not taken main since. That is about 650 commits, including the nvidia-dev merge (#3203) and the fixes that came after it.

Please merge with a merge commit, not squash or rebase. That way git records that main is in amd-dev, and the next sync does not hit the same conflicts again.

What is in it

  • 4fedcbc8: a merge commit. Its parents are amd-dev 10582c42 (first parent) and main 24d21a41.

  • 5eb7f8fb: a second merge, of the current amd-dev head 36e16cf4 (73 commits newer than 10582c42), resolved by the same rules (below). git merge-tree --write-tree upstream/amd-dev HEAD returns this head's tree, so the PR merges into amd-dev without conflicts.

  • 3277acaf: a third merge, of amd-dev 6bab0c53 (11 commits newer than 36e16cf4: bake indices through the view heap's slots, XCL_FFX_RESET, black skipped Bink movies, BVH-builder binds, reflection fallback, XCL_TRACE_INDEXED, XCL_SKIP_CS, …). Four files conflicted:

    • title_textures.rs: main's Transition record is kept beside amd-dev's Kept / kept(); amd-dev's tuple Transition and LIST_NOTES are not taken, since main tracks list transitions its own way.
    • console_list.rs: both sides' locals are kept, and XCL_SKIP_CS goes in front of main's pso_user_sgprs_exact.
    • real.rs: indexed::note_made goes in before main's console_heap::write + vram::track_srv. main's lazy flag sits beside the BVH-builder image_only.
    • bind.rs:
      • uncover_indexed takes amd-dev's indexed::resources.
      • Bake detection keeps main's original pipeline for is_kept.
      • main's skip_untranslated_dispatch is followed by left_out::direct.
    • indexed.rs calls main's read_committed_into where amd-dev has copy_readable; both read with zeros for unreadable pages.
  • 069c29fe: late_release seals a held resource's batch without waiting for a busy queue lease (queue_submit::try_with). Fixes the three-thread deadlock through the D3D12 runtime's lock that raylitebull found on Windows; the path is main's (byte-identical files), not the merge's.

Three fixes on top of the third merge, found in retail runs on Linux (RX 7800 XT, RADV):

  • 859e8ad2 ambient: find the stand-in's passes and build its helpers under Wine. The stand-in lighting never applied on this merge. There was no captured … sky dome or applied line, so with XCL_RT_GATE=miss every missed ray brought sky light indoors: overexposure and sparkles. It had three causes:
    • Merge regression: main's split-chain ExecuteIndirect path returned before the ambient hook. The hook now runs there too.
    • Role lookup: roles were looked up by the resolved PC pipeline, which lazy and background builds replace. Roles are now noted at the title's CreatePipelineState and looked up by the bound pipeline or the console record.
    • Helper compiles: the helper programs went through D3DCompile, which is vkd3d-shader under Wine and refuses them. They now compile DXC first (dxc::compile_sm6_first), as do the depth-twin, present and mirror helpers. scatter's program stays on D3DCompile, because built with DXC it scattered writes to wrong places.
    • XCL_AMBIENT_DIAG=1 logs each lighting pass's path and role.
  • 2f3d1135 zero recycled page-pool tiles before a new texture uses them. This is a merge regression. amd-dev zeroed recycled pool tiles (XCL_ZERO_TARGET_PAGES, on by default); taking main's vram.rs dropped that. New render targets such as the probe light history then started with another image's bytes, which showed as a mosaic of other shots in the lighting.
    • It is now back on main's page pool, zeroed on the tile-mapping queue before the UpdateTileMappings. XCL_ZERO_TARGET_PAGES=0 turns it off.
    • In a run: 2 GiB of tiles zeroed by world+60 s, and the mosaic was gone.
  • e3fae4ed keep dispatch chain scratch until the GPU is done with it. The title's final Release of an allocator cleared its chain recordings even when alloc_pool still held the allocator because it was busy. A later submit then ran chains on freed scratch.
    • The world hangs on Linux are GPU read faults followed by a ring timeout, 2–4 min after world entry. A local address log puts several fault addresses in freed chain-scratch ranges.
    • Recordings now go only when the pool proves the allocator free. main has the same code (alloc_release).

How the conflicts were resolved:

A plain merge produced about 315 conflict hunks in 46 files. Most of them came from the same nvidia-dev line being integrated twice:

Rules applied:

  1. Code both sides got from nvidia-dev: main's version is kept, because it is newer and has the follow-up fixes. Changes from amd-dev's own 49 commits are re-applied on top of it.
  2. amd-dev's own features are kept and wired:
    • Ambient, barrier groups, depth twins, format aliases, ps_masks, rt_leave_out. These files are byte-identical to amd-dev.
    • Indirect light (8942a5b9).
    • XCL_RT_GATE, with the BVH builder off by default.
    • The write-watch reductions (f2f02bd0, fe5260b6, 3bb095a0).
    • Texture-upload spares and the upload wait fix (1be2221e, 512b0bbc).
    • Early-exit-safe multi-wave s_barrier in direct DXIL (965cc655).
    • The DXIL shrink/compact series.
    • The XMemVirtualAlloc fixes (108cbafa, 23d0f365).
    • DirectStorage swizzle (081da4b9).
    • Pipeline library off by default on AMD (f33df5a7). This lives in main's own shaders/pipeline_library.rs, and XCL_PSO_LIBRARY=0/1 overrides it.
  3. Commits left out because main already has them: 21 in total. 17 match by subject. The other four are b958a344 (= 3cde0cc3), 60345c97, 61559df6 (main has 2fc61b64) and da910ccd (main has its own pipeline library, AMD driver-cache default and sampler keys).

Where main's behaviour was kept over amd-dev's:

Please check these if they matter to you:

  • alloc_pool: release_when_done, release_finished and take_excess_aside are dropped, because main has its own probe-based allocator retirement. pending_gpu_marks() is rewritten for main's fence structure.
  • sparse.rs: based on main. Dropped:
    • the CPU wait for tile mappings (XCL_SPARSE_CPU_WAIT_MS, the RX 9070 device-removal fix),
    • wait_pending_mappings,
    • the readback-queue retire fences.
  • vram.rs: based on main. Dropped: zero-fill of recycled tiles and deferred unmap batches. vram_small.rs is not wired in; on amd-dev it was on by default.
  • bind.rs, two-pass paths: main's record buffers and scale-args code. Dropped: XCL_TWO_PASS_SHARED, the 4-UAV scale-args root signature, and the UNKNOWN_RES fence tracking.
  • console_heap.rs, title_textures.rs, dispatch_chain.rs, the present compositor, DXIL live lanes: main's versions.
  • The SRV/UAV paths in real.rs: main's slot() lookups.
  • 82d5eea8 (preparation progress per variant): not ported, because it conflicted everywhere with main's reworked preparation UI.
  • Memory defaults: main's. XCL_TEXTURE_LEVEL_PAGES and XCL_SMALL_TEXTURES stay opt-in, and the upload buffers stay at 512 MB.

Second merge (36e16cf4), what needed more than a mechanical resolution:

  • 29 of the 73 commits are already in main in some form; main's version is kept (duplicate tests dropped).
  • Ported onto main's code: the direct wave32 graphics reductions (8c79f57), quad-only PS reads beside main's EXEC fallback (45ed56c), the page comparison after remap and GPU-written new textures in main's texture selection (02ceae6, 0b985d7), the sparse range keeping (707123a, static renamed RANGES_KEPT), the look stats (2a630fd), urgent PSO workers on main's Build queue (4dea333), the RAM floor after main's compile gates (927524e), the --measure-* options (5ab4f64), the newer-forms selection (e35c384; main's EXEC-select fold stays on for every program).
  • Left out: the XCL_ASYNC_SUBMIT submit thread (27f5f62, db556c2, b54c6d9, 9f9a9bc, 077047a; built on amd-dev's ExecuteCommandLists hook and alloc_pool, which the first merge replaced), the unlocked sparse CPU read (09536b8, eabf2de; needs amd-dev's sparse landing), the shared deferred two-pass batch buffer (c7388f3, 34e95e7, 0bad17b; needs the dropped XCL_TWO_PASS_SHARED tracking), 5c5ee83 (main already keeps XCL_DXIL_NO_OPT runs out of the cache). From 36e16cf the newer-forms defaults and XCL_DIRECT_COMPACT_MIN are taken, its huge-compile defaults (64 KiB, 2 at a time) are not: they would turn off main's AMD medium-compute gate.

Tests changed:

Removed, because they test code that was dropped above:

  • title_textures::a_sampled_shadowed_texture_is_active_again
  • alloc_pool::excess_idle_aside_allocators_are_reclaimed_while_title_and_busy_ones_stay
  • the vram_small test module

Changed:

  • early_depth: false added to the older PsInterface literals.
  • main's robustness tests that expected multi-wave barriers to fall back to HLSL now expect amd-dev's direct safe barrier.

Tested

  • cargo build --release -p xcl and cargo build --release -p xcl --tests succeed on all three merge commits. These are cross builds to x86_64-pc-windows-gnu on Linux.

  • On 3277acaf, the unit tests of the modules the third merge touched were run under Wine 11.21, with XCL_DXC_DIR pointing at DXC 1.9.2609:

    • all pass: indexed (4), bvh_spare (4), ffx (3), title_textures (70 passed, 1 ignored), console_list (12), left_out (9).
    • Two d3d12x::bind tests fail: gpu_two_pass_indirect_commands_keep_their_own_records and prepared_initial_pipeline_commits_only_after_create_or_reset_success. They fail the same way on the previous head 069c29fe, because the Wine test prefix has no real D3D12 device; the merge did not cause them.
    • The rest of the suite was not run.
  • Retail title on Linux: Wine 11.21 staging, vkd3d-proton 3.1 with a newer dxil-spirv, RX 7800 XT (RDNA3), RADV. Several runs with this tree plus a few local patches (mimalloc, a pixel-shader loop cap, user: hide title console window when DWM cloaking is unavailable (#175) #794, Recompiler: split wave64 spin loops poll with a compare-exchange, not an add of 0 (#847) #1244, xcl run: XCL_SHORT_MOVIES=1 ends a title's Bink videos after their first frame #681), using XCL_RT_GATE=miss XCL_AMBIENT=sky and the default coherent window:

  • On e3fae4ed the release build and --tests build succeed, and the first new commit builds on its own. Unit tests under Wine:

    • pass: ambient 18, alloc_pool 28 (including the new a_final_release_retains_a_busy_allocator_and_not_a_free_one), depth_uav 21.
    • vram: 72 passed, 1 failed. d32s8_targets_take_their_own_size_of_video_memory fails the same way on 3277acaf.
    • dispatch_chain: 25 passed, 2 failed, both in the test helper slot_of ("adopted class"). One of them, failed_binding_keeps_indirect_commands_until_allocator_reset, fails the same way without the fix. The other is the new GPU test a_released_allocator_keeps_its_chains_until_the_gpu_is_done, which needs the same test setup fixed, so it proves nothing yet.
  • In the title:

    • The stand-in and zero-fill commits ran in several runs on a local stack: stand-in applied, no mosaic.
    • The chain fix has not run in the title yet.

Regression run

No xcl-smoke blocks yet: scripts/smoke.ps1 has not been run on this head or on main. These runs were on Linux/Wine outside the script (see Tested). Like #3203, the file list also trips the binary-file check: the GitHub files API returns no patch for these large merged files, so they are reported as binary.

Not tested

  • Windows and NVIDIA.
  • Most of the test suite (only the modules above were run, under Wine).
  • This exact tree in the title (only with the local patches listed above).
  • The amd-dev-specific stability fixes that were dropped in favour of main (above), on the GPUs they were made for.

AI use

Claude Code (Claude Opus 5.5) did the conflict resolution, with sub-agents doing the commit-by-commit resolution, and wrote this description, at my request and under my review.

🤖 Generated with Claude Code

bmjask added 30 commits November 27, 2026 17:30
Disable translated-shader caching whenever XCL_SAFE_BARRIER is set because the override changes direct-backend admission and generated barriers. Cover physical-wave boundaries, native wave32 mesh groups, and the explicit unsafe override.

Checked with cargo check for the Windows GNU target across library, tests, and benches.

Assisted-by: Codex (GPT-5.6-sol)
Adapt the default-on LDS ordering and read-run elision from PR xcl-dev#1252 to the current emitter while preserving coherent-memory, barrier, and wave-local remap state.

Assisted-by: Codex (GPT-5.6-sol)
The direct per-instruction and per-lane lowerings do not yet order real LDS accesses between the two hardware halves. Refuse that unsafe combination so runtime routing uses the HLSL path's ordered meetings, while retaining native waves, geometry, and DS cross-lane operations.

Assisted-by: Codex (GPT-5.6-sol)
Fused split-wave64 reduction tails emit their own guaranteed cross-half meeting, but did not record it in the LDS ordering state. Mark those exchanges as Met so a following LDS access does not pay for a redundant meeting.

Assisted-by: Codex (GPT-5.6-sol)
Recognize the compiler's exact min, max, and/or whole-wave pattern only when its saved-EXEC mask provenance and instruction flow are proven. Rebuild it with wave operations over launched lanes, repair the accumulator, and route recognized direct-DXIL graphics stages through the HLSL path.

The RTX partial-wave regression remains hardware-gated; GNU cross-target library, test, and bench compilation passes on Linux.

Assisted-by: Codex (GPT-5.6-sol)
Adapt PR xcl-dev#2252 to propagate the requested graphics wave mode into direct DXIL. Wave64 VS/PS programs whose upper-lane reads need HLSL reconstruction now fail closed, while native and safe split programs remain direct.

Assisted-by: Codex (GPT-5.6-sol)
A wave64 vertex or pixel shader can use v_writelane slots whose target lane was not launched in a partial hardware wave. Preserve proven slots in scalar shadows, select the native value when the physical upper lane exists, and include pixel helper lanes through the established quad recovery path. Direct DXIL falls back when it cannot represent the shadow.

The structural coverage includes native and split forms, direct fallback, and an intervening VALU overwrite that requires physical-lane selection.

Assisted-by: Codex (GPT-5.6-sol)
Pipeline pressure cannot safely evict and restore native generations while command-list state remembers only a reusable title address. Snapshot each registered pipeline before taking the bind-state lock and retain either its exact Pending identity or a pinned ready generation.

Evicted generations remain deferred: this stage starts no restoration, worker, wait, receipt, or pressure policy. Replacement decisions are dropped outside the state lock, and split continuations carry the exact retained identity.

Assisted-by: Codex (GPT-5.6-sol)
The required suite did not compile or execute custom benchmark targets, and translation timings did not cover the wave64 graphics analyses. Smoke every custom benchmark closure once and add equal-sized plain, native-spill, and split-spill translation workloads.

The bench-only Cargo selector excludes library and binary test harnesses, avoiding duplicate optimized-profile unit and GPU tests.

Assisted-by: Codex (GPT-5.6-sol)
Correctness-critical emission must not re-resolve a title address that may now name another pipeline, and it must never bind an unowned native pointer. Add a retained-identity consumer that exposes a raw pipeline only together with its exact immutable generation pin.

Legacy one-shot pipelines remain an explicit transitional disposition, while deferred restoration and failures remain fail-closed. No live draw, dispatch, ExecuteIndirect, worker, or restoration policy changes in this stage.

Assisted-by: Codex (GPT-5.6-sol)
A draw previously re-looked up its title pipeline address and then resolved it again inside ABI binding. Address reuse or generation replacement could redirect one recorded draw and leave its native object unpinned.

Snapshot the retained decision once outside the bind lock, record an available immutable generation before use, and carry the selected raw pipeline through draw classification, tracing, ABI binding, and rectangle handling. Deferred recipe states fail closed; legacy one-shot behavior remains explicitly unchanged for a later generalized pinning stage.

Assisted-by: Codex (GPT-5.6-sol)
Retained draw decisions previously fell back to the title-visible address for ordinary one-shot builds, allowing release and address reuse to redirect emission to another pipeline. Lazily retain one exact COM generation per used build, serialize its first pin with final release, and fail closed when no owned generation exists.

Assisted-by: Codex (GPT-5.6-sol)
Pipeline generations recorded by draws must survive bundle execution, command-list submission, and GPU retirement independently of recipe rebuilding. Reset and split paths now carry only retained exact identities, and generation owners are dropped outside the list-state lock.

The ordinary submission fast path remains marker-free when a recording has no exact generation pins.

Assisted-by: Codex (GPT-5.6-sol)
Direct Dispatch now carries the retained SetPipelineState identity through deferred demand, build waiting, generation pinning, ABI setup, and the native SetPipelineState call. Reusable title or native addresses can no longer redirect a recorded dispatch to a replacement pipeline.

This removes redundant registry resolution structurally; no runtime performance measurement was made in this Linux environment.

Assisted-by: Codex (GPT-5.6-sol)
Generation retirement scanned every outstanding receipt by calling the driver while holding one global mutex, producing quadratic fence probes while the GPU lagged. Snapshot one exact queue-marker owner per fence, observe progress outside the mutex, and retire all batches below each captured monotonic cutoff. Receipt clones are now Arc-only, and completed or duplicate generations are destroyed after unlocking.

The focused tests cover exact-owner deduplication, cutoff retirement, concurrent appends between phases, lock exclusion for probes and drops, poisoned duplicates, and COM-free receipt cloning.

Assisted-by: Codex (GPT-5.6-sol)
A bind captured before its pipeline finishes remains an Initial decision and repeats completion and generation locks on every later emission. Add a non-default synthetic benchmark that compares that steady path with an already-retained Ready choice and with fresh registry classification.

The fixture prewarms exact fake COM owners and excludes workers, DXC, driver compilation, and first-use allocation. A dispatch case also includes the initial-build gate. This records the baseline for a separate Initial-to-exact promotion change without altering default runtime behavior.

Assisted-by: Codex (GPT-5.6-sol)
A bind captured while its pipeline was unfinished stayed Initial forever, so every later draw or dispatch repeated completion, generation, and candidate bookkeeping locks after the build had finished. Publish the first successfully resolved exact generation into a cell shared by every clone of that retained decision.

Only exact available choices are cached; unavailable attempts remain retryable. Concurrent first consumers return one cell winner, including when a local failure races with another consumer's publication. The promoted owner survives release, address reuse, rebuild, and native Reset seeding.

Assisted-by: Codex (GPT-5.6-sol)
Replace the linear generation-owner scan on every translated draw and dispatch with an allocation-identity index. Preserve the ordered owner vector for submission lifetime, rebuild the index across bundle and failed-close restoration, and clear it on every recording transfer.

Assisted-by: Codex (GPT-5.6-sol)
Exercise the real generation-recording path at retained depths 1, 16, 64, and 256, then compare equal batches across distinct lists serially and in parallel. The feature-gated fixture uses exact fake-COM owners, stable synthetic list identities, and removes its state without touching a device.

Assisted-by: Codex (GPT-5.6-sol)
Compare equal batches of retained pipeline-state snapshots across distinct command lists serially and in parallel. Each worker owns a separate exact-resolution carrier so the measurement isolates the global bind-state mutex rather than a shared reference-count cache line.

Assisted-by: Codex (GPT-5.6-sol)
The adopted primary already forgets its state before final native Release. Avoid a second key-only forget after Release returns, when the runtime may already have created a new list at the same address.

Assisted-by: Codex (GPT-5.6-sol)
Replace the process-wide bind-state mutex with a 64-shard registry of per-list state locks. Registry guards are released before list locking, and forget extracts state so UMA transfer and retained pipeline destruction remain outside both lock classes.

Assisted-by: Codex (GPT-5.6-sol)
Keep four weak per-thread bind-entry references so repeated draw and dispatch state access bypasses registry shards. One-way live invalidation and a post-lock Acquire check reject stale entries after same-address list reuse without extending state or COM lifetimes.

Assisted-by: Codex (GPT-5.6-sol)
ABI binding took separate state locks for the root snapshot, three arena reservations, dispatch limits, and allocator. Capture the root state, reservations, and allocator in one critical section, and pass dispatch limits explicitly so failures cannot leak them into a later dispatch.

Compile-only checked for x86_64-pc-windows-gnu in debug and release; Windows execution was not available.

Assisted-by: Codex (GPT-5.6-sol)
Existing timing covered translation, DXC, driver compilation, and title-thread waits but not time accepted jobs spent waiting for a worker. Record speculative/preload and demand-band residence separately, split promoted jobs at the accepted priority transition, and abandon timings for cancelled work.

Timing aggregation stays outside the build-queue state lock so tracing does not add a nested serialization point to the measured path.

Compile-only checked for x86_64-pc-windows-gnu in debug and release; Windows execution was not available.

Assisted-by: Codex (GPT-5.6-sol)
Keyed compute submissions shared one process-wide registry lock and swept every in-flight key on each request. Route canonical keys across 64 shards, clean stale values only on exact-key contact, and remove terminal builds by exact weak identity.

Counter retirement is serialized before terminal removal, while displaced keys and builds are dropped after unlocking.

Compile-only checked for x86_64-pc-windows-gnu in debug and release; Windows execution was not available.

Assisted-by: Codex (GPT-5.6-sol)
Repeated deferred dispatches re-ran wanted promotion and took the queued and demand locks after record-time demand was already established. Publish completed submit demand on the shared build after want and scheduling finish, so later calls use one acquire load while concurrent first callers remain idempotent.

Cross-checked debug tests and release all-target builds for x86_64-pc-windows-gnu; Windows runtime tests were not run here.

Assisted-by: Codex (GPT-5.6-sol)
Choosing between more GetWriteWatch calls and scanning gap bytes needs Windows measurements. Keep the existing 8 MiB production policy, add opt-in exact coverage and call timing, and provide a deterministic allocation-safe planner plus a manual threshold benchmark for a later measured activation.

Cross-checked debug tests and release all-target builds for x86_64-pc-windows-gnu; the Windows benchmark, runtime tests, GPU tests, and smoke run were not run here.

Assisted-by: Codex (GPT-5.6-sol)
Retained deferred dispatches repeatedly took the completion mutex even after an initial build had reached terminal state. Publish terminal initial-build state through an observational release flag while keeping exact waits, generation ownership, release, and eviction serialized by the existing mutex.

Add serial and parallel CPU benchmarks for shared and distinct unpromoted completion probes, with the promoted path as a control.

Cross-checked debug tests and release all-target builds for x86_64-pc-windows-gnu; Windows tests and benchmarks were not run here.

Assisted-by: Codex (GPT-5.6-sol)
Dirty-page selection scans every active texture while holding the texture table, but existing activity reports hid both lock contention and scan cost. Preserve the exact resource-ordered selection and retention semantics while reporting lock wait, hold time, predicate work, matches, and retained uploads through the existing opt-in look sample.

Cross-checked debug tests and release all-target builds for x86_64-pc-windows-gnu; Windows runtime tests, GPU tests, and smoke were not run here.

Assisted-by: Codex (GPT-5.6-sol)
@github-actions github-actions Bot added area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-rebase Has merge conflicts with its base branch labels Nov 29, 2026
Brings amd-dev's 73 commits since 10582c4 onto the main-based merge
(4fedcbc). Commits main already carries keep main's version. Each new
amd-dev change is re-applied onto main's code where 4fedcbc chose main:
direct wave32 reductions on graphics_reductions, quad-local lane reads
beside main's own-lane fallback, remap compare and GPU-write keeping in
main's texture selection, cached mapped ranges and look stats in main's
sparse.rs, urgent PSO workers on main's Build queue, the RAM floor after
main's compile gates.

Left out: the XCL_ASYNC_SUBMIT submit thread series and the unlocked
CPU read (built on amd-dev's submission path, alloc_pool and sparse
landing), the shared deferred two-pass batch buffer and its smaller
ExecuteIndirect regions (main's feedback sizes them), XCL_DXIL_NO_OPT
cache keying (main bypasses the cache), and the 64 KiB / 2 huge-compile
defaults (main's AMD medium-compute gate stays). Main's EXEC-select
fold is not one of the newer forms.
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-rebase Has merge conflicts with its base branch labels Nov 29, 2026
@lucsoft
lucsoft marked this pull request as ready for review November 29, 2026 18:58
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
@raylitebull

Copy link
Copy Markdown
Member

Tested 4fedcbc as-is on Windows 11, RX 9070 XT, release build, on a retail title.

  • With preparation on (XCL_PREPARE_WORKERS=2): preparation finished (compute check ~780 s and 604 graphics pipelines in ~1020 s on a cold driver cache). The title then froze ~8 s after starting: 0 presents, 0 submits until killed. No device removal.
  • With your settings (XCL_RT_GATE=miss XCL_AMBIENT=sky, defaults otherwise) and XCL_PREPARE=0: loading screens at 30 fps, in-game pipeline builds, then from ~310 s 0 presents and 0 submits to the end of the 600 s run. Never reached the world. No device removal, peak commit 21.8 GB.
  • The same title reaches the world on current amd-dev on this PC in ~70 s.

Thread stacks of the frozen process show a three-thread deadlock through the D3D12 runtime's lock:

  1. Queue thread: real::q_execute_command_lists → queue_submit::with (holds the submit lease) → SubmissionChunk::submit_effects → sparse::readback_after_execute_with → ID3D12CommandAllocator::Reset → waits on an SRW lock inside D3D12Core.
  2. List reset: title_list::reset → list_x::reset_pc → alloc_pool::reset_list → inside D3D12Core, the runtime releases a resource → real::res_release → late_release::hold (takes HELD) → drain_known → queue_submit::with → Lease::enter waits for (1)'s lease.
  3. A title thread: real::res_release → late_release::hold waits for HELD held by (2).

vkd3d-proton doesn't have D3D12Core's lock, which would explain why this doesn't show on Linux. Two possible fixes: don't take the submit lease from a release hook that can run inside a runtime call (defer drain_known, or skip sealing when the lease is busy), or don't call into D3D12 (allocator Reset) while holding the lease. I haven't checked whether plain main hits this on Windows too.

The PR head has moved to 5eb7f8f since; I have not tested that commit.

… queue

late_release::Held::drain signals each queue's fence under HELD, and
native_queue_signal waits for the queue's submit lease. drain_known runs
from a resource's last Release, which D3D12's runtime can make inside a
call of its own (a list's Reset, alloc_pool::reset_list) while holding a
runtime lock; the thread with the lease can be waiting for that lock
(sparse::readback_after_execute_with resetting its allocator inside
queue_submit::with). On Windows the three threads then waited for each
other (title thread on HELD, the Reset thread on the lease, the queue
thread on the runtime lock); reported by raylitebull on xcl-dev#3444 for
main's code merged into amd-dev. vkd3d-proton has no such runtime lock.

Sealing now takes the lease only when it is free
(queue_submit::try_with, native_queue_try_signal); a queue whose turn is
another thread's leaves the batch open, and the next drain (the
late-release thread, every TICK) closes it.
@lucsoft

lucsoft commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for testing this on Windows and for the stacks – that pinned it down.

The deadlock isn't from the merge: late_release.rs, queue_submit.rs and sparse::readback_after_execute_with are byte-identical to main here, so main should hit the same three-thread wait on Windows. amd-dev doesn't have #2959's submit lease, which is why it doesn't show there.

The cycle closes in late_release::Held::drain: it signals each queue's fence under HELD through native_queue_signal, which waits for the queue's lease. I pushed 069c29fe (your first option): sealing takes the lease only when it is free (queue_submit::try_with, native_queue_try_signal). If another thread has the queue's turn, the batch stays open, and the next drain closes it – the late-release thread drains every TICK. HELD is never held while waiting for a lease now, so a Release from inside a runtime call no longer waits for the queue thread. There's a unit test for try_with (no wait for another thread's turn, re-entrant on the owner).

Tested only on Linux (Wine + vkd3d-proton, RX 7800 XT), where the deadlock can't happen: builds, tests build. I can't run Windows here – could you try the new head when you have a moment? If it's easier to review on its own, I can open it as a separate PR against main as well, since main has the same path.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
The stand-in lighting (XCL_RT_GATE=miss + XCL_AMBIENT) never applied on
this merge: no "captured … sky dome" or "applied" line in any run, so
every missed ray brought the sky's light indoors (overexposure, sparkles
in hair and skin, white specks). Three causes:

- Merge regression: main's ExecuteIndirect runs split programs through
  dispatch_chain::execute_indirect and returns before the ambient hook;
  amd-dev had no such branch. The chain path now calls the hook too.
- Roles were looked up by the resolved PC pipeline, which lazy and
  background builds replace with other objects. Roles are now noted at
  the title's own CreatePipelineState, looked up by the bound pipeline
  and, failing that, by the console record (fnv64 of the CS).
- The helper programs (SKY_REDUCE, AMBIENT_FILL, LIGHT_PLACE, …) were
  compiled with D3DCompile, which under Wine is vkd3d-shader and refuses
  them, so get_device made no device and every pass returned silently.
  They, and the depth UAV twins', present compositor's and mirror's
  helpers, now compile with DXC first (dxc::compile_sm6_first, x_5_x as
  x_6_0), D3DCompile as the fallback, and a refusal is logged. scatter's
  program stays on D3DCompile: built with DXC it scattered the title's
  writes to the wrong places.

XCL_AMBIENT_DIAG=1 logs the path and role each lighting pass takes.
amd-dev zeroed pool tiles that an evicted or freed texture had used
before mapping them into a new texture (XCL_ZERO_TARGET_PAGES, on by
default). Taking main's vram.rs in the merge dropped that, so new
render targets such as the screen-probe light history start out with
another image's bytes, which shows up as block garbage in the lighting.

Bring it back on main's page pool: TilePool marks tiles that come back
from cooling, take_batch_recycled reports the marked ones it hands out,
and bind_range zeroes them on the tile-mapping queue right before the
UpdateTileMappings that gives them to the texture. One CopyBufferRegion
per contiguous run, from a 1 MiB zeroed upload buffer into a buffer
placed over the whole pool heap. Title queues already wait for the
mapping fence in before_execute, so the zeros land before any work on
the texture. A new heap's tiles are zeros already and are left alone.
XCL_ZERO_TARGET_PAGES=0 turns it off; the zeroed tile count is logged
at powers of two.
The title's final Release of a command allocator cleared RECORDINGS for
it (alloc_release, real.rs) even when alloc_pool kept the allocator
alive because a list still held a recording on it or the GPU had not
passed its submits. The chains' scratch buffers, indirect command
storage and pipelines then went through late_release, which only waits
for work submitted before the release: a list submitted again (or a
submit reserved but not yet on the queue) ran its chains on freed
memory.

Retail runs on Linux/RADV lost the device (0x887a0005) 2-4 min after
world entry, each time after a gfxhub read fault (PERMISSION_FAULTS 0x3,
client 10, thread vkd3d_queue) and a ring timeout. A local log of every
buffer's GPU address range puts several of those fault addresses
(0x8016d3c02000, 0x801736c00000.., 0x8016f76c1000, 0x80164e630000) in
freed chain-scratch buffers of a run with the same address layout. A
Quint model of the recordings' lifetime finds the same: a recording is
freed at the final Release while a list can still submit it.

RECORDINGS of a PC allocator now go at console_list::allocator_reset,
which alloc_pool calls only for a backing it proved free (no list holds
a recording on it, every submit passed): reset_pc_allocator, forget's
free backings and sweep_release_owners. alloc_release clears them
itself only when the pool does not keep the allocator. As a side
effect, recordings on put-aside backings no longer wait for those
backings' own Release.
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
@raylitebull
raylitebull merged commit a1a84aa into xcl-dev:amd-dev Nov 30, 2026
1 of 5 checks passed
raylitebull added a commit that referenced this pull request Nov 30, 2026
Restores amd-dev's XCL_SPARSE_CPU_WAIT_MS (1000 ms by default, 0: off)
from 6fa964d, which the main -> amd-dev merge (#3444) dropped with
main's sparse.rs: a title submit whose wait for the sparse fence covers
tile mappings, and every wait for the texture page queue's mappings,
waits for the fence on the CPU before the title's lists go, and only
past the limit has the title's queue wait for it on the GPU (logged).

On amd-dev this was the RX 9070 device-removal fix: with every title
queue holding its work behind the mapping queue's fence, the fence
stopped short for 15 s and the device was removed.

It also fixes the two debug-layer e2e tests, which fail the same way on
plain main (1bd9cee) and pass on amd-dev (6bab0c5): with the GPU wait,
the debug layer's synchronized command queue validation holds a queue's
calls after a Wait for an unreached value on its own thread, and the
test title's copies and fence Signal after a tile mapping did not run
for more than 5 s ("GPU fence 1 not reached" in the sparse buffer heap,
depth bias, raytracing and streamed texture sections), though the CPU
wait finds the mapping done within 1 ms. With synchronized validation
turned off (experiment) the GPU wait passed those sections too.

Which waits cover mappings is tracked as on amd-dev: map_tiles,
unmap_tiles and poison_all set mapping_queued, the next signal records
mapped_value. Waits for uploads alone stay on the GPU. The CPU wait
holds no queue's submit lease (title_textures::refresh runs before the
lease is taken) and lets the upload gate go; it keeps the queue's wait
gate, so another submit on that queue still sees the wait done first.
amd-dev's wait_pending_mappings is not restored: main records the put-off
dispatches before the submit's refresh, so no mapping of theirs comes
between the refresh and the lists.
raylitebull added a commit that referenced this pull request Nov 30, 2026
…them

Restores amd-dev's XCL_ZERO_TARGET_PAGES (on by default, 0: off) from
6fa964d, which the main -> amd-dev merge (#3444) dropped with main's
vram.rs. Our run environment still sets XCL_ZERO_TARGET_PAGES=1; the
merged tree did not know the switch, so a pool tile given back by one
texture went to the next with the old texture's bytes in it (#505,
#1833: stale render-target, depth and UAV bytes in new targets).

As on amd-dev: the tile pool keeps a bit per tile that came back
(TilePool::dirty_bits), set when a tile cools back into the pool and
taken when it is handed out; the recycled tiles of a bind are zeroed
on the mapping queue through a buffer placed over the whole pool heap
(no extra video memory), from a 1 MiB zeroed upload buffer, in a ring
of 4 command lists, followed by an aliasing barrier and the mapping
fence's signal. They are flushed at 256 tiles and in before_execute
before the wait value is read, so every queue that waits for the page
mappings (title queues, texture uploads) waits for the zero-fill too.

Fitted to main: the list goes through native_queue_execute and the
signal through native_queue_signal, as Pages::map's do (the PAGES lock,
then the mapping queue's lease); a ring slot still on the GPU is waited
for at most 5 s, then that batch is skipped (logged) instead of
resetting an allocator in use; a reclaimed heap's zero alias goes with
it in PoolHeaps::take_heap (made in own_work, it has no Release hook).
Deferred unmap batches are not restored: main defers superseded texture
unmaps behind every queue's completion mark itself (held_unmaps,
c22c0ac).
raylitebull added a commit that referenced this pull request Nov 30, 2026
Wires vram_small back in, as on amd-dev (6fa964d; XCL_VRAM_SMALL, on by
default, 0: off). The main -> amd-dev merge (#3444) kept the module but
not its calls in vram.rs, and dropped its tests, so every sampled
texture under 64 KiB took a whole 64 KiB page of a reserved resource
again: up to 16x the video memory of a mip tail, icon or LUT, plus a
CreateReservedResource and UpdateTileMappings for each placement.

As on amd-dev: place_pages puts a texture under 64 KiB that does not
alias a live 64 KiB page (has_live_page: a sampled view over a render
target stays on the target's pages) into a block of a 16 MiB heap;
forget_for_recycle gives its block back before the pages are asked;
page_bytes counts the small pools for the activity log. vram_small.rs is
amd-dev's again, tests included; the GPU test now checks that the 4 KiB
textures took no 64 KiB page, as main's page_bytes_for counts pages
alone.
raylitebull added a commit that referenced this pull request Nov 30, 2026
…fault

Restores amd-dev's memory defaults, which the main -> amd-dev merge
(#3444) left at main's:

- XCL_TEXTURE_LEVEL_PAGES: on unless 0 (amd-dev 8942a5b; main: only
  with 1). A sampled texture's levels get pages when an upload first
  has texels for them: a retail title's 32,000 textures standing for
  18 GB held 1.3 GB of pages with it. With it comes amd-dev's guard
  (6fa964d) that main did not have: a sampled view over a live 64 KiB
  page (a render target's, has_live_page) maps all of its levels at
  once, since its texels come from the GPU and no upload would ever map
  them (should_use_lazy_levels).
- XCL_SMALL_TEXTURES: on unless set to something else than 1 (amd-dev
  8942a5b; main: only with 1), still off in unit tests unless a test
  asks for it.
- XCL_UPLOAD_KEEP_MB: back, 64 MB of idle texture upload buffers kept
  by default (amd-dev a68f609; main keeps 512 MB, with no switch).
  Upload heaps are commit and RAM while kept.

README says so, in amd-dev's words.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:directstorage DirectStorage queues, requests, decompression area:docs-ci Documentation, scripts, workflows, repo governance area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.