d3d12: order tile initialization on the GPU instead of waiting on the CPU #676
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/676"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-12-03T16:09:12Z.
Problem
Creating a view or buffer in a GPU reservation binds its tiles on the device's init queue and then waits for that queue on the CPU (
InitTransition::wait_for_queue), once per call.refresh_cpu_pagesdoes the same before everyExecuteCommandLists. On amdgpu each of those signals is a full CS that walks every userptr BO (#669), so the title's streaming thread spends much of the load blocked in SRV and CBV creation. JeffreyBytes measured 113.5 s of such waits in a ~250 s load on an RX 6700 XT (#669); on my RX 9060 XT the streaming thread had 33.8 % of its samples inwait_for_queue<initialize_gpu_tiles.Change
initialize_gpu_tilesandreset_gpu_tilesonly record theUpdateTileMappingsand mark the init queue as unsignalled. The resource and any tiles the update replaces are kept until the init fence reaches the value that covers it.wait_for_gpu_tilessignals the init queue once if anything is pending and makes the given queueWaitfor it on the GPU. It runs inexecute_lockedright beforeplacement::submit, in present aftergpu_mappings.refresh, and in the page-mapping command before its live binds. Many view creations between two submissions then cost one signal instead of one each.bind_published(the page-mapping worker and both inline paths) finishes the device's init queue on the CPU before its own binds, so they can't land ahead of a deferred initialization of the same buffer. The device's init slot is shared (Arc) so the worker job can reach it.apply(initial state transitions) andmap_reserved_tileskeep their CPU wait; it now also covers pending updates, since they use the same queue.TUXBOX_TILE_INIT=waitrestores the per-call CPU wait (docs/ENVIRONMENT.md).The audit of which queues need the ordering is on #669 (JeffreyBytes' list and mine): the guest queues, present and the page-mapping worker do; the upload, readback, lazy-publication, BLAS and detile queues only touch their own or committed memory.
Testing
On my RX 9060 XT (RADV / Mesa 26.3.1), Proton Experimental for the gate and GE-Proton11-15 for the game:
python tuxbox.py check(full gate):Evidence: TuxBox check of 149841d3d003, no uncommitted changes, GPU 1002:7590: 15 passed, 2 failed, 0 not run. Lanes and fixtures on the GPU and the D3D12 regression controls pass. The two failures are known on this card and unrelated: the translatoralucheck (23 of 372 instructions, signalling-NaN payloads through multiply-add, where RADV quiets the NaN) and the PythonGuestWatchtest, which fails under nixpkgs' Python wrapper (fixed in #675, not in this base).queue-page-mappings(placement while a mapping is queued, CPU-map resets) 5 of 5 runs with the change and 1 withTUXBOX_TILE_INIT=wait.queue-page-mappings' ordering checks are what guard the new path.106120ca+ #667, one run each with and without the change, same warm shader cache:Game Runningto the intro SRL 485 s -> 174 s, streaming thread samples in tile initialization 33.8 % -> 0 %. Both runs still end in the #669 stall (intro prestream, exit 5), so this doesn't fix #669 itself.Relation to the XMem/D3D12 rework
I know submission and tile mapping are being reworked. If this clashes with that design or the rework replaces this path, please close this instead of merging it. The measurements are on #669, so nothing is lost.
AI use
I made this branch with an AI coding agent (Claude Code, following
AGENTS.md). The agent read the code paths, wrote the change, built it, and ran the checks, the Lanes scenarios and the two game runs listed above on my machine; I started the game runs and pressed through the account picker.Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T16:24:09Z.
Will run 6700 XT tests on this soon.
This PR is set up to auto close #669, will you edit that in the development sidebar so it only references?
Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-12-03T16:57:57Z.
NVIDIA numbers for this change, from one 8-minute run each on an RTX 5090 (driver 620.70, GE-Proton11-15), default settings, into gameplay after the intro. Base is
106120caplus three local fixes that keep the device alive that long (#677 among them); the second run adds this PR's head149841d3, which merged without a code conflict.Both runs had
TUXBOX_SUBMIT_PROFILE=1,TUXBOX_STACK_SAMPLE=1,TUXBOX_GPU_TIMING=1andTUXBOX_STALL_DUMP=1. Figures are for the time after 200 s, when the game is in the playable scene.InitTransition::wait_for_queueregister_bufferandbind_published -> reset_native_gpu_tiles)gpu timing)So on this card the change does what it says: the title's threads no longer wait in
wait_for_queue. It does not make the frames faster here. They stay at about 20 s with the GPU nearly idle, and the differences between the two columns are within what I'd expect from one run each.What is left in the samples:
address_srv -> Placements::mapped_texture, waiting for thesubmissionsmutex. Submission preparation holds the same mutex, so these threads are waiting for submissions whose placement step takes 0.5-1.8 s a batch.placement::submit -> queue_use::Batch::execute -> memory_wait::submit -> QueuedCopies::record, with the innermost frames in a vkd3d call into the driver.For comparison, a build from before the page-mapping rework runs the same scene on this machine at about 0.7 s a frame with 0.37 s of submission time, of which the host call is 1-2 ms.
I haven't run the GPU checks on this PR's head.
🤖 Generated with Claude Code
Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T17:54:11Z.
RDNA 2 run on the head (
149841d3). RX 6700 XT 12 GB (1002:73df), Mesa 26.3.1 RADV, GE-Proton11-15, full check:No amdgpu faults or resets in the kernel log during the run. Game runs against #667 alone are next; I'll post them when they're done.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.