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

Closed
JB2WIN wants to merge 1 commit from upstream-pr/3517 into main
JB2WIN commented 2026-11-29 21:13:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T21:13:55Z.


Refs #3224, #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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5555186037 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3517). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T21:13:55Z. --- Refs #3224, #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)
Leyukaka commented 2026-11-29 21:32:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T21:32:15Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6104900960 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3517#pullrequestreview-6104900960). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T21:32:15Z. **Review:** COMMENTED --- 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.
JB2WIN commented 2026-11-29 22:00:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T22:00:12Z.


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 #3224, issuecomment-7263320436). A real GPU word 3 has not shown up in my captures. I'll reopen this if one does.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7263323794 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3517#issuecomment-7263323794). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T22:00:12Z. --- 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 #3224, issuecomment-7263320436). A real GPU word 3 has not shown up in my captures. I'll reopen this if one does. AI-assisted.
JB2WIN commented 2026-11-29 22:26:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T22:26:12Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7263671152 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3517#issuecomment-7263671152). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T22:26:12Z. --- @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

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!3517
No description provided.