textures: preserve implicit LOD for rounded mip dimensions #226

Manually merged
github merged 1 commit from gh-pr/226/head into gh-pr/226/base 2026-11-26 21:35:44 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 18:42 UTC · original
Vonsek:codex/bc7-npot-lod → main · +24 −9 · 2 files · 1 commits · merged 2026-11-21 19:11 UTC

Change

Addresses the mip-selection finding on #204. Keep implicit mip selection stable when a BC7 level has rounded-down logical dimensions. For a 28×128 texture, mip 4 has a 1×8 render target. Mapping the entire width to one pixel gives a horizontal derivative of 28 texels per pixel, large enough for the point-mip sampler to select level 5. A centered 1.75×8 viewport gives the intended derivative of 16 while keeping the same eight readback texels.

Verification

Base f02c237, change 8cd88b7, Windows 11 x64 build 26200, Python 3.12.10. From a fresh worktree:

python -m venv out/pe-env
.\out\pe-env\Scripts\python.exe -m pip install -r requirements-dev.txt
. ./tools/dev.ps1
$npotPython = (Resolve-Path out/pe-env/Scripts/python.exe).Path
cmake --preset dev "-DINTAKE_PYTHON=$npotPython"
cmake --build --preset dev --target offscreen_check --parallel 4
ctest --preset dev --no-tests=error -R '^(bc7_draw|pixel_aot)_(warp|hardware)$' -V
$npotDxc = (Get-Command dxc.exe).Source
.\out\pe-env\Scripts\python.exe -B tests/bc7_draw_check.py $npotDxc out/build/dev/offscreen_check.exe warp

Before the change, both WARP and hardware failed the independent 28×128 reproducer at mip 4, pixel (0, 0). With the block's red endpoint set to the mip number times eight, the shader returned 0.15686 (level 5) against the expected 0.125488 (level 4). The 188×4 case from review also failed on both adapters at mip 6, pixel (0, 0). Red was 0.0627441 expected and 0.0313721 observed. With the change both mip 6 and mip 7 matched exactly. The new regression test failed at the rounded level on the base renderer. After the change, each adapter matched all 32 channels at mip 4 in both orientations and checked the chain down to 1×1. All four CTests and the direct WARP invocation passed. WARP used the Microsoft Basic Render Driver 10.0.26100.9818. Hardware used the NVIDIA GeForce RTX 5080 on driver 32.0.16.1692. The debug layer was unavailable for both. No skips.

Evidence and follow-up

The MIT-licensed fixture generates a repeating mode-6 BC7 block that gives each level a different endpoint. It keeps only the visible texels from each edge block in the expected RGBA image. The 28×128 chain starts at resident mip 2, and the transposed 128×28 chain starts at mip 0. The new comparison runs through the existing translated copy shader and point sampler.

AI-assisted contribution.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for the fixture checks.
  • I considered a negative control or failure case for a new fixture.
  • I checked whether README or build instructions needed a change; the existing commands apply.
  • I did not include game files, dumps, distribution links or secrets.
**@⁠Vonsek** on GitHub · 2026-11-21 18:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/226) `Vonsek:codex/bc7-npot-lod` → `main` · +24 −9 · 2 files · 1 commits · merged 2026-11-21 19:11 UTC ## Change Addresses [the mip-selection finding on #204](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/204). Keep implicit mip selection stable when a BC7 level has rounded-down logical dimensions. For a 28×128 texture, mip 4 has a 1×8 render target. Mapping the entire width to one pixel gives a horizontal derivative of 28 texels per pixel, large enough for the point-mip sampler to select level 5. A centered 1.75×8 viewport gives the intended derivative of 16 while keeping the same eight readback texels. ## Verification Base `f02c237`, change `8cd88b7`, Windows 11 x64 build 26200, Python 3.12.10. From a fresh worktree: ```powershell python -m venv out/pe-env .\out\pe-env\Scripts\python.exe -m pip install -r requirements-dev.txt . ./tools/dev.ps1 $npotPython = (Resolve-Path out/pe-env/Scripts/python.exe).Path cmake --preset dev "-DINTAKE_PYTHON=$npotPython" cmake --build --preset dev --target offscreen_check --parallel 4 ctest --preset dev --no-tests=error -R '^(bc7_draw|pixel_aot)_(warp|hardware)$' -V $npotDxc = (Get-Command dxc.exe).Source .\out\pe-env\Scripts\python.exe -B tests/bc7_draw_check.py $npotDxc out/build/dev/offscreen_check.exe warp ``` Before the change, both WARP and hardware failed the independent 28×128 reproducer at mip 4, pixel (0, 0). With the block's red endpoint set to the mip number times eight, the shader returned 0.15686 (level 5) against the expected 0.125488 (level 4). The 188×4 case from review also failed on both adapters at mip 6, pixel (0, 0). Red was 0.0627441 expected and 0.0313721 observed. With the change both mip 6 and mip 7 matched exactly. The new regression test failed at the rounded level on the base renderer. After the change, each adapter matched all 32 channels at mip 4 in both orientations and checked the chain down to 1×1. All four CTests and the direct WARP invocation passed. WARP used the Microsoft Basic Render Driver 10.0.26100.9818. Hardware used the NVIDIA GeForce RTX 5080 on driver 32.0.16.1692. The debug layer was unavailable for both. No skips. ## Evidence and follow-up The MIT-licensed fixture generates a repeating mode-6 BC7 block that gives each level a different endpoint. It keeps only the visible texels from each edge block in the expected RGBA image. The 28×128 chain starts at resident mip 2, and the transposed 128×28 chain starts at mip 0. The new comparison runs through the existing translated copy shader and point sampler. AI-assisted contribution. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for the fixture checks. - [x] I considered a negative control or failure case for a new fixture. - [x] I checked whether README or build instructions needed a change; the existing commands apply. - [x] I did not include game files, dumps, distribution links or secrets.
An integer viewport can shrink a non-power-of-two mip enough to sample the next coarser level. Center the unrounded viewport over the logical render target to preserve the requested gradients and texel centers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:35:43 +00:00
github manually merged commit 8cd88b72c4 into gh-pr/226/base 2026-11-26 21:35:44 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-21 18:42 UTC · original · edited 2026-11-21 18:46 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T18:46:09.959824Z 8cd88b7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-21 18:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/226#issuecomment-7067455170) · edited 2026-11-21 18:46 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"8cd88b72c439338e292b0e5798ffee7ae660c339","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T18:46:09.959824Z">2026-11-21T18:46:09.959824Z</relative-time> | `8cd88b7` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠RonLogic on GitHub · 2026-11-21 19:01 UTC · original

Independent before/after check on Windows 11 build 26300.9974 with an RTX 4070 (driver 32.0.16.2124) and in-box WARP (10.0.26100.9818). The D3D12 debug layer was enabled on both backends.

I ran the updated BC7 fixture from 8cd88b7 against the renderer built from f02c237. Both backends reproduced the mismatch at mip 4 of the 28×128 case, pixel (0, 0). The green channel expected 0.188232 and returned 0.0941162. With the renderer from 8cd88b7, both orientations matched all 32 channels at mip 4 on both backends, with zero maximum absolute error.

ctest --test-dir out/build/followup --no-tests=error -R '^(bc7_draw|pixel_aot)_(warp|hardware)$' -V

All four tests passed on the PR head, with no skips.

**@⁠RonLogic** on GitHub · 2026-11-21 19:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/226#issuecomment-7067703522) Independent before/after check on Windows 11 build 26300.9974 with an RTX 4070 (driver 32.0.16.2124) and in-box WARP (10.0.26100.9818). The D3D12 debug layer was enabled on both backends. I ran the updated BC7 fixture from `8cd88b7` against the renderer built from `f02c237`. Both backends reproduced the mismatch at mip 4 of the 28×128 case, pixel (0, 0). The green channel expected `0.188232` and returned `0.0941162`. With the renderer from `8cd88b7`, both orientations matched all 32 channels at mip 4 on both backends, with zero maximum absolute error. ```powershell ctest --test-dir out/build/followup --no-tests=error -R '^(bc7_draw|pixel_aot)_(warp|hardware)$' -V ``` All four tests passed on the PR head, with no skips.
This discussion has been locked. Commenting is limited to contributors.
No description provided.