cpu: draw each completed archive record through D3D12 #857

Merged
lukaslw-lab merged 2 commits from upstream-pr/863 into main 2026-11-23 14:47:55 +00:00
lukaslw-lab commented 2026-11-23 14:32:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T14:32:41Z.


Change

Connects the archive texture handoff from #850 to D3D12. Refs #830.

The same Zig reader image runs against a GPU consumer (tests/cpu/archive/texture_gpu.cpp), built as archive_codec.dll in archive_gpu/ next to copies of the reader and blast. The AOT reader links a GPU build of the codec with the translated decoder. One device, queue and pipeline serve both records. Each completed record uploads its 4×4 RGBA8 texture, draws a point-sampled quad onto a 16×16 target, signals and waits for its own fence value, and reads the frame back. QuadFrames (quad_frames.hpp) holds the device and frame state. It accepts any copyable texture size and format.

Shared interfaces touched:

  • texture.hpp adds finish_archive_textures(), which codec.cpp's completed() calls once after the last record so GPU objects are released at a defined point rather than at DLL detach. The stdout consumer's version is empty, so #850's output and test are unchanged. The Zig reader is unchanged.
  • tests/cpu/shim_gpu_device.h (#814) gains a non-throwing shim_try_create_device() and shim_report(). shim_create_device() now wraps them with identical behavior. All cpu_shim_* tests pass.

Verification

Commit 3fb24dc (rebased on 223a908) on Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, Python 3.13.7. Adapters: Microsoft Basic Render Driver (in-box WARP, driver 10.0.19041.7811) and NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1047). D3D12 debug layer not enabled.

ctest --preset dev --no-tests=error -R '^cpu_(archive_texture|native_archive|shim_)' -V
17 total: 15 passed, 2 skipped (exit 77), 0 failed
ctest --preset release --no-tests=error -R '^cpu_(archive_texture|native_archive|shim_)' -V
17 total: 15 passed, 2 skipped (exit 77), 0 failed

The two skips are cpu_shim_chain_warp and cpu_shim_shadow_warp, which need mesh shaders that this Windows 10 in-box WARP lacks. They skip identically on main.

cpu_archive_texture_gpu_warp and cpu_archive_texture_gpu_hardware each run six cases under native Windows, pe_map and AOT (18 runs per adapter). All runs must report the same adapter and driver. Frames are compared per pixel with an independent CPU reference (pixel (x, y) = texel (x/4, y/4)); a mismatch names the first differing pixel.

Case Frames Trace and exit
Two valid records Both match Both upload hashes, fences 1 and 2, gpu release 0, exit 0
Second record truncated First only Fence 1, both records freed, device released once, exit 2
First record truncated None No device created, exit 2
stale: second upload skipped Second repeats the first (144 bytes differ from its reference) upload skipped, exit 0
fail: second texture one byte short First only Upload refused before GPU work, gpu release 0, exit 4
leak: one device object never released Both match gpu release 1

python -B tests/docs_links_check.py (177 links), python -B tests/bidi_controls_check.py (700 files) and git diff --check pass. The full dev suite is still running; I'll post its result as a comment.

Evidence and follow-up

  • Source-built fixture, MIT. Inputs are the two generated records from tests/cpu/archive_check.py; the texture rule is #850's.
  • Negative controls: stale shows a missed upload is detected, leak shows the release count detects a leaked device object, and fail and both truncated cases cover cleanup and exit status on each failure path.
  • The decoded record bytes are checked through the frames: the red channel carries them under #850's rule. The decoder's alloc/input/output/free events are part of the exact trace.
  • The GPU code returns errors instead of throwing. In the pe_map run the codec DLL is mapped, and a C++ exception thrown and caught inside it escaped as 0xE06D7363, while the same DLL loaded by Windows caught it. A standalone 15-line DLL shows the same: catch (int) and catch (...) fail when mapped, __try/__except works, and RtlPcToFileHeader returns NULL for the mapped image. I'll open a separate issue with that repro.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6561600749 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/863). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-23T14:32:41Z. --- ## Change Connects the archive texture handoff from #850 to D3D12. Refs #830. The same Zig reader image runs against a GPU consumer (`tests/cpu/archive/texture_gpu.cpp`), built as `archive_codec.dll` in `archive_gpu/` next to copies of the reader and blast. The AOT reader links a GPU build of the codec with the translated decoder. One device, queue and pipeline serve both records. Each completed record uploads its 4×4 RGBA8 texture, draws a point-sampled quad onto a 16×16 target, signals and waits for its own fence value, and reads the frame back. `QuadFrames` (`quad_frames.hpp`) holds the device and frame state. It accepts any copyable texture size and format. Shared interfaces touched: - `texture.hpp` adds `finish_archive_textures()`, which `codec.cpp`'s `completed()` calls once after the last record so GPU objects are released at a defined point rather than at DLL detach. The stdout consumer's version is empty, so #850's output and test are unchanged. The Zig reader is unchanged. - `tests/cpu/shim_gpu_device.h` (#814) gains a non-throwing `shim_try_create_device()` and `shim_report()`. `shim_create_device()` now wraps them with identical behavior. All `cpu_shim_*` tests pass. ## Verification Commit `3fb24dc` (rebased on `223a908`) on Windows 10 22H2 (build 19045), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, Python 3.13.7. Adapters: Microsoft Basic Render Driver (in-box WARP, driver 10.0.19041.7811) and NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1047). D3D12 debug layer not enabled. ``` ctest --preset dev --no-tests=error -R '^cpu_(archive_texture|native_archive|shim_)' -V 17 total: 15 passed, 2 skipped (exit 77), 0 failed ctest --preset release --no-tests=error -R '^cpu_(archive_texture|native_archive|shim_)' -V 17 total: 15 passed, 2 skipped (exit 77), 0 failed ``` The two skips are `cpu_shim_chain_warp` and `cpu_shim_shadow_warp`, which need mesh shaders that this Windows 10 in-box WARP lacks. They skip identically on `main`. `cpu_archive_texture_gpu_warp` and `cpu_archive_texture_gpu_hardware` each run six cases under native Windows, `pe_map` and AOT (18 runs per adapter). All runs must report the same adapter and driver. Frames are compared per pixel with an independent CPU reference (pixel `(x, y)` = texel `(x/4, y/4)`); a mismatch names the first differing pixel. | Case | Frames | Trace and exit | |---|---|---| | Two valid records | Both match | Both upload hashes, fences 1 and 2, `gpu release 0`, exit 0 | | Second record truncated | First only | Fence 1, both records freed, device released once, exit 2 | | First record truncated | None | No device created, exit 2 | | `stale`: second upload skipped | Second repeats the first (144 bytes differ from its reference) | `upload skipped`, exit 0 | | `fail`: second texture one byte short | First only | Upload refused before GPU work, `gpu release 0`, exit 4 | | `leak`: one device object never released | Both match | `gpu release 1` | `python -B tests/docs_links_check.py` (177 links), `python -B tests/bidi_controls_check.py` (700 files) and `git diff --check` pass. The full `dev` suite is still running; I'll post its result as a comment. ## Evidence and follow-up - Source-built fixture, MIT. Inputs are the two generated records from `tests/cpu/archive_check.py`; the texture rule is #850's. - Negative controls: `stale` shows a missed upload is detected, `leak` shows the release count detects a leaked device object, and `fail` and both truncated cases cover cleanup and exit status on each failure path. - The decoded record bytes are checked through the frames: the red channel carries them under #850's rule. The decoder's `alloc`/`input`/`output`/`free` events are part of the exact trace. - The GPU code returns errors instead of throwing. In the `pe_map` run the codec DLL is mapped, and a C++ exception thrown and caught inside it escaped as `0xE06D7363`, while the same DLL loaded by Windows caught it. A standalone 15-line DLL shows the same: `catch (int)` and `catch (...)` fail when mapped, `__try`/`__except` works, and `RtlPcToFileHeader` returns NULL for the mapped image. I'll open a separate issue with that repro. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:09 +00:00
R0Y00 commented 2026-11-24 06:49:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T14:35:59Z.


I built the Zig reader and GPU codec and ran both GPU CTests plus the original texture publication check. All 18 cases matched on each of WARP and RTX 4060 Laptop, including the two fences, truncated input, stale upload, incomplete texture and retained device-reference controls.

I tightened hardware capability detection in the test harness. Only the initial hardware probe can skip with exit 77. Once that probe finds a device, 77 from any runner is a failed comparison. A synthetic child-process check exercised both paths and the three local CTests passed. Windows CI is rerunning on this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7104243060 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/863#issuecomment-7104243060). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T14:35:59Z. --- I built the Zig reader and GPU codec and ran both GPU CTests plus the original texture publication check. All 18 cases matched on each of WARP and RTX 4060 Laptop, including the two fences, truncated input, stale upload, incomplete texture and retained device-reference controls. I tightened hardware capability detection in the test harness. Only the initial hardware probe can skip with exit 77. Once that probe finds a device, 77 from any runner is a failed comparison. A synthetic child-process check exercised both paths and the three local CTests passed. Windows CI is rerunning on this head.
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!857
No description provided.