textures: detile opt-in single-mip BC7 surfaces on CPU copy-out #2263

Manually merged
github merged 3 commits from gh-pr/2263/head into gh-pr/2263/base 2026-11-27 00:10:54 +00:00
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 08:48 UTC · original
RavenCurseBurg:textures/bc7-4k-cpu-readback → main · +85 −13 · 3 files · 3 commits · merged 2026-11-25 09:08 UTC

For the opt-in single-mip X2W_XG_BC7_4K_S_LAYOUT profile, CopyFromSubresource returned success with the caller's entire destination still filled with its initial byte. Give this profile a slot-9 implementation that calls the existing Bc16Surface::detile. It copies visible BC7 blocks into caller-pitched rows, checks the buffer spans for the direction of transfer, and supports zero or explicit slice pitch. CPU readback works with the XG stand-in alone, including when rendering is enabled.

The native test feeds slot 9 independently generated tiled bytes. It compares the full linear payload, inter-row and trailing padding, surrounding guards and source bytes for 64×64, 81×69 and 200×72. It also checks both orders of adjacent buffers, the Scarlett option and plane/subresource/pitch refusals. The 64 KiB chain has its own vtable. Refs #1140.

Five Windows CTests passed on 4974eeeb, including the native layout fixture, the address-order negative control and WARP draws of linear and tiled backing (4,096 and 5,589 pixels per layout). The native test passed independently on a second Windows host. Restoring the old no-op left byte 0x10 unchanged in the 81×69 fixture. Ignoring destination row pitch first changed padding at 0x160. Both controls failed at the expected comparison. Build, WARP and mutation logs
Windows reproduction (x64 MSVC, from the repository root):

./tools/dev.ps1
python -m venv out/pe-env
cmake --preset dev -B out/bc7 -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
cmake --build out/bc7 --target startup_stub_xg_xs startup_bc7_4k_s_check startup_stream_consumer
ctest --test-dir out/bc7 --no-tests=error -V -R '^(startup_xg_bc7_(layout|draw_warp)|startup_bc7_4k_s(_x_first_control)?|bc7_tile_swizzle)$'

Result: 5/5 passed, no skips. startup_xg_bc7_layout returned exact copy-in, copy-out, padding and guard bytes at 81×69 (16,384 tiled bytes), 64×64 (4,096), and 200×72 (32,768). startup_xg_bc7_draw_warp matched all 4,096 or 5,589 pixels for each of the linear and tiled draws. The address-order control and tile oracle both passed.

For each mutation, rebuild startup_stub_xg_xs and run ctest --test-dir out/bc7 --no-tests=error -V -R '^startup_xg_bc7_layout$'. Leaving the default slot 9 in the 4 KiB table produced 81x69 copy-out rows and guards: first difference at byte 0x10, got cd, expected 54. Calling surface.detile(source, dest, row_bytes) instead of using the destination row pitch produced first difference at byte 0x160, got 54, expected cd. Both runs exited nonzero at the byte comparison. In-repository CI for the implementation

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 08:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263) `RavenCurseBurg:textures/bc7-4k-cpu-readback` → `main` · +85 −13 · 3 files · 3 commits · merged 2026-11-25 09:08 UTC For the opt-in single-mip `X2W_XG_BC7_4K_S_LAYOUT` profile, `CopyFromSubresource` returned success with the caller's entire destination still filled with its initial byte. Give this profile a slot-9 implementation that calls the existing `Bc16Surface::detile`. It copies visible BC7 blocks into caller-pitched rows, checks the buffer spans for the direction of transfer, and supports zero or explicit slice pitch. CPU readback works with the XG stand-in alone, including when rendering is enabled. The native test feeds slot 9 independently generated tiled bytes. It compares the full linear payload, inter-row and trailing padding, surrounding guards and source bytes for 64×64, 81×69 and 200×72. It also checks both orders of adjacent buffers, the Scarlett option and plane/subresource/pitch refusals. The 64 KiB chain has its own vtable. Refs [#1140](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/1140). Five Windows CTests passed on `4974eeeb`, including the native layout fixture, the address-order negative control and WARP draws of linear and tiled backing (4,096 and 5,589 pixels per layout). The native test passed independently on a second Windows host. Restoring the old no-op left byte `0x10` unchanged in the 81×69 fixture. Ignoring destination row pitch first changed padding at `0x160`. Both controls failed at the expected comparison. [Build, WARP and mutation logs](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45578908738) Windows reproduction (x64 MSVC, from the repository root): ```powershell ./tools/dev.ps1 python -m venv out/pe-env cmake --preset dev -B out/bc7 -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded cmake --build out/bc7 --target startup_stub_xg_xs startup_bc7_4k_s_check startup_stream_consumer ctest --test-dir out/bc7 --no-tests=error -V -R '^(startup_xg_bc7_(layout|draw_warp)|startup_bc7_4k_s(_x_first_control)?|bc7_tile_swizzle)$' ``` Result: 5/5 passed, no skips. `startup_xg_bc7_layout` returned exact copy-in, copy-out, padding and guard bytes at 81×69 (16,384 tiled bytes), 64×64 (4,096), and 200×72 (32,768). `startup_xg_bc7_draw_warp` matched all 4,096 or 5,589 pixels for each of the linear and tiled draws. The address-order control and tile oracle both passed. For each mutation, rebuild `startup_stub_xg_xs` and run `ctest --test-dir out/bc7 --no-tests=error -V -R '^startup_xg_bc7_layout$'`. Leaving the default slot 9 in the 4 KiB table produced `81x69 copy-out rows and guards: first difference at byte 0x10, got cd, expected 54`. Calling `surface.detile(source, dest, row_bytes)` instead of using the destination row pitch produced `first difference at byte 0x160, got 54, expected cd`. Both runs exited nonzero at the byte comparison. [In-repository CI for the implementation](https://github.com/R0Y00/Xbox2Windows/actions/runs/45579478026)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:10:52 +00:00
github manually merged commit 6344c7bafd into gh-pr/2263/base 2026-11-27 00:10:54 +00:00
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 08:57 UTC · original

The PR body now includes the complete build and CTest commands, the five positive results, and the exact byte mismatches for both Windows controls. d75aab5b also rewraps the runtime note. The implemented bounds checks keep the HRESULT used by the existing copy-in path. In-repository checks on this head

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 08:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263#issuecomment-7157694532) The PR body now includes the complete build and CTest commands, the five positive results, and the exact byte mismatches for both Windows controls. `d75aab5b` also rewraps the runtime note. The implemented bounds checks keep the HRESULT used by the existing copy-in path. [In-repository checks on this head](https://github.com/R0Y00/Xbox2Windows/actions/runs/45580069411)
Author
Owner

@⁠RavenCurseBurg on GitHub · 2026-11-25 09:07 UTC · original

The two selectors are disjoint: the 4 KiB predicate requires D3D12_TEXTURE_LAYOUT_UNKNOWN and one mip, while bc64::supports requires explicit layout 0x109 and six or nine mips. 6344c7ba records that at the vtable selection. On this exact commit all seven focused Windows CTests passed, including startup_bc64_supports and its layout control. Restoring the no-op and ignoring row pitch still failed at the expected bytes. In-repository CI · Seven focused tests and mutation results

**@⁠RavenCurseBurg** on GitHub · 2026-11-25 09:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263#issuecomment-7157906918) The two selectors are disjoint: the 4 KiB predicate requires `D3D12_TEXTURE_LAYOUT_UNKNOWN` and one mip, while `bc64::supports` requires explicit layout `0x109` and six or nine mips. `6344c7ba` records that at the vtable selection. On this exact commit all seven focused Windows CTests passed, including `startup_bc64_supports` and its layout control. Restoring the no-op and ignoring row pitch still failed at the expected bytes. [In-repository CI](https://github.com/R0Y00/Xbox2Windows/actions/runs/45581773057) · [Seven focused tests and mutation results](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45581940061)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 08:49 UTC · original · reviewed

Review of head 4974eeebc5d9337008a91cc06f0e414ad2807444 (3 files, +83/-12).

Summary: Slot 9 (CopyFromSubresource) for the opt-in single-mip BC7 4K_S profile. It reuses Bc16Surface::detile. I found no correctness problems. P1=0, P2=0.

What I checked by reading

  • copy_bc7_4k_s<into> (src/startup_stubs/xg_xs.cpp): the buffer spans are chosen per direction. Copy-in uses dest=surface.size(), src=linear. Copy-out uses dest=linear, src=surface.size().
  • The overlap test uses dest_bytes and source_bytes, so adjacent buffers are accepted in both orders. Real overlap returns E_INVALIDARG.
  • The slice_pitch bound (0 or at least linear_bytes) is the same for both directions.
  • Bc16Surface::detile (bc7_4k_s.h:51) writes only columns*16 bytes per row. Inter-row padding and the trailing bytes stay untouched, as the new test expects.
  • bc7_4k_s_copy_from order is right: Scarlett option gives E_NOTIMPL, then plane/subresource give E_INVALIDARG, then the copy.
  • Table selection: bc7_4k overrides bc64/default slots, and the 64 KiB chain keeps its own vtable. No other slot changes.
  • The copy-in path is unchanged apart from the template parameter.
  • The test is independent of the implementation. It builds the expected rows from oracle_surface output. It covers padding, guards, source preservation, both buffer orders and five refusal cases that check the destination is untouched. It also runs with X2W_D3D12_RENDER=1.

Commands executed locally (Linux)

  • git diff --stat origin/main...HEAD: 3 files changed.
  • python3 tests/docs_links_check.py: self-test passed, 18 files and 432 links checked.
  • python3 tests/bidi_controls_check.py: self-test passed, 1546 files, no bidi controls.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/startup_xg_bc7_layout_check.py: cannot run on Linux (ctypes.WINFUNCTYPE and the Windows DLL). I did not run it.
  • I did not run a mutation of the new logic. The native test needs the Windows build. I did not queue the Windows VM for this review. The PR body's mutation claims (no-op and ignored row pitch) are plausible from the test assertions, but I have not reproduced them.

State at review time

  • Mergeable: yes. Title and body are neutral.
  • Run platform-independent Python checks on Linux: pass. Build on Windows and Assemble and translate gfx1013 fixtures: still pending when I looked. /O2: skipping.

Nits

  • N1: The "Build, WARP and mutation logs" link in the PR body points to an Actions run in a different repository (RavenCurseBurg/Xbox2Windows). Reviewers cannot verify it here. Please paste the commands and results into the body, or rely on the in-repo Windows CI.
  • N2: docs/startup-runtime.md has a short line break after "The reported pitch describes the padded". It reads fine and could be re-wrapped.
  • N3: The bounds failure returns E_FAIL where an invalid argument might fit better. This matches the existing copy-in behavior, so I would leave it.

Verdict: logic looks correct. Please wait for the pending Windows CI jobs to pass before marking ready.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 08:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263#pullrequestreview-6054396262) · **reviewed** Review of head `4974eeebc5d9337008a91cc06f0e414ad2807444` (3 files, +83/-12). **Summary:** Slot 9 (`CopyFromSubresource`) for the opt-in single-mip BC7 4K_S profile. It reuses `Bc16Surface::detile`. I found no correctness problems. P1=0, P2=0. **What I checked by reading** - `copy_bc7_4k_s<into>` (`src/startup_stubs/xg_xs.cpp`): the buffer spans are chosen per direction. Copy-in uses dest=`surface.size()`, src=linear. Copy-out uses dest=linear, src=`surface.size()`. - The overlap test uses `dest_bytes` and `source_bytes`, so adjacent buffers are accepted in both orders. Real overlap returns `E_INVALIDARG`. - The `slice_pitch` bound (0 or at least `linear_bytes`) is the same for both directions. - `Bc16Surface::detile` (`bc7_4k_s.h:51`) writes only `columns*16` bytes per row. Inter-row padding and the trailing bytes stay untouched, as the new test expects. - `bc7_4k_s_copy_from` order is right: Scarlett option gives `E_NOTIMPL`, then plane/subresource give `E_INVALIDARG`, then the copy. - Table selection: `bc7_4k` overrides `bc64`/default slots, and the 64 KiB chain keeps its own vtable. No other slot changes. - The copy-in path is unchanged apart from the template parameter. - The test is independent of the implementation. It builds the expected rows from `oracle_surface` output. It covers padding, guards, source preservation, both buffer orders and five refusal cases that check the destination is untouched. It also runs with `X2W_D3D12_RENDER=1`. **Commands executed locally (Linux)** - `git diff --stat origin/main...HEAD`: 3 files changed. - `python3 tests/docs_links_check.py`: self-test passed, 18 files and 432 links checked. - `python3 tests/bidi_controls_check.py`: self-test passed, 1546 files, no bidi controls. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/startup_xg_bc7_layout_check.py`: cannot run on Linux (`ctypes.WINFUNCTYPE` and the Windows DLL). I did not run it. - I did not run a mutation of the new logic. The native test needs the Windows build. I did not queue the Windows VM for this review. The PR body's mutation claims (no-op and ignored row pitch) are plausible from the test assertions, but I have not reproduced them. **State at review time** - Mergeable: yes. Title and body are neutral. - `Run platform-independent Python checks on Linux`: pass. `Build on Windows` and `Assemble and translate gfx1013 fixtures`: still pending when I looked. `/O2`: skipping. **Nits** - N1: The "Build, WARP and mutation logs" link in the PR body points to an Actions run in a different repository (`RavenCurseBurg/Xbox2Windows`). Reviewers cannot verify it here. Please paste the commands and results into the body, or rely on the in-repo Windows CI. - N2: `docs/startup-runtime.md` has a short line break after "The reported pitch describes the padded". It reads fine and could be re-wrapped. - N3: The bounds failure returns `E_FAIL` where an invalid argument might fit better. This matches the existing copy-in behavior, so I would leave it. Verdict: logic looks correct. Please wait for the pending Windows CI jobs to pass before marking ready. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 08:59 UTC · original · reviewed

Re-review at head d75aab5b6f (previous review covered 4974eee).

Incremental change since 4974eee: docs only (docs/startup-runtime.md, 2 lines re-wrapped, no wording change). No source or test change.

Re-read of the full source diff (src/startup_stubs/xg_xs.cpp):

  • copy_bc7_4k_s<into>: overlap and readable/writable bounds now use the right extents per direction (linear extent vs tiled size). Correct.
  • bc7_4k_s_copy_from: option != 0 gives E_NOTIMPL, plane/subresource != 0 gives E_INVALIDARG, as documented. Detile uses Bc16Surface::detile with the caller row pitch, so row padding is preserved.
  • Nit: bc7_4k_table is built from table, not bc_table, so a BC7 4K surface that bc64::supports() also accepts loses the bc64 tiling slot. This is fine if the two are exclusive; a one-line comment saying so would help.

Commands executed locally (worktree at head):

  • git diff --stat 4974eee..HEAD: 1 file, docs only.
  • python3 tests/docs_links_check.py: self-test passed, 18 files, 432 links OK.
  • python3 tests/bidi_controls_check.py: 1546 files, no bidirectional controls.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/startup_xg_bc7_layout_check.py: cannot run on Linux (uses ctypes.WINFUNCTYPE, Windows only). No logic mutation was possible locally. The Windows CI job "Build and test on Windows" passes at this head, and the Linux Python checks job passes.
  • gh pr checks: all pass (two jobs skipped by design). Mergeable, title neutral.

Findings: P1=0, P2=0, one nit (above).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 08:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263#pullrequestreview-6054526093) · **reviewed** Re-review at head d75aab5b6f3b11693e91e9df3212bd18096d970d (previous review covered 4974eee). Incremental change since 4974eee: docs only (`docs/startup-runtime.md`, 2 lines re-wrapped, no wording change). No source or test change. Re-read of the full source diff (`src/startup_stubs/xg_xs.cpp`): - `copy_bc7_4k_s<into>`: overlap and readable/writable bounds now use the right extents per direction (linear extent vs tiled size). Correct. - `bc7_4k_s_copy_from`: option != 0 gives E_NOTIMPL, plane/subresource != 0 gives E_INVALIDARG, as documented. Detile uses `Bc16Surface::detile` with the caller row pitch, so row padding is preserved. - Nit: `bc7_4k_table` is built from `table`, not `bc_table`, so a BC7 4K surface that `bc64::supports()` also accepts loses the bc64 tiling slot. This is fine if the two are exclusive; a one-line comment saying so would help. Commands executed locally (worktree at head): - `git diff --stat 4974eee..HEAD`: 1 file, docs only. - `python3 tests/docs_links_check.py`: self-test passed, 18 files, 432 links OK. - `python3 tests/bidi_controls_check.py`: 1546 files, no bidirectional controls. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/startup_xg_bc7_layout_check.py`: cannot run on Linux (uses `ctypes.WINFUNCTYPE`, Windows only). No logic mutation was possible locally. The Windows CI job "Build and test on Windows" passes at this head, and the Linux Python checks job passes. - `gh pr checks`: all pass (two jobs skipped by design). Mergeable, title neutral. Findings: P1=0, P2=0, one nit (above). AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 09:09 UTC · original · reviewed

Re-review of head 6344c7bafdbdf18fd8142db5329a27d9f448745e.

What is new since the last reviewed head (d75aab5b): one comment line in src/startup_stubs/xg_xs.cpp (the "4 KiB profile requires UNKNOWN layout and one mip; BC64 requires layout 0x109 and six or nine mips" note). No code change. I re-read the whole PR diff again anyway.

Check of the claim in the comment: bc64::supports() needs MipLevels 6 or 9 and layout word 0x109. The 4 KiB profile is a one-mip surface. So the two profiles cannot both match, and the order bc7_4k ? bc7_4k_table : (bc64 ? bc_table : table) is safe.

Code review (whole PR):

  • copy_bc7_4k_s<into>: size/overlap/readable/writable checks use the right byte counts for each direction (surface.size() for the tiled side, linear_bytes for the linear side). Good.
  • bc7_4k_s_copy_from is in slot 9 only for the opt-in 4 KiB computer. It rejects scarlett_option (E_NOTIMPL) and plane/subresource != 0 (E_INVALIDARG). Good.
  • Bc16Surface::detile is the exact inverse of the block_offset copy-in path, so it is a true round trip.
  • P1 = 0, P2 = 0.
  • Nit: the PR is not Draft. Our flow expects Draft until a Win2025 WARP pass. CI Windows is green, so this is only a process note.

Commands run locally (worktree at this head):

  • git diff --stat origin/main...HEAD: 3 files, +85/-13
  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: 18 Markdown files, 432 links OK
  • python3 tests/bidi_controls_check.py: 1546 files, no bidi controls
  • python3 tests/startup_xg_bc7_layout_check.py: cannot run on Linux (ctypes.WINFUNCTYPE is Windows-only). The new check_copy_from is exercised by the Windows CI job, which passed ("Build and test on Windows": pass; "Assemble and translate gfx1013 fixtures": pass; "Run platform-independent Python checks on Linux": pass).
  • Mutation: not done. The new logic lives in a Windows-only C++ stub, so I could not build and mutate it on Linux. I did not run win2025, because the only delta is a comment.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 09:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2263#pullrequestreview-6054659305) · **reviewed** Re-review of head `6344c7bafdbdf18fd8142db5329a27d9f448745e`. **What is new since the last reviewed head (`d75aab5b`):** one comment line in `src/startup_stubs/xg_xs.cpp` (the "4 KiB profile requires UNKNOWN layout and one mip; BC64 requires layout 0x109 and six or nine mips" note). No code change. I re-read the whole PR diff again anyway. **Check of the claim in the comment:** `bc64::supports()` needs `MipLevels` 6 or 9 and layout word `0x109`. The 4 KiB profile is a one-mip surface. So the two profiles cannot both match, and the order `bc7_4k ? bc7_4k_table : (bc64 ? bc_table : table)` is safe. **Code review (whole PR):** - `copy_bc7_4k_s<into>`: size/overlap/readable/writable checks use the right byte counts for each direction (`surface.size()` for the tiled side, `linear_bytes` for the linear side). Good. - `bc7_4k_s_copy_from` is in slot 9 only for the opt-in 4 KiB computer. It rejects `scarlett_option` (E_NOTIMPL) and plane/subresource != 0 (E_INVALIDARG). Good. - `Bc16Surface::detile` is the exact inverse of the `block_offset` copy-in path, so it is a true round trip. - P1 = 0, P2 = 0. - Nit: the PR is not Draft. Our flow expects Draft until a Win2025 WARP pass. CI Windows is green, so this is only a process note. **Commands run locally (worktree at this head):** - `git diff --stat origin/main...HEAD`: 3 files, +85/-13 - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: 18 Markdown files, 432 links OK - `python3 tests/bidi_controls_check.py`: 1546 files, no bidi controls - `python3 tests/startup_xg_bc7_layout_check.py`: cannot run on Linux (`ctypes.WINFUNCTYPE` is Windows-only). The new `check_copy_from` is exercised by the Windows CI job, which passed ("Build and test on Windows": pass; "Assemble and translate gfx1013 fixtures": pass; "Run platform-independent Python checks on Linux": pass). - Mutation: not done. The new logic lives in a Windows-only C++ stub, so I could not build and mutate it on Linux. I did not run `win2025`, because the only delta is a comment. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.