Skip to content

GPU: D3D12: remove NewFrame() API, and introduce a timeout to Collect()#1316

Draft
slomp wants to merge 15 commits intowolfpld:masterfrom
slomp:slomp/d3d12-ring
Draft

GPU: D3D12: remove NewFrame() API, and introduce a timeout to Collect()#1316
slomp wants to merge 15 commits intowolfpld:masterfrom
slomp:slomp/d3d12-ring

Conversation

@slomp
Copy link
Copy Markdown
Contributor

@slomp slomp commented Mar 23, 2026

This PR removes the need for calling NewFrame() periodically.

Some applications may run "headless" or may use the GPU for compute-only purposes, and do not have the concept of a frame boundary. Timestamp queries are now produced and collected in a circular buffer.

In addition, Collect() now operates on a fixed range of queries (4K window) and applies a timeout to the collect window to mitigate ambiguous timestamp resolves and race conditions with the GPU command processor writing to the timestamp heap.

The follow scenarios have been identified and verified:

  • timestamp queries are generated, but never executed (command-buffer is recorded, but never sent to a GPU queue for execution)
  • timestamp queries being generated in one order, but placed in GPU queue(s) at arbitrary order
  • timestamp arriving way too late in the timestamp heap

The only scenario where ambiguity can happen is as follows:

  1. a command buffer (CB1) is recorded, but not yet executed
  2. time goes by, and several command buffers are subsequently recorded and executed
  3. Collect() ends up giving up on CB1's "reserved" queries
  4. CB1 is finally sent to the queue and executed
  5. but around the same instant, another command buffer is recorded, claiming query ids that clash with CB1
  6. the GPU will resolve the CB1 timestamps, and write to the timestamp heap
  7. Collect() is not going to be able to disambiguate the timestamp

While technically possible, it is quite a contrived case. There does not seem to be a proper solution for the case above without some amount of costly query tracking along with some CPU-GPU synchronization on top of it. The existing implementation is also prone to the same "bad-timing" problem.

@slomp slomp marked this pull request as draft March 23, 2026 23:59
@slomp slomp changed the title eliminate NewFrame, and account for "abandoned" and "out-of-order" ti… D3D12: remove NewFrame() API; account for abandoned/out-of-order timestamp queries Mar 24, 2026
@slomp slomp force-pushed the slomp/d3d12-ring branch 2 times, most recently from 0cb1d81 to 0e62844 Compare March 27, 2026 21:12
@slomp slomp force-pushed the slomp/d3d12-ring branch from 4ce6662 to bf3694e Compare March 29, 2026 21:08
@slomp slomp changed the title D3D12: remove NewFrame() API; account for abandoned/out-of-order timestamp queries D3D12: remove NewFrame() API, and introduce a timeout to Collect() Mar 29, 2026
@slomp slomp changed the title D3D12: remove NewFrame() API, and introduce a timeout to Collect() GPU: D3D12: remove NewFrame() API, and introduce a timeout to Collect() Mar 29, 2026
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