translator: check 3D image sampling with a source-built draw #1237

Merged
Jess-Doit merged 3 commits from upstream-pr/1244 into main 2026-11-24 05:58:21 +00:00
Jess-Doit commented 2026-11-24 05:06:58 +00:00 (Migrated from github.com)

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


Change

Refs #1149. This is the first of the two fixtures claimed there. tools/startup/gfx2hlsl.py translates image_sample with dim:SQ_RSRC_IMG_3D into a Texture3D<float4> sampled with a float3 coordinate, but nothing checked it. This adds a source-built check, with no translator change.

The fixture is a gfx1013 pixel stage in tests/startup_image_3d_check.py, recorded as words and as assembly. It:

  1. loads a texture descriptor from table 0;
  2. builds an all-zero inline sampler with s_mov_b32;
  3. takes x = 0.75 and y = 0.25 from literals and z from root constant 1 (s9);
  4. samples with dim:SQ_RSRC_IMG_3D and exports the result.

Checks

Translation (pure Python, no arguments)

  • 3D: Texture3D<float4> r0 : register(t0), r0.Sample(q0, float3(F(v0), F(v1), F(v2))) with v2 = ud1, and the manifest lines srv 0 tex3d table 0 0 and smp 0 0x0 0x0 0x0 0x0.
  • 2D: the same words with only the dim field changed give Texture2D and float2(F(v0), F(v1)), with srv 0 tex2d.
  • 1D: dim:SQ_RSRC_IMG_1D is refused (image dimension SQ_RSRC_IMG_1D).

binary <llvm-mc>: the 3D, 2D and 1D sources reassemble to the recorded words. This is added to the gfx1013 CI job.

draw <dxc> <offscreen_check> <adapter> [fxc]: compiles the translated stage with DXC ps_6_0, and with FXC ps_5_1 when available, then draws one pixel through offscreen_check --startup-image-3d (tests/startup_image_3d.cpp).

  • Texture: 2×2×2 R32G32B32A32_FLOAT. Texel (x, y, z) holds ((1 + x + 2y + 4z) / 8, x, y, z), so the readback names the texel. Sampling uses a static point sampler with wrap addressing.

  • Cases: z = 0.25, 0.75 and 1.75 must read texels (1, 0, 0), (1, 0, 1) and (1, 0, 1); the last one wraps. All four channels are compared bit for bit.

  • Negative controls on the translated HLSL:

    • z replaced by 0.25 must read slice 0 at z = 0.75;
    • x and z exchanged must read texel (0, 0, 1) at z = 0.25.

    Each must fail with exactly that texel.

Verification

Tested 6d9935be (on 0e995c19) 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). The D3D12 debug layer was enabled and reported 0 errors and 0 warnings on every draw, including the controls.

. .\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_image_3d_' -V
}
python -B tests/startup_image_3d_check.py binary <llvm-mc>

Debug and Release each passed 3/3 (startup_image_3d_{controls,warp,hardware}), with no skips. On both adapters, with both compilers:

z=0.25: 3e800000,3f800000,00000000,00000000
z=0.75: 3f400000,3f800000,00000000,3f800000
z=1.75: 3f400000,3f800000,00000000,3f800000
z fixed to slice 0: fails as expected, reads 3e800000,3f800000,00000000,00000000
x and z exchanged: fails as expected, reads 3f200000,00000000,00000000,3f800000

The binary check passed with a local LLVM 23.1.6 llvm-mc. CI runs it with LLVM 15.

The second #1149 fixture, s_bfm_b32 inline-sampler folding, will follow separately.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575069045 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1244). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T05:06:58Z. --- ## Change Refs #1149. This is the first of the two fixtures claimed there. `tools/startup/gfx2hlsl.py` translates `image_sample` with `dim:SQ_RSRC_IMG_3D` into a `Texture3D<float4>` sampled with a `float3` coordinate, but nothing checked it. This adds a source-built check, with no translator change. The fixture is a gfx1013 pixel stage in `tests/startup_image_3d_check.py`, recorded as words and as assembly. It: 1. loads a texture descriptor from table 0; 2. builds an all-zero inline sampler with `s_mov_b32`; 3. takes x = 0.75 and y = 0.25 from literals and z from root constant 1 (`s9`); 4. samples with `dim:SQ_RSRC_IMG_3D` and exports the result. ## Checks **Translation (pure Python, no arguments)** - **3D:** `Texture3D<float4> r0 : register(t0)`, `r0.Sample(q0, float3(F(v0), F(v1), F(v2)))` with `v2 = ud1`, and the manifest lines `srv 0 tex3d table 0 0` and `smp 0 0x0 0x0 0x0 0x0`. - **2D:** the same words with only the dim field changed give `Texture2D` and `float2(F(v0), F(v1))`, with `srv 0 tex2d`. - **1D:** `dim:SQ_RSRC_IMG_1D` is refused (`image dimension SQ_RSRC_IMG_1D`). **`binary <llvm-mc>`:** the 3D, 2D and 1D sources reassemble to the recorded words. This is added to the gfx1013 CI job. **`draw <dxc> <offscreen_check> <adapter> [fxc]`:** compiles the translated stage with DXC `ps_6_0`, and with FXC `ps_5_1` when available, then draws one pixel through `offscreen_check --startup-image-3d` (`tests/startup_image_3d.cpp`). - **Texture:** 2×2×2 `R32G32B32A32_FLOAT`. Texel (x, y, z) holds ((1 + x + 2y + 4z) / 8, x, y, z), so the readback names the texel. Sampling uses a static point sampler with wrap addressing. - **Cases:** z = 0.25, 0.75 and 1.75 must read texels (1, 0, 0), (1, 0, 1) and (1, 0, 1); the last one wraps. All four channels are compared bit for bit. - **Negative controls on the translated HLSL:** - z replaced by 0.25 must read slice 0 at z = 0.75; - x and z exchanged must read texel (0, 0, 1) at z = 0.25. Each must fail with exactly that texel. ## Verification Tested `6d9935be` (on `0e995c19`) 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`). The D3D12 debug layer was enabled and reported 0 errors and 0 warnings on every draw, including the controls. ```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_image_3d_' -V } python -B tests/startup_image_3d_check.py binary <llvm-mc> ``` Debug and Release each passed 3/3 (`startup_image_3d_{controls,warp,hardware}`), with no skips. On both adapters, with both compilers: ```text z=0.25: 3e800000,3f800000,00000000,00000000 z=0.75: 3f400000,3f800000,00000000,3f800000 z=1.75: 3f400000,3f800000,00000000,3f800000 z fixed to slice 0: fails as expected, reads 3e800000,3f800000,00000000,00000000 x and z exchanged: fails as expected, reads 3f200000,00000000,00000000,3f800000 ``` The binary check passed with a local LLVM 23.1.6 `llvm-mc`. CI runs it with LLVM 15. The second #1149 fixture, `s_bfm_b32` inline-sampler folding, will follow separately. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 06:47:14 +00:00
tedin7 commented 2026-11-24 06:47:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:31Z.

Review: COMMENTED


Reviewed commit 6d9935be (Linux host — Windows offscreen_check build and startup_image_3d_{warp,hardware} draw tests were not executed locally).

Code & Edge-Case Audit

  • tools/startup/gfx2hlsl.py: unchanged; this PR adds a source-built fixture, desktop readback harness, CI entries, and docs for image_sample with dim:SQ_RSRC_IMG_3D.
  • tests/startup_image_3d_check.py:
    • PS_SOURCE, SOURCE_2D, and SOURCE_1D match PS_WORDS, WORDS_2D, and WORDS_1D under llvm-mc-19 -arch=amdgcn -mcpu=gfx1013.
    • dim:SQ_RSRC_IMG_3D lowers to Texture3D<float4> r0 : register(t0); sampled with r0.Sample(q0, float3(F(v0), F(v1), F(v2))) where v2 = ud1 (root constant 1), dmask:0xf, and manifest srv 0 tex3d table 0 0. Changing only dim to SQ_RSRC_IMG_2D lowers to Texture2D<float4> with float2(F(v0), F(v1)), and dim:SQ_RSRC_IMG_1D raises Unsupported: image dimension SQ_RSRC_IMG_1D.
  • tests/startup_image_3d.cpp & tests/offscreen_check.cpp:
    • Uploads a 2x2x2 R32G32B32A32_FLOAT Texture3D with dyadic-rational texels ((1 + x + 2y + 4z) / 8, x, y, z) and compares exact IEEE-754 bits (std::memcmp) for z = 0.25, 0.75, and 1.75 (wrap to slice 1), plus two negative-control mutants (z fixed to slice 0, x and z exchanged).
  • AGENTS.md / docs/startup-runtime.md: title-neutral and consistent with the implementation.

Checks Run (Linux / Python / LLVM-19)

  • git diff --check origin/main...HEAD: pass (0 issues)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: pass (16 Markdown files, 280 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: pass (1051 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/startup_image_3d_check.py: pass (dim 3D, dim 2D, dim 1D controls)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_image_3d_check.py binary /usr/bin/llvm-mc-19: pass (fixture words match llvm-mc)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py & binary /usr/bin/llvm-mc-19: pass
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/startup_uniform_lane_check.py: pass
  • LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/compute_store_check.py binary /usr/bin/llvm-mc-19 /usr/bin/llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: pass (exit 0)
  • Windows build and ctest -R "^startup_image_3d_": not run locally.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034084191 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1244#pullrequestreview-6034084191). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:17:31Z. **Review:** COMMENTED --- Reviewed commit `6d9935be` (Linux host — Windows `offscreen_check` build and `startup_image_3d_{warp,hardware}` draw tests were not executed locally). ### Code & Edge-Case Audit - `tools/startup/gfx2hlsl.py`: unchanged; this PR adds a source-built fixture, desktop readback harness, CI entries, and docs for `image_sample` with `dim:SQ_RSRC_IMG_3D`. - `tests/startup_image_3d_check.py`: - `PS_SOURCE`, `SOURCE_2D`, and `SOURCE_1D` match `PS_WORDS`, `WORDS_2D`, and `WORDS_1D` under `llvm-mc-19 -arch=amdgcn -mcpu=gfx1013`. - `dim:SQ_RSRC_IMG_3D` lowers to `Texture3D<float4> r0 : register(t0);` sampled with `r0.Sample(q0, float3(F(v0), F(v1), F(v2)))` where `v2 = ud1` (root constant 1), `dmask:0xf`, and manifest `srv 0 tex3d table 0 0`. Changing only `dim` to `SQ_RSRC_IMG_2D` lowers to `Texture2D<float4>` with `float2(F(v0), F(v1))`, and `dim:SQ_RSRC_IMG_1D` raises `Unsupported: image dimension SQ_RSRC_IMG_1D`. - `tests/startup_image_3d.cpp` & `tests/offscreen_check.cpp`: - Uploads a 2x2x2 `R32G32B32A32_FLOAT` `Texture3D` with dyadic-rational texels `((1 + x + 2y + 4z) / 8, x, y, z)` and compares exact IEEE-754 bits (`std::memcmp`) for `z = 0.25`, `0.75`, and `1.75` (wrap to slice 1), plus two negative-control mutants (`z fixed to slice 0`, `x and z exchanged`). - `AGENTS.md` / `docs/startup-runtime.md`: title-neutral and consistent with the implementation. ### Checks Run (Linux / Python / LLVM-19) - `git diff --check origin/main...HEAD`: pass (0 issues) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py`: pass (16 Markdown files, 280 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py`: pass (1051 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/startup_image_3d_check.py`: pass (`dim 3D`, `dim 2D`, `dim 1D` controls) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_image_3d_check.py binary /usr/bin/llvm-mc-19`: pass (`fixture words match llvm-mc`) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_sampler_heap_check.py` & `binary /usr/bin/llvm-mc-19`: pass - `/root/.local/share/x2w-rev-venv/bin/python -B tests/startup_uniform_lane_check.py`: pass - `LLVM_LIB=/usr/lib/llvm-19/lib/libLLVM-19.so /root/.local/share/x2w-rev-venv/bin/python -B tests/compute_store_check.py binary /usr/bin/llvm-mc-19 /usr/bin/llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so`: pass (exit 0) - Windows build and `ctest -R "^startup_image_3d_"`: not run locally.
tedin7 commented 2026-11-24 06:50:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:20:50Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 6d9935be496f009f0107f95cf149098d1ba18465:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 24.56s (configure 1.86s)
    • Test (ctest --preset dev -R '^startup_image_3d_(controls|warp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (1.24s: startup_image_3d_controls 0.19s, startup_image_3d_warp 1.16s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 28.41s (configure 1.76s)
    • Test (ctest --preset release -R '^startup_image_3d_(controls|warp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (1.09s: startup_image_3d_controls 0.22s, startup_image_3d_warp 0.99s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122861422 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1244#issuecomment-7122861422). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T05:20:50Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `6d9935be496f009f0107f95cf149098d1ba18465`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `24.56s` (configure `1.86s`) - Test (`ctest --preset dev -R '^startup_image_3d_(controls|warp)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`1.24s`: `startup_image_3d_controls` `0.19s`, `startup_image_3d_warp` `1.16s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `28.41s` (configure `1.76s`) - Test (`ctest --preset release -R '^startup_image_3d_(controls|warp)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`1.09s`: `startup_image_3d_controls` `0.22s`, `startup_image_3d_warp` `0.99s`)
Jess-Doit commented 2026-11-24 06:50:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:27:43Z.


Merged current main (7a4043e4) into the branch as b74f9b91 to clear the conflicts with #1237 in tests/desktop_gpu.h and tests/offscreen_check.cpp. Both sides were kept: #1237's new check_startup_sampler_heap signature and op arity, plus this PR's --startup-image-3d op. There is no change to this PR's own files.

Retested b74f9b91 on the same host (Windows 10 22H2 19045.6456, GTX 1060 6 GB, driver 32.0.15.6094, and in-box WARP 10.0.19041.5794, with the debug layer enabled):

cmake --build --preset $preset --target offscreen_check d3d12_xs_shim -j 2
ctest --preset $preset --no-tests=error -R '^(startup_image_3d_|startup_sampler_heap_)' -V

Debug and Release each passed 8/8 with no skips: startup_image_3d_{controls,warp,hardware} and #1237's startup_sampler_heap_{controls,warp,hardware,wrapped_warp,wrapped_hardware}. Readbacks and control failures match the PR body.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122969377 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1244#issuecomment-7122969377). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T05:27:43Z. --- Merged current main (`7a4043e4`) into the branch as `b74f9b91` to clear the conflicts with #1237 in `tests/desktop_gpu.h` and `tests/offscreen_check.cpp`. Both sides were kept: #1237's new `check_startup_sampler_heap` signature and op arity, plus this PR's `--startup-image-3d` op. There is no change to this PR's own files. Retested `b74f9b91` on the same host (Windows 10 22H2 `19045.6456`, GTX 1060 6 GB, driver `32.0.15.6094`, and in-box WARP `10.0.19041.5794`, with the debug layer enabled): ```powershell cmake --build --preset $preset --target offscreen_check d3d12_xs_shim -j 2 ctest --preset $preset --no-tests=error -R '^(startup_image_3d_|startup_sampler_heap_)' -V ``` Debug and Release each passed 8/8 with no skips: `startup_image_3d_{controls,warp,hardware}` and #1237's `startup_sampler_heap_{controls,warp,hardware,wrapped_warp,wrapped_hardware}`. Readbacks and control failures match the PR body.
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!1237
No description provided.