textures: sample CPU-uploaded RGBA8 and BC7 textures from the shim-startup EXE entry #808

Merged
yummancito merged 2 commits from upstream-pr/814 into main 2026-11-23 08:09:41 +00:00
yummancito commented 2026-11-23 07:24:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by yummancito on 2026-11-23T07:24:50Z.


Summary

The shim-startup EXE already renders a triangle (#560), reuses a compute-written
texture across three draws (#705) and runs the translated compute -> mesh -> pixel
chain (#682). None of those exercise a texture whose texels are uploaded from the
CPU
. This PR adds that path, driven from the same EXE entry and compared byte for
byte across the native EXE, the pe_map mapped image and the AOT-recompiled EXE.

Advances the EXE-entry raster milestone; no issue is closed.

What it adds

  • tests/cpu/shim_tex_gpu.cpp, tests/tex_quad.hlsl: a vertex-buffer quad (POSITION +
    TEXCOORD) sampling an 8x8 texture through an SRV with a point-clamp static sampler.
    The texture is created in a DEFAULT heap, filled through an UPLOAD staging buffer
    (placed footprints), transitioned to PIXEL_SHADER_RESOURCE, and read back with a
    fence wait.
  • Formats: R8G8B8A8_UNORM (original asymmetric rule, 64/64 distinct texels) and
    BC7_UNORM (the repository's mode-6 block builder and the 4 KiB standard-swizzle
    tiled-to-linear conversion from tests/bc7_draw_check.py).
  • tests/cpu/tex_gen.py: single source of truth for the texel tables and every CPU
    reference frame; it also emits the header the provider embeds.
  • tests/cpu/shim_tex_check.py and ctest cpu_shim_upload_texture_{warp,hardware}.
  • EXE entry: draw requests 20-24 (tex, texuv, texbad, bc7, scene) in
    shim_startup.asm / shim_draw_provider.cpp. Existing requests 1-13 are untouched.
  • Commit 1 (cpu: share the shim draw device selection in a header) is a no-behavior
    refactor: the new texture fixture needs the same WARP/hardware selection and the 77
    capability skip as shim_draw_gpu.cpp, and moving the existing helpers into
    shim_gpu_device.h avoids two copies that could drift. The existing draw tests are
    unchanged and still pass.

Cases

Case Expectation
tex RGBA8 table, exit 42, frame equals the CPU rule (8f9271e5)
bc7 BC7 table, exit 42, frame equals the CPU rule (b2d756a4)
scene one frame, two draws with an SRV rebind: RGBA8 left, BC7 right, exit 42 (d54d504f)
texuv U shifted by half a texel in the vertex buffer: must exit 20, match its own rule (85aac638) and differ from the exact frame
texbad one texel corrupted in the upload: must exit 20, match its own rule (ba7ee0ab) and differ from the exact frame

Every case must also agree across the three runners, publish a full 16,384-byte frame,
show no extra diagnostics, and keep the startup output unchanged.

Difference from upstream

cpu_shim_texture_reuse_* (#705) writes an R32_UINT texture from a compute dispatch.
This fixture uploads texels from the CPU, uses real vertex data with UVs, covers a
block-compressed format, and has negative controls for the sampling coordinates and for
the upload contents. I found no open PR covering this (checked #613, #522, #506, which
touch other files).

Evidence

Commits under test: 774e6df, 70d34e9 on upstream/main a81b55a
(rebased once to resolve conflicts in CMakeLists.txt and shim_startup.asm with the
new shadow draw modes 14-16; my modes 20-24 do not overlap them).
Environment: Windows 11 Pro 10.0.26300, MSVC 19.44.35228, DXC from Vulkan SDK 1.4.363.0.
Hardware adapter: NVIDIA GeForce RTX 5060, driver 621.14 (UMD 32.0.16.2114), LUID 0xc90c.
Software adapter: Microsoft Basic Render Driver, LUID 0x1071b. Debug layer unavailable.

Both presets were configured with --fresh and built from scratch with no extra cache arguments.

ctest --preset <dev|release> --no-tests=error -R '^cpu_shim_upload_texture_(warp|hardware)$' -V
ctest --preset <dev|release> --no-tests=error -R '^cpu_' -j 4
Preset ^cpu_ Upload-texture tests Skipped
dev 147/147 pass warp + hardware pass 0
release 147/147 pass warp + hardware pass 0

Root signature, texture, shader, PE and memory groups (desktop_root_signature,
era_heap, desktop_memory_query, offscreen_warp, bcpack_*, bc7_*,
pixel_aot_*, static_exe_intake, conditional_import_paths, script_*): 73/77 pass
in each preset, with the same four non-passing tests in dev and release:

  • pixel_aot_e64_approx_hardware (introduced by #729) and pixel_aot_sdwa_unary_hardware
    fail with E_OUTOFMEMORY (HRESULT 0x8007000E) when creating the translated pixel
    pipeline on my RTX 5060. Both fail identically on unmodified upstream/main a81b55a
    on the same machine (verified by checking out upstream/main detached, rebuilding and
    running them), so they are not caused by this PR. I did not touch those tests and did not
    open an issue; the only related open issue I found (#312) is about denormal modes, not
    this error.
  • pixel_aot_hardware and pixel_aot_predicate_rounding_hardware hit the default 60 s
    CTest timeout when the area group runs with -j 4. Run alone with a longer timeout they
    pass (48-57 s; on unmodified upstream/main predicate_rounding also takes about 54 s),
    so they are slow rather than broken, and neither involves files changed here.

Adapter identification: a temporary, uncommitted print in shim_create_device showed the
device actually created. With X2W_SHIM_DRAW_ADAPTER=hardware, cases tex, bc7, scene
and texbad all created the RTX 5060; with warp all created the Basic Render Driver.

Negative-control mutations (each applied to the fixture, rebuilt, and run; each must fail):
no corruption, no UV shift, damaged BC7 block, no SRV rebind in scene, skipped upload,
linear sampler. All six made cpu_shim_upload_texture_warp fail. Removing the corruption
fails with texbad native exits: expected 20, got 42; removing the shift fails with
texuv native exits: expected 20, got 42.

Bug found and fixed while preparing this

The first version of the staging copy iterated Footprint.Height rows. For BC7 that is 8
texel rows while only 2 block rows exist (rows=2, row_bytes=32), so it read 256 bytes
from a 64-byte table and wrote past the staging buffer. The copy now uses NumRows and
RowSizeInBytes from GetCopyableFootprints, and fill_staging throws unless
rows * row_bytes equals the source table size exactly and the last row ends inside the
staging buffer. Reintroducing the old row count makes bc7 fail with
staging geometry mismatch: rows=8 ... table_bytes=64.

Known risks and limitations

  • 8x8 textures, one mip, one array slice; only RGBA8 and BC7 mode 6. No mipmaps, BC1/BC3/BC5,
    other BC7 modes, arrays or cube maps.
  • Point sampling with clamp only; filtering and wrap modes are not covered.
  • Adapter identity is not printed by the test itself. It was confirmed with a temporary print.
  • Hardware results come from one adapter (RTX 5060). Other vendors are untested.
  • The BC7 reference frame comes from the repository's block builder, not from an independent
    decoder; the GPU decode is the independent side of the comparison.
  • This shows the texture path works from the EXE entry. It does not show that any title runs.

Files

CMakeLists.txt, README.md, docs/experiments.md, tests/cpu/shim_draw_gpu.cpp,
tests/cpu/shim_draw_provider.cpp, tests/cpu/shim_gpu_device.h (new),
tests/cpu/shim_startup.asm, tests/cpu/shim_tex_check.py (new),
tests/cpu/shim_tex_gpu.cpp (new), tests/cpu/tex_gen.py (new), tests/tex_quad.hlsl (new).
817 insertions, 43 deletions.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6554400264 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/814). Originally posted by [yummancito](https://github.com/yummancito) on 2026-11-23T07:24:50Z. --- ## Summary The shim-startup EXE already renders a triangle (#560), reuses a compute-written texture across three draws (#705) and runs the translated compute -> mesh -> pixel chain (#682). None of those exercise a texture whose texels are **uploaded from the CPU**. This PR adds that path, driven from the same EXE entry and compared byte for byte across the native EXE, the `pe_map` mapped image and the AOT-recompiled EXE. Advances the EXE-entry raster milestone; no issue is closed. ## What it adds - `tests/cpu/shim_tex_gpu.cpp`, `tests/tex_quad.hlsl`: a vertex-buffer quad (POSITION + TEXCOORD) sampling an 8x8 texture through an SRV with a point-clamp static sampler. The texture is created in a DEFAULT heap, filled through an UPLOAD staging buffer (placed footprints), transitioned to `PIXEL_SHADER_RESOURCE`, and read back with a fence wait. - Formats: `R8G8B8A8_UNORM` (original asymmetric rule, 64/64 distinct texels) and `BC7_UNORM` (the repository's mode-6 block builder and the 4 KiB standard-swizzle tiled-to-linear conversion from `tests/bc7_draw_check.py`). - `tests/cpu/tex_gen.py`: single source of truth for the texel tables and every CPU reference frame; it also emits the header the provider embeds. - `tests/cpu/shim_tex_check.py` and ctest `cpu_shim_upload_texture_{warp,hardware}`. - EXE entry: draw requests 20-24 (`tex`, `texuv`, `texbad`, `bc7`, `scene`) in `shim_startup.asm` / `shim_draw_provider.cpp`. Existing requests 1-13 are untouched. - Commit 1 (`cpu: share the shim draw device selection in a header`) is a no-behavior refactor: the new texture fixture needs the same WARP/hardware selection and the 77 capability skip as `shim_draw_gpu.cpp`, and moving the existing helpers into `shim_gpu_device.h` avoids two copies that could drift. The existing draw tests are unchanged and still pass. ## Cases | Case | Expectation | |---|---| | `tex` | RGBA8 table, exit 42, frame equals the CPU rule (`8f9271e5`) | | `bc7` | BC7 table, exit 42, frame equals the CPU rule (`b2d756a4`) | | `scene` | one frame, two draws with an SRV rebind: RGBA8 left, BC7 right, exit 42 (`d54d504f`) | | `texuv` | U shifted by half a texel in the vertex buffer: must exit 20, match its own rule (`85aac638`) and differ from the exact frame | | `texbad` | one texel corrupted in the upload: must exit 20, match its own rule (`ba7ee0ab`) and differ from the exact frame | Every case must also agree across the three runners, publish a full 16,384-byte frame, show no extra diagnostics, and keep the startup output unchanged. ## Difference from upstream `cpu_shim_texture_reuse_*` (#705) writes an `R32_UINT` texture from a compute dispatch. This fixture uploads texels from the CPU, uses real vertex data with UVs, covers a block-compressed format, and has negative controls for the sampling coordinates and for the upload contents. I found no open PR covering this (checked #613, #522, #506, which touch other files). ## Evidence Commits under test: `774e6df`, `70d34e9` on `upstream/main` `a81b55a` (rebased once to resolve conflicts in `CMakeLists.txt` and `shim_startup.asm` with the new shadow draw modes 14-16; my modes 20-24 do not overlap them). Environment: Windows 11 Pro 10.0.26300, MSVC 19.44.35228, DXC from Vulkan SDK 1.4.363.0. Hardware adapter: NVIDIA GeForce RTX 5060, driver 621.14 (UMD 32.0.16.2114), LUID 0xc90c. Software adapter: Microsoft Basic Render Driver, LUID 0x1071b. Debug layer unavailable. Both presets were configured with `--fresh` and built from scratch with no extra cache arguments. ```powershell ctest --preset <dev|release> --no-tests=error -R '^cpu_shim_upload_texture_(warp|hardware)$' -V ctest --preset <dev|release> --no-tests=error -R '^cpu_' -j 4 ``` | Preset | `^cpu_` | Upload-texture tests | Skipped | |---|---|---|---| | dev | 147/147 pass | warp + hardware pass | 0 | | release | 147/147 pass | warp + hardware pass | 0 | Root signature, texture, shader, PE and memory groups (`desktop_root_signature`, `era_heap`, `desktop_memory_query`, `offscreen_warp`, `bcpack_*`, `bc7_*`, `pixel_aot_*`, `static_exe_intake`, `conditional_import_paths`, `script_*`): 73/77 pass in each preset, with the same four non-passing tests in dev and release: - `pixel_aot_e64_approx_hardware` (introduced by #729) and `pixel_aot_sdwa_unary_hardware` fail with `E_OUTOFMEMORY` (HRESULT 0x8007000E) when creating the translated pixel pipeline on my RTX 5060. **Both fail identically on unmodified `upstream/main` `a81b55a`** on the same machine (verified by checking out `upstream/main` detached, rebuilding and running them), so they are not caused by this PR. I did not touch those tests and did not open an issue; the only related open issue I found (#312) is about denormal modes, not this error. - `pixel_aot_hardware` and `pixel_aot_predicate_rounding_hardware` hit the default 60 s CTest timeout when the area group runs with `-j 4`. Run alone with a longer timeout they pass (48-57 s; on unmodified `upstream/main` `predicate_rounding` also takes about 54 s), so they are slow rather than broken, and neither involves files changed here. Adapter identification: a temporary, uncommitted print in `shim_create_device` showed the device actually created. With `X2W_SHIM_DRAW_ADAPTER=hardware`, cases `tex`, `bc7`, `scene` and `texbad` all created the RTX 5060; with `warp` all created the Basic Render Driver. Negative-control mutations (each applied to the fixture, rebuilt, and run; each must fail): no corruption, no UV shift, damaged BC7 block, no SRV rebind in `scene`, skipped upload, linear sampler. All six made `cpu_shim_upload_texture_warp` fail. Removing the corruption fails with `texbad native exits: expected 20, got 42`; removing the shift fails with `texuv native exits: expected 20, got 42`. ## Bug found and fixed while preparing this The first version of the staging copy iterated `Footprint.Height` rows. For BC7 that is 8 texel rows while only 2 block rows exist (`rows=2`, `row_bytes=32`), so it read 256 bytes from a 64-byte table and wrote past the staging buffer. The copy now uses `NumRows` and `RowSizeInBytes` from `GetCopyableFootprints`, and `fill_staging` throws unless `rows * row_bytes` equals the source table size exactly and the last row ends inside the staging buffer. Reintroducing the old row count makes `bc7` fail with `staging geometry mismatch: rows=8 ... table_bytes=64`. ## Known risks and limitations - 8x8 textures, one mip, one array slice; only RGBA8 and BC7 mode 6. No mipmaps, BC1/BC3/BC5, other BC7 modes, arrays or cube maps. - Point sampling with clamp only; filtering and wrap modes are not covered. - Adapter identity is not printed by the test itself. It was confirmed with a temporary print. - Hardware results come from one adapter (RTX 5060). Other vendors are untested. - The BC7 reference frame comes from the repository's block builder, not from an independent decoder; the GPU decode is the independent side of the comparison. - This shows the texture path works from the EXE entry. It does not show that any title runs. ## Files `CMakeLists.txt`, `README.md`, `docs/experiments.md`, `tests/cpu/shim_draw_gpu.cpp`, `tests/cpu/shim_draw_provider.cpp`, `tests/cpu/shim_gpu_device.h` (new), `tests/cpu/shim_startup.asm`, `tests/cpu/shim_tex_check.py` (new), `tests/cpu/shim_tex_gpu.cpp` (new), `tests/cpu/tex_gen.py` (new), `tests/tex_quad.hlsl` (new). 817 insertions, 43 deletions. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:54 +00:00
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!808
No description provided.