Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16683,6 +16683,180 @@ cmake --build --preset dev --target startup_stream_consumer startup_heap_indexed
ctest --preset dev --no-tests=error -R "^startup_(heap_indexed_root.*|root_heap_(warp|hardware))$" -V
```

## Source-built native compute translation and offline cache

`tools/startup/compute_native.py` turns a bounded set of gfx1013 compute machine
code into a validated, signed desktop compute container and records it in a
revision-scoped cache. The machine code is assembled from source by LLVM 15
(`llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013`), decoded by `pixel_aot.disassemble`,
lowered by the existing `compute_store_aot.lower`, compiled by DXC as `cs_6_0 -E main`,
validated and signed through `probe_roots`/`dxil_retarget`, and probed with
`CreateRootSignature` and `CreateComputePipelineState`. It is an offline
translator and cache producer. It does not execute anything through the startup
stand-in, does not load a slot 62 pipeline, does not parse slot 67, and does not
change the shim.

### Fixture profiles

Two source-built programs are supported. Both read two descriptor words through
the table pointer, apply a lane guard, and store to a `RWTexture2D<uint>`:

| Profile | Group | Dispatch | Output |
|---|---|---|---|
| `1d` | 32x1x1 | 6x1x1 | 192 words, one column per dispatch |
| `2d` | 8x4x1 | 3x2x1 | 24 columns by 8 rows, 96-byte row stride |

The 2-D store uses the translator's proven two-axis layout. The guard is the
column bound, the only lane guard the translator verifies, and the load is a
column broadcast because the accepted load form has no row term. Other group
shapes, other descriptors, LDS, missing source bindings, a wrong table register
and a linear-index guard are refused with a named reason.

### Record and cache protocol

A record is a canonical little-endian structure with a fixed magic, the scalar
contract fields, the root parameter list, a SHA-256 of the code and the code
bytes. The supported contract is `version 1`, `stage 5` (compute), `isa gfx1013`,
`guest_wave 32`, translator revision 1, decoder identity 1, `cs_6_0`, and no
interpreted `COMPUTE_PGM_RSRC2`: `rsrc2_interpretation` must be 0 and
`recorded_rsrc2` must be 0. A nonzero field, another guest wave or another
profile is refused rather than defaulted.

The cache uses revision `x2w-startup-compute-native-2`. For each record:

| File | Contents |
|---|---|
| `req_<key>.csn` | the canonical record |
| `<key>.csn.src` | the request manifest (`status request`) |
| `<key>.csn.hlsl` | the accepted HLSL |
| `<key>.csn.cso` | the signed desktop container |
| `<key>.csn.manifest` | `x2w-native-compute 2` manifest with the status and evidence |

`<key>` is FNV-1a 64 over the revision string and the canonical record digest,
formatted as 16 lowercase hex digits. The manifest repeats the key, revision,
record digest, code size and digest, group, HLSL digest, output size and digest,
the dependency identity, the two validation HRESULTs, the `RTS0` contract, the
intrinsic-gate verdict, the signing state, and one `pso-<backend>` line per
probed adapter. Publication writes the artifacts first and the manifest last; a
reader accepts only a manifest whose digests, identity and backend evidence all
match, and an interrupted publication therefore never reads as a hit. A refusal
is written as `status refused` with its reason before any obsolete success
artifact is removed, and it is permanent for that revision. Refusal manifests
carry no dependency identity, so a translator change does not expire them; a
cache produced under another translator must be regenerated rather than reused.

### Dependency identity and toolchain pins

Every validated manifest declares eight identity fields. Three of them hash the
working-tree content of the repository tools used to produce the artifact:
`translator` (`compute_store_aot.py`), `decoder` (`pixel_aot.py`) and `pipeline`
(all of `compute_store_aot.py`, `pixel_aot.py`, `resource_inventory.py`,
`dxil_retarget.py`, `probe_roots.py`, `xbox_intrinsic_gate.py` and
`compute_native.py`). The other five are the pinned toolchain:

| Field | Pinned value |
|---|---|
| `llvm` | `de2e35a4f9b3f6a06d2a8a3342b3f62a3842b1923b8dfc2a6ce48e0cc2d1e85d` (LLVM 15.0.7 `libLLVM-15.so.1`) |
| `compiler` | `495033935c058fc6d318ac257afdfa910795bf41b7e5ba905a0e7191dc8bd4fa` (`dxcompiler.dll`, Windows SDK 10.0.26100) |
| `validator` | `db108ffef7bcecb984bdccf2b4725719d65b2ce7f1ebc40019dbe6c5a7016e09` (`dxil.dll`) |
| `target` | `dxil-ms-dx` |
| `dxc_flags` | `cs_6_0 -E main` |

The three content identities hash the bytes on disk, so the same tools checked
out with `core.autocrlf=true` and with LF line endings produce different
`translator`, `decoder` and `pipeline` values. A cache is therefore
machine-local: it is valid for the checkout that produced it, and a manifest
from another checkout is refused as stale rather than silently accepted. The
toolchain pins are file hashes and do not depend on line endings.

### Reproduction

Requirements: x64 Windows with the Visual Studio C++ tools and the Windows SDK,
CMake/Ninja, Python 3.11 or newer, WSL with LLVM 15 for the assemble and
translate stages, `root_probe.exe`/`root_device_probe.exe` built from this
repository, and a physical D3D12 adapter for the full cache suite because both
backends are required; the preflight alone can be limited with `--warp-only`.

```powershell
.\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev --target root_probe root_device_probe

$py = 'out\pe-env\Scripts\python.exe'
$dxc = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxc.exe'

# Machine-code preflight: translate, refusals, reference, assemble, disassemble,
# compile, validate, probe.
& $py -B tests\compute_native_check.py --out out\native-compute\preflight `
--wsl-distro Ubuntu-22.04 --dxc $dxc `
--root-probe out\build\dev\root_probe.exe --device-probe out\build\dev\root_device_probe.exe

# Full offline cache suite: 156 checks over requests, translation, publication,
# acceptance, identity, locking, refusals, cache hits and stale entries.
& $py -B tests\compute_native_cache_check.py --out out\native-compute\fresh `
--wsl-distro Ubuntu-22.04 --dxc $dxc `
--probe out\build\dev\root_probe.exe --pso-probe out\build\dev\root_device_probe.exe
```

`--linux-worker` is the internal entry point that the Windows orchestrator runs
inside WSL; it is not the command to start on Windows. The stages can also be
split by hand with `compute_native.py --pending <cache> --stage request`,
`--stage translate --llvm <libLLVM>` and `--stage compile --dxc <dxc> --probe
<root_probe> --pso-probe <root_device_probe>`.

### Measured results

On Windows 11 build 26300.9974 with LLVM 15.0.7 in WSL Ubuntu-22.04, Windows SDK
10.0.26100 DXC, WARP and an Intel Iris Xe (`8086:9a49`, driver 31.0.101.5333):

| Item | `1d` | `2d` |
|---|---|---|
| Machine code | 124 bytes, SHA-256 `57f31991…` | 128 bytes, SHA-256 `8374d7b3…` |
| Record | 336 bytes, SHA-256 `420b4d31…` | 340 bytes, SHA-256 `15c4cc21…` |
| Cache key | `d55528b6b2cfa1f8` | `95c4c65e03a8b336` |
| HLSL | 466 bytes, SHA-256 `6b6e8250…` | 482 bytes, SHA-256 `6836ef38…` |
| Signed container | 3640 bytes, SHA-256 `92d6a012…` | 3660 bytes, SHA-256 `6be3003e…` |

Both manifest identities were `translator compute_store_aot/d47dacfb7be907f9`,
`decoder pixel_aot/419cde0d50268c70` and `pipeline a6002e220219d61b` on the
checkout that produced them. Validation returned `0x00000000` for the container
and the module through `dxil.dll`, the root-signature contract `RTS0` was
present, the intrinsic gate returned `ALLOW`, and signing left a nonzero
container digest. `CreateRootSignature` and `CreateComputePipelineState` returned
`0x00000000` on WARP and on the physical adapter at shader model `0x65`.

The preflight passed its translate, refusal, reference, assemble, disassemble,
compile, validate and probe stages, with 9 text refusals and 9 byte refusals. The
refusals include a `COMPUTE_PGM_RSRC2` combined with explicit group registers
(`COMPUTE_PGM_RSRC2 places the group IDs; do not also give group registers`) and
`TG_SIZE_EN` (`COMPUTE_PGM_RSRC2 TG_SIZE_EN is not supported`); the adapter does
not interpret that field. The cache suite passed all 156 checks, including a
second compile that translated and compiled nothing and reported both keys as
`hit`, every identity and evidence mutation as non-accepted, artifact/digest
mismatches, interrupted publication, lock contention, and a published refusal
that removes the obsolete artifacts only after the refusal itself is visible.

A manifest rewritten to a different identity is refused, not revalidated:
`translator 'compute_store_aot/036cdd081f7f709a' is not the pinned
'compute_store_aot/d47dacfb7be907f9'`, and likewise for `decoder` and
`pipeline`. The cache is trusted only as far as the local filesystem and the
toolchain pins: every accepted entry is re-hashed on read, and nothing verifies
who wrote it.

### Scope and registration

Not covered here: native runtime execution, GPU readback through the startup
stand-in, a slot 62 loader, production slot 67 parsing, ExecuteIndirect, any new
instruction lowering, profiles other than the two above, interpreted
`COMPUTE_PGM_RSRC2`, `TG_SIZE_EN`, and guest waves other than 32.

The two Python checks are not registered in `CMakeLists.txt`: they need a WSL
distribution name, an explicitly selected DXC, both probe executables and
optionally a physical adapter, none of which the build system currently names.
They are run manually with the commands above. Registering them would need the
WSL distribution and toolchain paths exposed as cache variables, and a decision
about whether a missing adapter is a skip (77) or a failure.

## Startup range provenance

[Issue #870](https://github.com/R0Y00/Xbox2Windows/issues/870) asks which producer last wrote the range a
Expand Down
Loading
Loading