Skip to content

runtime: compile a supported graphics pair on first use in the stand-in - #2981

Merged
R0Y00 merged 5 commits into
mainfrom
codex/native-graphics-first-draw
Nov 28, 2026
Merged

R0Y00 merged 5 commits into
mainfrom
codex/native-graphics-first-draw

Conversation

@R0Y00

@R0Y00 R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Refs #2978

With X2W_NATIVE_SHADERS set, the graphics runtime links a supported VS/PS pair, compiles both stages in process and uses the native binding manifest to create the pipeline. The fixture starts with an empty cache and uses a fresh process for the second draw.

Tested locally on Windows 11 build 26200.9974, Release, NVIDIA GeForce RTX 4060 Laptop driver 32.0.16.1656 and WARP, with the D3D12 debug layer enabled.

cmake --build --preset dev --target startup_stream_consumer d3d12_xs_shim
ctest --preset dev --no-tests=error -V -R '^startup_native_graphics_draw_(hardware|warp)$'

Both tests passed. Cold and warm draws each produced exactly 16 red and 16 clear RGBA8 pixels. Frontend, VS and PS cache hits changed from 0,0,0 to 1,1,1. An unsupported pixel stage left all 32 pixels clear. The hardware slot 67 regression also matched all 320 words. Scope is a source-built draw on one fixed target format. Independent review and CI are pending.

@R0Y00

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Validation of 671b9ac8188919499fa05ebd94269a33e76fbf76

I rebuilt and ran the source-built fixtures in a separate checkout on Windows 11 26200.9974, MSVC 19.51.36231, Release /O2, and Windows SDK 10.0.26100 DXC. WARP used Microsoft Basic Render Driver 10.0.26100.9818. Hardware used RTX 4060 Laptop driver 32.0.16.1656. The native graphics fixture enabled the D3D12 debug layer on both adapters and reported no error messages.

cmake --build --preset release --target startup_stream_consumer d3d12_xs_shim compile_dxil
ctest --preset release --no-tests=error -V -R '^(startup_native_graphics_draw_(hardware|warp)|startup_compute_dispatch_native_(hardware|warp)|startup_stream_draw_(hardware|warp))$'

Five passed and one capability skip. Both native graphics draws produced 16 red and 16 clear pixels after the fence. Fresh processes showed frontend/VS/PS cache hits 0,0,0 then 1,1,1. An additional cold-cache run of the invalid PS kept all 32 pixels clear, logged the decoder refusal, and left only .a, .b, and .root request inputs. Both legacy stream draw fixtures passed, including late manifest publication. I also reran the WARP legacy fixture with X2W_NATIVE_SHADERS set and observed the native decoder refusal followed by successful manifest-based draws. Slot 67 matched 320 words on hardware. WARP checked refusal and fallback, then reported a capability skip for the native path because it lacks 32-lane waves.

Review finding

try_native_graphics in src/startup_stubs/d3d12_draw.inl detaches both blobs into the live translation and returns true even when load_translation leaves state == 2. cached_translation then bypasses the existing on-disk manifest, and the native parse clears the manifest retry deadline. This differs from the tested early decoder refusal, which returns false and reaches the legacy loader. Please stage the native parse and root signature in a temporary translation and publish it only on success. Add a late-failure control with a valid legacy entry already present and verify that it still draws. This finding is from the control flow, and the fixture did not inject a root-signature failure. A later graphics PSO rejection also caches a null PSO for the pass, so the ready=1 diagnostic currently means the root and stages are ready for PSO creation.

Hosted CI passed Windows build/test, Linux Python checks, and gfx1013 assembly/translation. The hosted /O2 job was skipped. The local Release run above used synthetic inputs.

@Not-Saii

Copy link
Copy Markdown
Contributor

I claimed #2978 shortly before this PR opened and have a branch for it too. I am not opening a second PR. This is what the branch does differently, in case any of it is useful here or as a follow-up.

Branch: Not-Saii:native/first-graphics-draw-2978, three commits on 05438d65. Tested locally at 5639d957 on Windows 11 build 26300.9974, Debug, D3D12 debug layer enabled with no error message, NVIDIA GeForce RTX 4090 driver 32.0.16.1088 and WARP (Microsoft Basic Render Driver 10.0.26100.9818). startup_draw_native_hardware and startup_draw_native_warp pass. The note is docs/experiments/startup-graphics-native-draw.md on the branch.

Differences from this PR

  1. Compile at the first draw, not at pipeline creation. The hook is in translation_for_targets, and cached_translation is untouched. A pipeline that is created and never drawn compiles nothing. Control: with the draw skipped, the cache holds request files only.
  2. The result is an ordinary cache entry. The stand-in publishes <key>.vs.cso, <key>.ps.cso and then <key>.txt with the job compile_dxil gfx1013-container-pair --requests runs, moved to src/graphics_request_job.cpp so the tool and the stand-in share it. A second process loads the entry at pipeline creation and compiles nothing. The check compares names, sizes and modification times of every cache file across that run.
  3. An existing <key>.txt wins. The in-process compile runs only when the manifest is absent, and the first draw looks for it again first. Control: a manifest moved into place between pipeline creation and the first draw is loaded and not replaced. On the review finding above: with this order a valid on-disk entry is loaded before any native work, so a late native failure cannot bypass it. That is from the control flow and this control. I did not inject a root-signature failure either.
  4. Refusals name the stage. Three controls, each leaving the target at the clear colour and no <key>.* file:
    • (pixel stage): native compute +0x0: unsupported pixel entry VGPR 0
    • (vertex stage): native compute +0x8: vertex fetch call outside the entry
    • (pair stage): native compute +0x0: graphics stages disagree on TEXCOORD0

Costs

  • More code than this PR: the tool's graphics job moves to a shared file, and the stream consumer gets two test switches (X2W_TEST_NO_DRAW, X2W_TEST_PUBLISH_BEFORE_DRAW).
  • The compile runs on the drawing thread with the draw lock held. Its cost on a start-up run was not measured.
  • The two changes do not combine as they are. With a compile at pipeline creation in place, the first-draw hook never runs.

Regression runs on the branch (full dev build, same machine): 31 of 31 stream draw, pixel-history and native graphics tests pass, WARP and hardware. native_rectangle_pso_warp passes (the tool's rectangle mode goes through the moved job). The pr preset has 36 passes. Capability skips, not passes: startup_compute_dispatch_native_warp, native_comparison_pso_warp and the four spirv_minlod_*_warp tests.

I can rebase any of points 1 to 4 onto this PR once it merges, open the branch as an alternative PR, or drop it. Tell me which is useful.

AI-assisted (Claude Code).

@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.

Strong milestone — the first native graphics draw through the stand-in. The try_native_graphics() path cleanly sits between load_translation() fallback and the manifest-based path, and the test exercises cold/warm cache behavior plus refusal of unsupported stages.

Findings

✅ What works well

  • Placement in cached_translation(): The new try_native_graphics() call happens after publish_shader_request but before load_translation(). This is correct — if the request file exists, native compilation is attempted; if it fails, load_translation() falls back to the published manifest path. No regression for existing workflows.
  • try_native_graphics() structure: Reads the request → prepare_direct_graphics() → format_graphics_runtime_manifest() → compiles both stages through ShaderDxilCompiler::runtime_worker() → passes manifest to load_translation(). The lambda stage() abstracts the compile+blob creation loop. Clean.
  • Manifest passthrough to load_translation(): The provided flag prevents load_translation() from re-reading .txt and .cso files when a native manifest is already available. The two .cso reads are guarded by !provided, and the manifest string is used directly. This avoids a double-load.
  • x2w-draw native graphics logging: The ready=%u cache(frontend,vs,ps)=%u,%u,%u message gives exact cache hit counts. The refusal path also logs with the error reason. Useful for debugging.
  • Test fixture: Triangle VS + patched PS, checking all 32 pixels for cold/warm draw, and a third process with an unsupported stage verifying untouched clear color. Good separation of concerns.

⚠️ Issues / observations

  1. prepare_direct_graphics() refusal: If the request has an unsupported binding layout, format_graphics_runtime_manifest returns std::nullopt and the exception message is "unsupported graphics binding layout". This is caught by the catch block and logged as "refused: unsupported graphics binding layout". However, the test expects the string "refused:" in stderr — the actual log would be "x2w-draw native graphics %016llx refused: unsupported graphics binding layout". The assertion returncode == 0 and "refused:" in run.stderr works because the fallback load_translation() path still runs after the native attempt fails. Verify that the test's unsupported stage scenario exercises the right code path (native refusal vs. manifest rejection).

  2. Shader model: Both stages compile with "vs_6_6" and "ps_6_6". This is the minimum shader model for SM6.6 wave32 features. If the target adapter doesn't support SM 6.6, compile() will fail and the pipeline creation will refuse. Consider whether to detect the adapter's SM support and fall back gracefully, or if this is intentionally restricted (consistent with the compute path requiring SM 6.6 + wave32).

  3. direct_compute_cache.h include in d3d12_xs_device.cpp: The include brings in direct_compute_cache.h which defines prepare_direct_graphics() and format_graphics_runtime_manifest(). Since this file is d3d12_xs_device.cpp (the device initialization), it should be correct, but note that this couples the device init to the direct compute cache machinery. If this header includes heavy dependencies, consider a forward declaration or a lighter header.

  4. cache_path for native request file: cache_path(path, L"req_", tr.key, L".a") constructs req_<key>.a in the cache directory. The manifest reader (load_translation()) reads cache_path(path, L"", tr.key, L".txt") — the published request. These are two different paths, so native compilation reads from the request file while manifest loading reads from the .txt output. Correct.

Recommendation

Ready to land with the one question about the test's refusal path (item 1). The feature is well-placed, well-tested, and follows the pattern established by the compute path.

🏷 Future: if prepare_direct_graphics() or the compilation path gains more refusal reasons, consider adding a classification layer (e.g., refused_invalid_request vs refused_unsupported_binding vs refused_compile_failure) for more precise logging and potential retry logic.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Follow-up on exact head 671b9ac8188919499fa05ebd94269a33e76fbf76. I ran ctest --preset {dev,release} --no-tests=error --output-on-failure -R '^startup_(native_graphics_draw|compute_dispatch_native|stream_draw)_(warp|hardware)$' on Windows 11 26200.9974. Both builds gave five passes and one native-compute WARP capability skip. Cold/hot graphics both read back 16 red and 16 clear pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656; the unsupported stage left all 32 clear. Debug used embedded /Z7; Release was /O2.

I reproduced the late fallback failure with local Release fault injection on WARP. I first published an ordinary disk <key>.txt, .vs.cso, and .ps.cso via the offline CLI and verified that it drew 16 red/16 clear with native disabled. Independently forcing an unsupported native manifest version or E_FAIL at native root creation gives ready=0, no draw and 32 clear pixels at this head, despite that valid cache. In a separate same-process control using X2W_TEST_PUBLISH_MANIFEST, both faults also prevent drawing after the manifest appears and the retry window elapses. The disk cache files are byte-identical throughout.

I tested a local fix that parses and builds the root in a temporary Translation, commits it only on state == 1, and otherwise falls through to the original disk loader. Both injected faults then drew 16 red/16 clear with a pre-existing manifest and on the later draw after publication. Please carry these two negative controls into the PR. This fix addresses late manifest/root failures and preserves the existing retry. The agreed compile-on-first-draw timing and existing-cache precedence remain separate acceptance points, and this test does not inject a later PSO failure.

@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.

What works

  1. try_native_graphics() fills a missing gap: the stand-in now
    accepts X2W_NATIVE_SHADERS and compiles a VS/PS pair inline from the
    published request, with a first-use compile path and subsequent cache
    hit path (--180s timeout is reasonable).
  2. load_translation() signature change is safe: the default
    argument manifest = {} is backwards-compatible. When an empty
    string is provided externally, the existing cache-path read still
    runs. Good.
  3. The fixture tests the cold/warm transition and the unsupported
    stage refusal in the same test, checking pixel counts in each case.
    No debug layer warnings expected (good quality gate).
  4. The CMakeLists.txt test harness uses both warp and hardware
    adaptives, with skip=77 for hardware-only features.

Issues

  1. x2w::read_graphics_request() path: the cache_path(path, L"req_", tr.key, L".a") call uses the translation's key directly. If the
    request file isn't found, the function returns false without logging
    a reason. This is correct for the graceful fallback, but the log at
    the end of this PR says refused: no graphics request for an
    unsupported -- consider if that should become a debug-level event or
    a specific refusal with the missing key.
  2. The try_native_graphics() function returns false if the runtime
    doesn't know the path to DXC or the request file. The fallback to
    the published translation is correct, but the transition between
    compiled and cached paths should be observable in logs for
    diagnosing first-use vs subsequent issues.

Recommendations

  • Consider adding a debug log entry when try_native_graphics()
    returns false so developers can distinguish the reason from the
    overall pipeline path taken.
  • The prepare_direct_graphics() call should verify it handles the
    request's pixel/vertex roots and binding layout correctly before the
    pipeline creation.

Overall

Solid step for native graphics through the stand-in. The first-use
compile + cache hit path looks correct. Approvable.

@R0Y00

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Retargeted to main. For the draw-loader conflict, keep the supplied-manifest path together with main's ManifestRetry handling. I tested the temporary Translation fix on main e04217f. Keep the VS/PS in local COM owners and commit the candidate only when state == 1. With this fix, forcing an unsupported native manifest or E_FAIL at native root creation preserved the valid disk cache and allowed a same-process draw after delayed manifest publication. Both faults produced the expected 16 red / 16 clear pixels after fallback in Debug and Release /O2 on WARP and RTX 4060 Laptop, with the D3D12 debug layer enabled and published files byte-identical. The ordinary draw, stream draw and slot-67 regressions gave five passes and one native-compute WARP capability skip per preset. Please carry the fallback fix and two fault controls into the rebased PR.

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

I reapplied the complete PR and the transactional manifest-load fix onto current main ca659396, with the Opus-only #3084 candidate in the local base. The isolated integration (3712c974, tree a62b28610efd46a847cdce191081abd9616369a4) retains original 671b9ac8 as a merge parent. Nothing was pushed. Debug and Release /O2 each gave six passes and one native-compute WARP 77 skip with ctest --test-dir <build> --no-tests=error -j 1 -V -R '^(startup_(native_graphics_draw|stream_draw|compute_dispatch_native)_(warp|hardware)|startup_manifest_retry)$'.

I also reran the two fault controls on WARP and RTX. Both an unsupported native manifest and a native root-creation E_FAIL preserved the working disk translation and allowed same-process retry after a missing manifest was published. A third control found a later failure: with a valid disk entry already present, forcing E_FAIL only for the native CreateGraphicsPipelineState left all 32 pixels clear in both presets on both adapters. The baseline disk entry drew 16 red / 16 clear, and its files stayed byte-identical. The native candidate logs ready=1 before pipeline_for attempts PSO creation, and that function caches the null PSO. Please keep the original commits in the integration and extend fallback through this native-only PSO failure, preserving the disk path for the same render-target key. The remote head still has the draw-loader conflict.

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

The broader runtime integration is now in #3094, stacked on #3091. This PR remains the record of the original first-use draw and the fallback review. I linked the manifest, root-signature and PSO findings there so they can be verified against the runtime head. The #2978 claim is unchanged. Please preserve the original commit and review history when reconciling the two PRs, and keep this one open until the overlap and the full disk fallback have been verified.

@R0Y00
R0Y00 requested a review from KelboLive November 28, 2026 00:30
@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

At f76a6cf, Debug and Release /O2 each passed five tests and had one capability skip (77, WARP native wave32 compute). Hardware native Dispatch passed with the merged cache-stamp test correction from #3231. The WARP and RTX graphics fixtures each read back 16 red and 16 clear pixels on cold and hot runs, used the already published disk pair unchanged when present, and recovered the same pixels on a later draw in the same process after a native refusal and publication. The unsupported stage retained all 32 clear pixels. Windows 11 26200.9974, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656. D3D12 debug layer enabled for the graphics fixture.

cmake --build --preset dev --target startup_stream_consumer d3d12_xs_shim compile_dxil
ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_(native_graphics_draw|compute_dispatch_native|stream_draw)_(warp|hardware)$'

Repeat with the release preset. Please review the first-draw timing, published-disk precedence and transactional candidate state on this head.

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

The refreshed first-draw head 850aba8 (tree e3ae37972ded055bb93f729762b3348321d6ebe9) incorporates the slot-67 baseline and preserves both sets of CMake controls. On Windows 11 26200.9974 with RTX 4060 Laptop and inbox WARP, Debug and Release /O2 each gave five passes and one capability skip. Both MRT late-manifest checks recovered on the later draw, both first-draw fixtures passed, and hardware native Dispatch passed. Inbox WARP native Dispatch reported 77.

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_(native_graphics_draw|mrt_dxc|compute_dispatch_native)_(warp|hardware)$'

@R0Y00
R0Y00 removed the request for review from KelboLive November 28, 2026 01:59
@R0Y00
R0Y00 requested a review from KelboLive November 28, 2026 02:01
@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

@lambirou, could you independently review first-draw head 850aba8? Please focus on publication of the native VS/PS candidate, precedence for an already-published disk pair, and a later draw after a late refusal. The commands and Windows results are in the current-head receipt. The required Windows CI has passed.

@lambirou lambirou 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.

Independent review of 850aba86c088c2198e2baa09698d8223589aaecb.

I rebuilt the head in a clean worktree and ran the focused suite on Windows 11 26300, WARP 10.0.26100.10068 and RX 9060 XT 32.0.32029.2010. Debug and Release each gave 7 passed and 1 capability skip (startup_compute_dispatch_native_warp, 32-lane waves). The new startup_native_graphics_draw_{warp,hardware} passed in both presets: cold cache=0,0,0, hot 1,1,1, 16 red and 16 clear pixels; the published disk pair drew with no native attempt and its .txt/.vs.cso/.ps.cso files stayed byte-identical; the failed native attempt left the first target clear and the later draw after publication recovered 16 red and 16 clear; the unsupported pixel stage kept all 32 clear.

Focus points:

  • Candidate publication is transactional. try_native_graphics builds a local Translation, attaches both blobs, calls load_translation(candidate, {}, manifest), and assigns tr = std::move(candidate) only after state == 1; the blobs are detached only then. A manifest or root failure discards the candidate and leaves the live entry's manifest_retry intact.
  • Published disk precedence holds. When <key>.txt exists at cached_translation, load_translation clears the retry and try_native_graphics is not called. The no-native graphics assertion and unchanged cache files in the fixture confirm it.
  • A later draw after a late refusal recovers. The shipped control uses a missing SDK, which fails before the candidate is built. I additionally injected E_FAIL at create_translated_root after the candidate and blobs were constructed (local patch, reverted). The first draw stayed all clear; the later draw after publishing the disk manifest drew 16 red and 16 clear on WARP and the RX 9060 XT, with native graphics ... ready=0. This confirms the candidate discard preserves the retry.

One coverage request: please commit a permanent late-failure control (the root-creation E_FAIL or an unsupported provided manifest). The current failed native attempt case exits before the candidate exists, so it would not catch a regression that mutates the live translation before state == 1.

The D3D12 debug layer is unavailable on this machine (0x887a002d), so I could not repeat the debug-layer assertions; the normal draw path and both adapters passed. PSO-failure fallback is out of scope here and tracked by #3139/#3094.

@R0Y00

R0Y00 commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner Author

@lambirou, the permanent late rejection control is on 3440edf. Both native stages compile, then the fixture supplies an unsupported manifest version to the local candidate. It requires the manifest diagnostic and ready=0, verifies the first 32 pixels are still clear, publishes the original disk manifest, and checks 16 red plus 16 clear pixels on the later draw in the same process. The three disk files stay byte-identical. The missing-DXC early control remains separate.

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^startup_(native_graphics_draw|mrt_dxc|compute_dispatch_native)_(warp|hardware)$"

Debug and Release /O2 each had 5 passes and 1 capability skip (inbox WARP native wave32 Compute). Both late graphics cases passed on RTX 4060 Laptop (32.0.16.1656) and WARP 10.0.26100.9818, Windows 11 26200.9974, debug layer enabled. Please recheck the new control on this head.

Mutation check in the Debug WARP fixture: locally clearing the live manifest retry when the native candidate fails leaves the cold/hot draws, disk precedence and missing-DXC negative passing. The new late-manifest case fails at the second-draw pixel assertion (CTest exit 8). With that local mutation removed and the shim rebuilt, the same test passes (CTest exit 0). The published head contains only the test control.

@lambirou lambirou 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.

Re-checked 3440edff857bbda116ad2949c8a2d4487cc15c8f.

The new control is the one I asked for. It compiles both stages, attaches both blobs to the local candidate, replaces the provided manifest with x2w-manifest 0, and requires unsupported manifest version for <key> plus native graphics <key> ready=0. The first draw stays all clear, the original disk manifest is published, and the later draw in the same process gives 16 red and 16 clear on both adapters; the three disk files stay byte-identical. The missing-DXC early control remains separate.

On Windows 11 26300, WARP 10.0.26100.10068 and RX 9060 XT 32.0.32029.2010:

  • Debug: 5 passed, 1 capability skip (startup_compute_dispatch_native_warp).
  • Release: 5 passed, 1 capability skip.
  • startup_native_graphics_draw_{warp,hardware}: 2/2 in each preset; both retry cases pass.
  • No regressions in startup_mrt_dxc_{warp,hardware} or hardware native Dispatch.

Hosted CI is green on this head: Windows build/test, Linux Python checks, and gfx1013 assembly/translation passed; /O2 and the coverage chart are skipped as usual. The D3D12 debug layer is still unavailable here (0x887a002d), so I could not repeat those assertions; your run covers them.

Candidate publication, published-disk precedence, and the later draw after a late refusal now all have committed coverage. Approved.

@R0Y00
R0Y00 merged commit c827d8b into main Nov 28, 2026
5 checks passed
tedin7 added a commit to tedin7/Xbox2Windows that referenced this pull request Nov 28, 2026
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.

4 participants