startup: show the build revision in the output window title #2203

Merged
JohnConnorNPC merged 4 commits from upstream-pr/2211 into main 2026-11-25 05:55:47 +00:00
JohnConnorNPC commented 2026-11-25 05:21:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-25T05:21:05Z.


What

This is a debug aid. The presenter window title and the D3D12XboxCreateDevice log line now show which source revision the shim was built from:

  • the output window is created as Xbox2Windows <rev> - output;
  • the per-30-frame title reads Xbox2Windows <rev> - frame N, F fps, D translated draws (...);
  • the x2w-d3d12 D3D12XboxCreateDevice ... -> 0x........ line ends with build=<rev>.

<rev> is git rev-parse --short=8 HEAD. It gets -dirty when tracked files differ from HEAD; untracked files do not count. It is unknown when git is missing or the source directory is not the top of a work tree, for example a tarball. A tarball unpacked inside another repository also reports unknown. A build started with an inherited GIT_DIR ignores it.

Why

When a screenshot or log comes back, the reader can tell which build produced it without asking.

Design

  • cmake/x2w_build_rev.cmake runs on every build from an always-run custom target. It writes a tiny generated source, generated/x2w_build_rev.cpp, that defines x2w_build_rev and x2w_build_rev_w (declared in src/x2w_build_rev.h). It rewrites the file only when the text changes, so an unchanged revision recompiles nothing.
  • The source builds into a static x2w_build_rev library (/Zl, so it links into targets with either CRT). It is linked into every target that compiles d3d12_xs_device.cpp: d3d12_xs_shim, offscreen_check and cpu_placed_dxr_provider.
  • The titles and the log line format the revision at run time (%ls / %s). The revision is not a macro in a header included by d3d12_xs_device.cpp. That file takes 64–100 s to compile, and a header would recompile it on every commit and on every clean/dirty flip. Now only the tiny source recompiles and the DLLs relink.
  • Why build time and not configure time: a configure-time value goes stale after the next commit. Worktrees and packed refs also make CMAKE_CONFIGURE_DEPENDS on .git/HEAD unreliable.
  • The git calls use git -C <src> and --no-optional-locks, so a build never takes the index lock. GIT_CEILING_DIRECTORIES is set to the source parent.

Tests

New check tests/startup_build_rev_check.py. It is added to the python-linux list in windows.yml and to AGENTS.md, and registered as ctest startup_build_rev_controls and startup_build_rev_dll.

  • Controls (no arguments): run the generator against temporary git repositories with an empty global config, no system config and a test identity. There are 10 cases:

    • clean commit;
    • unchanged rerun (mtime pinned to an old value first, then asserted unchanged);
    • untracked file only;
    • tracked edit;
    • new commit;
    • not a repository;
    • a directory inside another repository;
    • inherited GIT_DIR;
    • no git executable.

    The check exits 77 only when git or cmake is not on PATH.

  • dll <d3d12_xs.dll> <x2w_build_rev.cpp>: the built shim must contain the generated revision, both ASCII and UTF-16LE. It must also contain both UTF-16LE title formats and the full log format ending in build=%s. A generated source without the definitions fails as unmeasured.

Results on 75756a7f (Linux, clang-cl 19 + xwin SDK cross build with Ninja, host Python 3; runtime under Proton Wine):

Command Result
python -B tools/run_checks_parallel.py <the windows.yml python-linux list, 95 checks> all 95 checks passed, exit 0
cmake --build <b> --target d3d12_xs_shim offscreen_check cpu_placed_dxr_provider startup_null_views_check exit 0
python3 -B tests/startup_build_rev_check.py startup_build_rev_check: 10 cases ok, exit 0
python3 -B tests/startup_build_rev_check.py dll <b>/d3d12_xs.dll <b>/generated/x2w_build_rev.cpp ok ...: revision 75756a7f, 5 strings, exit 0
wine startup_null_views_check.exe hardware (links the shim) log line ... -> 0x00000000 build=75756a7f, device OK, exit 0
No-change rebuild only the generator step runs
Rebuild after a docs-only commit ninja -n -d explain never mentions d3d12_xs_device.cpp.obj; the generated source recompiles and the shim relinks

Mutations: each was run once and the file restored by hash. Every one fails the check on its own case.

Mutation Fails at
drop the -dirty suffix tracked edit
drop --untracked-files=no untracked file only
file(CONFIGURE) -> file(WRITE) unchanged rerun
ignore git's result not a repository
keep the old file on a clean tree new commit
drop GIT_CEILING_DIRECTORIES directory inside another repository
keep an inherited GIT_DIR inherited GIT_DIR
output title without the revision dll: output-window title
frame title without the revision dll: frame title
log format without build=%s dll: device-create log format
generated source with another revision dll: narrow and UTF-16 revision
generated source without definitions dll: revision unmeasured

Not measured

  • The window title on a running Windows desktop. No source-built fixture opens the presenter window, so the title is checked as format strings in the built DLL. The log line was observed at run time under Wine.
  • MSVC builds, ctest --preset dev/release and the Visual Studio generator. This PR's CI compiles the shim and offscreen_check with MSVC, but the PR test filter does not run the startup_build_rev_* ctests. Windows git path forms in the controls (backslash temp paths, GIT_CEILING_DIRECTORIES) are therefore not exercised on Windows by the PR job.

Limitation

tools/startup/triage_run.py keeps only allowlisted fields, so redacted triage output will not carry build=. Adding it is a follow-up.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6597799784 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2211). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-25T05:21:05Z. --- ## What This is a debug aid. The presenter window title and the `D3D12XboxCreateDevice` log line now show which source revision the shim was built from: - the output window is created as `Xbox2Windows <rev> - output`; - the per-30-frame title reads `Xbox2Windows <rev> - frame N, F fps, D translated draws (...)`; - the `x2w-d3d12 D3D12XboxCreateDevice ... -> 0x........` line ends with `build=<rev>`. `<rev>` is `git rev-parse --short=8 HEAD`. It gets `-dirty` when tracked files differ from HEAD; untracked files do not count. It is `unknown` when git is missing or the source directory is not the top of a work tree, for example a tarball. A tarball unpacked inside another repository also reports `unknown`. A build started with an inherited `GIT_DIR` ignores it. ## Why When a screenshot or log comes back, the reader can tell which build produced it without asking. ## Design - `cmake/x2w_build_rev.cmake` runs on every build from an always-run custom target. It writes a tiny generated source, `generated/x2w_build_rev.cpp`, that defines `x2w_build_rev` and `x2w_build_rev_w` (declared in `src/x2w_build_rev.h`). It rewrites the file only when the text changes, so an unchanged revision recompiles nothing. - The source builds into a static `x2w_build_rev` library (`/Zl`, so it links into targets with either CRT). It is linked into every target that compiles `d3d12_xs_device.cpp`: `d3d12_xs_shim`, `offscreen_check` and `cpu_placed_dxr_provider`. - The titles and the log line format the revision at run time (`%ls` / `%s`). The revision is not a macro in a header included by `d3d12_xs_device.cpp`. That file takes 64–100 s to compile, and a header would recompile it on every commit and on every clean/dirty flip. Now only the tiny source recompiles and the DLLs relink. - Why build time and not configure time: a configure-time value goes stale after the next commit. Worktrees and packed refs also make `CMAKE_CONFIGURE_DEPENDS` on `.git/HEAD` unreliable. - The git calls use `git -C <src>` and `--no-optional-locks`, so a build never takes the index lock. `GIT_CEILING_DIRECTORIES` is set to the source parent. ## Tests New check `tests/startup_build_rev_check.py`. It is added to the python-linux list in `windows.yml` and to `AGENTS.md`, and registered as ctest `startup_build_rev_controls` and `startup_build_rev_dll`. - **Controls** (no arguments): run the generator against temporary git repositories with an empty global config, no system config and a test identity. There are 10 cases: - clean commit; - unchanged rerun (mtime pinned to an old value first, then asserted unchanged); - untracked file only; - tracked edit; - new commit; - not a repository; - a directory inside another repository; - inherited `GIT_DIR`; - no git executable. The check exits 77 only when git or cmake is not on PATH. - **`dll <d3d12_xs.dll> <x2w_build_rev.cpp>`**: the built shim must contain the generated revision, both ASCII and UTF-16LE. It must also contain both UTF-16LE title formats and the full log format ending in `build=%s`. A generated source without the definitions fails as unmeasured. Results on 75756a7f (Linux, clang-cl 19 + xwin SDK cross build with Ninja, host Python 3; runtime under Proton Wine): | Command | Result | |---|---| | `python -B tools/run_checks_parallel.py <the windows.yml python-linux list, 95 checks>` | `all 95 checks passed`, exit 0 | | `cmake --build <b> --target d3d12_xs_shim offscreen_check cpu_placed_dxr_provider startup_null_views_check` | exit 0 | | `python3 -B tests/startup_build_rev_check.py` | `startup_build_rev_check: 10 cases ok`, exit 0 | | `python3 -B tests/startup_build_rev_check.py dll <b>/d3d12_xs.dll <b>/generated/x2w_build_rev.cpp` | `ok ...: revision 75756a7f, 5 strings`, exit 0 | | `wine startup_null_views_check.exe hardware` (links the shim) | log line `... -> 0x00000000 build=75756a7f`, `device OK`, exit 0 | | No-change rebuild | only the generator step runs | | Rebuild after a docs-only commit | `ninja -n -d explain` never mentions `d3d12_xs_device.cpp.obj`; the generated source recompiles and the shim relinks | Mutations: each was run once and the file restored by hash. Every one fails the check on its own case. | Mutation | Fails at | |---|---| | drop the `-dirty` suffix | tracked edit | | drop `--untracked-files=no` | untracked file only | | `file(CONFIGURE)` -> `file(WRITE)` | unchanged rerun | | ignore git's result | not a repository | | keep the old file on a clean tree | new commit | | drop `GIT_CEILING_DIRECTORIES` | directory inside another repository | | keep an inherited `GIT_DIR` | inherited `GIT_DIR` | | output title without the revision | dll: output-window title | | frame title without the revision | dll: frame title | | log format without `build=%s` | dll: device-create log format | | generated source with another revision | dll: narrow and UTF-16 revision | | generated source without definitions | dll: revision unmeasured | ## Not measured - The window title on a running Windows desktop. No source-built fixture opens the presenter window, so the title is checked as format strings in the built DLL. The log line was observed at run time under Wine. - MSVC builds, `ctest --preset dev`/`release` and the Visual Studio generator. This PR's CI compiles the shim and `offscreen_check` with MSVC, but the PR test filter does not run the `startup_build_rev_*` ctests. Windows git path forms in the controls (backslash temp paths, `GIT_CEILING_DIRECTORIES`) are therefore not exercised on Windows by the PR job. ## Limitation `tools/startup/triage_run.py` keeps only allowlisted fields, so redacted triage output will not carry `build=`. Adding it is a follow-up. AI-assisted.
upstream-sync closed this pull request 2026-11-25 06:01:29 +00:00
tedin7 commented 2026-11-25 06:01:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:25:18Z.

Review: COMMENTED


Review of head 75756a7f634db7068a69f39d97b697d6cd02b0d8 (comment only).

Result: no P1, no P2.

What I checked

  • cmake/x2w_build_rev.cmake: short HEAD, -dirty only for tracked changes, unknown without git, outside a top-level work tree, or with an inherited GIT_DIR. GIT_CEILING_DIRECTORIES stops the lookup above the source dir. --no-optional-locks avoids index-lock contention. The output is rewritten only when its text changes.
  • x2w_build_rev is a static library built with /Zl and linked into all three targets that compile d3d12_xs_device.cpp (d3d12_xs_shim, offscreen_check, cpu_placed_dxr_provider). I found no sibling target that compiles that file and misses the link.
  • Title buffers: 80 wchars for 22 fixed characters plus at most 46 for the revision, and 256 for about 100 plus 46 plus three numbers. Both fit.
  • The CI job "Build and test on Windows" is green. The Linux checks job is green. The /O2 job was skipped.

Commands run locally on the PR head

  • python3 tests/startup_build_rev_check.py -> 10 cases ok
  • python3 tests/docs_links_check.py -> Checked 18 Markdown files and 407 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls.
  • git diff --check origin/main...HEAD -> clean

Mutation checks (each reverted with git checkout -- .)

  • --untracked-files=no changed to all: the test FAILS ("untracked file only: revision '...-dirty', expected ...").
  • -dirty suffix removed: the test FAILS ("tracked edit").
  • GIT_CEILING_DIRECTORIES line removed: the test FAILS ("directory inside another repository").

So the new logic is guarded by tests that fail when it breaks.

Nits (non-blocking)

  • src/startup_stubs/d3d12_xs_device.cpp:16: the new #include "x2w_build_rev.h" sits between the startup_stubs/* includes. Moving it next to the other top-level includes would be tidier.
  • The startup_build_rev_dll test depends on the built shim, so I did not run it on Linux. I did not run a separate Windows VM job. The change is not shader or math code, and the CI Windows job covers the build and test.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052272186 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2211#pullrequestreview-6052272186). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T05:25:18Z. **Review:** COMMENTED --- Review of head `75756a7f634db7068a69f39d97b697d6cd02b0d8` (comment only). **Result: no P1, no P2.** What I checked - `cmake/x2w_build_rev.cmake`: short HEAD, `-dirty` only for tracked changes, `unknown` without git, outside a top-level work tree, or with an inherited `GIT_DIR`. `GIT_CEILING_DIRECTORIES` stops the lookup above the source dir. `--no-optional-locks` avoids index-lock contention. The output is rewritten only when its text changes. - `x2w_build_rev` is a static library built with `/Zl` and linked into all three targets that compile `d3d12_xs_device.cpp` (`d3d12_xs_shim`, `offscreen_check`, `cpu_placed_dxr_provider`). I found no sibling target that compiles that file and misses the link. - Title buffers: 80 wchars for 22 fixed characters plus at most 46 for the revision, and 256 for about 100 plus 46 plus three numbers. Both fit. - The CI job "Build and test on Windows" is green. The Linux checks job is green. The /O2 job was skipped. Commands run locally on the PR head - `python3 tests/startup_build_rev_check.py` -> `10 cases ok` - `python3 tests/docs_links_check.py` -> `Checked 18 Markdown files and 407 links.` - `python3 tests/bidi_controls_check.py` -> `no bidirectional controls.` - `git diff --check origin/main...HEAD` -> clean Mutation checks (each reverted with `git checkout -- .`) - `--untracked-files=no` changed to `all`: the test FAILS ("untracked file only: revision '...-dirty', expected ..."). - `-dirty` suffix removed: the test FAILS ("tracked edit"). - `GIT_CEILING_DIRECTORIES` line removed: the test FAILS ("directory inside another repository"). So the new logic is guarded by tests that fail when it breaks. Nits (non-blocking) - `src/startup_stubs/d3d12_xs_device.cpp:16`: the new `#include "x2w_build_rev.h"` sits between the `startup_stubs/*` includes. Moving it next to the other top-level includes would be tidier. - The `startup_build_rev_dll` test depends on the built shim, so I did not run it on Linux. I did not run a separate Windows VM job. The change is not shader or math code, and the CI Windows job covers the build and test. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-25 06:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T05:56:22Z.


Verified 75756a7f on Windows x64 Release before merging. ctest --preset release --no-tests=error -R "^startup_(build_rev|null_views)" -V passed 4/4. The revision generator passed all 10 controls, including tracked edits, a new commit and an unchanged rerun. The built DLL contains the title strings, and D3D12XboxCreateDevice logged build=75756a7f on both RTX 4060 Laptop and WARP.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7154282327 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2211#issuecomment-7154282327). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T05:56:22Z. --- Verified 75756a7f on Windows x64 Release before merging. `ctest --preset release --no-tests=error -R "^startup_(build_rev|null_views)" -V` passed 4/4. The revision generator passed all 10 controls, including tracked edits, a new commit and an unchanged rerun. The built DLL contains the title strings, and D3D12XboxCreateDevice logged `build=75756a7f` on both RTX 4060 Laptop and WARP.
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!2203
No description provided.