textures: detile opt-in BC7 backing for startup draws #1253

Merged
Jess-Doit merged 2 commits from upstream-pr/1260 into main 2026-11-24 06:29:17 +00:00
Jess-Doit commented 2026-11-24 05:56:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-24T05:56:37Z.


Change

Refs #1140. Depends on #1243. The opt-in BC7 4 KiB tiled profile now supports CopyIntoSubresource with X2W_D3D12_RENDER=1 when the companion D3D12 stand-in is loaded.

  • A successful copy records the layout and logical extent of the backing memory. The draw uploader validates the matching placed texture and detiles its visible BC7 blocks into the desktop upload footprint.
  • The copy, layout query and upload use the same tile addressing. The desktop resource rounds its top mip to whole blocks. The source fixture checks the original visible extent.
    Because the desktop texture is larger than the title's when a dimension is not a multiple of 4 (81×69 becomes 84×72), a normalized coordinate addresses a slightly different texel than on the console. Texel loads and the visible pixels compared here are unaffected; sampling near the right or bottom edge of such a texture is not covered.
  • The supported profile remains single-slice, single-mip BC7_UNORM with unknown layout, default alignment and no resource flags. Render-mode copy without the companion stand-in still returns E_NOTIMPL.

Fixture

startup_xg_bc7_draw_{warp,hardware} draws source-built position-tagged BC7 through the wrapped stream pipeline, with a linear upload and a real XG tiled copy for each size. Each draw is compared to a CPU reference for all 4,096 pixels of the 64×64 surface and all 5,589 visible pixels of the 81×69 surface. The larger case crosses both tile boundaries and uses padded desktop upload rows.

For the bypass control, replace the bc7.detile(...) call in upload_texture with std::memcpy(rows, memory, static_cast<std::size_t>(bytes < bc7.size() ? bytes : bc7.size()));. Rebuild startup_stream_consumer with cmake --build --preset $preset -j 2 --target startup_stream_consumer and run ctest --preset $preset --no-tests=error -R '^startup_xg_bc7_draw_' -V. Both tests failed as expected in Debug and Release. The linear readbacks still matched. For both tiled sizes, the first mismatch on both adapters was pixel (4, 0), RGBA bytes 00 06 18 3c instead of 08 00 18 3c.

Verification

Tested 5efd401f on copy-branch base c49b4c24 (includes main 7a4043e4 and the sampler-heap changes). Windows 10 22H2 build 19045.6456, MSVC x64 19.44.35230.0.

Adapter Driver
NVIDIA GeForce GTX 1060 6GB 32.0.15.6094
Windows 10 in-box WARP (Microsoft Basic Render Driver) 10.0.19041.5794
Configuration Passed Failed Skipped D3D12 errors D3D12 warnings
Debug 19 0 0 0 0
Release 19 0 0 0 0

Both full builds completed. The counts are from the focused suite after restoring the detiler. The suite covers the BC7 layout and draws, stream requests and draws, sampler-heap tests, startup stubs, XG swizzle controls and GFX10 texture round-trips. On both adapters, the linear and tiled uploads matched the CPU pixels for both sizes. The initial fixture run reported D3D12 warning 820 for clearing a target without an optimized clear value. The fixture now supplies the matching clear value.

Build with a Python environment containing requirements-dev.txt. Provide the pinned Mesa AddrLib for the optional swizzle comparisons as described in docs/experiments.md.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
$env:XBOX2WINDOWS_ADAPTER = '1060'
$env:X2W_D3D12_DEBUG = '1'
$python = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path
$filter = '^(startup_xg.*|startup_stream_.*|startup_sampler_heap_.*|startup_stubs|xg_swizzle_.*|cpu_native_xg_swizzle|gfx10_texture_roundtrip.*)$'
foreach ($preset in 'dev', 'release') {
    $env:ZIG_GLOBAL_CACHE_DIR = Join-Path (Get-Location) 'out/zig-global'
    $env:ZIG_LOCAL_CACHE_DIR = Join-Path (Get-Location) "out/zig-$preset"
    cmake --preset $preset "-DINTAKE_PYTHON:FILEPATH=$python"
    cmake --build --preset $preset -j 2
    ctest --preset $preset --no-tests=error -R $filter -V
}

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6575639896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1260). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-24T05:56:37Z. --- ## Change Refs #1140. Depends on #1243. The opt-in BC7 4 KiB tiled profile now supports `CopyIntoSubresource` with `X2W_D3D12_RENDER=1` when the companion D3D12 stand-in is loaded. - A successful copy records the layout and logical extent of the backing memory. The draw uploader validates the matching placed texture and detiles its visible BC7 blocks into the desktop upload footprint. - The copy, layout query and upload use the same tile addressing. The desktop resource rounds its top mip to whole blocks. The source fixture checks the original visible extent. Because the desktop texture is larger than the title's when a dimension is not a multiple of 4 (81×69 becomes 84×72), a normalized coordinate addresses a slightly different texel than on the console. Texel loads and the visible pixels compared here are unaffected; sampling near the right or bottom edge of such a texture is not covered. - The supported profile remains single-slice, single-mip `BC7_UNORM` with unknown layout, default alignment and no resource flags. Render-mode copy without the companion stand-in still returns `E_NOTIMPL`. ## Fixture `startup_xg_bc7_draw_{warp,hardware}` draws source-built position-tagged BC7 through the wrapped stream pipeline, with a linear upload and a real XG tiled copy for each size. Each draw is compared to a CPU reference for all 4,096 pixels of the 64×64 surface and all 5,589 visible pixels of the 81×69 surface. The larger case crosses both tile boundaries and uses padded desktop upload rows. For the bypass control, replace the `bc7.detile(...)` call in `upload_texture` with `std::memcpy(rows, memory, static_cast<std::size_t>(bytes < bc7.size() ? bytes : bc7.size()));`. Rebuild `startup_stream_consumer` with `cmake --build --preset $preset -j 2 --target startup_stream_consumer` and run `ctest --preset $preset --no-tests=error -R '^startup_xg_bc7_draw_' -V`. Both tests failed as expected in Debug and Release. The linear readbacks still matched. For both tiled sizes, the first mismatch on both adapters was pixel `(4, 0)`, RGBA bytes `00 06 18 3c` instead of `08 00 18 3c`. ## Verification Tested `5efd401f` on copy-branch base `c49b4c24` (includes main `7a4043e4` and the sampler-heap changes). Windows 10 22H2 build `19045.6456`, MSVC x64 `19.44.35230.0`. | Adapter | Driver | |---|---| | NVIDIA GeForce GTX 1060 6GB | `32.0.15.6094` | | Windows 10 in-box WARP (Microsoft Basic Render Driver) | `10.0.19041.5794` | | Configuration | Passed | Failed | Skipped | D3D12 errors | D3D12 warnings | |---|---:|---:|---:|---:|---:| | Debug | 19 | 0 | 0 | 0 | 0 | | Release | 19 | 0 | 0 | 0 | 0 | Both full builds completed. The counts are from the focused suite after restoring the detiler. The suite covers the BC7 layout and draws, stream requests and draws, sampler-heap tests, startup stubs, XG swizzle controls and GFX10 texture round-trips. On both adapters, the linear and tiled uploads matched the CPU pixels for both sizes. The initial fixture run reported D3D12 warning 820 for clearing a target without an optimized clear value. The fixture now supplies the matching clear value. Build with a Python environment containing `requirements-dev.txt`. Provide the pinned Mesa AddrLib for the optional swizzle comparisons as described in `docs/experiments.md`. ```powershell . .\tools\dev.ps1 $env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0' $env:XBOX2WINDOWS_ADAPTER = '1060' $env:X2W_D3D12_DEBUG = '1' $python = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path $filter = '^(startup_xg.*|startup_stream_.*|startup_sampler_heap_.*|startup_stubs|xg_swizzle_.*|cpu_native_xg_swizzle|gfx10_texture_roundtrip.*)$' foreach ($preset in 'dev', 'release') { $env:ZIG_GLOBAL_CACHE_DIR = Join-Path (Get-Location) 'out/zig-global' $env:ZIG_LOCAL_CACHE_DIR = Join-Path (Get-Location) "out/zig-$preset" cmake --preset $preset "-DINTAKE_PYTHON:FILEPATH=$python" cmake --build --preset $preset -j 2 ctest --preset $preset --no-tests=error -R $filter -V } ``` AI-assisted (Codex).
upstream-sync closed this pull request 2026-11-24 06:47:23 +00:00
tedin7 commented 2026-11-24 06:47:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:04:09Z.

Review: COMMENTED


Dual-platform peer review at 5efd401fc9e7f8759c5bcf1c8bfa6a7f949aa2ef:

Checks

  • Linux (x2w-rev-venv):
    • git diff --check HEAD~1..HEAD — passed
    • python -B tests/docs_links_check.py — passed (16 Markdown files, 281 links)
    • python -B tests/bidi_controls_check.py — passed (1053 tracked files)
    • python -B tests/bc7_blocks_check.py — passed (8 passed, 2 skipped)
    • python -B tests/bc7_tiles_check.py — passed (6 passed)
    • python -B -m py_compile tests/startup_stream_draw_check.py tests/startup_xg_bc7_draw_check.py — passed
  • Windows Server 2025 (MSVC 14.44, D3D12 WARP & hardware):
    • Targets: startup_stream_consumer, d3d12_xs_shim, startup_stub_xg_xs
    • ctest --preset dev --no-tests=error -R '^startup_(xg_bc7_|stream_draw_warp|stream_request_warp)': 5/5 passed (startup_xg_bc7_layout, startup_stream_request_warp, startup_stream_draw_warp, startup_xg_bc7_draw_warp, startup_xg_bc7_draw_hardware)
    • ctest --preset release --no-tests=error -R '^startup_(xg_bc7_|stream_draw_warp|stream_request_warp)': 5/5 passed (same 5 tests)

Review Notes

  • Extracting Bc7Surface and supports_bc7_4k_s into src/startup_stubs/bc7_4k_s.h cleanly shares the GFX10 4 KiB BC7 geometry and detiler between xg_xs.cpp, d3d12_xs_device.cpp, and d3d12_draw.inl.
  • upload_texture in src/startup_stubs/d3d12_draw.inl validates the original console desc, dimensions, format, and SliceFootprints layout before detiling, and tracks state.tiled_bc7 alongside hash and generation so alternating linear and tiled writes at the same title address cannot hit a stale upload cache entry.
  • tests/startup_xg_bc7_draw_check.py covers both block-aligned (64x64) and unaligned (81x69) dimensions across both linear and tiled layouts against a pixel-exact CPU reference.
  • Minor observation (non-blocking): reserve_upload_ring inherits the ring_bytes / 4 (64 MiB) single-allocation cap and upload_texture calls std::memset on the write-combined upload ring slice before bc7.detile; both are fine for the tested fixtures and typical single-mip BC7 surfaces within 64 MiB.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034452625 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1260#pullrequestreview-6034452625). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:04:09Z. **Review:** COMMENTED --- Dual-platform peer review at `5efd401fc9e7f8759c5bcf1c8bfa6a7f949aa2ef`: ### Checks - **Linux (`x2w-rev-venv`)**: - `git diff --check HEAD~1..HEAD` — passed - `python -B tests/docs_links_check.py` — passed (16 Markdown files, 281 links) - `python -B tests/bidi_controls_check.py` — passed (1053 tracked files) - `python -B tests/bc7_blocks_check.py` — passed (8 passed, 2 skipped) - `python -B tests/bc7_tiles_check.py` — passed (6 passed) - `python -B -m py_compile tests/startup_stream_draw_check.py tests/startup_xg_bc7_draw_check.py` — passed - **Windows Server 2025 (MSVC 14.44, D3D12 WARP & hardware)**: - Targets: `startup_stream_consumer`, `d3d12_xs_shim`, `startup_stub_xg_xs` - `ctest --preset dev --no-tests=error -R '^startup_(xg_bc7_|stream_draw_warp|stream_request_warp)'`: **5/5 passed** (`startup_xg_bc7_layout`, `startup_stream_request_warp`, `startup_stream_draw_warp`, `startup_xg_bc7_draw_warp`, `startup_xg_bc7_draw_hardware`) - `ctest --preset release --no-tests=error -R '^startup_(xg_bc7_|stream_draw_warp|stream_request_warp)'`: **5/5 passed** (same 5 tests) ### Review Notes - Extracting `Bc7Surface` and `supports_bc7_4k_s` into `src/startup_stubs/bc7_4k_s.h` cleanly shares the GFX10 4 KiB BC7 geometry and detiler between `xg_xs.cpp`, `d3d12_xs_device.cpp`, and `d3d12_draw.inl`. - `upload_texture` in `src/startup_stubs/d3d12_draw.inl` validates the original console desc, dimensions, format, and `SliceFootprints` layout before detiling, and tracks `state.tiled_bc7` alongside `hash` and `generation` so alternating linear and tiled writes at the same title address cannot hit a stale upload cache entry. - `tests/startup_xg_bc7_draw_check.py` covers both block-aligned (`64x64`) and unaligned (`81x69`) dimensions across both `linear` and `tiled` layouts against a pixel-exact CPU reference. - Minor observation (non-blocking): `reserve_upload_ring` inherits the `ring_bytes / 4` (64 MiB) single-allocation cap and `upload_texture` calls `std::memset` on the write-combined upload ring slice before `bc7.detile`; both are fine for the tested fixtures and typical single-mip BC7 surfaces within 64 MiB.
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!1253
No description provided.