Skip to content

startup: gate the BVH builder compute stages all or none - #2920

Merged
R0Y00 merged 8 commits into
R0Y00:mainfrom
lambirou:startup/bvh-builder-gate
Nov 27, 2026
Merged

R0Y00 merged 8 commits into
R0Y00:mainfrom
lambirou:startup/bvh-builder-gate

Conversation

@lambirou

@lambirou lambirou commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The console BVH structure builder's compute stages feed each other through title memory. A stage that runs on data a missing stage never wrote computes store offsets from garbage; the observed failure ran 14 of 35 translated stages and the title died within a second on pointers that had become bounding-box bit patterns.

This adds an opt-in all-or-none gate:

  • X2W_COMPUTE_BUILDER_GATE=1, off by default.
  • At device slot 62, the gate resolves the caller module of the return address and tracks only pipelines whose basename is XboxBvhBuilder.dll. An unresolved caller is left untracked rather than guessed.
  • A builder Dispatch runs only while every tracked builder pipeline has a real desktop PSO. The first builder Dispatch attempts the missing pipelines on the spot. One failure turns the builder off for the rest of the run and refuses the Dispatch with a named reason.
  • The gate is keyed on the slot 62 wrapper's builder tag, not on compute_request_key. It is called at both public Dispatch paths: list slot 14 Dispatch and list slot 61 ExecuteIndirect with a Dispatch signature.
  • Slot 67 never receives the builder tag, so its request-publication path is unchanged. A non-builder Dispatch is unchanged.
  • Counted in the compute totals line as builder gate refused N.

The pure classifier and state machine are in src/startup_stubs/compute_builder_gate.h; the runtime wiring is covered by a source-built module named XboxBvhBuilder.dll that calls the public slot 62 vtable entry.

Tests

ctest --preset dev --no-tests=error -R '^startup_compute_builder_gate$' -V
ctest --preset dev --no-tests=error -R '^startup_compute_builder_gate_runtime$' -V
ctest --preset dev --no-tests=error -R '^startup_compute_builder_gate_request_warp$' -V

Passed locally on WARP:

  • startup_compute_builder_gate: 106 cases, 0 failures (classifier, gate off, all present, one missing, on-the-spot creation, permanent off after a failure, non-builder unaffected, full table refusal).
  • startup_compute_builder_gate_runtime: two builder pipelines created through the source-built XboxBvhBuilder.dll; a direct Dispatch and an indirect ExecuteIndirect are both refused with the gate enabled; the same direct call through a non-builder slot 62 wrapper produces no gate refusal.
  • startup_compute_builder_gate_request_warp: the existing slot 67 request check passes with X2W_COMPUTE_BUILDER_GATE=1, so request publication keeps its normal path.

d3d12_xs_shim builds with the hook.

Limits

The runtime helper uses a fake console container. It proves the caller-module tag and that both public Dispatch paths reach the gate; it does not claim a completed translated builder set. A console DXIL program still fails desktop PSO creation by name and turns the builder off, which is the intended conservative result until real translations exist. A real-title run with the gate on must report either all have a desktop PSO or one named reason.

Refs #870, #1758.

AI-assisted.

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

PR #2920 by @lambirou -- startup: gate the BVH builder compute stages all or none

What works

  • Solid foundational work establishing the 0x100 linear layout in gfx10_layout.h with careful derivation from AMD addrlib
  • The linear_mode = 0 constant elegantly extends block_log2() to accept mode 0 without changing the tiled modes switch logic
  • supports() check is correct: mode == linear_mode bypasses the block_log2 >= 12 requirement since linear has no tail
  • Test infrastructure is excellent -- linear_order_control (expected failure with largest mip first), linear_addrlib (338K element addresses), and the unpadded negative control all add strong coverage
  • Documentation accurately restates addrlib's linear mode algorithm in clear, testable terms

Issues

  • supports() currently allows block-compressed formats (BC1-BC7) in linear mode via the fallthrough -- BC formats are block-based and don't have linear row semantics; consider gating them out explicitly like 1D does in #2929
  • The check script in startup_address_console_check.py builds linear backing bytes from addrlib equations. This is correct but the linear path could break if the hardcoded equations drift from addrlib; a comment linking to the Mesa commit that derives these equations would help

Recommendations

  • Good discipline in including the negative control (unpadded rows test) to verify the 256-byte pitch requirement
  • Consider adding a TODO or assert in supports() that blocks linear mode for BC formats until explicitly validated against addrlib

Overall

A well-researched, well-tested implementation. The linear layout extension is cleanly separated from tiled modes. Minor concern about BC format handling in linear mode, but the existing refusal behavior is safe. Ready for merge.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The runtime gate cannot see the pipelines it tracks at 160b21d9. Slot 62 marks the wrapper as builder_pipeline, but neither it nor note_compute_binding_pipeline sets compute_request_key. The only assignment to that field is in the slot 67 specialization, which never records a builder pipeline. Both list_dispatch and the Dispatch arm of list_execute_indirect require a nonzero request key before calling compute_builder_dispatch_allowed. A slot 62 builder wrapper therefore bypasses both gates, and the helper unit test cannot catch that wiring gap.

Please exercise the public creation and dispatch paths with a source-built helper DLL whose basename matches the builder module. The fixture should show that an incomplete builder set refuses both direct and indirect Dispatch with the flag enabled, while a non-builder path and request publication keep their normal behavior. If the experimental flag is intended as a diagnostic cutoff only, describe that limit and still verify that it actually reaches the intended caller.

Copy link
Copy Markdown
Contributor Author

Fixed in 1dfaeeec, on top of current main 3e9542a6.

The wiring gap was real: the gate was behind compute_request_key, which slot 62 never sets. The gate now keys on the slot 62 wrapper's builder_pipeline tag and is called at both public Dispatch paths, independent of the request key:

  • direct Dispatch (list slot 14);
  • indirect ExecuteIndirect with a Dispatch signature (list slot 61), before the signature/argument checks.

Added a source-built runtime fixture:

  • XboxBvhBuilder.dll helper that calls the public slot 62 vtable entry, so the gate's caller-module lookup resolves the matching basename;
  • two tracked builder pipelines, then both a direct Dispatch and an indirect ExecuteIndirect are refused with the gate enabled;
  • the same direct call through a non-builder slot 62 wrapper produces no gate refusal;
  • the existing slot 67 request check runs with X2W_COMPUTE_BUILDER_GATE=1 and passes.

Local CTest: startup_compute_builder_gate (106 cases), startup_compute_builder_gate_runtime, and startup_compute_builder_gate_request_warp all pass. The fixture uses a fake console container, so it proves the tag and both Dispatch wirings; it does not claim a completed translated builder set.

Copy link
Copy Markdown
Contributor Author

The fix is on 3e10c525, rebased on current main e446b072, with CI green. startup_compute_builder_gate, startup_compute_builder_gate_runtime and startup_compute_builder_gate_request_warp pass locally and on CI. The stale CHANGES_REQUESTED review predates the new head; could you take another look?

Copy link
Copy Markdown
Contributor Author

@R0Y00 the gate wiring and the runtime helper-DLL fixture are on 3e10c525, rebased on current main and green. The CHANGES_REQUESTED review predates this head; could you re-review when you have a moment?

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The new wrapper tag routes slot 62 through the gate. The completed-set path still drops the first Dispatch. On 3e10c525, a source-built WARP control passed two valid desktop DXIL compute shaders through the slot 62 helper and bound one placeholder. The log first said 2 tracked pipelines, all have a desktop PSO; Dispatch allowed, then refused the same Dispatch(1, 1, 1) with requires a desktop compute pipeline and root. The three existing focused tests passed in both Debug and Release /O2 at that head.

The same state transition is present in the latest head 9b2bcc67: make_compute_builder_pipeline publishes the PSO and metadata on the wrapper, while compute_builder_dispatch_allowed returns without rebinding that PSO or refreshing the command list's cached compute pipeline and root. The downstream direct and indirect paths still use that cached state. Please refresh and bind the current pipeline on the list when the gate completes the set, and add a completed-set control that verifies the first direct Dispatch and an indirect Dispatch with valid arguments reach the GPU.

Copy link
Copy Markdown
Contributor Author

Fixed in b163d809, on current main.

When the gate completes the set it now refreshes the recording's cached compute state (pipeline_real, compute_pipeline, compute_pipeline_root) and binds the new desktop PSO on the list; when the title's bound root equals the pipeline root, it also re-binds that root. The caller's subsequent Dispatch decision therefore sees the completed pipeline instead of the placeholder bound before the gate ran.

The runtime fixture now has a completed-set mode: two valid desktop DXIL compute shaders created through the source-built XboxBvhBuilder.dll, an empty desktop root, the first direct Dispatch(1,1,1) and an indirect ExecuteIndirect with a placed D3D12_DISPATCH_ARGUMENTS{1,1,1}. The log reports all have a desktop PSO for the set and neither path is refused. The incomplete-set, non-builder and slot 67 request controls still pass.

Local CTest: startup_compute_builder_gate (106 cases), startup_compute_builder_gate_runtime, startup_compute_builder_gate_request_warp all pass.

Copy link
Copy Markdown
Contributor Author

Windows dev + release receipt on b163d809:

ctest --preset dev     -R "startup_compute_builder_gate"  -> 3/3 passed
ctest --preset release -R "startup_compute_builder_gate"  -> 3/3 passed

All three run on WARP: the 106-case unit test, the runtime fixture (incomplete set refused direct + indirect; completed set direct + indirect reaches the list; non-builder untouched), and the slot 67 request check with the gate enabled.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The first-dispatch state issue is resolved at b163d809. The gate now updates the list's cached pipeline/root state and binds the PSO before either caller continues. I rebuilt the gate unit test, runtime fixture, builder module and slot-67 consumer on local integration tree 7d83e45a against main 98007de5. ctest --preset <dev|release> --no-tests=error -V -R '^startup_compute_builder_gate($|_)' passed 3/3 in Debug /Z7 and 3/3 in Release /O2, with no skips (Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818). The completed set gets past the first direct dispatch and the valid indirect dispatch without the previous refusal, the incomplete set still refuses both paths, and the slot-67 request control still matches. This fixture checks command recording with a source-built no-op shader and does not measure shader output or original EXE behavior.

@R0Y00
R0Y00 merged commit e04217f into R0Y00:main Nov 27, 2026
5 checks passed
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.

3 participants