Skip to content

runtime: bind the title's sampler heap for published native compute - #3540

Merged
tedin7 merged 6 commits into
R0Y00:mainfrom
JB2WIN:native/sampler-heap-runtime
Nov 30, 2026
Merged

tedin7 merged 6 commits into
R0Y00:mainfrom
JB2WIN:native/sampler-heap-runtime

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Change

#3076 stage 2a. A native compute program that reads samplers from the directly indexed sampler heap at a fixed index (stage 1, SamplerDescriptorHeap[i]) now gets a published runtime manifest, and the stand-in's Dispatch binds the title's sampler heap for it. Until now compile_dxil --requests published no manifest for such a program.

  • Writer (format_compute_runtime_manifest): the single heap_sampler binding is taken out of the view bookkeeping before the sort, stride and contiguity loops, and written as smpidx <bytes> after the static sampler lines. Exactly one binding, with root compute_sampler_heap, register 0 and a span of whole 16-byte entries up to 16*2047. Any other shape keeps the reason sampler heap.
  • Reader (load_compute_translation): smpidx is accepted once, with whole 16-byte entries below the fallback entry 2047. Otherwise the reason is a sampler heap span that is not 16-byte entries below the fallback.
  • Root: create_translated_root gets a trailing extra_flags parameter, and a translation with smpidx adds D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED. Graphics callers are unchanged.
  • Dispatch: the heap is the draw path's snapshot (prepare_draw_sampler_heap, keeping the list's fallback setting). It is bound with the view heap before the root signature. Refusals, all before a descriptor is taken: no sampler heap is set on the list, sampler heap creation failed, the sampler heap has no readable entries, the sampler heap is smaller than the program reads.

Refs #3076, #3023. The in-process route is unchanged. dynamic_sampler, create_sampler_snapshot_heap and decode_statics are not touched (#3199).

Verification

Build on 2ff74a6a, Windows 11, NVIDIA GeForce RTX 3080.

  • New startup_compute_dispatch_sampler_heap_hardware, a stand-in dispatch through a title sampler heap in title memory with the debug layer on and no error:

    • all 32 lanes equal the CPU model of entry 67;
    • four decoys in slot 67 each change the output;
    • a view heap only gives no sampler heap is set on the list;
    • a 67-entry heap gives the sampler heap is smaller than the program reads;
    • a 68-entry heap (1088 bytes) runs;
    • a manifest span of 1104 on 68 entries is refused;
    • smpidx removed from the .txt gives pipeline creation failed, which shows the root flag matters;
    • the reader rejects smpidx 0, 20, 32768, -16 and a second smpidx.

    _warp runs the manifest and reader parts, then exits 77 (no 32-lane waves).

  • New CPU test native_compute_manifest_sampler_heap (24 checks): the exact text, smpl plus smpidx, the binding placed first, between or last among t0 and a stride SRV with the same text, and nullopt for two bindings, a wrong root, or a bad span.

  • native_sampler_heap_check.py: the "no .txt" assertion becomes the exact published manifest (SAMPLE smpidx 1088, TWO smpidx 1104, MIXED smpl 0 … then smpidx 1088). This is the intended behaviour change.

  • ctest -R "startup_compute|native_sampler|startup_sampler|direct_compute|native_compute": baseline 228 tests with 0 failures; after 231 with 0 failures. The skips are the same WARP cases plus the new one.

  • Mutations, each rebuilt and run on hardware:

    • without the root flag: the hardware test fails;
    • without writing smpidx: the hardware test, the CPU test and native_sampler_heap_hardware fail;
    • the bound entry shifted by one: every lane reads the neighbour's texel, and the dispatch is still logged as translated.

Evidence and follow-up

All fixtures are source-built (the stage 1 program and its CPU model, the stand-in's own heap). No game data.

Not covered by a test: the wrapper-only sampler heap path (a heap without title memory, refused as empty if no shadow heap is readable), ExecuteIndirect, a draw and a sampler-heap dispatch alternating on one list, and sampler heap creation failed. The 1.0 root with the flag is verified on the RTX 3080 only. No revision bump: manifests published before keep their meaning, and only programs that had no manifest get one.

On main this publishes no extra local capture program, because those stop earlier, at the resource heap. It is groundwork for #3023 stage 3, where gather through the sampler heap follows next.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (docs/experiments/native-sampler-heap.md)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

JB2WIN and others added 3 commits November 30, 2026 03:44
Refs R0Y00#3076 (stage 2a). A native compute program that reads the directly indexed
sampler heap (SamplerDescriptorHeap[i], fixed index) now gets a published runtime
manifest and runs through the stand-in's Dispatch path with the title's sampler
heap bound.

- format_compute_runtime_manifest writes the one heap_sampler binding as the last
  line before `native`: `smpidx <bytes>`. Any other shape keeps the reason
  "sampler heap" and publishes nothing.
- load_compute_translation reads `smpidx` once (whole 16-byte entries, at most
  16 * 2047) and refuses anything else with a named reason.
- create_translated_root takes extra root flags; a translation with smpidx gets
  SAMPLER_HEAP_DIRECTLY_INDEXED.
- record_translated_dispatch refuses "no sampler heap is set on the list",
  "sampler heap creation failed" and "the sampler heap is smaller than the program
  reads" before any descriptor is taken, and otherwise binds the draw path's
  snapshot of the title heap (entry n = title byte 16 * n) before the root.

Out of scope: the in-process route (R0Y00#3154), dynamic_sampler,
create_sampler_snapshot_heap and decode_statics (R0Y00#3199).

Tests: native_compute_manifest_sampler_heap (CPU), native_sampler_heap_check.py
(the published manifests are exact), startup_compute_dispatch_sampler_heap_{warp,
hardware} (new stand-in consumer mode sampler-heap: entry 67 of a title heap is
sampled, decoys in slot 67 change the output, refusals and the 68-entry boundary).

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds the five stage 2a reasons, plus the output UAV element-limit reason
from main, to COMPUTE_DISPATCH_REASONS so startup_triage_run_check.py
covers them.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

The Linux Python job failed in startup_triage_run_check.py, because the new dispatch refusals were missing from COMPUTE_DISPATCH_REASONS. 37a6b26 adds them. It also adds an output UAV interval exceeds the D3D12 buffer view element limit from #3471, which is on main and was missing from the list as well. I merged main first (d626269). startup_triage_run_check.py now reports 0 failed, and ctest -R 'sampler_heap|native_compute_manifest|startup_compute_dispatch|output_uav' passes 43/43.

AI-assisted.

@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 37a6b269 by reading the diff; not built or run.

Verdict: approve. The writer and the reader agree on the one shape they accept: a single heap_sampler binding of whole 16-byte entries below entry 2047 (src/direct_compute_cache.cpp:948-959, d3d12_compute_dispatch.inl:433-437). Every other shape keeps the old reasons. The heaps are bound before SetComputeRootSignature, and every new refusal comes before a view descriptor is taken. No MUST.

  • SHOULD "sampler heap creation failed" (d3d12_compute_dispatch.inl:1309) is the only new reason missing from COMPUTE_DISPATCH_REASONS. startup_triage_run_check.py does not catch it, because its reason_start pattern only collects literals that start with a/an/the/no/…. So triage_run.py would report this refusal as other (text omitted), the case that check exists to prevent. Rewording it to "the sampler heap could not be created" and listing it fixes both.
  • SHOULD At :268 the PR returns "the device does not take a directly indexed sampler heap" for any create_translated_root failure when smpidx is set. Serialisation or root creation can also fail for other reasons (parameter count, static samplers), and this text would hide those. Checking the resource binding tier first, or keeping "root signature creation failed" for other HRESULTs, would make the reason reliable.
  • Checked: prepare_draw_sampler_heap sets sampler_snapshot on every true return, so the ->count dereference at :1310 is safe. A program without smpidx keeps the bound sampler heap. #3542 adds the same #3471 reason line, and git merge-tree of the two heads merges cleanly.

Tests: native_compute_manifest_sampler_heap proves the writer text and its refusals. startup_compute_dispatch_sampler_heap_hardware proves the dispatch, the decoys and each size refusal, and the smpidx-removed control shows the root flag matters. The _warp variant exits 77 after the reader checks. Neither test is in the pr preset filter, so CI ran only the Linux triage check; the dispatch evidence is the author's RTX 3080 run.

JB2WIN and others added 3 commits November 30, 2026 08:46
Reword "sampler heap creation failed" to "the sampler heap could not be
created" and list it in COMPUTE_DISPATCH_REASONS, so triage_run.py counts it
under its own name instead of "other (text omitted)".

Name the missing directly indexed sampler heap capability only when the root
failed on an adapter that reports shader model below 6.6; any other root
creation failure keeps "root signature creation failed". The decision is
compute_root_refusal(), checked without a device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mpler heap root

compute_root_refusal now takes whether the root serialised. A serialisation
failure is always "root signature creation failed"; the directly indexed
sampler heap text needs a serialised root with the flag that
CreateRootSignature refused on an adapter below shader model 6.6 or resource
binding tier 3. That is an inference from reported capabilities, not proof.
The check covers all eight combinations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The two compute root refusal texts moved into translated_sampler_bindings.h,
which the allowlist check did not read. Scan that function too, so a new or
misspelt reason there fails the check. Query the adapter only when the root
took the sampler heap flag and serialized, and spell "serializ..." as the rest
of the code does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JB2WIN

JB2WIN commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both addressed in 170d676, 376dc82 and 8d5163e.

  1. The refusal is now "the sampler heap could not be created" and is listed in COMPUTE_DISPATCH_REASONS. startup_triage_run_check.py now also scans compute_root_refusal in translated_sampler_bindings.h, where the two root texts live; a wrong text there fails the check.
  2. A serialization failure always keeps "root signature creation failed". "the device does not take a directly indexed sampler heap" is given only when CreateRootSignature refuses a serialized root with the flag on an adapter below shader model 6.6 or resource binding tier 3. That is an inference from the reported capabilities, and the comment and doc say so. A device-free check covers all eight combinations and fails against the earlier logic. The tier query itself is untested here: the RTX 3080 has the capability.

Targeted ctest: 16 run, 14 passed, 2 WARP skips.

AI-assisted.

@tedin7
tedin7 merged commit a71ee7d into R0Y00:main Nov 30, 2026
5 checks passed
R0Y00 pushed a commit that referenced this pull request Nov 30, 2026
…tion (#3626)

install_compute_translation copied every field of a loaded candidate except
sampler_heap_bytes (#3540's `smpidx`). The root keeps its
SAMPLER_HEAP_DIRECTLY_INDEXED flag, but the dispatch then sees a zero span,
binds only the view heap and sets that root without a sampler heap: a
debug-layer error, and the program reads no samplers.

Co-authored-by: lukaslw-lab <291379150+lukaslw-lab@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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