startup: accept 2D gather samplers that differ only in fields a fixed-mip gather cannot observe #2187

Manually merged
github merged 4 commits from gh-pr/2187/head into gh-pr/2187/base 2026-11-27 00:04:09 +00:00
Owner

@⁠rasptum on GitHub · 2026-11-25 03:19 UTC · original
rasptum:shader/gather4-lz-sampler → main · +144 −1 · 3 files · 4 commits · merged 2026-11-25 06:24 UTC

Refs #1802

The image_gather4_lz lowering in tools/startup/gfx2hlsl.py (2D, fixed mip, landed in #1927) validates the constant sampler against one exact profile: clamp to the last texel in X and Y, bilinear XY, point mip filtering, and no LOD fields. This change keeps that profile. It stops refusing three sampler fields that a fixed-mip 2D gather cannot observe, one commit each:

  1. CLAMP_Z (SQ_IMG_SAMP_WORD0 bits 8:6). A 2D view has no third coordinate.
  2. Point XY_MAG_FILTER / XY_MIN_FILTER (WORD2 bits 21:20 and 23:22, value 0). These are checked as bilinear.
  3. MIP_POINT_PRECLAMP (WORD2 bit 28). It acts only on mip selection, and the _lz gather reads mip zero.

Source for all three: the Direct3D 11.3 functional spec, 22.4.2 gather4. It says gather4 "Gathers the four texels that would be used in a bi-linear filtering operation", "Only the addressing modes of the sampler are used", and "the top level of any mip pyramid is used".

  • Two in-repo points agree with it. The renderer these draws use already binds a point static sampler (FILTER_MIN_MAG_MIP_POINT, tests/pixel_aot_vs.hlsl) and reads the bilinear footprint. The level-zero comparison path already accepts MIP_POINT_PRECLAMP for the same reason (pixel_aot.comparison_sampler_state).
  • The relaxations apply only to the words the profile check sees. The static sampler bound in the manifest keeps the guest's original words.

Still refused:

  • wrap, mirror or border addressing in X or Y;
  • an anisotropy ratio, or anisotropic XY filtering;
  • a linear mip filter;
  • LOD bias;
  • WORD2 bits 29 to 31;
  • every other field the profile already refused.

Tests (tests/startup_image_gather_lz_check.py, hand-assembled words as before):

  • Controls translate CLAMP_Z 1 to 7; point magnification, minification and both; MIP_POINT_PRECLAMP; and their combinations. Each translation carries the title's words into the manifest, and every form listed above stays refused.
  • Negative controls: each relaxation has one that removes it from the profile and expects the refusal again. Removing each relaxation from the translator (local mutants) also fails the controls.
  • Draws (WARP and hardware): three new draws run with CLAMP_Z set, with point XY plus CLAMP_Z, and with all three fields set. Each reads the same four texels as the reference; the existing mutant draw still fails.

Effect, measured locally by aggregate count only: in one local shader-request cache, all three pipelines that refused at this sampler check get past it. One now translates fully. The other two reach later refusals: s_bfm_b64, which open PRs cover, and a descriptor operand.

Test:

ctest --preset dev --no-tests=error -R '^(startup_image_gather_lz(_warp|_hardware)?|pixel_aot_compare_gather_.*|startup_gfx2hlsl_.*|startup_translator.*|startup_image_.*)$' -V

Result at 3f30a943 (on 56b801be):

  • dev: 83 of 83 pass.
  • release: 81 of 83 pass. startup_image_2d_array_hardware and startup_image_sample_a16_hardware hit the 120 s timeout under --parallel 4. Both pass when run serially (50 s and 27 s), and so does startup_image_gather_lz_hardware. This change touches neither test's path.
  • No capability skips.
  • Hardware: NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.15.9636, Windows 10.0.19045, debug layer enabled.

docs_links_check, bidi_controls_check, form_coverage_check and startup_translator_check pass.

🤖 Generated with Claude Code

**@⁠rasptum** on GitHub · 2026-11-25 03:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2187) `rasptum:shader/gather4-lz-sampler` → `main` · +144 −1 · 3 files · 4 commits · merged 2026-11-25 06:24 UTC Refs #1802 The `image_gather4_lz` lowering in `tools/startup/gfx2hlsl.py` (2D, fixed mip, landed in #1927) validates the constant sampler against one exact profile: clamp to the last texel in X and Y, bilinear XY, point mip filtering, and no LOD fields. This change keeps that profile. It stops refusing three sampler fields that a fixed-mip 2D gather cannot observe, one commit each: 1. **`CLAMP_Z`** (SQ_IMG_SAMP_WORD0 bits 8:6). A 2D view has no third coordinate. 2. **Point `XY_MAG_FILTER` / `XY_MIN_FILTER`** (WORD2 bits 21:20 and 23:22, value 0). These are checked as bilinear. 3. **`MIP_POINT_PRECLAMP`** (WORD2 bit 28). It acts only on mip selection, and the `_lz` gather reads mip zero. Source for all three: the [Direct3D 11.3 functional spec, 22.4.2 gather4](https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#Gather4). It says gather4 "Gathers the four texels that would be used in a bi-linear filtering operation", "Only the addressing modes of the sampler are used", and "the top level of any mip pyramid is used". - Two in-repo points agree with it. The renderer these draws use already binds a point static sampler (`FILTER_MIN_MAG_MIP_POINT`, `tests/pixel_aot_vs.hlsl`) and reads the bilinear footprint. The level-zero comparison path already accepts `MIP_POINT_PRECLAMP` for the same reason (`pixel_aot.comparison_sampler_state`). - The relaxations apply only to the words the profile check sees. The static sampler bound in the manifest keeps the guest's original words. Still refused: - wrap, mirror or border addressing in X or Y; - an anisotropy ratio, or anisotropic XY filtering; - a linear mip filter; - LOD bias; - WORD2 bits 29 to 31; - every other field the profile already refused. Tests (`tests/startup_image_gather_lz_check.py`, hand-assembled words as before): - Controls translate `CLAMP_Z` 1 to 7; point magnification, minification and both; `MIP_POINT_PRECLAMP`; and their combinations. Each translation carries the title's words into the manifest, and every form listed above stays refused. - **Negative controls:** each relaxation has one that removes it from the profile and expects the refusal again. Removing each relaxation from the translator (local mutants) also fails the controls. - **Draws (WARP and hardware):** three new draws run with `CLAMP_Z` set, with point XY plus `CLAMP_Z`, and with all three fields set. Each reads the same four texels as the reference; the existing mutant draw still fails. Effect, measured locally by aggregate count only: in one local shader-request cache, all three pipelines that refused at this sampler check get past it. One now translates fully. The other two reach later refusals: `s_bfm_b64`, which open PRs cover, and a descriptor operand. Test: ```powershell ctest --preset dev --no-tests=error -R '^(startup_image_gather_lz(_warp|_hardware)?|pixel_aot_compare_gather_.*|startup_gfx2hlsl_.*|startup_translator.*|startup_image_.*)$' -V ``` Result at `3f30a943` (on `56b801be`): - dev: 83 of 83 pass. - release: 81 of 83 pass. `startup_image_2d_array_hardware` and `startup_image_sample_a16_hardware` hit the 120 s timeout under `--parallel 4`. Both pass when run serially (50 s and 27 s), and so does `startup_image_gather_lz_hardware`. This change touches neither test's path. - No capability skips. - Hardware: NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.15.9636, Windows 10.0.19045, debug layer enabled. `docs_links_check`, `bidi_controls_check`, `form_coverage_check` and `startup_translator_check` pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
image_gather4_lz on a 2D view was refused when the sampler's Z address mode (SQ_IMG_SAMP_WORD0
bits 8:6) was not 0. A 2D view has no third coordinate, and the Direct3D 11.3 functional spec,
22.4.2 (gather4), says "Only the addressing modes of the sampler are used". The profile check now
sees CLAMP_Z as 0; the X and Y modes must still clamp to the last texel, the other word 0 fields
still refuse, and the bound static sampler keeps the title's own words.

tests/startup_image_gather_lz_check.py: CLAMP_Z 1..7 translate and carry their words in the
manifest; wrap or mirror in X or Y and an anisotropy ratio stay refused with CLAMP_Z set; a
negative control without the 2D profile refuses again; one WARP/hardware draw runs with CLAMP_Z set.

Refs #1802

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The image_gather4_lz sampler check required bilinear XY filtering. Direct3D 11.3 functional spec,
22.4.2 (gather4): gather4 "Gathers the four texels that would be used in a bi-linear filtering
operation" and "Only the addressing modes of the sampler are used", so a point XY_MAG_FILTER or
XY_MIN_FILTER (SQ_IMG_SAMP_WORD2 bits 21:20 and 23:22, value 0) returns the same footprint and is
now checked as bilinear. The draw renderer already binds a point static sampler
(FILTER_MIN_MAG_MIP_POINT, tests/pixel_aot_vs.hlsl) and reads the bilinear footprint on WARP and
hardware. Anisotropic XY, a linear mip filter and a LOD bias stay refused; the bound static sampler
keeps the title's words.

tests/startup_image_gather_lz_check.py: point magnification, minification and both translate, with
and without CLAMP_Z; anisotropic, linear-mip and biased words stay refused; a negative control whose
profile only clears CLAMP_Z refuses the point filter again; one draw runs with point XY and CLAMP_Z.

Refs #1802

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SQ_IMG_SAMP_WORD2 bit 28 (MIP_POINT_PRECLAMP) acts only on mip selection. image_gather4_lz reads
mip zero, and Direct3D gather uses "the top level of any mip pyramid" (Direct3D 11.3 functional
spec, 22.4.2), so the gather sampler check no longer sees the bit. The level-zero comparison path
already accepts it for the same reason (pixel_aot.comparison_sampler_state). Bits 29-31 stay
refused, and the bound static sampler keeps the title's words.

tests/startup_image_gather_lz_check.py: the bit translates alone and with CLAMP_Z and a point XY
filter; bits 29, 30 and 31 stay refused; a negative control keeps the bit and expects the refusal;
one WARP/hardware draw runs with clamp-last-texel in X, Y and Z, point XY and mip filtering and the
bit set.

Refs #1802

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gather_2d_profile_words docstring and the docs/experiments.md paragraph
now say that a point XY filter reading the same four texels as bilinear is
the D3D11.3 functional spec rule (22.4.2 gather4) and has not been measured
on console hardware. Comment and docs only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:04:06 +00:00
github manually merged commit 767773388d into gh-pr/2187/base 2026-11-27 00:04:09 +00:00
Author
Owner

@⁠rasptum on GitHub · 2026-11-25 03:34 UTC · original

Thanks. The gather_2d_profile_words docstring and the docs/experiments.md paragraph now say that "a point filter reads the same four texels" is the D3D11.3 rule (22.4.2 gather4) and has not been measured on console hardware; the three monkeypatched negative controls stay as they are, since removing each relaxation from the translator itself (local mutants) also fails them.
Comment and docs only; startup_image_gather_lz_check, docs_links_check and bidi_controls_check pass. AI-assisted (Claude Code).

**@⁠rasptum** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2187#issuecomment-7152045052) Thanks. The `gather_2d_profile_words` docstring and the docs/experiments.md paragraph now say that "a point filter reads the same four texels" is the D3D11.3 rule (22.4.2 gather4) and has not been measured on console hardware; the three monkeypatched negative controls stay as they are, since removing each relaxation from the translator itself (local mutants) also fails them. Comment and docs only; `startup_image_gather_lz_check`, `docs_links_check` and `bidi_controls_check` pass. AI-assisted (Claude Code).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 03:21 UTC · original · reviewed

Review of head 3f30a943116ceeca8479cc8e54e8d45c870708c9.

Verdict: no P1, no P2. Looks correct for what it claims.

What I checked

  • gather_2d_profile_words (tools/startup/gfx2hlsl.py): clears CLAMP_Z (WORD0 bits 8:6) and MIP_POINT_PRECLAMP (WORD2 bit 28), and turns point XY mag/min (value 0) into bilinear (value 1) before check_gather_sampler. Aniso (2, 3), bits 29-31, WORD1/WORD3 and the X/Y address modes stay checked.
  • The renderer side (GATHER_RESOURCES in tools/pixel_aot.py) uses Load taps, so it does not depend on the sampler filter. This matches the claimed semantics.
  • Only the validated words are rewritten. The manifest still binds the title's own words (asserted in the tests).
  • Title is neutral, PR is MERGEABLE, no clean-room concern seen in the diff or docs.

Commands run locally on the PR head

  • python3 tests/startup_image_gather_lz_check.py -> pass ("Four fixed-mip gather channels and unsupported encodings checked")
  • python3 tests/docs_links_check.py -> pass (18 files, 401 links)
  • python3 tests/bidi_controls_check.py -> pass
  • git diff --check origin/main...HEAD -> clean
  • Mutations of the new logic, each run against the test, then reverted:
    • keep bit 28 -> test fails (killed)
    • keep CLAMP_Z -> test fails (killed)
    • only fix MAG filter, not MIN -> test fails (killed)
    • != 3 instead of == 0 in the filter check -> passes, but this is an equivalent mutant (0 becomes 1, 1 stays, 2 becomes 3 and is still refused).

CI at review time: Linux python checks pass; Windows build/test and fixtures jobs were still pending. I did not run Win2025 (not needed for this change by itself; the D3D12 draw cases added in draw() need the Windows job to go green).

Nits (non-blocking)

  • gather_2d_profile_words doc says a point filter "reads the same four texels". This is taken from the D3D11.3 spec. It is not shown that the console hardware gather ignores the filter in the same way. A one-line note that this is the spec rule would make the limit clear.
  • tests/startup_image_gather_lz_check.py: the three negative controls monkeypatch G.gather_2d_profile_words. They work, but they are the "old behaviour is refused" kind. The direct refusals right next to them already cover the kept fields.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 03:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6051375120) · **reviewed** Review of head `3f30a943116ceeca8479cc8e54e8d45c870708c9`. **Verdict: no P1, no P2. Looks correct for what it claims.** What I checked - `gather_2d_profile_words` (`tools/startup/gfx2hlsl.py`): clears CLAMP_Z (WORD0 bits 8:6) and MIP_POINT_PRECLAMP (WORD2 bit 28), and turns point XY mag/min (value 0) into bilinear (value 1) before `check_gather_sampler`. Aniso (2, 3), bits 29-31, WORD1/WORD3 and the X/Y address modes stay checked. - The renderer side (`GATHER_RESOURCES` in `tools/pixel_aot.py`) uses `Load` taps, so it does not depend on the sampler filter. This matches the claimed semantics. - Only the validated words are rewritten. The manifest still binds the title's own words (asserted in the tests). - Title is neutral, PR is MERGEABLE, no clean-room concern seen in the diff or docs. Commands run locally on the PR head - `python3 tests/startup_image_gather_lz_check.py` -> pass ("Four fixed-mip gather channels and unsupported encodings checked") - `python3 tests/docs_links_check.py` -> pass (18 files, 401 links) - `python3 tests/bidi_controls_check.py` -> pass - `git diff --check origin/main...HEAD` -> clean - Mutations of the new logic, each run against the test, then reverted: - keep bit 28 -> test fails (killed) - keep CLAMP_Z -> test fails (killed) - only fix MAG filter, not MIN -> test fails (killed) - `!= 3` instead of `== 0` in the filter check -> passes, but this is an equivalent mutant (0 becomes 1, 1 stays, 2 becomes 3 and is still refused). CI at review time: Linux python checks pass; Windows build/test and fixtures jobs were still pending. I did not run Win2025 (not needed for this change by itself; the D3D12 draw cases added in `draw()` need the Windows job to go green). Nits (non-blocking) - `gather_2d_profile_words` doc says a point filter "reads the same four texels". This is taken from the D3D11.3 spec. It is not shown that the console hardware gather ignores the filter in the same way. A one-line note that this is the spec rule would make the limit clear. - `tests/startup_image_gather_lz_check.py`: the three negative controls monkeypatch `G.gather_2d_profile_words`. They work, but they are the "old behaviour is refused" kind. The direct refusals right next to them already cover the kept fields. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 03:41 UTC · original · reviewed

Re-review of head 767773388dbfb009db0d65bb310de44c2d03101f (3 new commits since the previously reviewed 3f30a943).

Scope read: tools/startup/gfx2hlsl.py (gather_2d_profile_words, one call site), tests/startup_image_gather_lz_check.py, docs/experiments.md. Title is neutral, PR is mergeable, CI checks listed as pass (Linux Python, Windows build and test, gfx1013 fixtures).

Logic

  • CLAMP_Z cleared, point XY (mag, min) promoted to bilinear, MIP_POINT_PRECLAMP cleared before check_gather_sampler. The bound static sampler keeps the title's own words (manifest asserts check this). Matches the D3D11.3 gather4 text it cites.
  • Still refused: anisotropic XY, linear mip filter, LOD bias, X/Y wrap or mirror, bits 29-31, aniso ratio in word0 bits 11:9. All have explicit refusal asserts.
  • The doc and the docstring now say the point-filter rule comes from the D3D11.3 spec and has not been measured on console hardware. That is the right wording.

Commands run locally on this head

  • python3 -B tests/startup_image_gather_lz_check.py -> rc 0, "Four fixed-mip gather channels and unsupported encodings checked". The D3D12 draw part did not run on Linux, and I did not queue a Windows run. The CI Windows job passed.
  • python3 tests/docs_links_check.py -> 18 files, 401 links OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean

Mutations (each reverted with git checkout -- .)

  1. Stop clearing CLAMP_Z -> test fails (Unsupported raised). Killed.
  2. Promote only the mag filter, not min -> test fails. Killed.
  3. Stop clearing MIP_POINT_PRECLAMP -> test fails. Killed.

Findings

  • P1: none
  • P2: none
  • nit: tests/startup_image_gather_lz_check.py negative controls monkeypatch G.gather_2d_profile_words. That works because the call site looks the name up at call time. It would break silently if the call site ever bound the function early. Low risk.
  • nit: the point-filter equivalence is spec-derived only. The PR already says so. A hardware readback with a real point sampler would turn it into a measurement later.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6051528468) · **reviewed** Re-review of head `767773388dbfb009db0d65bb310de44c2d03101f` (3 new commits since the previously reviewed `3f30a943`). **Scope read:** `tools/startup/gfx2hlsl.py` (`gather_2d_profile_words`, one call site), `tests/startup_image_gather_lz_check.py`, `docs/experiments.md`. Title is neutral, PR is mergeable, CI checks listed as pass (Linux Python, Windows build and test, gfx1013 fixtures). **Logic** - CLAMP_Z cleared, point XY (mag, min) promoted to bilinear, MIP_POINT_PRECLAMP cleared before `check_gather_sampler`. The bound static sampler keeps the title's own words (manifest asserts check this). Matches the D3D11.3 gather4 text it cites. - Still refused: anisotropic XY, linear mip filter, LOD bias, X/Y wrap or mirror, bits 29-31, aniso ratio in word0 bits 11:9. All have explicit refusal asserts. - The doc and the docstring now say the point-filter rule comes from the D3D11.3 spec and has not been measured on console hardware. That is the right wording. **Commands run locally on this head** - `python3 -B tests/startup_image_gather_lz_check.py` -> rc 0, "Four fixed-mip gather channels and unsupported encodings checked". The D3D12 draw part did not run on Linux, and I did not queue a Windows run. The CI Windows job passed. - `python3 tests/docs_links_check.py` -> 18 files, 401 links OK - `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean **Mutations (each reverted with `git checkout -- .`)** 1. Stop clearing CLAMP_Z -> test fails (Unsupported raised). Killed. 2. Promote only the mag filter, not min -> test fails. Killed. 3. Stop clearing MIP_POINT_PRECLAMP -> test fails. Killed. **Findings** - P1: none - P2: none - nit: `tests/startup_image_gather_lz_check.py` negative controls monkeypatch `G.gather_2d_profile_words`. That works because the call site looks the name up at call time. It would break silently if the call site ever bound the function early. Low risk. - nit: the point-filter equivalence is spec-derived only. The PR already says so. A hardware readback with a real point sampler would turn it into a measurement later. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠stan495 on GitHub · 2026-11-25 05:42 UTC · original · approved these changes

Verified head 76777338 on Windows x64 (Python 3.12). The point-filter and CLAMP_Z / MIP_POINT_PRECLAMP relaxation is clearly scoped and documented as derived from the D3D11.3 gather spec.

  • python -B tests/startup_image_gather_lz_check.py -> passed (Four fixed-mip gather channels and unsupported encodings checked)
  • python -B tests/docs_links_check.py -> passed (18 Markdown files, 401 links)

Verdict: Approved at 76777338.

**@⁠stan495** on GitHub · 2026-11-25 05:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6052424421) · **approved these changes** Verified head `76777338` on Windows x64 (Python 3.12). The point-filter and `CLAMP_Z` / `MIP_POINT_PRECLAMP` relaxation is clearly scoped and documented as derived from the D3D11.3 gather spec. - `python -B tests/startup_image_gather_lz_check.py` -> passed (`Four fixed-mip gather channels and unsupported encodings checked`) - `python -B tests/docs_links_check.py` -> passed (18 Markdown files, 401 links) Verdict: Approved at `76777338`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.