startup: carry the constant sampler LOD range for image_sample, _l and _lz #2257

Merged
JB2WIN merged 1 commit from upstream-pr/2265 into main 2026-11-25 09:10:23 +00:00
JB2WIN commented 2026-11-25 08:51:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T08:51:40Z.


Refs #2177

Change

This is the constant-sampler slice agreed in #2177. image_sample, image_sample_l and image_sample_lz now emit a constant sampler as an smpl line, the same manifest path #2051 added for image_sample_b, so the runtime sets MinLOD = MIN_LOD/256 and MaxLOD = MAX_LOD/256. A shared helper in tools/startup/gfx2hlsl.py applies #2051's validation to all four forms.

New refusals for the three forms. Each is a behaviour change, since these samplers used to translate without limits:

  • a constant sampler with a descriptor LOD bias (word 2, bits 19:0);
  • a constant sampler with MIN_LOD > MAX_LOD.

A constant sampler with MAX_LOD ≠ 0 now clamps the level, where it used to be unbounded.

What stays as before:

  • Mip filter 0 is still refused only for image_sample_b, where the bias matters. For the other three forms such a sampler stays an smp line. Refusing it there would drop every pipeline with an all-zero inline sampler, and seven existing checks build exactly that. Your note named only the bias and malformed ranges. If you want it refused there too, the switch is mip_filter_none_ok in Stage.lod_sampler_words, and those fixtures would need updating.
  • Heap and register samplers and the default-sampler shortcut are accepted unchanged. translate_to and translate_compute print one line per module saying their LOD fields are not validated (#2221), and the docs describe the gap. A sampler that is neither heap nor constant stays refused.
  • image_sample_c keeps its MAX_LOD rule.

Test

New check tests/startup_image_sample_lod_check.py, registered as startup_image_sample_lod_controls, _warp and _hardware. It also has an LLVM 15.0.7 binary mode, and is listed in the pure-Python job and in AGENTS.md. Each form is drawn on its own:

Form Setup smpl reads plain-smp control reads
_l explicit LOD 2, MAX_LOD 1 mip 1 mip 2
image_sample MIN_LOD 2 above implicit LOD 1 mip 2 mip 1
_lz MIN_LOD 1 mip 1 mip 0
  • Implicit LOD: for image_sample, LOD 1 comes from replacing only the u initialiser of the translated HLSL, as in #2051. The Sample call is untouched.
  • #2051 regression: image_sample_b's three discriminators stay green.
  • Changed existing control: one control in startup_image_sample_b_check.py used to assert that a plain image_sample has no smpl line. That is now intended, so it asserts instead that the same words give the same smpl line.
  • Mutations:
    • Not emitting smpl for _l, image_sample or _lz fails the controls; each was tried separately.
    • Swapping MinLOD and MaxLOD in the decoder fails startup_sampler_comparison, startup_image_sample_b_warp and startup_image_sample_lod_{warp,hardware}.

Run with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP (Microsoft Basic Render Driver) and Windows 11 build 26200, debug layer on with 0 errors. DXC ps_6_0 and FXC ps_5_1 gave the same results.

ctest --preset dev --no-tests=error -R '^startup_(image_|gfx2hlsl|sampler)'   # 130/130 passed, 0 skips (before rebasing on f5f7ccc1)

After the rebase, all tests/startup_image_*_check.py, tests/startup_gfx2hlsl_*_check.py, tests/startup_translator_check.py and tests/docs_links_check.py pass.

Not drawn: fractional LOD values, a linear mip filter, 1D, 3D, a16 and compute stages. Heap LOD stays with #2221.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6600719736 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2265). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T08:51:40Z. --- Refs #2177 ## Change This is the constant-sampler slice agreed in #2177. `image_sample`, `image_sample_l` and `image_sample_lz` now emit a constant sampler as an `smpl` line, the same manifest path #2051 added for `image_sample_b`, so the runtime sets `MinLOD = MIN_LOD/256` and `MaxLOD = MAX_LOD/256`. A shared helper in `tools/startup/gfx2hlsl.py` applies #2051's validation to all four forms. New refusals for the three forms. Each is a behaviour change, since these samplers used to translate without limits: - a constant sampler with a descriptor LOD bias (word 2, bits 19:0); - a constant sampler with `MIN_LOD > MAX_LOD`. A constant sampler with `MAX_LOD` ≠ 0 now clamps the level, where it used to be unbounded. What stays as before: - **Mip filter 0** is still refused only for `image_sample_b`, where the bias matters. For the other three forms such a sampler stays an `smp` line. Refusing it there would drop every pipeline with an all-zero inline sampler, and seven existing checks build exactly that. Your note named only the bias and malformed ranges. If you want it refused there too, the switch is `mip_filter_none_ok` in `Stage.lod_sampler_words`, and those fixtures would need updating. - **Heap and register samplers and the default-sampler shortcut** are accepted unchanged. `translate_to` and `translate_compute` print one line per module saying their LOD fields are not validated (#2221), and the docs describe the gap. A sampler that is neither heap nor constant stays refused. - **`image_sample_c`** keeps its MAX_LOD rule. ## Test New check `tests/startup_image_sample_lod_check.py`, registered as `startup_image_sample_lod_controls`, `_warp` and `_hardware`. It also has an LLVM 15.0.7 `binary` mode, and is listed in the pure-Python job and in `AGENTS.md`. Each form is drawn on its own: | Form | Setup | `smpl` reads | plain-`smp` control reads | |---|---|---|---| | `_l` | explicit LOD 2, MAX_LOD 1 | mip 1 | mip 2 | | `image_sample` | MIN_LOD 2 above implicit LOD 1 | mip 2 | mip 1 | | `_lz` | MIN_LOD 1 | mip 1 | mip 0 | - **Implicit LOD:** for `image_sample`, LOD 1 comes from replacing only the `u` initialiser of the translated HLSL, as in #2051. The `Sample` call is untouched. - **#2051 regression:** `image_sample_b`'s three discriminators stay green. - **Changed existing control:** one control in `startup_image_sample_b_check.py` used to assert that a plain `image_sample` has no `smpl` line. That is now intended, so it asserts instead that the same words give the same `smpl` line. - **Mutations:** - Not emitting `smpl` for `_l`, `image_sample` or `_lz` fails the controls; each was tried separately. - Swapping MinLOD and MaxLOD in the decoder fails `startup_sampler_comparison`, `startup_image_sample_b_warp` and `startup_image_sample_lod_{warp,hardware}`. Run with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP (Microsoft Basic Render Driver) and Windows 11 build 26200, debug layer on with 0 errors. DXC `ps_6_0` and FXC `ps_5_1` gave the same results. ```powershell ctest --preset dev --no-tests=error -R '^startup_(image_|gfx2hlsl|sampler)' # 130/130 passed, 0 skips (before rebasing on f5f7ccc1) ``` After the rebase, all `tests/startup_image_*_check.py`, `tests/startup_gfx2hlsl_*_check.py`, `tests/startup_translator_check.py` and `tests/docs_links_check.py` pass. **Not drawn:** fractional LOD values, a linear mip filter, 1D, 3D, a16 and compute stages. Heap LOD stays with #2221. AI-assisted.
tedin7 commented 2026-11-25 09:04:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T08:54:23Z.

Review: COMMENTED


Review of head 0750f9ae00ec09356d57a46a81e1aa4f1b5333b3 (Linux-side only).

Scope read: git diff --stat origin/main...HEAD (9 files, +441/-14), then targeted reads of tools/startup/gfx2hlsl.py, src/startup_stubs/translated_sampler_bindings.h, CMakeLists.txt and the image_sample_b test change. Title is neutral, PR is mergeable. Linux CI job passes. Windows and fixture CI jobs were still pending when I looked.

Commands run locally (all passed):

  • python3 -B tests/startup_image_sample_lod_check.py (controls: smpl line and call, refusals, mip filter 0 stays smp, heap accepted and logged once, draw model)
  • python3 -B tests/startup_image_sample_b_check.py
  • python3 tests/docs_links_check.py (433 links ok)
  • python3 tests/bidi_controls_check.py (clean)
  • git diff --check origin/main...HEAD (clean)

Mutations (both killed, tree restored with git checkout -- .):

  1. lod_limits=bool((words[2] >> 26) & 3) forced to False in the new constant-sampler branch: startup_image_sample_lod_check.py fails ('l limits' manifest shows smp, not smpl).
  2. The bias refusal if words[2] & 0xfffff: forced to if False:: fails with l bias was accepted.

Findings

  • P1: none.
  • P2: none.
  • Nit (src/startup_stubs/translated_sampler_bindings.h, the lod_limits comment): the first line is now about 150 columns, while the file otherwise wraps near 120. Please re-wrap it.
  • Nit (tools/startup/gfx2hlsl.py, around lines 2021-2038): a constant image_sample, _l or _lz sampler with a non-zero LOD bias or MIN_LOD above MAX_LOD is now refused. Before this change it translated. This looks intended and is covered by tests, but please say in the PR body that it can drop pipelines that translated before.
  • Note: the new startup_image_sample_lod_{warp,hardware} draw tests were not run by me. I did not run the Windows WARP job. The PR's Windows CI job is the relevant evidence and was pending, so it should be green before this leaves review.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6054454325 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2265#pullrequestreview-6054454325). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T08:54:23Z. **Review:** COMMENTED --- Review of head `0750f9ae00ec09356d57a46a81e1aa4f1b5333b3` (Linux-side only). **Scope read:** `git diff --stat origin/main...HEAD` (9 files, +441/-14), then targeted reads of `tools/startup/gfx2hlsl.py`, `src/startup_stubs/translated_sampler_bindings.h`, `CMakeLists.txt` and the `image_sample_b` test change. Title is neutral, PR is mergeable. Linux CI job passes. Windows and fixture CI jobs were still pending when I looked. **Commands run locally (all passed):** - `python3 -B tests/startup_image_sample_lod_check.py` (controls: smpl line and call, refusals, mip filter 0 stays smp, heap accepted and logged once, draw model) - `python3 -B tests/startup_image_sample_b_check.py` - `python3 tests/docs_links_check.py` (433 links ok) - `python3 tests/bidi_controls_check.py` (clean) - `git diff --check origin/main...HEAD` (clean) **Mutations (both killed, tree restored with `git checkout -- .`):** 1. `lod_limits=bool((words[2] >> 26) & 3)` forced to `False` in the new constant-sampler branch: `startup_image_sample_lod_check.py` fails ('l limits' manifest shows `smp`, not `smpl`). 2. The bias refusal `if words[2] & 0xfffff:` forced to `if False:`: fails with `l bias was accepted`. **Findings** - P1: none. - P2: none. - Nit (`src/startup_stubs/translated_sampler_bindings.h`, the `lod_limits` comment): the first line is now about 150 columns, while the file otherwise wraps near 120. Please re-wrap it. - Nit (`tools/startup/gfx2hlsl.py`, around lines 2021-2038): a constant `image_sample`, `_l` or `_lz` sampler with a non-zero LOD bias or MIN_LOD above MAX_LOD is now refused. Before this change it translated. This looks intended and is covered by tests, but please say in the PR body that it can drop pipelines that translated before. - Note: the new `startup_image_sample_lod_{warp,hardware}` draw tests were not run by me. I did not run the Windows WARP job. The PR's Windows CI job is the relevant evidence and was pending, so it should be green before this leaves review. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 10:05:21 +00:00
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!2257
No description provided.