Trace each CopyTextureRegionX location by its active type #67

Closed
github-bot wants to merge 1 commit from gh-pr/67/head into gh-pr/67/base
Owner

@⁠philip-roy-jones on GitHub · 2026-11-21 22:38 UTC · original
fix/d3d12-copy-location-trace → main · +32 −7 · 1 files · 1 commits · closed without merging

Library / area: d3d12_xs, Scarlett command-list slot 83 (CopyTextureRegionX).

Exports changed (exports.txt rows): None.

Source of the behaviour: Each D3D12_TEXTURE_COPY_LOCATION has its own Type field selecting a subresource index or a placed footprint. The original trace assumed the destination was always a subresource and the source was always a footprint. An RGBA8 readback put the footprint on the destination and exposed the reversed interpretation. Microsoft's structure definition

The trace now reads the active member separately at each endpoint. An unknown type prints its tag. The regression covers a nonzero subresource index, a footprint offset above 4 GiB, distinct dimensions and an unknown type.

Guest evidence

I replayed the same x64 guest executable and shader blobs on upstream main and this commit. In both cases mdbg launched the guest, which called D3D12XboxCreateDevice, drew into a 16×16 R8G8B8A8_UNORM target, copied it to a buffer with a 256-byte row pitch, waited for its fence and mapped two pixels. The control omitted only DrawInstanced(3, 1, 0, 0). The guest reported Microsoft Basic Render Driver (1414:008c).

Launch Expected and observed inside (8,8) Expected and observed outside (1,1) Child exits, main / PR
Green triangle on blue 00 ff 00 ff 00 00 ff ff 0 / 0
Draw omitted 00 00 ff ff 00 00 ff ff 0 / 0

The actual copy traces below omit the process-specific resource addresses.

main  dst{type=1 sub=0} at (0,0,0) src{type=0 off=0x0 fmt=0 0x0x0 pitch=0}
PR    dst{type=1 off=0x0 fmt=28 16x16x1 pitch=256} at (0,0,0) src{type=0 sub=0}

The guest fixture extends the launcher in #59 and lives on a separate fork branch. Its authored gfx1030 vertex and pixel shaders were assembled with LLVM, translated by tombox-xshader and compiled by SDK DXC to shader-model-6.0 DXIL. Each draw/control launch used a fresh cache and recorded two translated stages and one successful PSO. The Rust regression in this PR runs directly on upstream. Guest fixture and runner at 20f0fc7

Windows x64 verification

An x64 Visual Studio developer shell had stable MSVC Rust 1.100.0, LLVM 19.1.7 with the AMDGPU target, and Windows SDK 10.0.26100.0. The following commands built and tested the compared revisions.

$env:TOMBOX_DXC_DIR = 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64'
$env:TOMBOX_DXC = Join-Path $env:TOMBOX_DXC_DIR dxc.exe
git fetch origin main
git switch --detach cd08e9da6c7d65cbc6b8cfb22541674871b02df6
cargo build --locked -p d3d12_xs --target-dir target
cargo test --locked -p d3d12_xs
cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants --skip pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample

git switch fix/d3d12-copy-location-trace
git rev-parse HEAD # cf7f12b218f90a8923bfedb973e66315c0317597
cargo build --locked -p d3d12_xs --target-dir target
cargo test --locked -p d3d12_xs
cargo test --locked -p d3d12_xs --lib cmdlist_wrap::tests::copy_trace_selects_the_active_location_fields -- --exact
cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants --skip pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample
git diff --check cd08e9da6c7d65cbc6b8cfb22541674871b02df6...HEAD

Both builds passed. The unfiltered suite had 408 passes on main and 409 on this branch, with the same 37 ignored and two failures on each. FXC rejected uint64_t in the centroid test. The per-sample test recorded 4,160 base invocations against 4,096 expected. The filtered runs passed all remaining unit tests and both process-debug integration tests. The focused regression and whitespace check passed.

I also rebuilt upstream e843998f0db8d59397eedd0df517b007a2b347a7 after the PR opened. It changed documentation and progress files. Its two launches (PIDs 2972 and 30260) returned the same four pixels and both children exited 0.

To reproduce the guest evidence, run python tools/verify/run_d3d12_guest.py --triangle on the linked fixture commit. For each runtime under comparison, copy its built target/debug/d3d12_xs.dll beside the staged guest and run these commands from that directory. Use a fresh directory for each cache.

$env:TOMBOX_SHADER_PREWARM = '0'
$env:TOMBOX_LOG = "$PWD/triangle.compat.log"
$env:TOMBOX_SHADER_CACHE_DIR = "$PWD/triangle-cache"
./mdbg.exe "$PWD/d3d12_guest.exe" triangle
$env:TOMBOX_LOG = "$PWD/no-draw.compat.log"
$env:TOMBOX_SHADER_CACHE_DIR = "$PWD/no-draw-cache"
./mdbg.exe "$PWD/d3d12_guest.exe" no-draw
  • cargo test -p d3d12_xs passes (the same two baseline failures reproduced).
  • No game or console files and no binaries included.
  • No fake success. The guest compares mapped bytes and the runner verifies the child exit.
**@⁠philip-roy-jones** on GitHub · 2026-11-21 22:38 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/67) `fix/d3d12-copy-location-trace` → `main` · +32 −7 · 1 files · 1 commits · closed without merging **Library / area:** `d3d12_xs`, Scarlett command-list slot 83 (`CopyTextureRegionX`). **Exports changed (exports.txt rows):** None. **Source of the behaviour:** Each `D3D12_TEXTURE_COPY_LOCATION` has its own `Type` field selecting a subresource index or a placed footprint. The original trace assumed the destination was always a subresource and the source was always a footprint. An RGBA8 readback put the footprint on the destination and exposed the reversed interpretation. [Microsoft's structure definition](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_texture_copy_location) The trace now reads the active member separately at each endpoint. An unknown type prints its tag. The regression covers a nonzero subresource index, a footprint offset above 4 GiB, distinct dimensions and an unknown type. ### Guest evidence I replayed the same x64 guest executable and shader blobs on upstream main and this commit. In both cases `mdbg` launched the guest, which called `D3D12XboxCreateDevice`, drew into a 16×16 `R8G8B8A8_UNORM` target, copied it to a buffer with a 256-byte row pitch, waited for its fence and mapped two pixels. The control omitted only `DrawInstanced(3, 1, 0, 0)`. The guest reported Microsoft Basic Render Driver (`1414:008c`). | Launch | Expected and observed inside (8,8) | Expected and observed outside (1,1) | Child exits, main / PR | | --- | --- | --- | --- | | Green triangle on blue | `00 ff 00 ff` | `00 00 ff ff` | 0 / 0 | | Draw omitted | `00 00 ff ff` | `00 00 ff ff` | 0 / 0 | The actual copy traces below omit the process-specific resource addresses. ```text main dst{type=1 sub=0} at (0,0,0) src{type=0 off=0x0 fmt=0 0x0x0 pitch=0} PR dst{type=1 off=0x0 fmt=28 16x16x1 pitch=256} at (0,0,0) src{type=0 sub=0} ``` The guest fixture extends the launcher in #59 and lives on a separate fork branch. Its authored gfx1030 vertex and pixel shaders were assembled with LLVM, translated by `tombox-xshader` and compiled by SDK DXC to shader-model-6.0 DXIL. Each draw/control launch used a fresh cache and recorded two translated stages and one successful PSO. The Rust regression in this PR runs directly on upstream. [Guest fixture and runner at `20f0fc7`](https://github.com/philip-roy-jones/xbox-emulator/tree/20f0fc74414611367feaeb45ce1969f534b30a19/tools/verify) ### Windows x64 verification An x64 Visual Studio developer shell had stable MSVC Rust 1.100.0, LLVM 19.1.7 with the AMDGPU target, and Windows SDK 10.0.26100.0. The following commands built and tested the compared revisions. ```powershell $env:TOMBOX_DXC_DIR = 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64' $env:TOMBOX_DXC = Join-Path $env:TOMBOX_DXC_DIR dxc.exe git fetch origin main git switch --detach cd08e9da6c7d65cbc6b8cfb22541674871b02df6 cargo build --locked -p d3d12_xs --target-dir target cargo test --locked -p d3d12_xs cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants --skip pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample git switch fix/d3d12-copy-location-trace git rev-parse HEAD # cf7f12b218f90a8923bfedb973e66315c0317597 cargo build --locked -p d3d12_xs --target-dir target cargo test --locked -p d3d12_xs cargo test --locked -p d3d12_xs --lib cmdlist_wrap::tests::copy_trace_selects_the_active_location_fields -- --exact cargo test --locked -p d3d12_xs -- --test-threads=1 --skip centroid_bind::tests::lowered_pixel_shader_compiles_with_fxc_in_both_variants --skip pso_ext::ps::tests::per_sample_iteration_runs_the_translated_ps_once_per_sample_like_ps_iter_sample git diff --check cd08e9da6c7d65cbc6b8cfb22541674871b02df6...HEAD ``` Both builds passed. The unfiltered suite had 408 passes on main and 409 on this branch, with the same 37 ignored and two failures on each. FXC rejected `uint64_t` in the centroid test. The per-sample test recorded 4,160 base invocations against 4,096 expected. The filtered runs passed all remaining unit tests and both process-debug integration tests. The focused regression and whitespace check passed. I also rebuilt upstream `e843998f0db8d59397eedd0df517b007a2b347a7` after the PR opened. It changed documentation and progress files. Its two launches (PIDs 2972 and 30260) returned the same four pixels and both children exited 0. To reproduce the guest evidence, run `python tools/verify/run_d3d12_guest.py --triangle` on the linked fixture commit. For each runtime under comparison, copy its built `target/debug/d3d12_xs.dll` beside the staged guest and run these commands from that directory. Use a fresh directory for each cache. ```powershell $env:TOMBOX_SHADER_PREWARM = '0' $env:TOMBOX_LOG = "$PWD/triangle.compat.log" $env:TOMBOX_SHADER_CACHE_DIR = "$PWD/triangle-cache" ./mdbg.exe "$PWD/d3d12_guest.exe" triangle $env:TOMBOX_LOG = "$PWD/no-draw.compat.log" $env:TOMBOX_SHADER_CACHE_DIR = "$PWD/no-draw-cache" ./mdbg.exe "$PWD/d3d12_guest.exe" no-draw ``` - [ ] `cargo test -p d3d12_xs` passes (the same two baseline failures reproduced). - [x] No game or console files and no binaries included. - [x] No fake success. The guest compares mapped bytes and the runner verifies the child exit.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:09:07 +00:00
github-bot closed this pull request 2026-11-26 06:09:07 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.