native: accept a literal sampler whose word 3 is a GPU value when no axis is BORDER #3519

Closed
github-bot wants to merge 1 commit from github-bot/gh-3517 into main AGit
Owner

@⁠JB2WIN on GitHub · 2026-11-29 21:13 UTC · original
JB2WIN:native/sampler-dynamic-word3 → main · +20 −0 · 2 files · 1 commits · closed without merging

Refs #3226, #3023.

A literal (static) sampler whose words 0-2 are constants but whose word 3 comes from a GPU value was refused as nonconstant sampler. The static sampler reads word 3 only for the border colour (bits 31:30, decode_sampler in src/startup_stubs/translated_sampler_bindings.h), and only a BORDER address mode uses it (CLAMP_X/Y/Z 6 or 7). So with words 0-2 constant and no BORDER axis, word 3 cannot change the sampler. The translator now sets it to 0. With a BORDER axis it refuses, named sampler border colour from a GPU value.

This is a step on the #3023 heap-texture route. In my local prototype of that route (texture loads and image fields stubbed in), 299 requests stop at nonconstant sampler with words 0-2 constant and word 3 numeric. On main today those programs stop earlier, at the heap refusal, so this PR alone moves no request in the local cohort. It is groundwork, measured on the prototype only.

Tests:

  • native_sampler_heap_check.py: dynamic_word3 (literal words 0-2, v_readfirstlane_b32 s15, v0 as word 3) compiles. border_word3 (the same with CLAMP_X 6) refuses with the new reason.
  • native_sampler_heap_hardware, native_exec_symbol_b64_controls, startup_inline_sampler_{controls,warp,hardware}, startup_compute_dispatch_native_hardware: pass (WARP skips as on main).
  • With src/ reverted, native_sampler_heap_hardware fails.

AI-assisted.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-29 21:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3517) `JB2WIN:native/sampler-dynamic-word3` → `main` · +20 −0 · 2 files · 1 commits · closed without merging Refs #3226, #3023. A literal (static) sampler whose words 0-2 are constants but whose word 3 comes from a GPU value was refused as `nonconstant sampler`. The static sampler reads word 3 only for the border colour (bits 31:30, `decode_sampler` in `src/startup_stubs/translated_sampler_bindings.h`), and only a BORDER address mode uses it (CLAMP_X/Y/Z 6 or 7). So with words 0-2 constant and no BORDER axis, word 3 cannot change the sampler. The translator now sets it to 0. With a BORDER axis it refuses, named `sampler border colour from a GPU value`. This is a step on the #3023 heap-texture route. In my local prototype of that route (texture loads and image fields stubbed in), 299 requests stop at `nonconstant sampler` with words 0-2 constant and word 3 numeric. On `main` today those programs stop earlier, at the heap refusal, so this PR alone moves no request in the local cohort. It is groundwork, measured on the prototype only. Tests: - `native_sampler_heap_check.py`: `dynamic_word3` (literal words 0-2, `v_readfirstlane_b32 s15, v0` as word 3) compiles. `border_word3` (the same with CLAMP_X 6) refuses with the new reason. - `native_sampler_heap_hardware`, `native_exec_symbol_b64_controls`, `startup_inline_sampler_{controls,warp,hardware}`, `startup_compute_dispatch_native_hardware`: pass (WARP skips as on main). - With `src/` reverted, `native_sampler_heap_hardware` fails. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A static sampler reads word 3 only for the border colour (bits 31:30, decode_sampler), which only a BORDER
address mode uses. With words 0-2 constant and no CLAMP_X/Y/Z of 6 or 7, a GPU value in word 3 cannot change
the sampler, so it becomes 0. A BORDER axis keeps it refused (sampler border colour from a GPU value).

Refs #3224, #3023

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 21:15:20 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 21:32 UTC · original · reviewed

Diff-only review at ace59889, nothing built or run.

The logic is correct for non-comparison samplers: decode_sampler reads word 3 only in bits 31:30, and modes 6 and 7 are the only BORDER address modes, so a GPU word 3 cannot change the sampler when no axis is BORDER.

SHOULD: for a comparison sampler, word 3 is zeroed before the border & 0x3ffff000 check (main src/gfx1013_compute_native.cpp:1170-1175, "unsupported comparison sampler fields"), so that check is vacuous for a GPU word 3. The decoded sampler is the same, but a constraint enforced on literal words is dropped without a note. Either refuse a GPU word 3 when comparison, or say in the comment why bits 29:12 do not matter. No test covers comparison + GPU word 3.

SHOULD: border_word3 only has CLAMP_X = 6, so a mutant that checks only X (axis < 1) or == 6 instead of >= 6 would pass. One refusal case with CLAMP_Z = 7 pins both.

**@⁠Leyukaka** on GitHub · 2026-11-29 21:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3517#pullrequestreview-6104900960) · **reviewed** Diff-only review at ace59889, nothing built or run. The logic is correct for non-comparison samplers: `decode_sampler` reads word 3 only in bits 31:30, and modes 6 and 7 are the only BORDER address modes, so a GPU word 3 cannot change the sampler when no axis is BORDER. SHOULD: for a comparison sampler, word 3 is zeroed before the `border & 0x3ffff000` check (main `src/gfx1013_compute_native.cpp:1170-1175`, "unsupported comparison sampler fields"), so that check is vacuous for a GPU word 3. The decoded sampler is the same, but a constraint enforced on literal words is dropped without a note. Either refuse a GPU word 3 when `comparison`, or say in the comment why bits 29:12 do not matter. No test covers comparison + GPU word 3. SHOULD: `border_word3` only has CLAMP_X = 6, so a mutant that checks only X (`axis < 1`) or `== 6` instead of `>= 6` would pass. One refusal case with CLAMP_Z = 7 pins both.
github-bot closed this pull request 2026-11-29 22:03:21 +00:00
Author
Owner

@⁠JB2WIN on GitHub · 2026-11-29 22:00 UTC · original

Closing this one. A remeasure of my local prototype with this change showed that it moves none of the 299: all of them have CLAMP_BORDER on X and Y, so they stop at the new sampler border colour from a GPU value.

The cause is elsewhere. In all 299, word 3 is written by s_brev_b32 (163), s_bfe_u32 (67), or by a value that has already been through one of them (43). The symbol analysis does not fold either instruction even when the operands are constant. With the fold, word 3 is the constant 0x80000000 (OPAQUE_WHITE), and the sampler is literal. So the fold is the fix (claim on #3226, issuecomment-7263320436). A real GPU word 3 has not shown up in my captures. I'll reopen this if one does.

AI-assisted.

**@⁠JB2WIN** on GitHub · 2026-11-29 22:00 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3517#issuecomment-7263323794) Closing this one. A remeasure of my local prototype with this change showed that it moves none of the 299: all of them have CLAMP_BORDER on X and Y, so they stop at the new `sampler border colour from a GPU value`. The cause is elsewhere. In all 299, word 3 is written by `s_brev_b32` (163), `s_bfe_u32` (67), or by a value that has already been through one of them (43). The symbol analysis does not fold either instruction even when the operands are constant. With the fold, word 3 is the constant 0x80000000 (OPAQUE_WHITE), and the sampler is literal. So the fold is the fix (claim on #3226, issuecomment-7263320436). A real GPU word 3 has not shown up in my captures. I'll reopen this if one does. AI-assisted.
Author
Owner

@⁠JB2WIN on GitHub · 2026-11-29 22:26 UTC · original

@⁠Leyukaka thanks. Our messages crossed: I closed this after the remeasure (comment above), because the 299 get a constant word 3 from the s_brev_b32/s_bfe_u32 fold instead. Both of your points still apply to that follow-up. Those 299 are comparison samplers with CLAMP_BORDER on X and Y, so the comparison path's border & 0x3ffff000 check will be checked on a real constant word 3 there. Its test will also include a CLAMP_Z = 7 case.

AI-assisted.

**@⁠JB2WIN** on GitHub · 2026-11-29 22:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3517#issuecomment-7263671152) @⁠Leyukaka thanks. Our messages crossed: I closed this after the remeasure (comment above), because the 299 get a constant word 3 from the `s_brev_b32`/`s_bfe_u32` fold instead. Both of your points still apply to that follow-up. Those 299 are comparison samplers with CLAMP_BORDER on X and Y, so the comparison path's `border & 0x3ffff000` check will be checked on a real constant word 3 there. Its test will also include a CLAMP_Z = 7 case. AI-assisted.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.