Skip to content

gpu: bind both heaps before a directly indexed root signature - #49

Merged
simnJS merged 2 commits into
mainfrom
gpu/bind-heaps-before-root-signature
Nov 25, 2026
Merged

simnJS merged 2 commits into
mainfrom
gpu/bind-heaps-before-root-signature

Conversation

@fogydes

@fogydes fogydes commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

Part of #45, message id 1419. It builds on #46 (merged), whose debug-layer harness found it and checks it.

D3D12 lets a root signature with CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED or SAMPLER_HEAP_DIRECTLY_INDEXED be set only once a heap of that type is bound ("SetDescriptorHeaps must be called to bind a sampler descriptor before setting a root signature with D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED flag"). Translated pipelines' root signatures carry both flags (pipeline/host.rs). But when a title binds no sampler heap, or no view heap, draw::State::bind bound only what the title had, then set the root signature anyway. That is invalid D3D12 usage of the kind that can hang an NVIDIA GPU.

  • draw::State::wanted_heaps now puts XTP's own heap in place of each one the title binds none of (or one without a host heap). That means the view heap it already had (OWN_VIEW_HEAP, until now only for root SRV tables), and a new sampler heap of 16 null samplers (OWN_SAMPLER_HEAP, descriptor::own_sampler_heap, HostHeap::own_samplers). The root_srvs argument is gone: the view slot is always filled. Code that special-cases OWN_VIEW_HEAP (picked buffers, the stride table, root SRV tables) behaves as before: XTP's heaps have no stride table, so that path still refuses as it did with no heap.
  • Test helpers that set such a root signature themselves bind the same heaps (descriptor::heaps_with_own_samplers, test-only): in descriptor/host.rs, in pipeline/host.rs (render_r8_uint and the compute helper), and in rectangles/geometry.rs (Target::bind and the stream-output pass). The last one is behind rectangle_geometry_obeys_depth_bounds failing on main.
  • Every known_layer_errors(&[1419], "#45") allowance is gone; none is left in the tree.

Area

gpu: draw.rs, descriptor.rs, descriptor/host.rs, test helpers in pipeline/host.rs and rectangles/geometry.rs.

Tests

  • cargo xtask pr-check passes on my machine

  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

  • draw::tests::lists_without_a_view_heap_use_xtps_own now expects both of XTP's heaps without the title's, and the title's view heap with XTP's sampler heap after it binds one.

  • Under the layer (XTP_TEST_ADAPTER=warp XTP_D3D12_DEBUG=1 XTP_REQUIRE_GPU=1 RUST_TEST_THREADS=1 cargo test -p xtp-gpu --features diagnostics --locked), rebased on main f74e985: 410 passed, no 1419 anywhere, including rectangle_geometry_obeys_depth_bounds and a_pipeline_with_a_geometry_shader_runs_the_export_shader. The tests that had the allowance fail with message 1419 without this change (the draw tests through State::bind, the others through the helpers).

  • Ran on the title: BTP 6, Series S, diagnostics build on WARP, fresh data and cache, 150 s, stopped by its exact process handle, with this change and on its parent. Both runs gave 32 frame lines through to the stop, median 13.9 fps, the same 16 warnings, and no errors. No gameplay stage is claimed, and no log is included.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

AI assistance: Claude Code (Opus 5.5) drafted the change, tests and verification. No external code was copied or translated. I answer for every line.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

🤖 Generated with Claude Code

@fogydes
fogydes requested a review from simnJS November 25, 2026 06:23
@github-actions github-actions Bot added area/gpu touches crates/xtp-gpu size/M 100 to 399 changed lines labels Nov 25, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this is a clean fix and the reasoning holds up. #46 has merged, so could you retarget this to main and rebase (it's well behind now)? Main has since gained two more 1419 sites: the allowance at pipeline/host.rs:2049, and Target::bind in rectangles/geometry.rs (~417 and ~1178), which sets the root signature with no heaps bound — that's the current rectangle_geometry_obeys_depth_bounds failure on main. Covering them with heaps_with_own_samplers would be great. Small nit: the description says 8 tests, the commit says seven. We'll approve once it's green on main.

@fogydes
fogydes changed the base branch from ci/gpu-tests-debug-layer to main November 25, 2026 06:36
@github-actions github-actions Bot added the conflict conflicts with its base branch label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

This pull request now conflicts with its base branch. Please rebase it on main (or merge main into it) and resolve the conflicts; the conflict label goes away by itself once it merges cleanly.

@fogydes
fogydes force-pushed the gpu/bind-heaps-before-root-signature branch from 87db613 to c1fa1b2 Compare November 25, 2026 06:43
@github-actions github-actions Bot removed the conflict conflicts with its base branch label Nov 25, 2026
@fogydes

fogydes commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. Done in c1fa1b2: retargeted to main and rebased onto f74e985.

  • rectangles/geometry.rs: Target::bind and the stream-output pass (around 1178) now bind heaps_with_own_samplers(None) before their root signature. rectangle_geometry_obeys_depth_bounds passes under the layer.
  • pipeline/host.rs: the allowance in a_pipeline_with_a_geometry_shader_runs_the_export_shader is gone (it draws through render_r8_uint, which binds them already), and so is the one main added at the top of render_r8_uint. No known_layer_errors(&[1419] is left in the tree.
  • The count: the commit and description now say every 1419 allowance goes, without a number, since main keeps adding tests that go through these helpers.

Under the layer on main: 410 passed. The full WARP pr-check passes; its first attempt hit resource::tests::a_released_targets_copy_goes_when_its_memory_is_used_again once, a test this change does not touch, and the rerun was clean. #50 is rebased onto main too, and #51 is being rebased (main changed run_as).

@github-actions github-actions Bot added the conflict conflicts with its base branch label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

This pull request now conflicts with its base branch. Please rebase it on main (or merge main into it) and resolve the conflicts; the conflict label goes away by itself once it merges cleanly.

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. c1fa1b2 covers the last round: the pipeline/host.rs allowances are gone, Target::bind binds both heaps, and the description no longer counts tests. The debug-layer job at this head shows no 1419, and rectangle_geometry_obeys_depth_bounds passes.

Main has moved since (now 4ccd539) and the PR conflicts again. For the rebase:

  1. State::bind on main now calls wanted_heaps(constant_reads || root_uavs || root_srvs && bounded_root_srvs()). With your parameterless wanted_heaps() those three locals have no other use, so they can go; filling both slots already covers the root UAV and constant-read cases.
  2. Main added two 1419 allowances in descriptor/host.rs: stride_table_reads_stay_inside_the_table_and_tell_remapped_slots and views_read_through_the_table_only_are_refreshed_for_picks. Both run through run_table_program, which you already fix, so please remove them. known_layer_errors does not fail once the error stops, so a stale one would go unnoticed.
  3. Main now has testgpu::bind_indexed_heaps, which does in tests what heaps_with_own_samplers does. The depth-bounds test already calls it before Target::bind. Please keep one helper and drop the double binding.
  4. My mistake last time: the stream-output pass uses empty_root(ALLOW_STREAM_OUTPUT), which indexes no heap, so that hunk is not needed.
  5. Optional: own_samplers has 16 slots. A shader indexing the sampler heap past 15 while the title has no hosted sampler heap reads out of bounds; 2048 null samplers (the shader-visible maximum, a few dozen KB) would cover any index a title can form.
  6. The description already discloses the AI help, so please drop the Co-Authored-By trailer when you rebase.

We'll approve once it is rebased and green.

@fogydes

fogydes commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (05db757) and pushed 935b09f on top, with follow-ups from an in-house review:

  • main's red gpu-debug-layer job: three tests that main added since ci, gpu, docs: run the WARP GPU tests under the D3D12 debug layer #46 set a directly indexed root signature without both heaps (1419): draw::tests::a_cbv_fill_reads_an_in_flight_shaders_output_on_the_gpu, host::twins::tests::classes_written_in_a_list_are_tested_equal_in_the_same_list and pipeline::host::tests::a_loop_counter_counts_the_lanes_a_limit_stops. They now bind both heaps, so this PR should turn that job green on main.
  • Docs: reworded for the rule (XTP's own heap in each slot the title binds no hosted heap of): own_view_heap, HostHeap::own, and the draw test helpers.
  • Test: TestHeap::samplers, and the new title_sampler_heaps_take_their_slot covers a title sampler heap alone ([OWN_VIEW_HEAP, s]), with views ([v, s]), and that unchanged heaps keep host_roots while changed ones reset it.
  • One helper: testgpu::bind_indexed_heaps now binds the static own heaps through heaps_with_own_samplers, so tests bind heaps one way.
  • Logging: set_host_heaps logs once if a wanted heap can't be made, so a silent 1419 can't come back unseen.

Under the layer there is no 1419 anywhere, and the full WARP pr-check passes.

@fogydes
fogydes requested a review from simnJS November 25, 2026 12:02
@github-actions github-actions Bot added overlap another open PR changes the same files conflict conflicts with its base branch and removed conflict conflicts with its base branch labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown

This pull request now conflicts with its base branch. Please rebase it on main (or merge main into it) and resolve the conflicts; the conflict label goes away by itself once it merges cleanly.

simnJS
simnJS previously approved these changes Nov 25, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this covers the last round. The three locals are gone, the descriptor/host.rs allowances are removed, and with heaps set in bind_pipeline no 1419 allowance is left. CI is fully green, gpu-debug-layer included. The sampler-slot test is a nice addition.

One thing before I merge: both commits still carry the Co-Authored-By trailer. Please drop it (a force-push is fine for that); the AI line in the description is what CONTRIBUTING asks for. Main has also moved a lot since (several fixes for the same 1419 tests landed today), so please merge main in at the same time and check the result.

Non-blocking nits, fine for a follow-up:

  • rectangles/geometry.rs:748 and :790 still call bind_indexed_heaps just before Target::bind, which binds the same heaps at :419. One of the two can go.
  • The stream-output pass (:1242) uses empty_root(ALLOW_STREAM_OUTPUT), so its SetDescriptorHeaps isn't needed.
  • own_samplers still has 16 slots. 2048 would cover any index a shader can form.

Approving.

Pipelines' root signatures index the view and sampler heaps directly,
which D3D12 allows to be set only once both heaps are bound (debug
layer message 1419). Lists that bound no sampler heap of the title's,
or no view heap, set them anyway. The draw state now binds XTP's own
heap in place of each the title binds none of: the view heap it had,
and a new sampler heap of null samplers. Test helpers that set such a
root signature do the same (in the descriptor, pipeline and
rectangle-geometry tests), and every allowance for 1419 goes.

Part of #45.
Reword the docs for the rule of both heaps bound before a directly
indexed root signature, test a title sampler heap and unchanged heaps,
make bind_indexed_heaps use XTP's own static heaps, and log once when a
wanted heap has no host heap.
@fogydes
fogydes force-pushed the gpu/bind-heaps-before-root-signature branch from 935b09f to ac0024a Compare November 25, 2026 14:03
@github-actions github-actions Bot removed conflict conflicts with its base branch overlap another open PR changes the same files labels Nov 25, 2026
@fogydes
fogydes requested a review from simnJS November 25, 2026 14:04

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. Both trailers are gone, and the rebase onto 997af76 fits what main fixed today:

  • the twins and loop-counter fixes stay;
  • the draw allowances main already removed are no longer touched;
  • every 1419 allowance is gone;
  • rectangles/geometry.rs no longer binds the heaps twice, and the stream-output hunk is gone.

CI is fully green, gpu-debug-layer included. Optional: the description still mentions the stream-output pass. Approving and merging.

@simnJS
simnJS merged commit 60f8c69 into main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/gpu touches crates/xtp-gpu size/M 100 to 399 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants