diff options
Diffstat (limited to 'docs/boot.md')
| -rw-r--r-- | docs/boot.md | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/docs/boot.md b/docs/boot.md new file mode 100644 index 000000000..4738b9a73 --- /dev/null +++ b/docs/boot.md | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | # First boot: the runbook and the two traces | ||
| 2 | |||
| 3 | **Status: prepared, not yet run against the retail executable.** The package in the repository's test corpus does | ||
| 4 | not contain `game_scarlett_master.exe` (RT-5), so this page is the procedure and the trace tool for the day it | ||
| 5 | arrives. Nothing here quotes game data; a real trace stays on the player's machine. | ||
| 6 | |||
| 7 | ## 1. What the first boot produces | ||
| 8 | |||
| 9 | `gta6rt` has three passes over the executable (`runtime/README.md`, "Dry run" and "Current limits"): | ||
| 10 | |||
| 11 | | Pass | What it does | What a clean result shows | | ||
| 12 | |---|---|---| | ||
| 13 | | `--dry-run` | maps the image, binds its imports, applies TLS | every module in `map`, no exception | | ||
| 14 | | `--init` | runs TLS callbacks and `DllMain(PROCESS_ATTACH)` | `tls_callback` and `dllmain` events, no exception | | ||
| 15 | | `--run` | calls the entry point on the game thread and returns its exit code | `exit` (or a deliberate `error`) | | ||
| 16 | |||
| 17 | Two traces are written independently: | ||
| 18 | |||
| 19 | * **startup trace** (`--trace FILE`): one JSON object per line, flushed per event, so it survives a crash. Kinds | ||
| 20 | and fields are in [`runtime/README.md`](../runtime/README.md) ("Startup trace"). | ||
| 21 | * **D3D12 trace** (`--trace-d3d12`): one `[d3d12-trace] #<seq> <method> <outcome>` line per call, on stderr. The | ||
| 22 | ordinary `[rt]` diagnostics stay separate. | ||
| 23 | |||
| 24 | `tools/boot_trace.py` reads both and prints the triage units: modules, unimplemented calls and callers, | ||
| 25 | DllMain/TLS results, exceptions with their stack frames, the exit, and the D3D12 calls by outcome and first call | ||
| 26 | per method. The `[rt]` lines in the same stderr log carry the device parameters, feature ids and warnings; the | ||
| 27 | summary leaves them as a count, so grep `^\[rt\]` for those. | ||
| 28 | |||
| 29 | ## 2. Commands | ||
| 30 | |||
| 31 | Windows (from the repository root): | ||
| 32 | |||
| 33 | ```powershell | ||
| 34 | $env:LEONIDA_D3D12 = 'vulkan' | ||
| 35 | $exe = "C:\path\to\game_scarlett_master.exe" | ||
| 36 | $pkg = "C:\path\to\the\package" | ||
| 37 | $trace = Join-Path $env:TEMP boot.jsonl | ||
| 38 | $log = Join-Path $env:TEMP d3d12.log | ||
| 39 | .\runtime\build\gta6rt.exe --run $exe --game-dir $pkg --trace $trace --trace-d3d12 2> $log | ||
| 40 | python -I tools\boot_trace.py $trace --d3d12 $log | ||
| 41 | ``` | ||
| 42 | |||
| 43 | Windows PowerShell 5.1 writes `2>` as UTF-16LE; the tool names that file instead of parsing it. Use | ||
| 44 | `2>&1 | Out-File -Encoding utf8 $log` there, or PowerShell 7, which defaults to UTF-8. The tool strips the BOM that | ||
| 45 | 5.1 writes with `utf8`, and accepts the `program.exe : ` prefix 5.1 puts in front of the first stderr line when it | ||
| 46 | turns it into an error record, so that call is not lost. `cmd /c` writes the lines unchanged. | ||
| 47 | |||
| 48 | Linux under Wine (a cross build made with xwin, or the `runtime-windows` artifact; the backend must be Vulkan): | ||
| 49 | |||
| 50 | ```sh | ||
| 51 | export LEONIDA_D3D12=vulkan | ||
| 52 | wine runtime/build/windows/gta6rt.exe --run /path/to/game_scarlett_master.exe \ | ||
| 53 | --game-dir "Z:\\path\\to\\the\\package" \ | ||
| 54 | --trace "Z:\\tmp\\boot.jsonl" --trace-d3d12 2> /tmp/d3d12.log | ||
| 55 | python3 -I tools/boot_trace.py /tmp/boot.jsonl --d3d12 /tmp/d3d12.log | ||
| 56 | ``` | ||
| 57 | |||
| 58 | `--trace FILE` **refuses an existing file** (exit 2): it is created before the loader reads anything, so use a | ||
| 59 | fresh name or delete the old one. `LEONIDA_D3D12=vulkan` selects the Vulkan-backed device, the only backend that | ||
| 60 | writes the `[d3d12-trace]` lines; without it the layer uses the Windows D3D12 device and the trace has nothing to | ||
| 61 | read. Keep the traces out of the repository: they can quote whatever the game prints. | ||
| 62 | |||
| 63 | Useful switches: | ||
| 64 | |||
| 65 | * `LEONIDA_UNIMPLEMENTED=log` (default) logs every unimplemented import once and returns 0; `fail` returns | ||
| 66 | `E_NOTIMPL` for the `HRESULT` imports; `stop` ends the process with exit code 3 on the first such call, after | ||
| 67 | printing the caller's `module+RVA` and the argument registers (with a debugger attached it breaks instead). Start | ||
| 68 | with `log`, then use `stop` to pin the first blocker and `fail` to see how the game's own failure path reacts. | ||
| 69 | This switch covers imports only; it does not affect the D3D12 outcomes. | ||
| 70 | * `LEONIDA_VK_VALIDATION=1` enables the Khronos validation layer with the Vulkan backend (startup overhead; it is a | ||
| 71 | diagnostic). | ||
| 72 | * `DISABLE_RTSS_LAYER=1` and `DISABLE_VULKAN_OBS_CAPTURE=1` when MSI Afterburner or OBS is installed; their | ||
| 73 | implicit layers add swapchain usage that shows up as validation errors ([testing.md](testing.md), "Known | ||
| 74 | problems"). | ||
| 75 | * `--overlay DIR` sends the guest's writes to a private folder instead of the package. | ||
| 76 | |||
| 77 | ## 3. Triage order | ||
| 78 | |||
| 79 | Read the startup trace first; the first event that is not the expected one is the run's first fact. | ||
| 80 | |||
| 81 | 1. **`map`** — is the executable at its preferred base (`relocated: false`), and are the expected package DLLs | ||
| 82 | mapped? A missing module is an import-table or search-path problem. | ||
| 83 | 2. **`unimplemented_call`** — the first `dll!name` and its `caller` (module+RVA). Add a shim, a host binding or a | ||
| 84 | deliberate failure in `runtime/shims/registry.cpp`; rerun with `LEONIDA_UNIMPLEMENTED=stop` to halt at the first | ||
| 85 | remaining blocker. | ||
| 86 | 3. **`tls_callback` / `dllmain`** — a failed DllMain, or a TLS callback that faults, usually points at the CRT or | ||
| 87 | TLS index; the loader's own TLS is checked by `run_tiny_game_tls`. | ||
| 88 | 4. **`exception`** — code, `at`, access/address and the stack frames. The loader's vectored handler only records, | ||
| 89 | so the process behaviour is the same with or without the trace. | ||
| 90 | 5. **`exit` / `error`** — a clean exit is not a correct frame; continue to the D3D12 trace. | ||
| 91 | 6. **D3D12 trace** — the `failed`, `unsupported` and `refused` lines name the method. Compare its position with | ||
| 92 | the public SDK vtable; an unknown slot is expected until the executable names it (Q2, Q6). The `[rt]` lines in | ||
| 93 | the same log carry what the trace does not: the 24 device words, feature ids, warnings. | ||
| 94 | 7. **First frame** — after the device and queues, the first `CreateRootSignature`, PSO, `Draw*` and `PresentX` (or | ||
| 95 | DXGI) calls are the frame's critical path. The layer's M0–M4 tests already exercise the offscreen parts; the | ||
| 96 | present slots are the part that cannot be measured from the package alone. | ||
| 97 | |||
| 98 | The trace tool prints the first call per method and the `unsupported`/`failed`/`refused` lists; `--json` gives the | ||
| 99 | same summary for a script. Share that summary's **counts and error classes**, not the trace file or its debug | ||
| 100 | strings. | ||
| 101 | |||
| 102 | ## 4. The open questions, and the trace signal for each | ||
| 103 | |||
| 104 | The questions are in [`d3d12_vulkan.md`](d3d12_vulkan.md) §8.2; that table repeats 16, 19 and 20, and this one is | ||
| 105 | the de-duplicated 1–22. It maps each question to the event to look for; it does not answer them. | ||
| 106 | |||
| 107 | | # | Question | Signal in the first trace | | ||
| 108 | |---|---|---| | ||
| 109 | | 1 | `D3D12XboxCreateDevice` 24-word params and flags | first `D3D12XboxCreateDevice` in the D3D12 trace; the shim prints the 24 words only when `--trace-d3d12` is off, so run once without it (or grep `^\[rt\]`); accept unknown flags | | ||
| 110 | | 2 | Xbox device/heap/queue/command-list slots | queue, fence and allocator method names in the D3D12 trace; device slots past the PC vtable print an `[rt] d3d12_xs: device slot …` line instead and record nothing; compare with the SDK vtable | | ||
| 111 | | 3 | Root signature → `s0..s31` | `CreateRootSignature`, `SetGraphicsRootSignature`, then the shader's user-SGPR reads; mask `0x03000000` on a copy | | ||
| 112 | | 4 | Descriptor bytes and heap increments | first `CreateShaderResourceView`/`CreateSampler` and the first draw; dump the heap bytes and compare with the T#/S# parser | | ||
| 113 | | 5 | VA range and arena capacity | `GetGPUVirtualAddress` and every descriptor base; high-water mark | | ||
| 114 | | 6 | DXGI, `PresentX`, or both | first present/queue call; `PresentX` is a queue method past the public chain, so an unknown slot is the expected first finding | | ||
| 115 | | 7 | Standard AS build vs `XboxBvhBuilder` | first `BuildRaytracingAccelerationStructure`/`Copy...` vs slot-62 PSOs; see [embedded_shaders.md](embedded_shaders.md) | | ||
| 116 | | 8 | XDXR desc layouts | measured in [xdxr.md](xdxr.md); the live signal is a non-empty stream desc at slot 62 | | ||
| 117 | | 9 | Tiled textures / DCC | slot 76, `CopyTextureRegion`, resource descs; a `0x101` layout or tiled address | | ||
| 118 | | 10 | Binning, DCC, VRS, wave MMA, stream output | shader-side answered by `tools/feature_scan.py`; the trace adds PSO/stream subobjects | | ||
| 119 | | 11 | `CheckFeatureSupport` answers | the call's `ok`/`failed` and the `[rt]` feature-id line; the answer itself is not logged yet | | ||
| 120 | | 12 | Async compute / copy queues | queue creation and cross-queue fences | | ||
| 121 | | 13 | 144-byte push constants | device creation `[rt]` line; `push_constants_need_fallback` when the device reports fewer | | ||
| 122 | | 14 | Two code-base stages in one PSO | PSO creation log; the index metadata (`uses_code_base`) | | ||
| 123 | | 15 | `ExecuteIndirect` signatures | `CreateCommandSignature` and `ExecuteIndirect` calls | | ||
| 124 | | 16 | UAV counters and typed buffer formats | UAV descs and V# format logs; formats outside `Gen.FORMATS` read 0 | | ||
| 125 | | 17 | Upload/readback resources reaching shaders | `CreateCommittedResource` heap types and the VB/IB/descriptor that points at one | | ||
| 126 | | 18 | Placed/reserved/tiled resources | `CreatePlacedResource`, aliasing barriers, tile mappings | | ||
| 127 | | 19 | `0x03000000` root-signature bits | the root-signature blobs; the mask is a workaround, not the meaning | | ||
| 128 | | 20 | Which BVH builder programs the game uses | slot-62 PSOs on the first RT frame; map each to its `ILDN` container | | ||
| 129 | | 21 | PIX `Metadata` blob | metadata values; 0 and 1 are decoded silently, so an `unsupported` line means an unexpected value; if it is 2, decode the console blob from the executable's PIX calls, not the PC WinPixEventRuntime layout | | ||
| 130 | | 22 | `CheckFeatureSupport(OPTIONS5)` RaytracingTier | the `[rt]` feature id; the tier answer itself is not logged yet, and `DispatchRays` stays unimplemented | | ||
| 131 | |||
| 132 | ## 5. What a good first run looks like | ||
| 133 | |||
| 134 | * `map` lists the executable at its base, no `relocated`, and the package DLLs the imports need. | ||
| 135 | * `dllmain` is all `1`; no `exception` before the entry point. | ||
| 136 | * The D3D12 trace starts with the device, queue, allocator, list and fence, then the first resource/PSO/draw. | ||
| 137 | * The first `unsupported` is a named method, not a crash; it is the next D3D12 call to fix. `LEONIDA_UNIMPLEMENTED` | ||
| 138 | does not affect these outcomes. | ||
| 139 | * `exit` is the game's own code, not the loader's. A crash after the first frame is the next layer question. | ||
| 140 | |||
| 141 | ## 6. Limits | ||
| 142 | |||
| 143 | The retail executable is not in the package, so this page is untested against it; the tool and the trace formats | ||
| 144 | are tested on synthetic fixtures and on `tiny_game` (which has no D3D12 calls). The present slots (Q6) and the | ||
| 145 | Xbox device parameters (Q1) remain the first things the executable itself has to name. The D3D12 trace needs the | ||
| 146 | Vulkan backend; a build without it runs the game's calls through the PC device and records nothing. The runbook | ||
| 147 | does not make the game boot; it makes the first real trace readable. | ||