Skip to content

startup: bind LOD-clamped static samplers (smpl) in the translated compute Dispatch - #2585

Merged
tedin7 merged 77 commits into
R0Y00:mainfrom
NiiRoZz:startup/compute-dispatch-samplers
Nov 26, 2026
Merged

tedin7 merged 77 commits into
R0Y00:mainfrom
NiiRoZz:startup/compute-dispatch-samplers

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Depends on #2580. Refs #2274.

What changed

  • src/startup_stubs/d3d12_compute_dispatch.inl: the compute manifest reader accepts smpl <i> <w0> <w1> <w2> <w3> lines, the static sampler with the descriptor's MinLOD and MaxLOD that the translator writes since startup: write smpl for LOD-limited samplers in the compute manifest #2482. They go through the draw path's own code (TranslatedSamplers::read_manifest_line, decode_statics and create_translated_root in translated_sampler_bindings.h), so no second sampler mechanism is added. For compute, the only difference from a draw is that the root signature is set with SetComputeRootSignature; static samplers need nothing else at Dispatch.
  • The forms still not bound now refuse with their own reasons instead of the shared "a sampler that is not a plain static one": smpc gives "a comparison sampler" and smpheap gives "a sampler from the sampler heap". Binding the heap table for compute would need the draw path's sampler snapshot (snapshot_samplers, create_sampler_snapshot_heap) taken from the compute root's sampler heap pointer, SetDescriptorHeaps with the sampler heap, and SetComputeRootDescriptorTable. That is left for the first program that needs it.
  • tests/startup_compute_dispatch_texture_check.py and tests/startup_stream_consumer.cpp: a new filtered case. The existing sampling case uses a 1x1 texture, so it cannot tell filter or address modes apart. The new case puts a constant wrap, linear sampler (MAX_LOD 12, so the translator writes smpl 0 0x0 0xc00000 0x18500000 0x0) in the texture input program. The consumer's new dispatch-sampled-2x1 mode samples a 2x1 RGBA8 texture whose left texel has red 0 and right texel red 1.0, at the left edge. Only a linear filter that wraps reads 0.5 there.
    • Control: the same compiled program with the manifest's sampler changed to clamp reads red 0, which the positive check refuses.
    • Refusals: an smpc line and an added smpheap line each refuse with one logged reason and leave the output untouched.
  • docs/experiments.md: a subsection under the translated compute Dispatch section.

Measured

.\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -j1 -R "^startup_compute_dispatch_" -V

Result: 8 of 8 passed (WARP and hardware for startup_compute_dispatch, _texture, _heap and _heap_word), with no capability skips.

  • WARP: Microsoft Basic Render Driver, driver 10.0.26100.10068.
  • Hardware: NVIDIA GeForce RTX 5090, driver 32.0.16.2135.
  • Windows 11 build 26300.10075. Debug layer enabled, no error message.

New filtered case, on both adapters: every thread read red 0.5. With the clamp sampler, every thread read red 0. The smpc and smpheap controls refused with their reasons and left the output untouched.

Negative control for the code change: with the smpl match disabled, startup_compute_dispatch_texture_warp fails. The Dispatch logs refused: a sampler that is not a plain static one.

Local census (counts only): 7 compute programs, about 135 thousand Dispatch calls, refused first for "a sampler that is not a plain static one". All 7 manifests hold only smpl sampler lines: 6 with one line and 1 with two. None has smpc or smpheap. In 6 of the 7, word 0 is 0x92 (clamp in U, V and W). The other uses wrap. When their manifests are read against the new classifier, every line of all 7 is accepted and each has a compiled program, so all 7 now pass manifest loading.

Hypothesis / unverified

  • Not measured: the next refusal of those 7 programs. It would come from the bindings at Dispatch (tables, views, buffer ranges), which reading a manifest cannot show. No title run was made for this change.
  • MinLOD and MaxLOD are carried over by the decoder the draw path already uses. The fixture texture has one mip, so this test does not check the LOD clamp itself.
  • Comparison samplers and sampler heap tables in compute stay unbound.

🤖 Generated with Claude Code

tedin7 and others added 30 commits November 24, 2026 19:53
…33 and 35)

Header-only state in list_compute_root.h with a Linux-testable check. Dispatch (slot 14) is not handled here; the state is exposed through ready() and table() for it. Refs R0Y00#870.
Compute root constants are kept per list next to the graphics ones, in a shared 16 x 8 word store that refuses parameter >= 16 and offset >= 8. A new compute root signature clears them.
Part of R0Y00#870. Forward Dispatch only with a desktop compute pipeline and root
bound and group counts within 65535 per axis; refuse otherwise.
…t against the bound root

Slot 43 clears a parameter's binding when a replacement is rejected, slot 33 clears all bindings, and the compute pipeline records its root so a mismatched pair is refused.
Compute root constants are kept per list next to the graphics ones, in a shared 16 x 8 word store that refuses parameter >= 16 and offset >= 8. A new compute root signature clears them.
Part of R0Y00#870. Forward Dispatch only with a desktop compute pipeline and root
bound and group counts within 65535 per axis; refuse otherwise.
…t against the bound root

Slot 43 clears a parameter's binding when a replacement is rejected, slot 33 clears all bindings, and the compute pipeline records its root so a mismatched pair is refused.
Conflicts in d3d12_xs_device.cpp and docs/experiments.md resolved by keeping both sides: the pipeline root
out-parameter of the stream builder next to the cached-mesh root, the bound root SRV mask next to the recorded
upload SRV addresses, and both table entries and document sections.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Conflicts in d3d12_draw.inl and d3d12_xs_device.cpp resolved by keeping both sides: graphics root constants
go through the shared store and still mark the words a slot 40 call set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A device slot 67 placeholder keeps the key of its published request. At
list slot 14 the stand-in loads the stage cs manifest and compiled
program for that key and records the dispatch: raw buffer inputs and
outputs from hardware descriptors in the recorded compute tables, entry
values from the recorded compute root constants. Other manifest lines
leave the pipeline untranslated; a dispatch that cannot be bound
completely is refused with one logged reason and records nothing.

startup_compute_dispatch_{warp,hardware} drives a source-built program
through the stand-in list and reads the output back, with controls
before translation, without a Dispatch and for a refused output.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Dispatches that arrive before the offline translation no longer use up
the lines kept for refusals at bind time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The per-call refusal lines share one small budget, so a run cannot rank
keys by dispatch count. Each key now keeps its Dispatch count, the calls
recorded and the reason and table descriptor of its first refusal; the
periodic totals are followed by the refused dispatches per reason and the
40 keys with the most dispatches. A manifest that exists but cannot be
bound is counted apart from an absent one ("not modelled").

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A `uav <i> tex2d float table <param> <byte> channels 4` manifest line is
bound from the token of the unordered access view the title created in
its descriptor memory. Everything else is refused with its own reason: an
entry that is no such token, a view the desktop did not create, a view
that is not 2D, a format a float4 store cannot target, and a texture
bound to two slots of one dispatch. Programs without entry values, inputs
or outputs load too: the translated root no longer emits an empty range
or drops the table when only outputs exist.

The fixture stores through the stand-in's own list into a 32x8
RGBA16_FLOAT texture and reads it back with CopyTextureRegion.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A `srv <i> tex2d table <param> <byte>` manifest line is bound from the
token of the shader resource view the title created, through the texture
the draw path samples for that resource, uploaded first when the title
filled it in memory. `smp` lines become static samplers of the translated
root. A dispatch is refused, never bound to a null view, when the entry
is no such token, the resource has no desktop texture, the view is not 2D
or names a packed format, or the upload fails. Sampler heaps, comparison
samplers and other texture kinds keep the translation unavailable.

The fixture samples a 1x1 texture into the stored words of the raw buffer
case; without a view the dispatch is refused and the output is untouched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s test

The device check drains the debug layer; a draw runs it on every 64th call
and the queue's execute drains the rest. A view token whose resource the
caller released is the caller's misuse, as on the draw path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…puts, print every census key

A texture is refused only when the same call reads and writes it; two
outputs of one texture share the unordered access state. A packed output
view format gets its own refusal reason. The census prints every
dispatched key instead of the first 40, and the wording on refused calls
says what may already be recorded (an input texture upload).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NiiRoZz and others added 5 commits November 25, 2026 23:50
Upstream now records the compute root and tables (slots 33 and 35) and has its own
DllMain with x2w_startup::d3d12_process_terminating, so this branch's flag and DllMain go.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Two device-free checks pass, and five mutations of the heap-index tracking are all caught

python -B tests/startup_gfx2hlsl_heap_record_check.py
    startup_gfx2hlsl_heap_record: PASS (manifest and HLSL exact; 19 refused controls; graphics, manifest and translation …)
python -B tests/startup_gfx2hlsl_heap_word_check.py
    startup_gfx2hlsl_heap_word: PASS (manifest and HLSL exact; 6 more forms; 10 refused controls)

The heap_word check is the new half here: 6 more forms accepted, 10 refused controls. It splits from
heap_record exactly where the change does — heap_record names the record, heap_word names what the index word
is (a root constant word, times a scale, plus an addend, modulo 2³²).

The other three checks in this PR (startup_compute_dispatch_check.py, …_heap_check.py, …_texture_check.py) exit 1
without arguments — they need DXC, an adapter and a dispatch mode, so they are the GPU half and I did not run them.

Mutations of heap_word_offset and the index tracking

mutation caught by
the root-constant branch returns scale 2 instead of 1 heap_word
the root-constant branch removed entirely heap_word
the rc mark no longer recognised (return mark[1:] if … else None → return None) heap_word
heap_index.clear() at a join replaced with pass heap_record and heap_word
any write stops ending a register's mark (wrote = scalar_destinations(…) → set()) heap_record and heap_word

The first three are heap_word's own business and it catches all three, which is what you would want from a check added
specifically for "6 more forms".

The last two are the interesting ones because they are caught by both, and they are the invariants that make the whole
scheme sound:

  • clearing at a join — the comment says "another path into the join may hold a different word". Without the clear, a
    mark from one predecessor survives into a block reachable from another, and the index is named for the wrong word.
  • any write ends a mark — wrote = set() means a later s_mov over the register leaves the stale mark in place, so
    the new value is named by the old word's identity.

Both are invisible unless a fixture has two paths into a join and a write between the naming and the use, and both
fixtures here do.

Note on the two PRs

This PR's gfx2hlsl.py hunk is a superset of the earlier heap-record change I reviewed (heap_record is unchanged apart
from being joined by heap_word), so the mutations above cover the whole current state of the file's heap handling rather
than only the delta. If the two are stacked, the merged result is what I measured.

Method note

Four of my first five anchors missed purely on indentation — I had copied the leading spaces from a git diff excerpt,
where the + prefix shifts the column by one. Anchors taken by line number from the file itself (Get-Content indexed)
all hit. Worth doing that way in a file this size.

AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.

NiiRoZz and others added 16 commits November 26, 2026 00:13
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tch-translated

# Conflicts:
#	docs/experiments.md
… into startup/compute-dispatch-heap-rootconst
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Not merging yet: this branch still carries the commits of two open PRs, so it cannot land on its own.

Suggested path for @NiiRoZz: land #2470 and #2490 first (or rebuild this branch from current main so only the smpl change is left in the diff), then this PR shrinks to the sampler part and can be tested on its own.

No push was made to the branch. No test was run on this head.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Merged origin/main into this branch (merge commit 03aa5ff, no force, no rebase). Conflicts were the pre-squash copies of the compute Dispatch chain; #2470 and #2490 are already in main via #2532 (checked by sm3, confirmed by MasterDomino in the #2470 thread), so I kept main's side everywhere and kept only this PR's own smpl change. git diff origin/main --stat now shows 4 files only: d3d12_compute_dispatch.inl (+7), startup_stream_consumer.cpp, startup_compute_dispatch_texture_check.py, docs/experiments.md.

Review of what is left:

  • smp and smpl lines go through the draw path's read_manifest_line; smpc and smpheap refuse with their own reasons. Sound.
  • The new filtered case (2x1 texture, wrap + linear sampler reads 0.5 at the left edge; clamp control reads 0; smpc/smpheap refused with one logged reason, output untouched) guards the behaviour: point or clamp would read 0.

Verification (Windows Server 2025, merged head 03aa5ff, applied on top of the PR head):

  • dev: ctest --preset dev -R '^startup_compute_dispatch_': 100% tests passed out of 8 (warp and hardware for dispatch, texture, heap, heap_word).
  • release: ctest --preset release -R '^startup_compute_dispatch_' --no-tests=error: 8/8 passed.
  • Linux: python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: clean.
  • RTX 3090: not available (pod full).

AI-assisted; commands listed were executed locally.

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

Merged origin/main into this branch (merge commit 03aa5ff, no force, no rebase). Conflicts were the pre-squash copies of the compute Dispatch chain; #2470 and #2490 are already in main via #2532 (checked by sm3, confirmed by MasterDomino in the #2470 thread), so I kept main's side everywhere and kept only this PR's own smpl change. git diff origin/main --stat now shows 4 files only: d3d12_compute_dispatch.inl (+7), startup_stream_consumer.cpp, startup_compute_dispatch_texture_check.py, docs/experiments.md.

Review of what is left:

  • smp and smpl lines go through the draw path's read_manifest_line; smpc and smpheap refuse with their own reasons. Sound.
  • The new filtered case (2x1 texture, wrap + linear sampler reads 0.5 at the left edge; clamp control reads 0; smpc/smpheap refused with one logged reason, output untouched) guards the behaviour: point or clamp would read 0.

Verification (Windows Server 2025, merged head 03aa5ff, applied on top of the PR head):

  • dev: ctest --preset dev -R '^startup_compute_dispatch_': 100% tests passed out of 8 (warp and hardware for dispatch, texture, heap, heap_word).
  • release: ctest --preset release -R '^startup_compute_dispatch_' --no-tests=error: 8/8 passed.
  • Linux: python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: clean.
  • RTX 3090: not available (pod full).

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 enabled auto-merge (squash) November 26, 2026 06:05
@tedin7
tedin7 merged commit bddd107 into R0Y00:main Nov 26, 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.

4 participants