textures: accept fixed-point texel snapping in magnified BC7 tail draws #308

Merged
rasptum merged 2 commits from upstream-pr/313 into main 2026-11-21 22:27:35 +00:00
rasptum commented 2026-11-21 21:47:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-21T21:47:17Z.


Change

bc7_draw_warp fails on the Windows 10 in-box WARP (10.0.19041.5794) on unmodified main (b53bfb0):

AssertionError: Tail draw failed for 4096x4 at mip 11:
requested_mip=0 sampled_mip=11
pixel_mismatch x=2044 y=0
channel=0 expected=0.0627441 actual=0.113708
channel=1 expected=0.0235291 actual=0.0705566
channel=2 expected=0.0941162 actual=0.125488
channel=3 expected=0.235229 actual=0.282227

The actual value is the second texel of the 2x1 mip (29, 18, 32, 72 of 255), read four pixels before the texel boundary at x=2048. This adapter converts the scaled texture coordinate to fixed point with 8 fractional bits, rounding to nearest, before it picks the point-sampled texel. A pixel center within 1/512 texel below a boundary therefore selects the next texel. The reference in draw_verified expected floor() of the exact coordinate for those pixels. Only the tail draws that magnify by 256x or more have such pixels, which is why only 4096x4 and 4x4096 at first resident mip 11 fail.

This PR accepts the next texel for exactly those pixels (center at or above 511/512 of a texel), as a whole RGBA texel, next to the existing exact-boundary case in tests/pixel_aot_render.cpp. No expected value changes and no fixture is removed. The translator is not involved: the copy shader samples with the interpolated coordinate as is.

It solves an independent problem (a test assumption stricter than the adapter's addressing precision) and makes the texture check usable on Windows 10 without the Agility SDK. It touches the compare loop of draw_verified only. #283 changes other hunks of the same file and does not overlap textually.

Verification

Commit e7ac54e on b53bfb0. Windows 10 22H2 (19045), debug layer enabled, debug_errors=0 debug_warnings=0. Adapters: in-box WARP 10.0.19041.5794; app-local WARP 1.0.22 with Agility SDK 1.620.2; NVIDIA GeForce RTX 3060, driver 596.36.

ctest --preset dev --no-tests=error -R '^bc7_draw_(warp|hardware)$'
Build Before (b53bfb0) After
in-box runtime, in-box WARP bc7_draw_warp failed, bc7_draw_hardware passed 2 of 2 passed
Agility 1.620.2, WARP 1.0.22 2 of 2 passed 2 of 2 passed

Full suite, ctest --preset dev --no-tests=error, 143 tests registered:

Build Passed Skipped (77) Failed
in-box runtime, in-box WARP 125 17 1: gpu_alias_lookup_writes_warp
Agility 1.620.2, WARP 1.0.22 138 3 2: bvh_wave64_warp, wave_shuffle_warp

The three remaining failures do not go through the changed code. bvh_wave64_warp and wave_shuffle_warp on WARP 1.0.22 are the lane misrouting tracked in #145. gpu_alias_lookup_writes_warp fails only on the in-box WARP (record=1 field=64 expected=0001f5a0 actual=0007d680) and passes on WARP 1.0.22; I have not investigated it yet.

New negative control in tests/bc7_draw_check.py: the copy shader with its coordinate shifted by 1/64 texel must still fail on the 4096x4 draw of the 2x1 mip. Measured first mismatch: x=2016 on the RTX 3060 and on WARP 1.0.22, x=2012 on the in-box WARP (2016 minus the same 4-pixel band). The control accepts x in 2012..2016 at y=0 and nothing else.

Evidence and follow-up

Measured with a local diagnostic build that counts mismatching pixels instead of stopping at the first (not part of this PR). Sub-case sweep of the 15 positive draws of bc7_draw_check.py:

Adapter Failing sub-cases
in-box WARP 10.0.19041.5794 2: tail 4096x4 first=11, tail 4x4096 first=11
WARP 1.0.9, 1.0.13, 1.0.15.1, 1.0.16.1, 1.0.17, 1.0.19, 1.0.20, 1.0.21, 1.0.22 0
RTX 3060, driver 596.36 0

Mismatching pixels per draw of the 2x1 mip on the in-box WARP, all of them equal to the next texel as a whole RGBA value:

Target Magnification Mismatching pixels Predicted by 8-bit round to nearest
4096x4 2048x 16 (x=2044..2047, 4 rows) 16
2048x2 1024x 4 (x=1022..1023, 2 rows) 4
1024x1 512x 1 (x=511) 1
512x1 256x 1 (x=255, an exact tie at 255.5/256) 1 if ties round up
256x1 and smaller 128x and below 0 0

The 4x4096 case is the same along y. Uploading the same texels as R8G8B8A8_UNORM instead of BC7 gives identical counts, so BC7 decoding, the sub-block upload and mip selection are not involved.

Assumptions and limits:

  • Direct3D defines texel addressing precision as 8 fractional bits: d3d12.h has D3D12_SUBTEXEL_FRACTIONAL_BIT_COUNT = 8, and the Direct3D 11.3 functional specification (3.2.4) says texture coordinates are snapped to fixed point after scaling by the texture size. That the in-box WARP rounds to nearest at that precision is inferred from the measured counts, not from WARP's code.
  • The tolerance is one-sided (only the next texel) and fixed at 1/512 texel. An adapter with fewer fractional bits would still fail, which is intended.
  • Only this one Windows 10 build and WARP version was measured. Other in-box WARP versions were not available.

docs/experiments.md gains one sentence in the tail-check paragraph. The reproduction command is unchanged.

AI-assisted (Claude Code). The Windows results were measured locally.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6534806228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/313). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-21T21:47:17Z. --- ## Change `bc7_draw_warp` fails on the Windows 10 in-box WARP (10.0.19041.5794) on unmodified `main` (b53bfb0): ``` AssertionError: Tail draw failed for 4096x4 at mip 11: requested_mip=0 sampled_mip=11 pixel_mismatch x=2044 y=0 channel=0 expected=0.0627441 actual=0.113708 channel=1 expected=0.0235291 actual=0.0705566 channel=2 expected=0.0941162 actual=0.125488 channel=3 expected=0.235229 actual=0.282227 ``` The actual value is the second texel of the 2x1 mip (29, 18, 32, 72 of 255), read four pixels before the texel boundary at x=2048. This adapter converts the scaled texture coordinate to fixed point with 8 fractional bits, rounding to nearest, before it picks the point-sampled texel. A pixel center within 1/512 texel below a boundary therefore selects the next texel. The reference in `draw_verified` expected `floor()` of the exact coordinate for those pixels. Only the tail draws that magnify by 256x or more have such pixels, which is why only `4096x4` and `4x4096` at first resident mip 11 fail. This PR accepts the next texel for exactly those pixels (center at or above 511/512 of a texel), as a whole RGBA texel, next to the existing exact-boundary case in `tests/pixel_aot_render.cpp`. No expected value changes and no fixture is removed. The translator is not involved: the copy shader samples with the interpolated coordinate as is. It solves an independent problem (a test assumption stricter than the adapter's addressing precision) and makes the texture check usable on Windows 10 without the Agility SDK. It touches the compare loop of `draw_verified` only. #283 changes other hunks of the same file and does not overlap textually. ## Verification Commit e7ac54e on b53bfb0. Windows 10 22H2 (19045), debug layer enabled, `debug_errors=0 debug_warnings=0`. Adapters: in-box WARP 10.0.19041.5794; app-local WARP 1.0.22 with Agility SDK 1.620.2; NVIDIA GeForce RTX 3060, driver 596.36. ``` ctest --preset dev --no-tests=error -R '^bc7_draw_(warp|hardware)$' ``` | Build | Before (b53bfb0) | After | |---|---|---| | in-box runtime, in-box WARP | `bc7_draw_warp` failed, `bc7_draw_hardware` passed | 2 of 2 passed | | Agility 1.620.2, WARP 1.0.22 | 2 of 2 passed | 2 of 2 passed | Full suite, `ctest --preset dev --no-tests=error`, 143 tests registered: | Build | Passed | Skipped (77) | Failed | |---|---|---|---| | in-box runtime, in-box WARP | 125 | 17 | 1: `gpu_alias_lookup_writes_warp` | | Agility 1.620.2, WARP 1.0.22 | 138 | 3 | 2: `bvh_wave64_warp`, `wave_shuffle_warp` | The three remaining failures do not go through the changed code. `bvh_wave64_warp` and `wave_shuffle_warp` on WARP 1.0.22 are the lane misrouting tracked in #145. `gpu_alias_lookup_writes_warp` fails only on the in-box WARP (`record=1 field=64 expected=0001f5a0 actual=0007d680`) and passes on WARP 1.0.22; I have not investigated it yet. New negative control in `tests/bc7_draw_check.py`: the copy shader with its coordinate shifted by 1/64 texel must still fail on the 4096x4 draw of the 2x1 mip. Measured first mismatch: x=2016 on the RTX 3060 and on WARP 1.0.22, x=2012 on the in-box WARP (2016 minus the same 4-pixel band). The control accepts x in 2012..2016 at y=0 and nothing else. ## Evidence and follow-up Measured with a local diagnostic build that counts mismatching pixels instead of stopping at the first (not part of this PR). Sub-case sweep of the 15 positive draws of `bc7_draw_check.py`: | Adapter | Failing sub-cases | |---|---| | in-box WARP 10.0.19041.5794 | 2: tail 4096x4 first=11, tail 4x4096 first=11 | | WARP 1.0.9, 1.0.13, 1.0.15.1, 1.0.16.1, 1.0.17, 1.0.19, 1.0.20, 1.0.21, 1.0.22 | 0 | | RTX 3060, driver 596.36 | 0 | Mismatching pixels per draw of the 2x1 mip on the in-box WARP, all of them equal to the next texel as a whole RGBA value: | Target | Magnification | Mismatching pixels | Predicted by 8-bit round to nearest | |---|---|---|---| | 4096x4 | 2048x | 16 (x=2044..2047, 4 rows) | 16 | | 2048x2 | 1024x | 4 (x=1022..1023, 2 rows) | 4 | | 1024x1 | 512x | 1 (x=511) | 1 | | 512x1 | 256x | 1 (x=255, an exact tie at 255.5/256) | 1 if ties round up | | 256x1 and smaller | 128x and below | 0 | 0 | The 4x4096 case is the same along y. Uploading the same texels as `R8G8B8A8_UNORM` instead of BC7 gives identical counts, so BC7 decoding, the sub-block upload and mip selection are not involved. Assumptions and limits: - Direct3D defines texel addressing precision as 8 fractional bits: `d3d12.h` has `D3D12_SUBTEXEL_FRACTIONAL_BIT_COUNT` = 8, and the Direct3D 11.3 functional specification (3.2.4) says texture coordinates are snapped to fixed point after scaling by the texture size. That the in-box WARP rounds to nearest at that precision is inferred from the measured counts, not from WARP's code. - The tolerance is one-sided (only the next texel) and fixed at 1/512 texel. An adapter with fewer fractional bits would still fail, which is intended. - Only this one Windows 10 build and WARP version was measured. Other in-box WARP versions were not available. `docs/experiments.md` gains one sentence in the tail-check paragraph. The reproduction command is unchanged. _AI-assisted (Claude Code). The Windows results were measured locally._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:42:22 +00:00
R0Y00 commented 2026-11-24 06:48:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:57:00Z.


The cross-adapter reference adjustment is approved specifically for point-sampled magnified tail mips. Keep the exact texel as the first choice. On each axis admit its immediate neighbor only where quantization can cross an actual boundary (up to 1/512 texel below, including the tie). Use a whole RGBA tuple from the same mip, with the existing edge addressing. Please show controls just inside and outside the interval and a mixed-channel negative control, alongside the existing wrong-mip and offset controls. In the notes distinguish the observed Win10 WARP values from the precision model inferred from them.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069832719 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/313#issuecomment-7069832719). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:57:00Z. --- The cross-adapter reference adjustment is approved specifically for point-sampled magnified tail mips. Keep the exact texel as the first choice. On each axis admit its immediate neighbor only where quantization can cross an actual boundary (up to 1/512 texel below, including the tie). Use a whole RGBA tuple from the same mip, with the existing edge addressing. Please show controls just inside and outside the interval and a mixed-channel negative control, alongside the existing wrong-mip and offset controls. In the notes distinguish the observed Win10 WARP values from the precision model inferred from them.
rasptum commented 2026-11-24 06:48:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-21T22:24:40Z.


Thanks, implemented in the follow-up commit. Point by point:

Scope: point-sampled magnified tail mips only. The neighbor branch runs only when req.isTailDraw && req.scale > 1. Only check_bc7_tail sets isTailDraw, and scale > 1 holds only for a requested mip above the first resident one. The renderer has a single static sampler (FILTER_MIN_MAG_MIP_POINT, clamp), so no other filter can reach it. A comment at the branch now says so.

Exact texel first. Unchanged: matches(expected) runs before anything else, and the neighbor branch is entered only if it fails.

One immediate neighbor per axis, only where quantization can cross a boundary. I replaced the 3x3 candidate loop with an explicit per-axis neighbor. Per axis it is the previous texel for a center exactly on a boundary (the case that already existed), the next texel for a center at or above 511/512 of a texel (tie included), and otherwise none. The candidates are then (near x, exact y), (exact x, near y) and (near x, near y). The diagonal is reachable only when both axes are inside their own interval. The old loop admitted the same set, so this is a readability change, not a behavior change.

Same mip, whole RGBA tuple, existing edge addressing. Candidates come from sampled.expected of the sampled level and are compared with one memcmp over the four channels. On the last texel of an axis no neighbor is admitted, since clamp addressing has no boundary above it.

Controls. Each control shader replaces chosen pixels with a texel fetched at its center, so the readback is identical on every adapter and the test exercises the acceptance logic itself, not the adapter's rounding. All use the 2x1 (or 1x2) mip at first resident mip 11.

Control Pixel replaced Returned Required result
inside x=2044 of 4096, and the tie x=255 of 512 next texel pass
outside x=2043 of 4096 next texel pixel_mismatch x=2043 y=0
outside-tie x=254 of 512 next texel pixel_mismatch x=254 y=0
mixed x=2044 of 4096 R,B of first texel with G,A of second pixel_mismatch x=2044 y=0
previous x=2048 of 4096 previous texel pixel_mismatch x=2048 y=0
edge x=4095 of 4096 first texel pixel_mismatch x=4095 y=0
inside-y y=2044 of 4096 next texel pass
outside-y y=2043 of 4096 next texel pixel_mismatch x=0 y=2043

The existing wrong-mip controls and the 1/64-texel offset control are unchanged.

Each control fails when the logic is broken locally (not committed), on WARP 1.0.22, the RTX 3060 and the in-box WARP alike:

Local change Control that fails
band widened to 1/256 outside
band removed inside (on the in-box WARP the plain 4096x4 tail draw fails first)
tie excluded (> for >=) inside (same note)
tuple check relaxed to per channel mixed
edge wraps instead of clamping edge

Observed versus inferred. docs/experiments.md now states them separately.

  • Observed on Windows 10 WARP 10.0.19041.5794: drawing the 2x1 mip of 4096x4 returned the second texel at 16 pixels of the 4096x4 target (x=2044..2047 in each row), 4 of 2048x2, 1 of 1024x1 (x=511), 1 of 512x1 (x=255) and none below. Same counts along y for 4x4096, and for the same texels as R8G8B8A8_UNORM. WARP 1.0.9 through 1.0.22 and the RTX 3060 returned the first texel at all of them.
  • Inferred: those positions are exactly where rounding the scaled coordinate to the nearest 1/256 texel, ties upward, reaches the boundary. D3D12_SUBTEXEL_FRACTIONAL_BIT_COUNT is 8 in d3d12.h, which fits the model but does not show how that WARP is implemented.

Results. Windows 10 22H2 (19045), debug layer enabled, RTX 3060 on driver 32.0.15.9636, branch rebased on 6ee2406 (head 4d65fc3).

ctest --preset dev --no-tests=error --timeout 120 -R '^bc7_draw_(warp|hardware)$': 2 of 2 passed on the in-box build (WARP 10.0.19041.5794) and 2 of 2 on the Agility 1.620.2 build with WARP 1.0.22.

Both were rerun after the final rebase, together with pixel_aot_warp and pixel_aot_hardware: 4 of 4 passed on each build.

Full suite, 143 tests, measured on the same two commits before that rebase (on 1292d15):

Build Passed Skipped (77) Failed
in-box runtime, in-box WARP 125 17 1: gpu_alias_lookup_writes_warp
Agility 1.620.2, WARP 1.0.22 138 3 2: bvh_wave64_warp, wave_shuffle_warp

The three failures are the same as before this PR and do not go through the changed code. The two on WARP 1.0.22 are the lane misrouting from #145. gpu_alias_lookup_writes_warp fails only on the in-box WARP and I have not investigated it.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070161686 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/313#issuecomment-7070161686). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-21T22:24:40Z. --- Thanks, implemented in the follow-up commit. Point by point: **Scope: point-sampled magnified tail mips only.** The neighbor branch runs only when `req.isTailDraw && req.scale > 1`. Only `check_bc7_tail` sets `isTailDraw`, and `scale > 1` holds only for a requested mip above the first resident one. The renderer has a single static sampler (`FILTER_MIN_MAG_MIP_POINT`, clamp), so no other filter can reach it. A comment at the branch now says so. **Exact texel first.** Unchanged: `matches(expected)` runs before anything else, and the neighbor branch is entered only if it fails. **One immediate neighbor per axis, only where quantization can cross a boundary.** I replaced the 3x3 candidate loop with an explicit per-axis neighbor. Per axis it is the previous texel for a center exactly on a boundary (the case that already existed), the next texel for a center at or above 511/512 of a texel (tie included), and otherwise none. The candidates are then (near x, exact y), (exact x, near y) and (near x, near y). The diagonal is reachable only when both axes are inside their own interval. The old loop admitted the same set, so this is a readability change, not a behavior change. **Same mip, whole RGBA tuple, existing edge addressing.** Candidates come from `sampled.expected` of the sampled level and are compared with one `memcmp` over the four channels. On the last texel of an axis no neighbor is admitted, since clamp addressing has no boundary above it. **Controls.** Each control shader replaces chosen pixels with a texel fetched at its center, so the readback is identical on every adapter and the test exercises the acceptance logic itself, not the adapter's rounding. All use the 2x1 (or 1x2) mip at first resident mip 11. | Control | Pixel replaced | Returned | Required result | |---|---|---|---| | inside | x=2044 of 4096, and the tie x=255 of 512 | next texel | pass | | outside | x=2043 of 4096 | next texel | `pixel_mismatch x=2043 y=0` | | outside-tie | x=254 of 512 | next texel | `pixel_mismatch x=254 y=0` | | mixed | x=2044 of 4096 | R,B of first texel with G,A of second | `pixel_mismatch x=2044 y=0` | | previous | x=2048 of 4096 | previous texel | `pixel_mismatch x=2048 y=0` | | edge | x=4095 of 4096 | first texel | `pixel_mismatch x=4095 y=0` | | inside-y | y=2044 of 4096 | next texel | pass | | outside-y | y=2043 of 4096 | next texel | `pixel_mismatch x=0 y=2043` | The existing wrong-mip controls and the 1/64-texel offset control are unchanged. Each control fails when the logic is broken locally (not committed), on WARP 1.0.22, the RTX 3060 and the in-box WARP alike: | Local change | Control that fails | |---|---| | band widened to 1/256 | outside | | band removed | inside (on the in-box WARP the plain 4096x4 tail draw fails first) | | tie excluded (`>` for `>=`) | inside (same note) | | tuple check relaxed to per channel | mixed | | edge wraps instead of clamping | edge | **Observed versus inferred.** `docs/experiments.md` now states them separately. - Observed on Windows 10 WARP 10.0.19041.5794: drawing the 2x1 mip of 4096x4 returned the second texel at 16 pixels of the 4096x4 target (x=2044..2047 in each row), 4 of 2048x2, 1 of 1024x1 (x=511), 1 of 512x1 (x=255) and none below. Same counts along y for 4x4096, and for the same texels as `R8G8B8A8_UNORM`. WARP 1.0.9 through 1.0.22 and the RTX 3060 returned the first texel at all of them. - Inferred: those positions are exactly where rounding the scaled coordinate to the nearest 1/256 texel, ties upward, reaches the boundary. `D3D12_SUBTEXEL_FRACTIONAL_BIT_COUNT` is 8 in `d3d12.h`, which fits the model but does not show how that WARP is implemented. **Results.** Windows 10 22H2 (19045), debug layer enabled, RTX 3060 on driver 32.0.15.9636, branch rebased on 6ee2406 (head `4d65fc3`). `ctest --preset dev --no-tests=error --timeout 120 -R '^bc7_draw_(warp|hardware)$'`: 2 of 2 passed on the in-box build (WARP 10.0.19041.5794) and 2 of 2 on the Agility 1.620.2 build with WARP 1.0.22. Both were rerun after the final rebase, together with `pixel_aot_warp` and `pixel_aot_hardware`: 4 of 4 passed on each build. Full suite, 143 tests, measured on the same two commits before that rebase (on 1292d15): | Build | Passed | Skipped (77) | Failed | |---|---|---|---| | in-box runtime, in-box WARP | 125 | 17 | 1: `gpu_alias_lookup_writes_warp` | | Agility 1.620.2, WARP 1.0.22 | 138 | 3 | 2: `bvh_wave64_warp`, `wave_shuffle_warp` | The three failures are the same as before this PR and do not go through the changed code. The two on WARP 1.0.22 are the lane misrouting from #145. `gpu_alias_lookup_writes_warp` fails only on the in-box WARP and I have not investigated it. _AI-assisted (Claude Code)._
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!308
No description provided.