test: refuse a comparison sample whose sampler is not constant #1873

Merged
ChazY11 merged 1 commit from upstream-pr/1880 into main 2026-11-24 20:13:24 +00:00
ChazY11 commented 2026-11-24 20:02:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T20:02:20Z.


What

Last case from #1877. image_compare takes the comparison function and the filter from the sampler's four words, so a
sampler it cannot resolve is refused:

words = self.const_words(ops[3])
if words is None:
    raise Unsupported('%s with a sampler that is not constant' % base)

Replacing that raise with pass left the four image checks green.

Change

check_compare_sampler_constant() in startup_inline_sampler_check.py, on a bare stage:

bare_stage().image_compare(['v5', '[v1, v2, v3]', 's0', 's4'],
                           ['dim:SQ_RSRC_IMG_2D', 'dmask:0x1'], 'c')
    -> Unsupported('image_sample_c with a sampler that is not constant')

bare_stage({n: ('const', 0) for n in range(4, 8)}).image_compare(... same ...)
    -> must NOT raise that message (the bare stage stops where it needs a pipeline)

The second call is the control: with s[4:7] in the symbol table as constants, const_words returns four words and the guard
is passed.

Tested

out/pe-env/Scripts/python.exe -B tests/startup_inline_sampler_check.py     # exit 0

Negative controls, each reverted:

raise -> pass                                          exit 1
const_words: any(w is None ...) -> all(...)             exit 1
reverted                                                exit 0

The second is the one that keeps "all four words must be constant" under test: with all, a sampler with one unresolved
word would be accepted and the case fails.

Scope

One test file, one new function called from controls(). This closes the three sites in #1877 (the other two are #1878 and
#1879).

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6590316541 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1880). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T20:02:20Z. --- ## What Last case from #1877. `image_compare` takes the comparison function and the filter from the sampler's four words, so a sampler it cannot resolve is refused: ```python words = self.const_words(ops[3]) if words is None: raise Unsupported('%s with a sampler that is not constant' % base) ``` Replacing that `raise` with `pass` left the four image checks green. ## Change `check_compare_sampler_constant()` in `startup_inline_sampler_check.py`, on a bare stage: ```python bare_stage().image_compare(['v5', '[v1, v2, v3]', 's0', 's4'], ['dim:SQ_RSRC_IMG_2D', 'dmask:0x1'], 'c') -> Unsupported('image_sample_c with a sampler that is not constant') bare_stage({n: ('const', 0) for n in range(4, 8)}).image_compare(... same ...) -> must NOT raise that message (the bare stage stops where it needs a pipeline) ``` The second call is the control: with `s[4:7]` in the symbol table as constants, `const_words` returns four words and the guard is passed. ## Tested ```powershell out/pe-env/Scripts/python.exe -B tests/startup_inline_sampler_check.py # exit 0 ``` Negative controls, each reverted: ```text raise -> pass exit 1 const_words: any(w is None ...) -> all(...) exit 1 reverted exit 0 ``` The second is the one that keeps "**all four** words must be constant" under test: with `all`, a sampler with one unresolved word would be accepted and the case fails. ## Scope One test file, one new function called from `controls()`. This closes the three sites in #1877 (the other two are #1878 and #1879). ## Notes - AI-assisted.
upstream-sync closed this pull request 2026-11-24 21:01:05 +00:00
tedin7 commented 2026-11-24 21:01:05 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Peer review of head 9bba6a77d7efb1f0b12fa048e85905d1a468d0e6 (PRODUCTION_REVIEW_ONLY, technical comment only).

No P1 and no P2 found. The new check guards real behavior and fails when the guard is broken.

The change adds one function, check_compare_sampler_constant, to tests/startup_inline_sampler_check.py (+34 lines), called at the start of controls(). I read it against image_compare in tools/startup/gfx2hlsl.py. The refusal it targets (words is None -> "image_sample_c with a sampler that is not constant", line ~888) is decided from the symbol table after the dim, dmask, operand-count and sampler-heap checks, so a bare Stage with an empty symbol table reaches it, and four constant words (s4..s7) pass it. No other test in the tree pins this refusal: the string appears in no other file under tests/.

Mutations of tools/startup/gfx2hlsl.py, one at a time, each run against tests/startup_inline_sampler_check.py and then restored with git checkout -- . (the tree is clean afterwards):

  • unresolved sampler no longer refused (words = (0, 0, 0, 0) instead of the raise): rc=1 ("Comparison sampling requires CLAMP_LAST_TEXEL in X and Y" escapes where the exact refusal text is asserted).
  • the refusal inverted (if words is not None: raise ...): rc=1 (TypeError, the guard no longer reaches the constant-words path).
  • the refusal made unconditional, so even four constant words are refused: rc=1 (the second half catches it, "image_sample_c with a sampler that is not constant").
  • the refusal's wording changed: rc=1 (the exact text is asserted).

Minor, non-blocking:

  • The first assertion pins the full refusal text, so a rewording of that message needs a matching test edit. That is acceptable for a refusal, but it is the reason the wording mutation fails.
  • The second half accepts an AttributeError as "got past the guard" (the bare stage has no pipeline). It would also pass if a different attribute error came from earlier in image_compare; the assertion that the refusal text is absent is what carries the check.
  • There is one blank line between the new function and def controls(); the file uses two elsewhere.

Commands run (Linux; this PR is Python-only, so no Windows run is needed):

  • git diff --check <merge-base>...HEAD: clean
  • tests/docs_links_check.py: pass
  • tests/bidi_controls_check.py: pass
  • tests/startup_inline_sampler_check.py: pass
  • the four mutations above
  • The merge against current main has no content conflicts (git merge-tree).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046534914 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1880#pullrequestreview-6046534914). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:08:17Z. **Review:** COMMENTED --- Peer review of head `9bba6a77d7efb1f0b12fa048e85905d1a468d0e6` (PRODUCTION_REVIEW_ONLY, technical comment only). **No P1 and no P2 found. The new check guards real behavior and fails when the guard is broken.** The change adds one function, `check_compare_sampler_constant`, to tests/startup_inline_sampler_check.py (+34 lines), called at the start of `controls()`. I read it against `image_compare` in tools/startup/gfx2hlsl.py. The refusal it targets (`words is None` -> "image_sample_c with a sampler that is not constant", line ~888) is decided from the symbol table after the dim, dmask, operand-count and sampler-heap checks, so a bare `Stage` with an empty symbol table reaches it, and four constant words (s4..s7) pass it. No other test in the tree pins this refusal: the string appears in no other file under tests/. Mutations of `tools/startup/gfx2hlsl.py`, one at a time, each run against `tests/startup_inline_sampler_check.py` and then restored with `git checkout -- .` (the tree is clean afterwards): - unresolved sampler no longer refused (`words = (0, 0, 0, 0)` instead of the raise): rc=1 ("Comparison sampling requires CLAMP_LAST_TEXEL in X and Y" escapes where the exact refusal text is asserted). - the refusal inverted (`if words is not None: raise ...`): rc=1 (TypeError, the guard no longer reaches the constant-words path). - the refusal made unconditional, so even four constant words are refused: rc=1 (the second half catches it, "image_sample_c with a sampler that is not constant"). - the refusal's wording changed: rc=1 (the exact text is asserted). Minor, non-blocking: - The first assertion pins the full refusal text, so a rewording of that message needs a matching test edit. That is acceptable for a refusal, but it is the reason the wording mutation fails. - The second half accepts an `AttributeError` as "got past the guard" (the bare stage has no pipeline). It would also pass if a different attribute error came from earlier in `image_compare`; the assertion that the refusal text is absent is what carries the check. - There is one blank line between the new function and `def controls()`; the file uses two elsewhere. Commands run (Linux; this PR is Python-only, so no Windows run is needed): - `git diff --check <merge-base>...HEAD`: clean - `tests/docs_links_check.py`: pass - `tests/bidi_controls_check.py`: pass - `tests/startup_inline_sampler_check.py`: pass - the four mutations above - The merge against current `main` has no content conflicts (`git merge-tree`). AI-assisted; commands listed were executed locally.
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!1873
No description provided.