Skip to content

D3D12.X: defer pred_buf drops until GPU fence completion - #2145

Open
Simon-CR wants to merge 1 commit into
xcl-dev:mainfrom
Simon-CR:pr/defer-pred-buf-release
Open

Simon-CR wants to merge 1 commit into
xcl-dev:mainfrom
Simon-CR:pr/defer-pred-buf-release

Conversation

@Simon-CR

Copy link
Copy Markdown

When a console command list calls SetPredicationBufferX, XCL creates a dedicated PC buffer (pred_buf) on the fly to hold the predicate value during recording. Previously, when that command list was released (on_release) or another command list was created at the same memory address (on_create), the old tracking entry and its pred_buf COM reference were dropped synchronously on the CPU — even if earlier GPU submissions referencing that buffer were still in flight.

This change defers dropping those PC-owned pred_buf resources behind GPU completion fences using late_release, matching the lifetime guarantee already enforced for title-owned resources: once retired outside the command-list tracking lock, pred_buf stays alive until every known GPU queue has passed a signalled batch fence, and then drops outside the HELD lock (dropping at once when no queues are active or when XCL_LATE_RELEASE=0).

What is in it

  • crates/xcl/src/hle/d3d12x/late_release.rs: extend Held / Batch with open_pc / dead_pc (Vec<ID3D12Resource>), add Held::drain_all, extract ensure_thread, add pub(super) unsafe fn hold_pc_resources, release gone_pc outside HELD in drain_known, and add GPU/unit tests held_pc_resources_wait_until_the_queue_is_past_their_batch and without_queues_held_pc_resources_go_at_once
  • crates/xcl/src/hle/d3d12x/list_x.rs: add retire_pred_buf and pass old.pred_buf.take() from on_create and on_release outside the LISTS lock, plus GPU test on_release_and_on_create_retire_pred_buf_until_queue_passes

Tested

Regression run

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1483 (PresentX 1483)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19090 MB
xcl-smoke v1
commit: 4fb33c7e37127a465645044e4c338aa98a022545
gpu: AMD Radeon RX 9070 XT
title: 5ec87c56
seconds: 60
exit: 0x0
frames shown: 1583 (PresentX 1583)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17029 MB

Not tested

  • D3D12 debug-layer validation run during heavy world streaming with SetPredicationBufferX, NVIDIA GPUs, Intel Arc GPUs, wave32-only GPUs, and Linux/Wine

AI use

  • Antigravity (frontier model; exact model identifier not exposed to agent) assisted with extending late_release for owned PC resources, wiring list_x::on_create/on_release retirement outside the lock, adding the unit and GPU tests, running the test suite and smoke runs, and drafting this description. All builds, tests, and regression runs were executed locally on the hardware above.

Command lists that call SetPredicationBufferX lazily allocate a PC ID3D12Resource predication buffer. When list_x::on_release removed a released list or list_x::on_create overwrote an entry at a reused command-list address, dropping that pred_buf synchronously inside COM Release could destroy the resource while previously submitted GPU command lists still referenced it. Extend late_release with hold_pc_resources so list_x::on_release and on_create defer pred_buf drops outside the LISTS lock until every known queue has passed the batch fence.
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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