textures: detile opt-in single-mip BC7 surfaces on CPU copy-out #2263
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2263
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2263/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCFor the opt-in single-mip
X2W_XG_BC7_4K_S_LAYOUTprofile,CopyFromSubresourcereturned success with the caller's entire destination still filled with its initial byte. Give this profile a slot-9 implementation that calls the existingBc16Surface::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 byte0x10unchanged in the 81×69 fixture. Ignoring destination row pitch first changed padding at0x160. Both controls failed at the expected comparison. Build, WARP and mutation logsWindows reproduction (x64 MSVC, from the repository root):
Result: 5/5 passed, no skips.
startup_xg_bc7_layoutreturned 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_warpmatched 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_xsand runctest --test-dir out/bc7 --no-tests=error -V -R '^startup_xg_bc7_layout$'. Leaving the default slot 9 in the 4 KiB table produced81x69 copy-out rows and guards: first difference at byte 0x10, got cd, expected 54. Callingsurface.detile(source, dest, row_bytes)instead of using the destination row pitch producedfirst 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: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.
d75aab5balso 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 09:07 UTC · original
The two selectors are disjoint: the 4 KiB predicate requires
D3D12_TEXTURE_LAYOUT_UNKNOWNand one mip, whilebc64::supportsrequires explicit layout0x109and six or nine mips.6344c7barecords that at the vtable selection. On this exact commit all seven focused Windows CTests passed, includingstartup_bc64_supportsand 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@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 reusesBc16Surface::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().dest_bytesandsource_bytes, so adjacent buffers are accepted in both orders. Real overlap returnsE_INVALIDARG.slice_pitchbound (0 or at leastlinear_bytes) is the same for both directions.Bc16Surface::detile(bc7_4k_s.h:51) writes onlycolumns*16bytes per row. Inter-row padding and the trailing bytes stay untouched, as the new test expects.bc7_4k_s_copy_fromorder is right: Scarlett option givesE_NOTIMPL, then plane/subresource giveE_INVALIDARG, then the copy.bc7_4koverridesbc64/default slots, and the 64 KiB chain keeps its own vtable. No other slot changes.oracle_surfaceoutput. It covers padding, guards, source preservation, both buffer orders and five refusal cases that check the destination is untouched. It also runs withX2W_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.WINFUNCTYPEand the Windows DLL). I did not run it.State at review time
Run platform-independent Python checks on Linux: pass.Build on WindowsandAssemble and translate gfx1013 fixtures: still pending when I looked./O2: skipping.Nits
RavenCurseBurg/Xbox2Windows). Reviewers cannot verify it here. Please paste the commands and results into the body, or rely on the in-repo Windows CI.docs/startup-runtime.mdhas a short line break after "The reported pitch describes the padded". It reads fine and could be re-wrapped.E_FAILwhere 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:59 UTC · original · reviewed
Re-review at head
d75aab5b6f(previous review covered4974eee).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 usesBc16Surface::detilewith the caller row pitch, so row padding is preserved.bc7_4k_tableis built fromtable, notbc_table, so a BC7 4K surface thatbc64::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 (usesctypes.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 09:09 UTC · original · reviewed
Re-review of head
6344c7bafdbdf18fd8142db5329a27d9f448745e.What is new since the last reviewed head (
d75aab5b): one comment line insrc/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()needsMipLevels6 or 9 and layout word0x109. The 4 KiB profile is a one-mip surface. So the two profiles cannot both match, and the orderbc7_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_bytesfor the linear side). Good.bc7_4k_s_copy_fromis in slot 9 only for the opt-in 4 KiB computer. It rejectsscarlett_option(E_NOTIMPL) and plane/subresource != 0 (E_INVALIDARG). Good.Bc16Surface::detileis the exact inverse of theblock_offsetcopy-in path, so it is a true round trip.Commands run locally (worktree at this head):
git diff --stat origin/main...HEAD: 3 files, +85/-13git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: 18 Markdown files, 432 links OKpython3 tests/bidi_controls_check.py: 1546 files, no bidi controlspython3 tests/startup_xg_bc7_layout_check.py: cannot run on Linux (ctypes.WINFUNCTYPEis Windows-only). The newcheck_copy_fromis 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).win2025, because the only delta is a comment.AI-assisted; commands listed were executed locally.