textures: copy BC7 blocks into the opt-in tiled layout #1236
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1243"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:03:51Z.
Change
Refs #1140. This follows #1218, which added the opt-in
X2W_XG_BC7_4K_S_LAYOUTlayout query for single-slice, single-mipBC7_UNORM2D textures.CopyIntoSubresource(slot 8) refused that profile withE_NOTIMPL; it now writes tiled data.y0 y1 x0 x1 y2 x2 y3 x3within a tile, tiles in row-major order.src/startup_stubs/xg_xs.cppnow computes the layout query and the copy from oneBc7Surfacedescription, so the reported span, pitch and padded extent and the copy offsets can't drift apart.E_INVALIDARG, destination untouched:X2W_D3D12_RENDER=1the copy still returnsE_NOTIMPL. The draw uploader reads backing memory as desktop rows, so tiled bytes would draw wrong until a matching detiler lands. This slice is for CPU-side diagnostics.The default (non-opt-in) copy path is unchanged. Doc fix on the way: the
X2W_XG_BC7_4K_S_LAYOUTrow indocs/startup-runtime.mdhad a stray indent that broke the switch table.Fixture
tests/startup_xg_bc7_layout_check.pyalready checked the layout query for 64×64 and 81×69 against the independent tile oracle intests/gfx10_texture_roundtrip_check.py. It now also checks the copy:0x5afiller after each block row, so the row pitch is wider than a block row. 81×69 also passes an exact slice pitch; 64×64 passes 0.0xa5and surrounded by guard bytes. Padding blocks stay0xa5, which differs from the oracle's own padding filler, so a copy that writes padding fails.0x80070057and leave the destination byte-identical. WithX2W_D3D12_RENDER=1, the copy returns0x80004001and also leaves the destination byte-identical.Negative control: with the block offset replaced by row-major (linear) order, the check fails at the first mismatched block:
BC7 81x69 tiled blocks, padding and guards: first difference at byte 0x26, got 01, expected 00.Verification
Tested
a2baada4(onf4a6caf4) on Windows 10 22H219045.6456, MSVC x64. These tests use no GPU.startup_xg_bc7_layoutfailed as expectedstartup_xg_bc7_layoutfailed as expectedThe 9 tests are
startup_xg_bc7_layout,startup_stubs,xg_swizzle_select,xg_swizzle_select_mutation,xg_swizzle_factory,xg_swizzle_factory_no_write,cpu_native_xg_swizzle,gfx10_texture_roundtripandgfx10_texture_roundtrip_controls. After restoring the change, both configurations passed 9/9 again.Fixture output, both configurations:
Still open in #1140:
AI-assisted (Codex, reviewed with Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:07:52Z.
Review: COMMENTED
Reviewed PR #1243 at commit
a2baada4(a2baada46c3cb7439bb4ddc8c9f1ddbc876faa47).Findings
Bc7Surface& GFX10 4 KiB tiling (src/startup_stubs/xg_xs.cpp):write_bc7_4k_s_layoutandcopy_bc7_4k_sunderBc7Surfacekeeps the reported span,padded_row_bytes(), padded extent, andblock_offset(column, row)in sync.block_offsetbit-packing(y & 3) | ((x & 3) << 2) | ((y & 4) << 2) | ((x & 4) << 3) | ((y & 8) << 3) | ((x & 8) << 4)matches the GFX10 4 KiB standard non-XOR BC7y0 y1 x0 x1 y2 x2 y3 x3block order.copy_bc7_4k_s):use_bc7_4k_s_layoutboundsWidth/Heightto1..16384(D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION), sosurface.rows >= 1(surface.rows - 1cannot underflow),surface.size() <= 256 MiB, andu64{surface.rows - 1} * row_pitch + row_bytes/u64{y} * row_pitchavoid 32-bit multiplication overflow.row_pitch < row_bytes, non-zeroslice_pitch < source_bytes,plane || subresource, and[dest, dest + surface.size())vs[source, source + source_bytes)overlap all returnE_INVALIDARGbefore touchingdest;x2w_local::readable/writableguard bad pointers withE_FAIL.(0..columns-1, 0..rows-1)blocks are copied; tile padding blocks are left untouched.X2W_D3D12_RENDER=1is checked first incomputer_copy_intoand returnsE_NOTIMPL, leavingdestunchanged.AGENTS.mdtitle-neutrality is preserved, anddocs/startup-runtime.mdfixes theX2W_XG_BC7_4K_S_LAYOUT=1table row indentation and documents theCopyIntoSubresourcediagnostic behavior.Verification (Linux host)
Windows MSVC build and CTest targets (
startup_xg_bc7_layout, etc., which require the compiledstartup_stub_xg_xsDLL) were not run locally on this Linux environment.Commands run on
a2baada4:git diff --check $(git merge-base origin/main HEAD)..HEAD-> exit 0 (clean)/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py-> passed (Self-test passed. Checked 16 Markdown files and 280 links., 0 fail, 0 skip)/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py-> passed (Self-test passed. Checked 1048 tracked source, script and build/CI files: no bidirectional controls., 0 fail, 0 skip)/root/.local/share/x2w-rev-venv/bin/python -B tests/form_coverage_check.py-> passed (form coverage checks passed, 0 fail, 0 skip)/root/.local/share/x2w-rev-venv/bin/python -B -m py_compile tests/startup_xg_bc7_layout_check.py-> exit 0/root/.local/share/x2w-rev-venv/bin/python -B tests/gfx10_texture_roundtrip_check.py-> passed (Ran 6 tests in 0.006s,gfx10_texture_roundtrip all: PASS, 0 fail, 0 skip)Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:14:53Z.
Windows Server 2025 retest on
a2baada46c3cb7439bb4ddc8c9f1ddbc876faa47(startup_stub_xg_xs,startup_stub_consumer):dev(Debug):ctest --preset dev -R '^(startup_xg_bc7_layout|startup_stubs)$'— 2/2 passed (startup_xg_bc7_layout0.14s,startup_stubs0.16s)release(Release /O2):ctest --preset release -R '^(startup_xg_bc7_layout|startup_stubs)$'— 2/2 passed (startup_xg_bc7_layout0.18s,startup_stubs0.19s)Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:30:09Z.
Merged current main (
7a4043e4) into the branch asc49b4c24to clear a conflict with #1237 indocs/startup-runtime.md. I kept this PR's switch-table row andCopyIntoSubresourceparagraph, and #1237's updated sampler-heap text. There is no code change froma2baada4.Retested
c49b4c24on Windows 10 22H219045.6456, MSVC x64, with a full build per configuration:Debug and Release each passed 9/9 with no skips. Thanks @tedin7 for the review.