Skip to content

tooling: support .rtv variant requests in compile_dxil --watch and --refusals - #3003

Merged
MasterDomino merged 2 commits into
R0Y00:cpp-migrationfrom
stan495:cpp-migration/compile-dxil-rtv-tooling
Nov 27, 2026
Merged

MasterDomino merged 2 commits into
R0Y00:cpp-migrationfrom
stan495:cpp-migration/compile-dxil-rtv-tooling

Conversation

@stan495

@stan495 stan495 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Target branch cpp-migration. Fixes #3001. Refs #2935.

Behavior

Wire req_<key>.rtv variant requests (#2989) into both compile_dxil --refusals and compile_dxil --watch (tools/startup/compile_dxil.cpp):

  • Shared marker deduplication & .psin resolution:
    • Extract dedupe_graphics_markers so --requests, --refusals, and --watch all give .rtv precedence when .a and .rtv share a key (matching tools/startup/gfx2hlsl.py::request_source).
    • Add graphics_psin_path to resolve req_<base>.psin from an .rtv file's rtv1 <base> ... header so --watch tracks base .psin / .psdep changes for RTV variants too.
  • compile_dxil --refusals:
    • Scans req_<key>.rtv alongside req_<key>.a, runs read-only prepare_direct_graphics(..., /*write_cache=*/false, input.rtv_formats), and validates format_graphics_runtime_manifest(pair, input.rtv_request) without invoking DXC or writing files.
  • compile_dxil --watch:
    • Scans req_<key>.rtv alongside .a/.c67, passes input.rtv_formats and input.rtv_request, and publishes <variant>.{vs.cso,ps.cso,psdep,txt} (with trailing rtv1 ... line) or <variant>.fail on refusal.
  • Tests & docs: extends tests/native_compile_dxil_refusals_check.py and tests/native_compile_dxil_watch_check.py with .rtv positive/negative controls and updates docs/experiments/native-compile-dxil-{refusals,watch}.md.

Verification

  • Commit under test: e71272c0 (based on origin/cpp-migration e0d83759)
  • Environment: x64 Windows Release, MSVC, Windows SDK 10.0.26100.0
  • Commands and observed results:
    .\tools\dev.ps1
    cmake --preset release
    cmake --build --preset release --target compile_dxil
    ctest --preset release --no-tests=error -V -R "^(native_compile_dxil_watch|native_compile_dxil_refusals|native_rtv_variant_controls|native_startup_request_cache_controls)$"
    # 4/4 passed:
    #   native_compile_dxil_refusals (1.12 sec)
    #   native_compile_dxil_watch (1.76 sec)
    #   native_rtv_variant_controls (1.75 sec)
    #   native_startup_request_cache_controls (0.91 sec)
    .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py    # Checked 50 Markdown files and 571 links.
    .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py # Checked 2162 tracked source, script and build/CI files: no bidirectional controls.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition — wire-in with the RTV variant request system and solid test coverage across refusals, --watch dedup, and recheck paths.

Findings

✅ What works well

  • dedupe_graphics_markers mirrors gfx2hlsl.py::request_source semantics exactly: same stem, .a + .rtv pair → keep the variant.
  • graphics_psin_path correctly parses the rtv1 <base hex> header and produces the matching req_<base>.psin.
  • Documentation updates for both native-compile-dxil-refusals.md and native-compile-dxil-watch.md are accurate and concise.
  • Test coverage in native_compile_dxil_refusals_check.py is thorough: valid variants, forged headers, missing manifests, bad format codes, and same-key dedup all exercise the logic.
  • Parallelism guard (--jobs 2 producing identical JSON output) is a nice defensive touch.

⚠️ Issues / observations

  1. dedupe_graphics_markers assumes sorted adjacency — the function only compares consecutive elements. This is correct since graphics_inputs is sorted via PathLess{} before dedup, but a comment like // inputs are PathLess-sorted before this call would make the invariant explicit for future readers.

  2. std::from_chars integer overflow — the rtv1 header token is validated for ASCII digit-only, but no length cap. You check token.size() > 20 which is fine (max 0xFFFFFFFFFFFFFFFF is 16 hex digits = 10 decimal digits). However, if someone writes 00000000000000000000 (20 zeros), from_chars parses it without issue. No overflow risk, but worth a note if the parsing logic changes later.

  3. std::swprintf buffer size — wchar_t name[32] accommodates req_ (4) + %016llx (16) + .psin (5) + null (1) = 27 wide chars, so 32 is fine. However, consider using std::format or snwprintf if this module starts accepting wider inputs.

  4. --watch live recheck path — the test shows .b file mutation followed by .psin touch triggering variant recheck. The production code should propagate the .b change to the variant .psin paths through graphics_psin_path. The test asserts 3 refused after .b mismatch — make sure both the base and variant .psin paths converge correctly.

Recommendation

Consider adding a brief comment at the top of dedupe_graphics_markers noting the pre-sorted invariant. Otherwise this is clean and ready to land.

🏷 Minor: native_compile_dxil_watch_check.py imports put_variant but the test also creates a live-watcher variant section — consider keeping it focused on the --watch lifecycle and moving the --once RTV compile test to native_compile_dxil_refusals_check.py (or vice versa) for better separation.

@stan495

stan495 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review, @KelboLive!

Added the explicit pre-sorted invariant comment on dedupe_graphics_markers in d53f823 (rebuilt compile_dxil and re-ran native_compile_dxil_refusals, native_compile_dxil_watch, and native_rtv_variant_controls — 3/3 passed).

A few quick notes on the remaining observations:

  • token.size() > 20 matches src/shader_compute_request.cpp because UINT64_MAX is 20 decimal digits (18446744073709551615), and std::from_chars returns std::errc::result_out_of_range on overflow.
  • wchar_t name[32] with std::swprintf(name, std::size(name), ...) safely bounds the fixed 27-character req_%016llx.psin output.
  • --once is a sub-mode of compile_dxil --watch, so testing --once RTV behavior inside native_compile_dxil_watch_check.py keeps the --watch CLI coverage in one place.

@MasterDomino MasterDomino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head d53f8230. Its last commit only adds the sorted-input comment on dedupe_graphics_markers; the code was tested at e71272c0. CI on the head is green. This closes the .rtv gap I noted on #2992. Approving and merging.

Code read:

  • Shared dedupe: dedupe_graphics_markers is now used by --requests, --refusals and --watch, with the variant winning for a key with both markers.
  • .psin for variants: graphics_psin_path resolves a variant's .psin to its base's, as gfx2hlsl.py::request_source does, so --watch rechecks a variant when the base description changes.
  • --refusals: a variant now also needs a runtime manifest, the same rule --requests applies.
  • --watch: variants are compiled with their formats and publish the rtv1 manifest line.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), plus WARP, release. This was tested together with #2975, #2986, #2996 and #2998 merged onto cpp-migration e0d83759; all five merge cleanly with each other. ctest --preset release --no-tests=error -R '^(native_.*|startup_compute_dispatch(_.*)?_(warp|hardware)|startup_slot67_indirect_dispatch_warp|startup_compute_translate_e2e_warp|startup_stream_draw.*|startup_native_graphics.*)$' gives 94 tests, 90 passed and 4 skipped (77, WARP has no 32-lane waves). native_compile_dxil_watch, native_compile_dxil_refusals and the three native_rtv_variant_* tests passed.

Mutation here: letting --watch ignore .rtv markers fails native_compile_dxil_watch on the variant's compiled graphics line. With it restored, it passes.

I will close #3001 by hand.

AI-assisted; the commands above were run locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants