startup: image_sample / _l / _lz drop the guest sampler LOD limits, and heap samplers pass unchecked #2169

Closed
opened 2026-11-25 02:56:59 +00:00 by JB2WIN · 6 comments
JB2WIN commented 2026-11-25 02:56:59 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:56:59Z.


Found while answering the review on #2051.

What happens today (tools/startup/gfx2hlsl.py and src/startup_stubs/translated_sampler_bindings.h, main):

  • image_sample, image_sample_l and image_sample_lz emit their constant sampler as a smp line. The runtime then builds the desktop sampler with MinLOD = 0 and MaxLOD unbounded, whatever the guest descriptor's MIN_LOD/MAX_LOD fields say (word 1, bits 11:0 and 23:12, both u4.8; RDNA 2 ISA section 8.2.7, Mesa gfx10-rsrc.json).
  • Heap and register samplers for these forms are accepted without any check of their LOD fields or bias.
  • image_sample_c already refuses MAX_LOD ≠ 0. #2051 carries MIN/MAX_LOD for image_sample_b through a new smpl line, and refuses heap or register samplers, a nonzero descriptor bias, mip filter 0 and MIN_LOD > MAX_LOD.

Effect. A guest sampler that clamps to a mip level, for example to hide a not-yet-streamed mip, reads a different level on the desktop, with no refusal. image_sample_l with an explicit LOD above the guest MAX_LOD is the clearest case.

Proposal (one PR, after #2051 lands):

  1. Emit smpl for image_sample, _l and _lz as well, so the limits are carried. The bias stays refused unless it is 0, as in #2051.
  2. Heap and register samplers: either refuse them for these forms too, or keep accepting them and log once that their limits are not applied. Refusing is the strict choice, but it would drop pipelines that translate today, so I'd like your call before changing that.
  3. Evidence: the same discriminator as in #2051 (guest MAX_LOD below a visible next mip, MIN_LOD above the implicit LOD), for each form on WARP and hardware, plus a control drawn through a plain smp line.

Which option do you want for point 2?

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6596153965 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T02:56:59Z. --- Found while answering the review on #2051. **What happens today** (`tools/startup/gfx2hlsl.py` and `src/startup_stubs/translated_sampler_bindings.h`, `main`): - `image_sample`, `image_sample_l` and `image_sample_lz` emit their constant sampler as a `smp` line. The runtime then builds the desktop sampler with `MinLOD = 0` and `MaxLOD` unbounded, whatever the guest descriptor's MIN_LOD/MAX_LOD fields say (word 1, bits 11:0 and 23:12, both u4.8; RDNA 2 ISA section 8.2.7, Mesa `gfx10-rsrc.json`). - Heap and register samplers for these forms are accepted without any check of their LOD fields or bias. - `image_sample_c` already refuses MAX_LOD ≠ 0. #2051 carries MIN/MAX_LOD for `image_sample_b` through a new `smpl` line, and refuses heap or register samplers, a nonzero descriptor bias, mip filter 0 and `MIN_LOD > MAX_LOD`. **Effect.** A guest sampler that clamps to a mip level, for example to hide a not-yet-streamed mip, reads a different level on the desktop, with no refusal. `image_sample_l` with an explicit LOD above the guest MAX_LOD is the clearest case. **Proposal** (one PR, after #2051 lands): 1. Emit `smpl` for `image_sample`, `_l` and `_lz` as well, so the limits are carried. The bias stays refused unless it is 0, as in #2051. 2. Heap and register samplers: either refuse them for these forms too, or keep accepting them and log once that their limits are not applied. Refusing is the strict choice, but it would drop pipelines that translate today, so I'd like your call before changing that. 3. Evidence: the same discriminator as in #2051 (guest MAX_LOD below a visible next mip, MIN_LOD above the implicit LOD), for each form on WARP and hardware, plus a control drawn through a plain `smp` line. Which option do you want for point 2? AI-assisted.
R0Y00 commented 2026-11-25 04:04:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:09:42Z.


Please take the independently reviewable constant-sampler slice after #2051. Carry the decoded LOD range for image_sample, _l and _lz, use the same validation for unhandled descriptor bias and malformed ranges, and show the three forms independently on WARP and hardware. Each comparison should have distinguishable mip values and a plain-smp control that reads a different level. Use an explicit LOD above MAX_LOD for _l, and a MIN_LOD above the effective starting LOD for the implicit and zero-LOD cases.

Keep existing heap/register behavior in this PR so the constant fix does not drop startup pipelines. Log once that these paths still have unvalidated LOD fields, and document the gap. To extend support, first show how the runtime can validate the actual sampler bound at draw time; use one non-default range that proves the dynamic path cannot accidentally fall through to an unconstrained sampler.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151649281 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7151649281). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:09:42Z. --- Please take the independently reviewable constant-sampler slice after #2051. Carry the decoded LOD range for `image_sample`, `_l` and `_lz`, use the same validation for unhandled descriptor bias and malformed ranges, and show the three forms independently on WARP and hardware. Each comparison should have distinguishable mip values and a plain-`smp` control that reads a different level. Use an explicit LOD above MAX_LOD for `_l`, and a MIN_LOD above the effective starting LOD for the implicit and zero-LOD cases. Keep existing heap/register behavior in this PR so the constant fix does not drop startup pipelines. Log once that these paths still have unvalidated LOD fields, and document the gap. To extend support, first show how the runtime can validate the actual sampler bound at draw time; use one non-default range that proves the dynamic path cannot accidentally fall through to an unconstrained sampler.
R0Y00 commented 2026-11-25 08:05:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T07:04:40Z.


The dependency #2051 is now on main (71c9c347). The independent Windows Release sampler and adjacent image checks passed 10/10. The existing constant-sampler slice is ready to continue from that base. Reuse the smpl manifest path and keep the three visible-mip discriminators from the earlier review. Runtime heap LOD remains under its separate #2221 claim.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7155462404 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7155462404). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T07:04:40Z. --- The dependency #2051 is now on main (71c9c347). The independent Windows Release sampler and adjacent image checks passed 10/10. The existing constant-sampler slice is ready to continue from that base. Reuse the smpl manifest path and keep the three visible-mip discriminators from the earlier review. Runtime heap LOD remains under its separate #2221 claim.
ChazY11 commented 2026-11-25 14:05:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T13:56:29Z.


Taking this, following the slice in your first comment and the base you named (71c9c347).

Plan, so you can redirect before I write anything:

  1. Carry the range, not just the sampler. image_sample, _l and _lz emit smpl with MIN_LOD/MAX_LOD decoded from word 1 (bits 11:0 and 23:12, u4.8), reusing the smpl manifest path #2051 added for image_sample_b rather than adding a second shape.
  2. Same validation as #2051 for these three forms: refuse a nonzero descriptor bias, mip filter 0, and MIN_LOD > MAX_LOD.
  3. Heap and register samplers keep translating, as you asked: no new refusal, one logged line saying their LOD fields are still unvalidated, plus the gap written into docs/experiments.md next to the form table.
  4. Evidence: the three discriminators you listed, each with distinguishable mip values and a plain-smp control that reads a different level — _l with an explicit LOD above MAX_LOD, and MIN_LOD above the effective starting LOD for image_sample and _lz. WARP and the card, with adapter/driver/build in the report.

Two things I will state in the PR rather than guess at:

  • whether image_sample's implicit LOD needs the gradient path to see the clamp at all, or whether MIN_LOD alone is enough to make the readback differ (I will measure it, and if the clamp is invisible without gradients I will say so instead of claiming a passing discriminator);
  • that the heap/register gap is documented and logged, not fixed — the runtime-side validation is #2221's, per your comment.

I will open the PR against main and keep it to the three forms; image_sample_c and image_sample_b are untouched.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164513209 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164513209). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T13:56:29Z. --- Taking this, following the slice in your first comment and the base you named (`71c9c347`). Plan, so you can redirect before I write anything: 1. **Carry the range, not just the sampler.** `image_sample`, `_l` and `_lz` emit `smpl` with MIN_LOD/MAX_LOD decoded from word 1 (bits 11:0 and 23:12, u4.8), reusing the `smpl` manifest path #2051 added for `image_sample_b` rather than adding a second shape. 2. **Same validation as #2051** for these three forms: refuse a nonzero descriptor bias, `mip filter 0`, and `MIN_LOD > MAX_LOD`. 3. **Heap and register samplers keep translating**, as you asked: no new refusal, one logged line saying their LOD fields are still unvalidated, plus the gap written into `docs/experiments.md` next to the form table. 4. **Evidence**: the three discriminators you listed, each with distinguishable mip values and a plain-`smp` control that reads a different level — `_l` with an explicit LOD above MAX_LOD, and MIN_LOD above the effective starting LOD for `image_sample` and `_lz`. WARP and the card, with adapter/driver/build in the report. Two things I will state in the PR rather than guess at: - whether `image_sample`'s implicit LOD needs the gradient path to see the clamp at all, or whether MIN_LOD alone is enough to make the readback differ (I will measure it, and if the clamp is invisible without gradients I will say so instead of claiming a passing discriminator); - that the heap/register gap is documented and logged, not fixed — the runtime-side validation is #2221's, per your comment. I will open the PR against `main` and keep it to the three forms; `image_sample_c` and `image_sample_b` are untouched. AI-assisted.
ChazY11 commented 2026-11-25 14:05:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T13:56:59Z.


Withdrawing my claim above: I checked main before starting and the slice is already there.

07c1c20f startup: carry the constant sampler LOD range for image_sample, _l and _lz (#2265)

tools/startup/gfx2hlsl.py on main already carries the decoded range for these three forms and validates them the way the first comment asked:

3050  elif how in ('sample', 'l', 'lz') and (heap or (words and self.default_sampler_words(words))):
3051      # ... its MIN_LOD, MAX_LOD and bias are not validated here (#2221).
3053      self.pipe.lod_unvalidated.add(name)          # logged once, keyed by form
3055  elif how in ('sample', 'l', 'lz') and words:
3059      self.lod_sampler_words(name, words, mip_filter_none_ok=True)
3060      smp = self.pipe.sampler(tuple(words), lod_limits=bool((words[2] >> 26) & 3))

and lod_sampler_words() names this issue in its docstring, sharing the bias / mip filter 0 / MIN_LOD > MAX_LOD refusals with image_sample_b.

So the constant-sampler work, the log-once for heap and register samplers, and the documented gap are all in #2265. I should have looked before claiming — my apologies for the notification.

What is still open in this issue, as far as I can tell from the code rather than the comments:

  • the three visible-mip discriminators and the plain-smp control — whether they exist as a check I could not tell from the diff alone, and that is the part I would verify next;
  • the runtime-side validation of a sampler actually bound at draw time, which your comment assigns to #2221.

If you want either of those, say which and I will take it. Otherwise I will leave the issue alone and go back to the operand-arity work (#2360) rather than duplicate #2265.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164525830 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164525830). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T13:56:59Z. --- Withdrawing my claim above: I checked `main` before starting and the slice is already there. ```text 07c1c20f startup: carry the constant sampler LOD range for image_sample, _l and _lz (#2265) ``` `tools/startup/gfx2hlsl.py` on `main` already carries the decoded range for these three forms and validates them the way the first comment asked: ```text 3050 elif how in ('sample', 'l', 'lz') and (heap or (words and self.default_sampler_words(words))): 3051 # ... its MIN_LOD, MAX_LOD and bias are not validated here (#2221). 3053 self.pipe.lod_unvalidated.add(name) # logged once, keyed by form 3055 elif how in ('sample', 'l', 'lz') and words: 3059 self.lod_sampler_words(name, words, mip_filter_none_ok=True) 3060 smp = self.pipe.sampler(tuple(words), lod_limits=bool((words[2] >> 26) & 3)) ``` and `lod_sampler_words()` names this issue in its docstring, sharing the bias / `mip filter 0` / `MIN_LOD > MAX_LOD` refusals with `image_sample_b`. So the constant-sampler work, the log-once for heap and register samplers, and the documented gap are all in `#2265`. I should have looked before claiming — my apologies for the notification. What is still open in this issue, as far as I can tell from the code rather than the comments: - the three visible-mip discriminators and the plain-`smp` control — whether they exist as a check I could not tell from the diff alone, and that is the part I would verify next; - the runtime-side validation of a sampler actually bound at draw time, which your comment assigns to #2221. If you want either of those, say which and I will take it. Otherwise I will leave the issue alone and go back to the operand-arity work (#2360) rather than duplicate `#2265`. AI-assisted.
ChazY11 commented 2026-11-25 14:05:16 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T13:59:43Z.


Ran the discriminators on a third adapter: all three forms and all three controls behave as the issue asked

Independent of the author's machine, on main at 2b30559b, Windows 11 build 26300.9974, DXC 10.0.26100.0, offscreen_check rebuilt from main:

controls                                                                    exit 0
dxc <renderer> warp  tests/startup_image_sample_lod_check.py draw ...       exit 0
dxc <renderer> hardware                                                     exit 0

Per form, WARP (the card prints the same lines; the only difference I saw is the descriptor heap size, 2097152 vs 1000000):

image_sample_l   slice=0 reads mip 1: 3e880000,3f800000,00000000,40000000
                 slice=1 reads mip 1: 3ec80000,3f800000,00000000,40400000
                 plain smp control fails as expected, reads mip 2

image_sample     slice=0 reads mip 2: 3f020000,00000000,00000000,40800000
                 slice=1 reads mip 2: 3f220000,00000000,00000000,40a00000
                 plain smp control fails as expected, reads mip 1

image_sample_lz  slice=0 reads mip 1: 3e880000,3f800000,00000000,40000000
                 slice=1 reads mip 1: 3ec80000,3f800000,00000000,40400000
                 plain smp control fails as expected, reads mip 0

So the two properties the first comment asked for both hold on hardware I did not write this on:

  1. the clamp is visible — each form reads a different mip than its plain-smp control (1 vs 2, 2 vs 1, 1 vs 0), so the discriminator is the sampler range and not something incidental about the scene;
  2. the control really is a control — it fails as expected in every case rather than passing by reading the same mip through a different path.

Adapter on this machine: NVIDIA GeForce RTX 5080 Laptop GPU, driver 32.0.15.8142. Debug layer enabled for both runs, debug_errors=0 debug_warnings=0.

Controls half, for the record:

image_sample / _l / _lz: smpl line and call; refused: LOD bias, MIN_LOD > MAX_LOD;
                         mip filter 0 stays smp; heap accepted and logged once
translate_to logs the unvalidated heap sampler once, and nothing for a constant sampler
draw model: every form reads its limit mip and its control reads another

With this, the constant-sampler slice of this issue is measured on three adapters (the author's, mine, and WARP on both) and the only part I can see still open is the run-time validation of a sampler actually bound at draw time, which your earlier comment assigns to #2221. Nothing else from my side — my earlier claim on this issue is withdrawn in the comment above.

AI-assisted; the three commands above were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164593761 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164593761). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T13:59:43Z. --- ## Ran the discriminators on a third adapter: all three forms and all three controls behave as the issue asked Independent of the author's machine, on `main` at `2b30559b`, Windows 11 build 26300.9974, DXC 10.0.26100.0, `offscreen_check` rebuilt from `main`: ```text controls exit 0 dxc <renderer> warp tests/startup_image_sample_lod_check.py draw ... exit 0 dxc <renderer> hardware exit 0 ``` Per form, WARP (the card prints the same lines; the only difference I saw is the descriptor heap size, 2097152 vs 1000000): ```text image_sample_l slice=0 reads mip 1: 3e880000,3f800000,00000000,40000000 slice=1 reads mip 1: 3ec80000,3f800000,00000000,40400000 plain smp control fails as expected, reads mip 2 image_sample slice=0 reads mip 2: 3f020000,00000000,00000000,40800000 slice=1 reads mip 2: 3f220000,00000000,00000000,40a00000 plain smp control fails as expected, reads mip 1 image_sample_lz slice=0 reads mip 1: 3e880000,3f800000,00000000,40000000 slice=1 reads mip 1: 3ec80000,3f800000,00000000,40400000 plain smp control fails as expected, reads mip 0 ``` So the two properties the first comment asked for both hold on hardware I did not write this on: 1. **the clamp is visible** — each form reads a different mip than its plain-`smp` control (1 vs 2, 2 vs 1, 1 vs 0), so the discriminator is the sampler range and not something incidental about the scene; 2. **the control really is a control** — it fails as expected in every case rather than passing by reading the same mip through a different path. Adapter on this machine: NVIDIA GeForce RTX 5080 Laptop GPU, driver 32.0.15.8142. Debug layer enabled for both runs, `debug_errors=0 debug_warnings=0`. Controls half, for the record: ```text image_sample / _l / _lz: smpl line and call; refused: LOD bias, MIN_LOD > MAX_LOD; mip filter 0 stays smp; heap accepted and logged once translate_to logs the unvalidated heap sampler once, and nothing for a constant sampler draw model: every form reads its limit mip and its control reads another ``` With this, the constant-sampler slice of this issue is measured on three adapters (the author's, mine, and WARP on both) and the only part I can see still open is the run-time validation of a sampler actually bound at draw time, which your earlier comment assigns to #2221. Nothing else from my side — my earlier claim on this issue is withdrawn in the comment above. AI-assisted; the three commands above were executed locally.
R0Y00 commented 2026-11-25 15:01:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T14:10:10Z.


Closing the constant-sampler issue after #2265. The independent RTX 5080 Laptop and WARP rerun reproduced all three discriminators: image_sample_l read mip 1 vs 2, image_sample read 2 vs 1, and image_sample_lz read 1 vs 0, each against its plain sampler control. The report has the adapter, driver and debug-layer result: https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164593761. Heap entries apply their runtime LOD limits through #2287, with the remaining scope documented in #2330 and tracked in #2221.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164862242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164862242). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T14:10:10Z. --- Closing the constant-sampler issue after #2265. The independent RTX 5080 Laptop and WARP rerun reproduced all three discriminators: image_sample_l read mip 1 vs 2, image_sample read 2 vs 1, and image_sample_lz read 1 vs 0, each against its plain sampler control. The report has the adapter, driver and debug-layer result: https://github.com/R0Y00/Xbox2Windows/issues/2177#issuecomment-7164593761. Heap entries apply their runtime LOD limits through #2287, with the remaining scope documented in #2330 and tracked in #2221.
Sign in to join this conversation.
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#2169
No description provided.