Skip to content

startup: census of direct draws not drawn and of clears - #3482

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:runtime-draw-refusal-census
Nov 30, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:runtime-draw-refusal-census

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Refs #3477 (items 1 and 3; items 2 and 4 are in #3480).

Counting and logging only. Every early return in draw_translated returns the same value, the translated and untranslated counters move as before, and the clear calls are forwarded or refused exactly as before.

Direct draws not drawn, per (pipeline key, reason) (item 1)

note_draw_refusal returned at once unless X2W_PIPELINE_COLOUR was on, so a direct draw that drew nothing left no key and no reason. It now always records the key and a fixed reason code; the prose text is still written only with the switch on.

count_direct_draw replaces the two identical counting blocks in draw_startup_direct and list_draw_indexed. For a draw that was not drawn it notes (key, code) in a third PerReasonRefusalCensus, direct-draw. When the refusal carries no key, the key of the bound pipeline is used if it is known.

Reason codes: no_recording_list, no_pipeline_bound, render_targets_not_bound, topology_not_translated, pipeline_not_decoded, no_target_translation, manifest_absent, manifest_refused, native_graphics_refused, d16_view_not_ready, formatted_buffer_not_ready, fixed_vertex_stream_refused, pipeline_state_unavailable, sampler_heap_unavailable, raw_uav_shape_unsupported, resource_binding_refused.

x2w-d3d12 direct-draw refusal 1: key=0000000000000000 reason=no_pipeline_bound calls=2 first_seen_frame=0

PerReasonRefusalCensus::note takes an optional frame number, stored on insertion only. first_seen_frame is printed only when a frame was given, so the two indirect census lines are unchanged.

Clear census (item 3)

clear_census.h adds ClearCensus, a table of 128 distinct clear shapes with a call count each. The key is:

  • kind: rtv, dsv, uav_uint, uav_float;
  • view format and resource dimension;
  • width, height and depth-or-array size, each rounded up to a power of two;
  • four 32-bit value words: the colour or the UAV values; for a depth clear, the depth bits, the stencil, the effective clear flags and zero.

A clear is noted only after the desktop Clear* call, so refused clears (null target, no flags, read-only view, unreadable rectangles or values) are not in it. Once the table is full, a new shape adds to overflow calls and to the total only.

x2w-render clear census: total 134; shapes 128 (overflow calls 1)
x2w-render clear rtv fmt=28 dim=3 size_log2=0x0x0 value_bits=00000000,00000000,00000000,00000000 calls=6 first_seen_frame=0

Both censuses are mutex-guarded and are printed with the other censuses: changed entries in the five-second report, everything in x2w_d3d12_census_report. frame_number is now written with InterlockedExchange and read with InterlockedCompareExchange. The first-4 log in list_clear_target is untouched.

Tests

Base c4b8a41b, preset dev:

ctest -j 1 -R '^(startup_draw_clear_census_warp|startup_clear_depth_stencil_warp|startup_clear_uav_warp|startup_per_reason_refusal_census)$'
  • Passed: startup_clear_uav_warp (extended: total, shape count, the uav_uint and uav_float lines with their value words), startup_per_reason_refusal_census.
  • Skipped (exit 77, SKIP: no debug layer message callback): startup_draw_clear_census_warp (new, startup_clear_depth_stencil warp census) and startup_clear_depth_stencil_warp. The D3D12 debug layer is not installed on the machine used.

Mutations, each rebuilt and run:

Mutation Failing test
uav_float clears not noted startup_clear_uav_warp
value words not copied into the key startup_clear_uav_warp

Merges cleanly with #3480 and #3481 (git merge-tree).

Not covered

  • The new assertions for the draw census, the RTV and DSV clears, the overflow count and first_seen_frame were not run. They are all in the census branch of startup_clear_depth_stencil.cpp, which skipped here. Could a reviewer with the debug layer run:

    ctest -R '^startup_(draw_clear_census|clear_depth_stencil)_warp$'
    
  • No mutation was run against that branch for the same reason: the X2W_PIPELINE_COLOUR guard, a census bypass at either draw entry, a first_seen_frame overwrite, the value words left out of the key comparison, the overflow increment.

  • Only direct draws are counted here; the indirect paths keep their own censuses.

  • The reason given to draws refused after pipeline creation (views, buffer copies, index data, default scissor) is still the single resource_binding_refused.

@R0Y00 R0Y00 added the priority: P0 Highest project priority label Nov 30, 2026 — with ChatGPT Codex Connector

Copy link
Copy Markdown
Contributor

Both requested WARP tests passed

I ran the stock tests at clean PR head 2215b108c9c394b9f034ef6b3c061911b0ce3c68 using the dev preset, MSVC 19.44.35230 and Windows SDK 10.0.26100.0 on Windows build 26300.10075.

Backend Stock tests Result
WARP 10.0.26100.10068 startup_draw_clear_census_warp, startup_clear_depth_stencil_warp, startup_clear_uav_warp 3/3 passed
Arc A770 8086:56a0, driver 32.0.101.9175 startup_clear_depth_stencil_hardware, startup_clear_uav_hardware 2/2 passed
CPU startup_per_reason_refusal_census 1/1 passed

The WARP depth/stencil and census tests went past the debug-message callback check. The census assertions covered the refusal count and first-seen frame, RTV/DSV clear shape counts, and 134 calls across 128 retained shapes with one overflow call. All five D3D12 runs recorded zero debug-layer errors and device removal reason 0x00000000. Zero skips. AI assisted with setup and reporting. The runs executed locally.

@lukaslw-lab lukaslw-lab 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.

Reviewed 2215b108 by reading the diff; not built or run. For scale, our native-only run on main 44a3ad5a + #3506 #3516 #3464 #3521 #3097 (without this PR): 180 s, 3,499 frames, not drawn 143113, clears 41981.

Verdict: approve. Acceptance is unchanged, and the census names exactly what we had to find by hand. Our stale-layer pass in #3560 (key 05dc00b8b79c1d4b, refused natively) would show here as native_graphics_refused with its key on every frame. No MUST.

  • SHOULD per_reason_refusal_census.h:44 says the scan "is the keyed sample, not the per-draw path". count_direct_draw (d3d12_draw.inl:3801-3809) now calls note() on every undrawn direct draw: about 41 per frame (800/s) in the run above, each a mutex plus a scan of up to 128 entries with strcmp. The cost is small at that rate, but the comment now says the opposite of what happens. Please update it, or make clear that per-draw use is intended. When the refusal has no key, known_pipeline_key also takes draw_lock shared for a non-real pipeline (:1255-1256), on a lock that is already contended in native runs.
  • NIT With only_if_changed, every shape that recurs each frame is reprinted every five seconds: about 12 clears per frame here, plus each recurring (key, reason). In long runs that is the bulk of the five-second report.
  • Checked, no finding:
    • Each note_draw_refusal site gets a code matching its prose, and code is reset at entry. Draws refused before any note get unknown from copy_sanitized.
    • Clears are noted only after the desktop call, so refused clears stay out.
    • first_seen_frame is printed only when given, so the indirect lines are unchanged.

Tests: startup_clear_uav_warp pins the UAV shapes and value words. The census branch of startup_clear_depth_stencil pins the draw (key, reason, frame), RTV/DSV and overflow lines. CI ran none of them (not in the pr filter); Alexofbulgaria's local run at this head passed.

@R0Y00
R0Y00 merged commit 516a982 into R0Y00:main Nov 30, 2026
5 checks passed
R0Y00 pushed a commit that referenced this pull request Nov 30, 2026
#3482 added the direct-draw and clear censuses to the same report block, so it is six lines
where startup_memory_srv_diag_check expected four. The check failed on both backends and main is
red at 077bff3.

Validate the four lines the check is about, in order, and require any remaining line to be one of
those censuses by prefix, so the block is still constrained rather than accepted whole.

Co-authored-by: Kelbo <kelbo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants