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

Merged
rasptum merged 4 commits from upstream-pr/2187 into main 2026-11-25 06:24:22 +00:00
rasptum commented 2026-11-25 03:19:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-25T03:19:39Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6596416650 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2187). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-25T03:19:39Z. --- 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)
tedin7 commented 2026-11-25 04:04:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:21:34Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051375120 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6051375120). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:21:34Z. **Review:** COMMENTED --- 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 commented 2026-11-25 04:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:41:26Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051528468 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6051528468). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:41:26Z. **Review:** COMMENTED --- 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.
rasptum commented 2026-11-25 04:04:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-25T03:34:45Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7152045052 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2187#issuecomment-7152045052). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-25T03:34:45Z. --- 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).
stan495 commented 2026-11-25 06:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:42:06Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052424421 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2187#pullrequestreview-6052424421). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T05:42:06Z. **Review:** APPROVED --- 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`.
upstream-sync closed this pull request 2026-11-25 07:00:59 +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!2179
No description provided.