Skip to content

startup: count a failed buffer copy as the null cause ring_full and refuse the draw; report upload ring statistics - #2864

Open
tedin7 wants to merge 3 commits into
R0Y00:mainfrom
tedin7:x2w-ring-full-stats
Open

tedin7 wants to merge 3 commits into
R0Y00:mainfrom
tedin7:x2w-ring-full-stats

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #870
Fixes #2863

What this unblocks: a translated draw whose buffer copy fails for lack of upload-ring space is refused and counted as ring_full, instead of running with a silent null binding that reads zeros; the render totals now show how full the ring is.

What changed

  • NullCause::ring_full (sixth slot) and BindingFacts::ring_failed in src/startup_stubs/null_binding_cause.h; the x2w-render totals line prints ring_full N after dimension N.
  • src/startup_stubs/d3d12_draw.inl: at the frame-copy site and the odd-size padded-stream site of the buffer binding, a readable range whose copy failed refuses the draw and counts ring_full (first six logged). Unreadable or empty descriptors stay null as before.
  • src/startup_stubs/d3d12_xs_device.cpp: x2w-render upload ring: reserved N MiB in N reservations, refusals N, capacity N MiB every 300 frames.
  • tests/startup_null_cause_labels_check.cpp: six causes, ring_full cases, totals-line text.

Why it is correct

A binding that could be read but not copied is not "nothing bound": drawing with it feeds the shader zeros in place of the title's data. Refusing the draw keeps the frame consistent and the count says why.

What stays as it was

Null bindings for entries, tokens, wrappers and dimensions, and unreadable buffer ranges, keep their causes and behaviour.

Source: Microsoft D3D12 documentation, ID3D12Device::CreateShaderResourceView and D3D12_BUFFER_SRV (a buffer view reads zeros only when its resource is unbound); this change is an accounting and refusal rule in our own stand-in, repo code src/startup_stubs/d3d12_draw.inl.

Verification

  • x86_64-w64-mingw32-g++ -std=c++17 -Isrc tests/startup_null_cause_labels_check.cpp under wine: pass (17 cases); --mutate buffer-token: fails.
  • tests/startup_null_views_check.cpp: mingw syntax check ok.
  • Syntax check of d3d12_xs_device.cpp with clang for mingw: no error in the changed code.
  • Win2025 (independent gate, proxmox, the change applied as a patch on a main-based head; regex ^(startup_null|startup_indirect_translated)): dev 23/23 and release 23/23 (15 passed, 8 hardware tests skipped).
  • Mutant (the ring_failed to ring_full rule dropped): killed on Win2025 (startup_null_cause_labels expected the sixth cause) and on Linux with g++ (4 of 17 cases fail).
  • Not covered: no WARP test forces a real upload-ring failure; the refusal path itself is covered by the cause classification check only.

Real-hardware testing: @Makto94 - thanks for the help.

AI-assisted; commands listed were executed locally.

…efuse the draw; report upload ring statistics
@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 14:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T14:57:19.723894Z 166b62a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 166b62a714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/startup_stubs/d3d12_draw.inl Resolved
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 07222b46ca69ec819147a3ff65bd07ffdc41bb7f:

  • Debug (--preset dev): build of d3d12_xs_device_obj d3d12_xs_shim startup_null_cause_labels_check startup_null_views_check ok; ctest --preset dev -R '^startup_null_cause_labels' 2/2 passed.
  • Release /O2 (--preset release): same targets build ok; ctest --preset release -R '^startup_null_cause_labels' 2/2 passed.

Fix in this head: a formatted buffer whose range is readable but whose frame copy fails (upload ring full) now counts ring_full before the early return, so it is no longer reported only as "unresolved buffer".

AI-assisted; commands listed were executed locally.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix. This cleanly addresses the silent null binding problem (#2863):

When the guest memory is readable but the upload ring is full, the draw is now refused and counted as ring_full instead of silently binding null (zeros). This is the right behavior a null binding would produce incorrect rendering that is much harder to diagnose.

Changes reviewed:

  • NullCause::ring_full (sixth slot) correct enum extension, no existing code depends on the old index
  • BindingFacts::ring_failed good separation ring failure is distinct from buffer not being bound
  • draw_translated refusal path checks readable_range first, then refuses with a one-shot log. The condition ordering is correct we only treat it as ring_full if the memory was actually readable
  • Upload ring stats atomic counters (InterlockedAdd64/Increment) are thread-safe for per-frame logging
  • Test update correctly expects 6 causes and the ring_full label

Minor note: The volatile LONG64 / volatile LONG for stats counters works fine with Interlocked operations. If you add a consumer (e.g., a telemetry hook) that reads all four stats at once, consider snapshotting them under a lock for consistency across the log line. Not blocking.

Looks good to merge. This unblocks #870 and is a prerequisite for #2847 (upload ring reuse builds on proper refusal semantics).

@Not-Saii Not-Saii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows hardware and read the diff. The full suite and the startup run used 166b62a7. After 07222b46 landed, I rebuilt and reran the 34 fixtures below on it: 34/34 passed.

Environment: Windows 11 build 26300.9974, MSVC 19.44.35230, Windows SDK 10.0.26100, NVIDIA GeForce RTX 4090 driver 610.88 (32.0.16.1088), WARP and hardware backends, D3D12 debug layer not enabled.

Fixtures

ctest --preset dev --no-tests=error -R '^(startup_null|startup_indirect_translated|startup_address_console_gate|upload_reservation$|startup_slot133_heap_cap)'

34/34 passed. That covers your gate regex on WARP and hardware (the hardware variants ran rather than skipped), plus the gate/gate-ring fixtures, upload_reservation and all six startup_slot133_heap_cap cases.

Full suite, in two passes so the hardware tests don't contend for the GPU:

ctest --preset dev --no-tests=error -j 20 -E '_hardware$' --timeout 600
ctest --preset dev --no-tests=error -j 4 -R '_hardware$' --timeout 600

The first pass passed 1752/1752 with 22 capability skips (77). The second ran 690 tests: 688 passed, including 8 capability skips, and 2 failed:

  • pixel_aot_cvt_flr_rpi_hardware timed out at 60 s under -j 4 and passed when rerun alone (26.6 s). This is contention.
  • compute_store_aot_mac_f32_hardware also fails when run alone: mac_f32: mad() fusion probe read back neither model alone: {'fused': False, 'unfused': False}. The probe comes from #2844, which is now on main. The run doesn't touch the startup stand-in, so it is unrelated to this PR. I'll report it separately.

Startup run from #2837 (on this PR alone, so the ring still caps at 256 MiB)

I used a release build and run.ps1 -Render -Translate -FakeUser -GpuMirror -ContinueAsserts 1000, 180 s, with A pressed every 5 s from 50 s. The new lines do what the PR says:

null bindings 7038 (entry 0, buffer 0, token 0, wrapper 0, dimension 0, ring_full 7038)
translated draws 4745 (not drawn 7038)
x2w-render upload ring: reserved 256 MiB in 12119 reservations, refusals 9088, capacity 256 MiB

On 7256cecf the same run counted those failures as buffer null bindings. Here they are named and the draws are refused. Ring refusals (9,088) exceed ring_full (7,038) because texture uploads and index copies also reserve from the ring, and those failures are not counted here (see 3).

From reading the diff

  1. Formatted buffers (the Codex point): fixed in 07222b46. Such a draw now counts ring_full before the early return. It also still counts in formatted-load draws refused, and the log line still says formatted buffer refused (unresolved buffer). A reader adding the two totals would count it twice, and the log names the wrong cause. Saying "upload ring" in that log line when readable_range is set would fix the second.
  2. BindingFacts::ring_failed is only used by the test. Both runtime sites call count_null_binding(NullCause::ring_full) directly. No runtime code sets ring_failed or reaches the new classifier rule. The mutant in the description, which drops the ring_failed → ring_full rule, therefore only shows that the unit test checks the classifier. It doesn't cover the draw path. Either route the two sites through classify_null_binding with ring_failed set, or drop the field and test the call sites.
  3. Other ring users are not counted. The index-buffer frame_copy (indices_ok && frame_copy(...)), the root-SRV upload_from_title and the texture reserve_upload_ring calls can also fail on ring space without touching ring_full. Textures are #2855. If the index path is in scope, it would explain part of the gap between refusals and ring_full above.
  4. The statistics line. reserved N MiB is cumulative and capacity is current, so once #2847 or #2849 lands, reserved will pass capacity routinely. Labelling it "reserved since start" would avoid misreading.
  5. Conflicts. git merge-tree reports conflicts with both #2847 and #2849 in d3d12_draw.inl and d3d12_xs_device.cpp. Both rewrite reserve_upload_ring, and #2847 also changes frame_copy. Whichever lands second will need the counters moved into the new reservation code.

Points 1–4 come from reading the code. I did not force a formatted-buffer or index-buffer ring failure.

# Conflicts:
#	src/startup_stubs/d3d12_draw.inl
#	src/startup_stubs/d3d12_xs_device.cpp
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged origin/main (GPU upload ring) into this branch: new head 65802fc.

Conflicts in src/startup_stubs/d3d12_draw.inl and src/startup_stubs/d3d12_xs_device.cpp resolved keeping both sides: main's reserve_upload_ring(self, ...) / frame_copy(self, ...) signatures and chunk reuse stay; the ring_full null-binding count and the reserved/capacity/refusal counters sit on top of every reservation path (including the new reuse pass).

Verification:

  • git diff --check origin/main...HEAD: clean
  • cmake -S . -B /tmp/cm-2864 -DDXC_EXECUTABLE=/bin/true: rc=0
  • g++ -std=c++17 -Isrc tests/startup_null_cause_labels_check.cpp: PASS (17 cases)
  • Win2025 on 65802fc (x2w_pipe.py win2025 2864 --regex 'startup_null_cause_labels|upload_reservation|startup_slot133_heap_cap' --keep-release): dev 100% passed out of 9; release 7/9 passed plus 2 skipped for capability (debug1 layer cases, not a pass).

AI-assisted; commands listed were executed locally.

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.

translated draws: a failed upload-ring copy of a readable buffer binds null silently; count it (ring_full) and report ring statistics

3 participants