startup: translate run-time sampler heap indexing into a bounded table #1210

Merged
Jess-Doit merged 3 commits from upstream-pr/1217 into main 2026-11-24 04:49:32 +00:00
Jess-Doit commented 2026-11-24 04:06:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T04:06:06Z.


Change

Refs #1143. Translator half, sampler heap only. #1192 is the matching desktop check.

With X2W_SAMPLER_HEAP=1, tools/startup/gfx2hlsl.py translates an s_load_dwordx4 from the sampler heap with a register offset into a bounded sampler table, instead of the fixed default sampler:

  • SamplerState qh[2048] : register(s0, space1) is the D3D12 limit for a shader-visible sampler heap. The sample reads qh[x2w_sampler_entry(offset)].
  • Contract at the manifest boundary: entries 0 to 2046 hold the title's sampler-heap entries, entry n at byte offset 16 n. Entry 2047 is reserved for a host fallback sampler. x2w_sampler_entry returns offset >> 4 for an offset that is a multiple of 16 and below 2047 × 16 (32752), and 2047 otherwise. The host can't check an offset the shader computes, so the guard is in the generated shader.
  • The byte offset is kept in the load's first destination register, so later instructions see it the way the hardware does.
  • The manifest gets smpheap 2048 1 fallback 2047 (count, register space, fallback entry), so the runtime can bind a matching table. The shortcut's pipe.notes entry isn't written in this mode.
  • A sample whose sampler operand no longer holds the four words of one heap load is refused (mixes sampler heap words).

Off by default: the stand-in doesn't bind that table yet. Its root signatures still carry static samplers only, so a translated pipeline with smpheap would fail to create. Without the switch, the output is unchanged, shortcut included. The follow-up builds the table in the stand-in from the title's sampler-heap entries, decoded like today's static samplers, and then turns this on.

Not covered: constant sampler-heap offsets are still refused, as before. Resource-heap indexing (#1143's other half) is also not covered. One finding for whoever takes constant offsets: on in-box WARP 10.0.19041.5794, a compile-time-constant index into the sampler table (qh[1]) read entry 0 with both DXC ps_6_0 and FXC ps_5_1. A run-time index that always evaluated to 1 read entry 1. The GTX 1060 read entry 1 in all four combinations.

Fixture

tests/startup_sampler_heap_check.py carries a source-built gfx1013 vertex+pixel pair: assembly source plus the recorded words.

  • Pixel stage: it loads a texture descriptor from table 0, then four sampler words from the sampler heap at the byte offset in root constant 1. It samples at (1.25, 0.5) and exports the result. The root signature blob is synthetic (one table, one root constant, SAMPLER_HEAP_DIRECTLY_INDEXED).
  • Desktop draw (offscreen_check --startup-sampler-heap, tests/startup_sampler_heap.cpp): a 2×1 R32_FLOAT texture {0.25, 0.75} and a 2048-entry point-sampler table. Entry 0 wraps, entry 1 clamps, entries 2 to 2046 use a black border, and the fallback entry 2047 uses a border of 0.5. So the colour names the entry the shader indexed.
Mode What it checks
no arguments (Linux Python job) the qh[s24 >> 4] / s24 = ud1 / smpheap 2048 1 translation; the default output unchanged; X2W_SAMPLER_HEAP=1 selects the table; constant offset still refused in both modes; the mixed operand refused
binary <llvm-mc> (gfx1013 job) the four fixture sources reassemble to the recorded words
draw <dxc> <offscreen_check> <adapter> [fxc] (ctest startup_sampler_heap_{warp,hardware}) offsets 0, 16 and 32, the last title entry (32736 = 2046 × 16), the first out-of-range offset (32752), 0xfffffff0 and the unaligned 8 read 3e800000, 3f400000, 0, 0, then 3f000000 (the fallback) three times; the negative control, the translated shader with its index replaced by qh[0], must fail at offset 16 with actual=3e800000

Verification

Tested on Windows 10 22H2 19045.6456 with a GTX 1060 6 GB (10de:1c03, driver 32.0.15.6094) and in-box WARP (1414:008c, 10.0.19041.5794), D3D12 debug layer enabled. DXC and FXC are from Windows SDK 10.0.26100.0.

. .\tools\dev.ps1
$env:XBOX2WINDOWS_ADAPTER = '1060'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset
    cmake --build --preset $preset --target offscreen_check -j 2
    ctest --preset $preset --no-tests=error -R '^startup_sampler_heap_' -V
}
python -B tests/startup_sampler_heap_check.py binary <llvm-mc>

Tested 1e0a9834 (a7ce0018 with main 3a156358 merged in). Debug and Release each passed 3/3 (startup_sampler_heap_controls, _warp, _hardware) with zero skips. On both adapters and with both compilers, the seven offsets read their expected words, and the dropped-index shader failed at offset 16 with actual=3e800000. binary mode matched the recorded words with a local LLVM 23.1.6 llvm-mc; the CI job runs LLVM 15. tests/docs_links_check.py and git diff --check are clean.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574369279 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T04:06:06Z. --- ## Change Refs #1143. Translator half, sampler heap only. #1192 is the matching desktop check. With `X2W_SAMPLER_HEAP=1`, `tools/startup/gfx2hlsl.py` translates an `s_load_dwordx4` from the sampler heap with a **register** offset into a bounded sampler table, instead of the fixed default sampler: - `SamplerState qh[2048] : register(s0, space1)` is the D3D12 limit for a shader-visible sampler heap. The sample reads `qh[x2w_sampler_entry(offset)]`. - **Contract at the manifest boundary:** entries 0 to 2046 hold the title's sampler-heap entries, entry n at byte offset 16 n. Entry 2047 is reserved for a host fallback sampler. `x2w_sampler_entry` returns `offset >> 4` for an offset that is a multiple of 16 and below 2047 × 16 (32752), and 2047 otherwise. The host can't check an offset the shader computes, so the guard is in the generated shader. - The byte offset is kept in the load's first destination register, so later instructions see it the way the hardware does. - The manifest gets `smpheap 2048 1 fallback 2047` (count, register space, fallback entry), so the runtime can bind a matching table. The shortcut's `pipe.notes` entry isn't written in this mode. - A sample whose sampler operand no longer holds the four words of one heap load is refused (`mixes sampler heap words`). **Off by default:** the stand-in doesn't bind that table yet. Its root signatures still carry static samplers only, so a translated pipeline with `smpheap` would fail to create. Without the switch, the output is unchanged, shortcut included. The follow-up builds the table in the stand-in from the title's sampler-heap entries, decoded like today's static samplers, and then turns this on. **Not covered:** constant sampler-heap offsets are still refused, as before. Resource-heap indexing (#1143's other half) is also not covered. One finding for whoever takes constant offsets: on in-box WARP `10.0.19041.5794`, a compile-time-constant index into the sampler table (`qh[1]`) read entry 0 with both DXC `ps_6_0` and FXC `ps_5_1`. A run-time index that always evaluated to 1 read entry 1. The GTX 1060 read entry 1 in all four combinations. ## Fixture `tests/startup_sampler_heap_check.py` carries a source-built gfx1013 vertex+pixel pair: assembly source plus the recorded words. - **Pixel stage:** it loads a texture descriptor from table 0, then four sampler words from the sampler heap at the byte offset in root constant 1. It samples at (1.25, 0.5) and exports the result. The root signature blob is synthetic (one table, one root constant, `SAMPLER_HEAP_DIRECTLY_INDEXED`). - **Desktop draw** (`offscreen_check --startup-sampler-heap`, `tests/startup_sampler_heap.cpp`): a 2×1 R32_FLOAT texture {0.25, 0.75} and a 2048-entry point-sampler table. Entry 0 wraps, entry 1 clamps, entries 2 to 2046 use a black border, and the fallback entry 2047 uses a border of 0.5. So the colour names the entry the shader indexed. | Mode | What it checks | |---|---| | no arguments (Linux Python job) | the `qh[s24 >> 4]` / `s24 = ud1` / `smpheap 2048 1` translation; the default output unchanged; `X2W_SAMPLER_HEAP=1` selects the table; constant offset still refused in both modes; the mixed operand refused | | `binary <llvm-mc>` (gfx1013 job) | the four fixture sources reassemble to the recorded words | | `draw <dxc> <offscreen_check> <adapter> [fxc]` (ctest `startup_sampler_heap_{warp,hardware}`) | offsets 0, 16 and 32, the last title entry (32736 = 2046 × 16), the first out-of-range offset (32752), `0xfffffff0` and the unaligned 8 read `3e800000`, `3f400000`, `0`, `0`, then `3f000000` (the fallback) three times; the negative control, the translated shader with its index replaced by `qh[0]`, must fail at offset 16 with `actual=3e800000` | ## Verification Tested on Windows 10 22H2 `19045.6456` with a GTX 1060 6 GB (`10de:1c03`, driver `32.0.15.6094`) and in-box WARP (`1414:008c`, `10.0.19041.5794`), D3D12 debug layer enabled. DXC and FXC are from Windows SDK `10.0.26100.0`. ```powershell . .\tools\dev.ps1 $env:XBOX2WINDOWS_ADAPTER = '1060' foreach ($preset in 'dev', 'release') { cmake --preset $preset cmake --build --preset $preset --target offscreen_check -j 2 ctest --preset $preset --no-tests=error -R '^startup_sampler_heap_' -V } python -B tests/startup_sampler_heap_check.py binary <llvm-mc> ``` Tested `1e0a9834` (`a7ce0018` with main `3a156358` merged in). Debug and Release each passed 3/3 (`startup_sampler_heap_controls`, `_warp`, `_hardware`) with zero skips. On both adapters and with both compilers, the seven offsets read their expected words, and the dropped-index shader failed at offset 16 with `actual=3e800000`. `binary` mode matched the recorded words with a local LLVM 23.1.6 `llvm-mc`; the CI job runs LLVM 15. `tests/docs_links_check.py` and `git diff --check` are clean. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 06:47:00 +00:00
tedin7 commented 2026-11-24 06:47:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:21:37Z.

Review: COMMENTED


Reviewed commit 3835fe22.

Diff & edge-case audit

  • tools/startup/gfx2hlsl.py: With X2W_SAMPLER_HEAP=1 (or sampler_heap=True), s_load_dwordx4 from ('smpheap',) with a register offset emits s<d> = <offset>; and tracks ('smpheap', d, i) across all 4 words; heap_sampler verifies all 4 words come from the same heap load (rejecting overwritten words via Unsupported) and emits qh[s<d> >> 4] over SamplerState qh[2048] : register(s0, space1) with smpheap 2048 1 in the manifest. Constant sampler-heap offsets remain rejected.
  • Note on bounds: qh[s<d> >> 4] does not clamp s<d> >> 4 to [0, 2047] in HLSL, so an out-of-range runtime byte offset (>= 32768) would index past the 2048-entry table; the fixture covers valid indices 0, 1, 2, and 2047.
  • tests/startup_sampler_heap.cpp, tests/offscreen_check.cpp, tests/startup_sampler_heap_check.py, CMakeLists.txt, docs/startup-runtime.md, AGENTS.md, .github/workflows/windows.yml: Consistent and title-neutral.

Checks run on Linux (3835fe22)

  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py: PASS (5/5 control assertions: runtime offset, constant offset refused in both modes, opt-out default sampler, X2W_SAMPLER_HEAP=1 selection, overwritten s25 refused).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py binary llvm-mc-19: PASS (fixture words match llvm-mc).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py (pure-Python mode): PASS (128 tests: 113 passed, 15 skipped, 0 failed).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: PASS (16 Markdown files, 274 links).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: PASS (1020 files).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py: PASS.
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/xgameruntime_table_check.py: PASS (28 exports).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py: PASS (10/10).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py: PASS (11/11).

Note: Windows MSVC/DXC/FXC build and startup_sampler_heap_warp / startup_sampler_heap_hardware draw tests were not executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033607458 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#pullrequestreview-6033607458). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:21:37Z. **Review:** COMMENTED --- Reviewed commit `3835fe22`. ### Diff & edge-case audit - `tools/startup/gfx2hlsl.py`: With `X2W_SAMPLER_HEAP=1` (or `sampler_heap=True`), `s_load_dwordx4` from `('smpheap',)` with a register offset emits `s<d> = <offset>;` and tracks `('smpheap', d, i)` across all 4 words; `heap_sampler` verifies all 4 words come from the same heap load (rejecting overwritten words via `Unsupported`) and emits `qh[s<d> >> 4]` over `SamplerState qh[2048] : register(s0, space1)` with `smpheap 2048 1` in the manifest. Constant sampler-heap offsets remain rejected. - Note on bounds: `qh[s<d> >> 4]` does not clamp `s<d> >> 4` to `[0, 2047]` in HLSL, so an out-of-range runtime byte offset (`>= 32768`) would index past the 2048-entry table; the fixture covers valid indices `0`, `1`, `2`, and `2047`. - `tests/startup_sampler_heap.cpp`, `tests/offscreen_check.cpp`, `tests/startup_sampler_heap_check.py`, `CMakeLists.txt`, `docs/startup-runtime.md`, `AGENTS.md`, `.github/workflows/windows.yml`: Consistent and title-neutral. ### Checks run on Linux (`3835fe22`) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py`: **PASS** (5/5 control assertions: runtime offset, constant offset refused in both modes, opt-out default sampler, `X2W_SAMPLER_HEAP=1` selection, overwritten `s25` refused). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py binary llvm-mc-19`: **PASS** (`fixture words match llvm-mc`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/rdna2_tools_check.py` (pure-Python mode): **PASS** (128 tests: 113 passed, 15 skipped, 0 failed). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: **PASS** (16 Markdown files, 274 links). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: **PASS** (1020 files). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py`: **PASS**. - `/root/.local/share/x2w-rev-venv/bin/python -B tests/xgameruntime_table_check.py`: **PASS** (28 exports). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/gpu_report_format_check.py`: **PASS** (10/10). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/hardware_reports_check.py`: **PASS** (11/11). Note: Windows MSVC/DXC/FXC build and `startup_sampler_heap_warp` / `startup_sampler_heap_hardware` draw tests were **not** executed locally.
tedin7 commented 2026-11-24 06:47:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:37:16Z.

Review: COMMENTED


Linux retest at commit a7ce0018 (delta 3835fe22..a7ce0018; Windows build and D3D12 runtime tests were not executed locally).

Delta 3835fe22..a7ce0018 audit

  • Previous HLSL out-of-bounds qh[s<d> >> 4] finding (offset >= 32768) is fixed: tools/startup/gfx2hlsl.py now reserves entry SAMPLER_HEAP_FALLBACK = 2047 (SAMPLER_HEAP_SIZE - 1) and emits uint x2w_sampler_entry(uint offset) { return (offset & 15u) != 0 || offset >= 32752u ? 2047u : offset >> 4; }, indexing qh[x2w_sampler_entry(s<d>)] and emitting smpheap 2048 1 fallback 2047 in the manifest. Any unaligned offset or offset >= 32752 (including >= 32768 and 0xfffffff0) is clamped to valid index 2047.
  • tests/startup_sampler_heap.cpp & tests/startup_sampler_heap_check.py & docs/startup-runtime.md: updated to reserve entry 2047 with border 0.5f as the fallback and add Windows draw cases for 2046 * 16, 2047 * 16, 0xfffffff0, and unaligned 8.

Checks run (Linux, commit a7ce0018)

  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py: passed (run-time offset: qh[x2w_sampler_entry(s24)] with s24 = ud1 (root constant 1); unaligned or >= 32752 reads entry 2047; manifest smpheap 2048 1 fallback 2047; constant-offset, opt-out, and overwritten-register controls passed).
  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py binary /usr/bin/llvm-mc-19: passed (fixture words match llvm-mc).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Self-test passed. Checked 16 Markdown files and 274 links.).
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Self-test passed. Checked 1020 tracked source, script and build/CI files: no bidirectional controls.).
  • Windows build and startup_sampler_heap_* D3D12 draw tests: not executed on Linux.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033715173 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#pullrequestreview-6033715173). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:37:16Z. **Review:** COMMENTED --- Linux retest at commit `a7ce0018` (delta `3835fe22..a7ce0018`; Windows build and D3D12 runtime tests were **not** executed locally). ### Delta `3835fe22..a7ce0018` audit - **Previous HLSL out-of-bounds `qh[s<d> >> 4]` finding (`offset >= 32768`) is fixed:** `tools/startup/gfx2hlsl.py` now reserves entry `SAMPLER_HEAP_FALLBACK = 2047` (`SAMPLER_HEAP_SIZE - 1`) and emits `uint x2w_sampler_entry(uint offset) { return (offset & 15u) != 0 || offset >= 32752u ? 2047u : offset >> 4; }`, indexing `qh[x2w_sampler_entry(s<d>)]` and emitting `smpheap 2048 1 fallback 2047` in the manifest. Any unaligned offset or offset `>= 32752` (including `>= 32768` and `0xfffffff0`) is clamped to valid index `2047`. - `tests/startup_sampler_heap.cpp` & `tests/startup_sampler_heap_check.py` & `docs/startup-runtime.md`: updated to reserve entry `2047` with border `0.5f` as the fallback and add Windows draw cases for `2046 * 16`, `2047 * 16`, `0xfffffff0`, and unaligned `8`. ### Checks run (Linux, commit `a7ce0018`) - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py`: passed (`run-time offset: qh[x2w_sampler_entry(s24)] with s24 = ud1 (root constant 1); unaligned or >= 32752 reads entry 2047; manifest smpheap 2048 1 fallback 2047`; constant-offset, opt-out, and overwritten-register controls passed). - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py binary /usr/bin/llvm-mc-19`: passed (`fixture words match llvm-mc`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: passed (`Self-test passed. Checked 16 Markdown files and 274 links.`). - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: passed (`Self-test passed. Checked 1020 tracked source, script and build/CI files: no bidirectional controls.`). - Windows build and `startup_sampler_heap_*` D3D12 draw tests: **not executed** on Linux.
tedin7 commented 2026-11-24 06:47:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:48:10Z.

Review: COMMENTED


Retested 1e0a9834 (delta a7ce0018..1e0a9834, merge with main) on Linux. Windows build and D3D12 startup_sampler_heap_* draw tests were not run locally.

Delta audit (a7ce0018..1e0a9834)

  • No changes to the PR's own files (.github/workflows/windows.yml, AGENTS.md, CMakeLists.txt, docs/startup-runtime.md, tests/desktop_gpu.h, tests/offscreen_check.cpp, tests/startup_sampler_heap.cpp, tests/startup_sampler_heap_check.py, tools/startup/gfx2hlsl.py) relative to a7ce0018; the delta only merges main (#1174, #1216, #1177).
  • x2w_sampler_entry(uint offset) bounds/alignment guard ((offset & 15u) != 0 || offset >= 32752u ? 2047u : offset >> 4), smpheap 2048 1 fallback 2047 manifest contract, and docs/tests remain intact and title-neutral.

Linux checks (/root/.local/share/x2w-rev-venv/bin/python -B)

  • tests/startup_sampler_heap_check.py: passed (5/5 control checks, exit 0)
  • tests/startup_sampler_heap_check.py binary /usr/bin/llvm-mc-19: passed (fixture words match llvm-mc, exit 0)
  • tests/form_coverage_check.py: passed (form coverage checks passed, exit 0)
  • tests/rdna2_tools_check.py (pure-Python mode): passed (129 tests: 114 passed, 15 skipped, 0 failed)
  • tests/docs_links_check.py: passed (16 Markdown files, 280 links, exit 0)
  • tests/bidi_controls_check.py: passed (1046 tracked files, exit 0)
  • git diff --check origin/main..HEAD: passed (exit 0)
  • Windows offscreen_check and startup_sampler_heap_{controls,warp,hardware}: not run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033788726 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#pullrequestreview-6033788726). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:48:10Z. **Review:** COMMENTED --- Retested `1e0a9834` (delta `a7ce0018..1e0a9834`, merge with `main`) on Linux. Windows build and D3D12 `startup_sampler_heap_*` draw tests were not run locally. ### Delta audit (`a7ce0018..1e0a9834`) - No changes to the PR's own files (`.github/workflows/windows.yml`, `AGENTS.md`, `CMakeLists.txt`, `docs/startup-runtime.md`, `tests/desktop_gpu.h`, `tests/offscreen_check.cpp`, `tests/startup_sampler_heap.cpp`, `tests/startup_sampler_heap_check.py`, `tools/startup/gfx2hlsl.py`) relative to `a7ce0018`; the delta only merges `main` (`#1174`, `#1216`, `#1177`). - `x2w_sampler_entry(uint offset)` bounds/alignment guard (`(offset & 15u) != 0 || offset >= 32752u ? 2047u : offset >> 4`), `smpheap 2048 1 fallback 2047` manifest contract, and docs/tests remain intact and title-neutral. ### Linux checks (`/root/.local/share/x2w-rev-venv/bin/python -B`) - `tests/startup_sampler_heap_check.py`: **passed** (5/5 control checks, exit 0) - `tests/startup_sampler_heap_check.py binary /usr/bin/llvm-mc-19`: **passed** (`fixture words match llvm-mc`, exit 0) - `tests/form_coverage_check.py`: **passed** (`form coverage checks passed`, exit 0) - `tests/rdna2_tools_check.py` (pure-Python mode): **passed** (129 tests: 114 passed, 15 skipped, 0 failed) - `tests/docs_links_check.py`: **passed** (16 Markdown files, 280 links, exit 0) - `tests/bidi_controls_check.py`: **passed** (1046 tracked files, exit 0) - `git diff --check origin/main..HEAD`: **passed** (exit 0) - Windows `offscreen_check` and `startup_sampler_heap_{controls,warp,hardware}`: **not run locally**.
R0Y00 commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T04:22:49Z.


The three source-built sampler heap tests passed locally in Release, including WARP and RTX. The authored expression qh[offset >> 4] currently accepts any offset value, while the table has only 2,048 entries. Please document the alignment and range preconditions at the manifest boundary and say how the host will enforce them before enabling this mode. If the caller cannot enforce them, keep the access guarded in the generated shader. A control for the last valid entry and the first out-of-range byte offset would make that boundary reproducible.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121964585 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#issuecomment-7121964585). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T04:22:49Z. --- The three source-built sampler heap tests passed locally in Release, including WARP and RTX. The authored expression qh[offset >> 4] currently accepts any offset value, while the table has only 2,048 entries. Please document the alignment and range preconditions at the manifest boundary and say how the host will enforce them before enabling this mode. If the caller cannot enforce them, keep the access guarded in the generated shader. A control for the last valid entry and the first out-of-range byte offset would make that boundary reproducible.
tedin7 commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:24:52Z.


Windows Server 2025 retest at 3835fe22 (Windows Server 2025 Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U, WARP):

Debug (dev preset)

Commands:

cmake --preset dev
cmake --build --preset dev --target offscreen_check -- -j 6
ctest --preset dev -R "^startup_sampler_heap_" --no-tests=error --output-on-failure

Results: 3 passed, 0 failed, 0 skipped (Total Test time: 2.01 sec)

  • startup_sampler_heap_controls: Passed (0.20 sec)
  • startup_sampler_heap_warp: Passed (1.06 sec)
  • startup_sampler_heap_hardware: Passed (0.72 sec)

Release (/O2, release preset)

Commands:

cmake --preset release
cmake --build --preset release --target offscreen_check -- -j 6
ctest --preset release -R "^startup_sampler_heap_" --no-tests=error --output-on-failure

Results: 3 passed, 0 failed, 0 skipped (Total Test time: 1.92 sec)

  • startup_sampler_heap_controls: Passed (0.18 sec)
  • startup_sampler_heap_warp: Passed (0.90 sec)
  • startup_sampler_heap_hardware: Passed (0.82 sec)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121996395 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#issuecomment-7121996395). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:24:52Z. --- Windows Server 2025 retest at `3835fe22` (`Windows Server 2025 Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U, WARP`): ### Debug (`dev` preset) Commands: ```powershell cmake --preset dev cmake --build --preset dev --target offscreen_check -- -j 6 ctest --preset dev -R "^startup_sampler_heap_" --no-tests=error --output-on-failure ``` Results: **3 passed, 0 failed, 0 skipped** (Total Test time: `2.01 sec`) - `startup_sampler_heap_controls`: Passed (`0.20 sec`) - `startup_sampler_heap_warp`: Passed (`1.06 sec`) - `startup_sampler_heap_hardware`: Passed (`0.72 sec`) ### Release (`/O2`, `release` preset) Commands: ```powershell cmake --preset release cmake --build --preset release --target offscreen_check -- -j 6 ctest --preset release -R "^startup_sampler_heap_" --no-tests=error --output-on-failure ``` Results: **3 passed, 0 failed, 0 skipped** (Total Test time: `1.92 sec`) - `startup_sampler_heap_controls`: Passed (`0.18 sec`) - `startup_sampler_heap_warp`: Passed (`0.90 sec`) - `startup_sampler_heap_hardware`: Passed (`0.82 sec`)
Jess-Doit commented 2026-11-24 06:50:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T04:28:35Z.


Thanks for checking this, and thanks @tedin7 for the Server 2025 retest. Fixed in a7ce0018. The host can't check an offset the shader computes, so the guard is in the generated shader:

  • Entries: 0 to 2046 are the title's sampler-heap entries, entry n at byte offset 16 n. Entry 2047 is reserved for a host fallback sampler.
  • Shader: it reads qh[x2w_sampler_entry(offset)]. That's offset >> 4 for a multiple of 16 below 2047 × 16 = 32752, and 2047 otherwise, including unaligned offsets.
  • Manifest: the line is now smpheap 2048 1 fallback 2047, so the binding side knows which entry to fill, and can count reads that land on it. The contract is written next to the constants in gfx2hlsl.py and in docs/startup-runtime.md.

The draw now also covers the boundary. The harness gives entry 2047 a 0.5 border to tell it apart:

Byte offset Entry Read
32736 2046, the last title entry 00000000
32752 first out of range: fallback 3f000000
0xfffffff0 fallback 3f000000
8 (unaligned) fallback 3f000000

Debug and Release pass 3/3 on a GTX 1060 and in-box WARP (Windows 10 19045.6456), with DXC ps_6_0 and FXC ps_5_1. The dropped-index control still fails at offset 16. The mode stays opt-in.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122054076 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1217#issuecomment-7122054076). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T04:28:35Z. --- Thanks for checking this, and thanks @tedin7 for the Server 2025 retest. Fixed in `a7ce0018`. The host can't check an offset the shader computes, so the guard is in the generated shader: - **Entries:** 0 to 2046 are the title's sampler-heap entries, entry n at byte offset 16 n. Entry 2047 is reserved for a host fallback sampler. - **Shader:** it reads `qh[x2w_sampler_entry(offset)]`. That's `offset >> 4` for a multiple of 16 below 2047 × 16 = 32752, and 2047 otherwise, including unaligned offsets. - **Manifest:** the line is now `smpheap 2048 1 fallback 2047`, so the binding side knows which entry to fill, and can count reads that land on it. The contract is written next to the constants in `gfx2hlsl.py` and in `docs/startup-runtime.md`. The draw now also covers the boundary. The harness gives entry 2047 a 0.5 border to tell it apart: | Byte offset | Entry | Read | |---|---|---| | 32736 | 2046, the last title entry | `00000000` | | 32752 | first out of range: fallback | `3f000000` | | `0xfffffff0` | fallback | `3f000000` | | 8 (unaligned) | fallback | `3f000000` | Debug and Release pass 3/3 on a GTX 1060 and in-box WARP (Windows 10 `19045.6456`), with DXC `ps_6_0` and FXC `ps_5_1`. The dropped-index control still fails at offset 16. The mode stays opt-in. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1210
No description provided.