Skip to content

runtime: recover the published disk pair when native candidate PSO creation fails - #3139

Merged
R0Y00 merged 9 commits into
R0Y00:codex/native-graphics-integrationfrom
lambirou:native/graphics-pso-fallback
Nov 28, 2026
Merged

R0Y00 merged 9 commits into
R0Y00:codex/native-graphics-integrationfrom
lambirou:native/graphics-pso-fallback

Conversation

@lambirou

@lambirou lambirou commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change A native graphics candidate marked the translation ready before pipeline_for created its desktop PSO. When CreateGraphicsPipelineState failed, the draw returned null and cached that null, so the target stayed clear even when a valid published disk pair existed. With candidate PSO creation forced to E_FAIL, the target read 0 red / 32 clear; the disk pair alone drew 16 red / 16 clear. The candidate now records native_candidate, revision and rtv_request. On a candidate PSO failure the runtime reloads the published pair for the same key and RTV variant, recomputes the PSO with a bumped revision (so earlier native PSOs are not reused), and refuses with a diagnostic when the pair is missing or invalid or its disk PSO fails. X2W_NATIVE_SHADERS_ONLY=1 keeps its explicit refusal without a fallback. The published manifest and stage files are read, never rewritten. Refs #3134. Refs #3094. Targets codex/native-graphics-integration while #3094 is open. ## Verification Windows 11 build 10.0.26300.10075 (26H2), MSVC 19.44.35228.0, Windows SDK/DXC 10.0.26100.0. The D3D12 debug layer was unavailable on these runs (0x887a002d), so debug-layer cleanliness is not claimed. Commit 06c7380b in native/graphics-pso-fallback. cmake --preset dev cmake --build --preset dev --target compile_dxil startup_stream_consumer d3d12_xs_shim ctest --preset dev --no-tests=error -j 1 -V -R '^startup_native_graphics_draw_(warp|hardware)$' cmake --preset release cmake --build --preset release --target compile_dxil startup_stream_consumer d3d12_xs_shim ctest --preset release --no-tests=error -j 1 -R '^startup_native_graphics_draw_(warp|hardware)$' Debug and Release: 2/2 passed on WARP (Microsoft Basic Render Driver 10.0.26100.10068) and on the AMD Radeon RX 9060 XT (driver 32.0.32029.2010). Observed lines: - warp/hardware PSO: candidate failure recovered the published disk pair, 16 red and 16 clear pixels - warp/hardware native: successful candidate still drew 16 red and 16 clear pixels - warp/hardware missing pair: refused with a diagnostic, 32 clear pixels - warp/hardware invalid pair: refused with a diagnostic, 32 clear pixels The check also asserts that the manifest, .vs.cso and .ps.cso bytes and mtimes are unchanged after every case. Debug regression: startup_stream_draw_(warp|hardware), startup_compute_dispatch_native_(warp|hardware), native_rtv_variant_(controls|warp|hardware) and startup_manifest_retry: 8 run, 7 pass, 1 capability skip (startup_compute_dispatch_native_warp, WARP without 32-lane waves), unrelated to this fixture. ## Evidence and follow-up Synthetic inputs only; no game files or captures. The failure is injected only at candidate CreateGraphicsPipelineState through X2W_TEST_NATIVE_GRAPHICS_PSO_FAILURE, so the published-pair path is the only variable. ## Review update (2026-11-27, 9360bcae) JVProg's ordering question was correct: there was no guarantee that the native and published translations have matching bindings. pipeline_for may replace *tr with the disk translation after the old code had already prepared d16_unorm16, formatted_buffers and the fixed vertex view. The PSO is now created first, then every binding is derived from the translation pipeline_for leaves in tr; if the fallback changes fixed_stream, the indexed-rectangle geometry key is recomputed before the draw. Added the two missing cases to startup_native_graphics_draw_check.py: - RTV variant (R32G32B32A32_FLOAT): a native draw publishes req_<key>.rtv, compile_dxil --watch --once publishes the variant, and the injected candidate PSO failure recovers it. The readback is 0000803f00000000000000000000803f; removing the variant manifest refuses with 32 clear pixels. - Invalid .ps.cso with a valid manifest: the translation loads, disk PSO creation fails, the draw is refused with 32 clear pixels, and the invalid bytes and mtime are unchanged. Verification: dev and release, WARP (Microsoft Basic Render Driver 10.0.26100.10068) and RX 9060 XT (driver 32.0.32029.2010): startup_native_graphics_draw_warp and _hardware 2/2 each; the debug regression set runs 8, passes 7, with one capability skip; release native draw 2/2. The D3D12 debug layer was unavailable (0x887a002d). ## Review update (2026-11-28, 4df09294) R0Y00's geometry-flag question is addressed: pipeline_for now receives the rectangle kind and derives geometry_rect from the translation it actually holds. After a disk fallback, the recursive call uses the disk pair's fixed_stream state instead of the native candidate's. The replaced candidate blobs are released before the swap. A valid same-key disk pair cannot drop fixed_stream while its shaders declare an input layout; a hand-edited version 2 manifest reaches CreateGraphicsPipelineState with E_INVALIDARG, and the draw now refuses with published disk pair pipeline failed. Verification at 4df09294, Debug and Release, WARP and RX 9060 XT: powershell ctest --preset dev --no-tests=error -j 1 -R '^(startup_native_graphics_draw_.*|startup_indirect_.*|startup_stream_draw_.*|startup_compute_dispatch_native_.*|native_rtv_variant_.*|startup_manifest_retry.*|startup_.*sampler.*)$' -E 'startup_audio_' ctest --preset release --no-tests=error -j 1 -R '^startup_native_graphics_draw_(warp|hardware)$|^native_rtv_variant_(warp|hardware)$' Debug: 104 passed, 1 capability skip (startup_compute_dispatch_native_warp), 0 failed. Release: 4/4. The D3D12 debug layer was unavailable (0x887a002d). ## Base update (2026-11-28, fdae7f16) Merged the updated codex/native-graphics-integration base (97cde4d5, including #3091's 247530b0 and current main) into this branch. The d3d12_draw.inl conflict keeps the new PSO recipe path and re-applies the recovered-geometry flag and revision cache invalidation to it. The fixed-mesh capture path is preserved. The native-graphics fixture respects the new disk-pair precedence; test-only X2W_TEST_NATIVE_GRAPHICS_PREFER_NATIVE (and the existing PSO-failure hook) forces the native candidate for the fallback cases. Tests at fdae7f16: - compiler suite 14/14 in Debug, including native_rtv_variant_{controls,warp,hardware} and native_compile_dxil_watch; - runtime draw/indirect/stream/sampler suite 84/84, one WARP capability skip (startup_compute_dispatch_native_warp); - Release startup_native_graphics_draw_{warp,hardware} and native_rtv_variant_{warp,hardware}: 4/4. The D3D12 debug layer was unavailable (0x887a002d). ## PSO-failure negative control (b409dc83) The control now begins with <key>.txt renamed to .pending, so the first draw takes the native path. A test-only X2W_TEST_MANIFEST_BEFORE_FALLBACK moves the valid manifest into place only when the failed candidate asks for its fallback. It asserts the injected candidate failure, the manifest publication before fallback, the recovered 16-red draw, unchanged manifest and stage bytes/mtimes, native-only refusal with the pair still pending and 32 clear pixels, plus the equivalent RTV-variant and missing-manifest controls. The earlier forced-native precedence is removed; production keeps the disk-first base behavior. At b409dc83: 14/14 compiler tests in Debug, 84/84 runtime tests with one WARP capability skip, and 4/4 in Release on WARP and RX 9060 XT. Debug layer unavailable (0x887a002d). ## RTV late-manifest fix (dbca1851) Restored the ordinary manifest_retry.due() reload before the native decision in translation_for_targets. The previous else if was unreachable while an RTV entry was unavailable, so a valid manifest published after the first draw was never loaded. Native compilation remains one attempt per RTV entry. ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_(mrt_dxc|native_graphics_draw)_(warp|hardware)$': - Debug: 4/4 passed. - Release: 6/6 passed, including native_rtv_variant_{warp,hardware}. - Broader runtime suite: 84/84 with one WARP capability skip; compiler suite 14/14. The injected-failure controls remain green. Debug layer unavailable (0x887a002d).

Base update (2026-11-28, 91d000a9)

Merged codex/native-graphics-integration c23cbc36 (including the reviewed #3091/#3094, sampler retirement and fixed-mesh sync) into the PSO fallback. The conflict keeps the translation revision bump and the pre-fallback geometry-flag derivation, adapts prepare_draw_sampler_heap(self, ...), and keeps the test's mtime snapshots and fault set.

Added a two-draw revision-invalidation control: a test-only revision bump between draws must create a second desktop PSO. Removing the revision from the PSO cache key makes the test fail with one pipeline instead of two.

Debug and Release: startup_native_graphics_draw_{warp,hardware}, startup_mrt_dxc_{warp,hardware} and native_rtv_variant_{warp,hardware} pass 6/6 each. The D3D12 debug layer was unavailable (0x887a002d).

A native graphics candidate reports ready=1 before pipeline_for creates its
desktop PSO. When CreateGraphicsPipelineState failed, the draw returned null
and cached that result, so the target stayed clear even when a valid published
pair existed in the shader cache.

Reload that pair for the same render-target key, bump a translation revision
so earlier native PSOs are not reused, and refuse the draw with a diagnostic
when the pair is missing or invalid. Native-only mode keeps its explicit
refusal. The published manifest and stage files are read, never rewritten.

Refs R0Y00#3134
@lambirou

Copy link
Copy Markdown
Contributor Author

Note: the Windows checks workflow triggers only for pull requests to main and cpp-migration, so this branch-targeted PR has no CI run. The complete local receipt is in the description.

@JVProg

JVProg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Hi @lambirou, I claimed #3134 shortly before this PR was opened and had been working on it locally. Rather than open a competing PR, I'm sharing what may be useful here.

One question about ordering. In draw_translated, d16_srvs_ready, formatted_buffers_ready and fixed_vertex_view run against tr before pipeline_for. With this change, pipeline_for can replace *tr with the disk translation, so later binding would use data prepared for the native one. Is it guaranteed that both have matching bindings? I haven't reproduced a failure from this; it comes from reading the diff (I haven't built or run this branch).

Two cases I didn't see in the diff. I tested these on my local implementation, not on yours:

  • RTV variant fallback (R32G32B32A32_FLOAT): draw natively, publish the variant with compile_dxil --watch --once, then inject the PSO failure. The disk readback matched the native one byte for byte. After removing the variant manifest, the draw was refused.
  • Invalid .ps.cso with a valid manifest: the translation loads, but creating the disk PSO fails. The target stayed clear and the invalid file was left unchanged.

Both passed on WARP and on an AMD Radeon RX 9070 XT (driver 32.0.32029.2010) in Debug and Release. The D3D12 debug layer was unavailable (0x887a002d). My base was b80513fd.

If these are useful, I can post the test code here.

I'm working with AI assistance.

@lambirou

Copy link
Copy Markdown
Contributor Author

CI-equivalent smoke receipt for this branch-targeted PR. The pr preset used by the Windows workflow for pull requests to main was built and run locally on native/graphics-pso-fallback (06c7380b) with the change applied.

cmake --preset dev
cmake --build --preset pr
ctest --preset pr --no-tests=error

41/41 passed, 0 failed (20.9 s). The 12 spirv_*_warp tests are capability skips because SPIR-V tools are not installed on this host; they are skipped, not failed. Windows build 10.0.26300.10075, WARP. The targeted startup_native_graphics_draw_{warp,hardware} receipt remains as described in the PR.

pipeline_for may replace the native candidate with the published disk
translation. Create the PSO before preparing the D16, formatted-buffer and
fixed-vertex bindings so they come from the final translation, and recompute
indexed-rectangle geometry when the fallback changes the fixed stream.

Add the RTV variant fallback and invalid pixel-blob cases.
@lambirou

Copy link
Copy Markdown
Contributor Author

Hi @JVProg, yes, the ordering was a real gap: both translations are prepared for the same key, but nothing guaranteed matching bindings. pipeline_for can replace *tr, while d16_srvs_ready, formatted_buffers_ready and fixed_vertex_view ran before it and later bindings used the native arrays.

Fixed on 9360bcae: the PSO is created first, then all binding preparation is derived from the translation pipeline_for leaves in tr. If the published fallback changes fixed_stream, the indexed-rectangle geometry key is recomputed before the draw.

I also added both cases you described to startup_native_graphics_draw_check.py:

  • RTV variant R32G32B32A32_FLOAT: native draw publishes req_<key>.rtv, compile_dxil --watch --once publishes the variant, injected PSO failure recovers it with readback 0000803f00000000000000000000803f; removing the variant manifest refuses with 32 clear pixels.
  • Invalid .ps.cso with a valid manifest: the translation loads, the disk PSO fails, the draw is refused with 32 clear pixels, and the invalid bytes and mtime are unchanged.

Dev and release on WARP and the RX 9060 XT: native draw 2/2 in each preset; debug regression 8 run, 7 pass, one capability skip (WARP without 32-lane waves). Debug layer unavailable (0x887a002d). If you still have your local test code, I would be glad to compare the RTV setup.

@JVProg

JVProg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks @lambirou. Here is the RTV block from my local test.

I haven't rebuilt or re-run this copy. The results in my earlier comment come from an earlier run on b80513fd with my implementation. The log strings it asserts are mine, so they would need to be changed to yours.

Comparing it by reading it against your test on 9360bcae, the setup differs in two ways:

  • Shader: mine uses pixel_stage() and WORDS from native_rtv_variant_check.py, so the four channels carry different raw bit patterns. Yours reuses the red shader and checks the exact expected bytes.
  • Cache: mine uses a separate, initially empty cache for the variant. Yours reuses the one that already holds the base pair.

Yours also checks things mine doesn't: modification times, and the exact clear value on refusal (mine only checks that the image differs from the native one).

RTV block
from native_rtv_variant_check import WORDS, pixel_stage

# Inside check(), after the 8-bit PSO cases:
    # A float target draws through an RTV variant, whose disk manifest must name the same specialization.
    variant_cache = folder / "variant-cache"
    variant_cache.mkdir()
    variant_ps, variant_pixels = folder / "variant-ps", folder / "variant-pixels"
    variant_ps.write_bytes(pixel_stage())
    variant_args = [consumer, vs, variant_ps, root, adapter, variant_pixels, "2"]  # R32G32B32A32_FLOAT
    variant_env = dict(env, X2W_SHADER_CACHE=str(variant_cache))

    def variant_draw(run_env):
        variant_pixels.unlink(missing_ok=True)
        run = subprocess.run(variant_args, env=run_env, capture_output=True, text=True, timeout=45)
        assert run.returncode == 0, run.stderr[-8000:]
        return run.stderr, variant_pixels.read_bytes()

    text, native_image = variant_draw(variant_env)
    assert "-> drawn;" in text and struct.pack("<4I", *WORDS) in native_image, text[-8000:]
    subprocess.run([compiler, "--watch", sdk, variant_cache, variant_cache, "--once"], check=True, timeout=45)
    marker, = variant_cache.glob("req_*.rtv")
    variant_manifest = variant_cache / (marker.stem.removeprefix("req_") + ".txt")
    variant_files = {p: p.read_bytes() for p in (variant_manifest, variant_manifest.with_suffix(".vs.cso"),
                                                 variant_manifest.with_suffix(".ps.cso"))}
    fault_env = dict(variant_env, X2W_TEST_NATIVE_GRAPHICS_PSO_FAILURE="1", X2W_NATIVE_SHADERS_ONLY="0")
    text, image = variant_draw(fault_env)
    assert "-> 0x80004005" in text and "using the published disk pair" in text and "-> drawn;" in text, text[-8000:]
    assert image == native_image, (image.hex(), native_image.hex())
    assert all(path.read_bytes() == expected for path, expected in variant_files.items())
    print(f"{adapter} PSO, RTV variant: published disk pair matches the native float readback")
    variant_manifest.unlink()
    text, image = variant_draw(fault_env)
    assert "no usable disk pair" in text and "-> drawn;" not in text and image != native_image, text[-8000:]
    print(f"{adapter} PSO, RTV variant without a manifest: explicit refusal, target not drawn")

AI was used.

@lambirou

Copy link
Copy Markdown
Contributor Author

Thanks, @JVProg. I ran your block against 9360bcae with only the log strings adapted to our wording (candidate pipeline failed 0x80004005 (injected), published disk pair recovered, no valid published disk pair). It passes on WARP:

  • native readback fe7fffff15000000eb00000068000000;
  • the injected candidate PSO failure recovers the published variant with the same bytes;
  • removing the variant manifest leaves 32 clear pixels and no draw.

I kept our version in the PR because it reuses the cache that already holds the base pair and additionally asserts the exact clear value and the manifest/stage mtimes. Your block is complementary: it covers a different pixel payload and a cache without the published base pair. I can add it as a second case if you think that combination is worth pinning in CI; the branch is otherwise unchanged at 9360bcae.

@KelboLive

Copy link
Copy Markdown
Contributor

LGTM! The PSO fallback recovery is correctly implemented:

Key features:

  • Properly handles native candidate PSO (Pipeline State Object) creation failures
  • Falls back to the published disk pair binding when direct compilation fails
  • Ensures graceful degradation rather than hard crashes on shader compilation errors

Implementation notes:

  • The fallback mechanism preserves the original descriptor bindings while using a different pipeline state
  • Error handling is comprehensive, covering both compile-time and runtime PSO creation failures
  • The recovery path maintains consistency with the game's expected resource layout

This improves runtime stability by providing a reliable fallback when native shader compilation fails, which is essential for compatibility across different GPU configurations.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independent Release /O2 retest on exact stack head 9360bcae (tree 7193cd488c831f84dec391e442c4fed45c321305). Built compile_dxil startup_stream_consumer d3d12_xs_shim and ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^startup_native_graphics_draw_(warp|hardware)$'. 2/2 passed, zero skips. WARP and RTX both recovered the published pair to 16 red / 16 clear after injected native PSO failure, and the same RTV variant recovered its disk pair. Missing and invalid pairs and invalid disk PS blobs kept the target clear, native success still drew, and the cache preservation checks passed. Windows 26200.9974, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, SDK/DXC 10.0.26100.0, D3D12 debug layer enabled.

One by-inspection question remains outside the triangle and RTV receipts. If a direct rectangle changes from a fixed-stream native translation to a legacy disk translation, the recursive pipeline_for still receives the original geometry flag. draw_translated only recalculates the flag when that first PSO returns non-null. If disk geometry preparation fails with the old flag, can the caller still retry with the disk translation’s actual flag? Please check this path or derive the rectangle geometry flag from the recovered translation before creating its PSO.

@JVProg

JVProg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks @lambirou for running it. I'm happy to leave that choice to you. The part of my block that seems to add something is the variant case with no published base pair in the cache. Your version already checks the exact clear value and the mtimes.

AI was used.

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

I reviewed 9360bcae merged over current codex/native-graphics-integration b80513fd, the PR's base. The merge is clean and git diff --cached --check is clean.

What I traced.

  • Fallback path: pipeline_for now treats a failed CreateGraphicsPipelineState on a native candidate as recoverable. It loads the published pair for the same key and RTV request into a fresh Translation, with count = false so the missing and ready counters don't move twice. It then bumps revision, swaps the pair into tr and recurses once. The recovered translation has native_candidate = false, so the recursion can't loop.
  • Binding order: after the reorder in draw_translated, the d16 views, formatted buffers, the fixed vertex view and the indirect checks all read the translation that pipeline_for leaves in tr. That answers JVProg's ordering question.
  • Sharing: translations are shared by key through translation_by_key(), so a swap made by one guest pipeline is seen by every BoundPipeline with that key. The revision term in the PSO cache key is what stops another pipeline from reusing a native PSO it created earlier against the swapped-in disk bindings. The logic is right, but no test reaches it (see the mutants).

What I ran. I did a full dev build, then ran

ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^(startup_native_graphics_draw_.*|startup_indirect_.*|startup_stream_draw_.*|startup_compute_dispatch_native_.*|native_rtv_variant_.*|startup_manifest_retry.*|startup_.*sampler.*)$' -E 'startup_audio_'
  • dev: 104 of 105 pass, with 1 capability skip (startup_compute_dispatch_native_warp, WARP without 32-lane waves). The indirect refusal census tests are part of this set, so the new refusal precedence (described below) doesn't change any code they assert.
  • release: I built compile_dxil startup_stream_consumer d3d12_xs_shim and ran ^startup_native_graphics_draw_(warp|hardware)$. 2/2 pass.
  • Debug layer: it was available on this host (x2w-d3d12 debug layer: 0x00000000 enabled), and the new assert_debug_clean passes in startup_native_graphics_draw_hardware.

Mutants in src/startup_stubs/d3d12_draw.inl. For each, I rebuilt d3d12_xs_shim startup_stream_consumer in dev and ran startup_native_graphics_draw_warp:

Mutant Result
candidate.native_candidate = true; removed (no fallback, as on the base) killed: this is the negative control
fallback loads with an empty RTV request killed (RTV case)
if (!native_shaders_only()) → if (true) survives, equivalent: load_translation refuses in native-only mode anyway, and only the diagnostic changes
revision term removed from the PSO cache key survives
fallback.revision = tr.revision + 1 → tr.revision survives
geometry-rect recompute after the fallback → never survives

Restored and rebuilt afterwards; the tree is clean.

Non-blocking.

  1. Revision is unpinned. Both revision mutants survive because the fixture has one guest pipeline per key. A case where two pipelines share a key would pin it:
    1. Pipeline A, for example with a different blend, creates a native PSO successfully.
    2. Pipeline B's candidate PSO then fails, which swaps the shared translation to the disk pair.
    3. A draws again and must create a new PSO rather than reuse its native one.
  2. Geometry recompute is unpinned. That would need a native candidate and a disk pair that differ in fixed_stream.
  3. Candidate blobs leak. tr = std::move(fallback) overwrites the candidate's raw vs / ps blob pointers without Release. Translation has no destructor, so they leak once per key that falls back. That's small, but releasing them before the swap is cheap.
  4. A cached null blocks later recovery. When no valid disk pair exists yet, bound.pipelines[key] = nullptr is cached. If compile_dxil --watch publishes the pair later in the same process, that pipeline still won't recover. The old code behaved the same way, and #3134 asks only for an already-published pair, so this is a possible follow-up, not a gap in this PR.
  5. Refusal precedence changed. The PSO and sampler heap are now created before the d16, formatted-buffer, fixed-stream and indirect refusals. A draw that is refused for one of those reasons now builds its PSO (cached) first. If PSO creation fails as well, the indirect refusal code becomes pipeline_unavailable instead of, say, missing_guest_root. The census tests above still pass. I'm noting it so it's a known trade-off.

Verdict: approve on 9360bcae. This targets codex/native-graphics-integration, so I'm leaving the merge to the branch owner.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; WARP and NVIDIA GeForce RTX 5090 (driver 32.0.16.1088); D3D12 debug layer enabled.
CI: none on this PR (the workflow runs only for main and cpp-migration).

This reply was AI-assisted.

@KelboLive

Copy link
Copy Markdown
Contributor

Agree with pigalot's APPROVED review: the fallback path is correct — pipeline_for treats a failed native candidate PSO as recoverable, loads the published pair into a fresh Translation with count=false, bumps revision to prevent stale reuse, and recurses once. The shared translation + revision cache key prevents cross-pipeline contamination.

pipeline_for received only the pre-fallback geometry flag. A direct rectangle
whose native candidate had a fixed vertex stream could therefore recurse into
the published disk pair with that stale flag, and the caller did not retry when
the disk PSO failed.

Pass the rectangle kind and derive the flag from the translation the function
actually holds. Release the replaced candidate blobs before the swap.
@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 the rectangle geometry flag is now derived from the translation pipeline_for actually holds. The function takes the rectangle kind and recomputes geometry_rect after a disk fallback, so the recursive call no longer reuses the native candidate's flag. The replaced candidate blobs are released before the swap.

On the true → false case: a valid same-key disk pair cannot drop fixed_stream while its shaders still declare an input layout. A hand-edited version 2 manifest without fixedvb reaches CreateGraphicsPipelineState with E_INVALIDARG; the caller now tries the disk translation's actual flag and refuses with published disk pair pipeline failed rather than retrying the GS with the stale flag. That diagnostic is the expected refusal for this malformed pair.

Tests at 4df09294, Debug and Release, WARP and RX 9060 XT (driver 32.0.32029.2010):

ctest --preset dev --no-tests=error -j 1 -R '^(startup_native_graphics_draw_.*|startup_indirect_.*|startup_stream_draw_.*|startup_compute_dispatch_native_.*|native_rtv_variant_.*|startup_manifest_retry.*|startup_.*sampler.*)$' -E 'startup_audio_'
ctest --preset release --no-tests=error -j 1 -R '^startup_native_graphics_draw_(warp|hardware)$|^native_rtv_variant_(warp|hardware)$'

Debug: 104 passed, 1 capability skip (startup_compute_dispatch_native_warp), 0 failed. Release: startup_native_graphics_draw_{warp,hardware} and native_rtv_variant_{warp,hardware} 4/4. The debug layer was unavailable (0x887a002d), so I do not claim debug-layer cleanliness.

AI was used.

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

The runtime base #3094 is now 97cde4d, and this PR conflicts in d3d12_draw.inl. The base now uses an already published disk pair before trying the native compiler on the first draw. Please update this PR on the current base and keep that precedence. The remaining PSO-failure control should start with no ready disk marker, make a valid disk pair available before fallback is attempted, and verify native-only refusal plus unchanged files. Keep the rectangle recomputation and exact-head WARP and hardware checks.

Bring origin/codex/native-graphics-integration (97cde4d, including the updated
native shader modules and current main) into the PSO fallback branch.

Keep the new PSO recipe path and re-apply the recovered geometry flag and
revision cache invalidation to it. Keep the fixed-mesh capture path from the
runtime branch, and adapt the native-graphics fixture to the new disk-pair
precedence with test-only force hooks.

Tests: startup_native_graphics_draw_{warp,hardware} and
native_rtv_variant_{warp,hardware} pass in Debug and Release; the draw,
indirect, stream and sampler regression set passes 84/84 with one WARP
capability skip.
@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 merged the updated codex/native-graphics-integration base 97cde4d5 into this branch at fdae7f16. The PR is clean and mergeable again.

The d3d12_draw.inl conflict was resolved by keeping the new PSO recipe path and re-applying the recovered-geometry and revision cache invalidation to it. The runtime's fixed-mesh capture path is preserved. The native-graphics fixture now respects the new disk-pair precedence; test-only X2W_TEST_NATIVE_GRAPHICS_PREFER_NATIVE and the existing PSO-failure hook force the native candidate for the fallback cases.

Tests at fdae7f16:

  • compiler suite 14/14 in Debug (including native_rtv_variant_{controls,warp,hardware} and native_compile_dxil_watch);
  • runtime draw/indirect/stream/sampler suite 84/84, one WARP capability skip (startup_compute_dispatch_native_warp);
  • Release startup_native_graphics_draw_{warp,hardware} and native_rtv_variant_{warp,hardware} 4/4.

The debug layer was unavailable (0x887a002d). AI was used.

akimfomin commented Nov 28, 2026 •

Copy link
Copy Markdown

PortBridge's saved Git comparison was for the older 4df0929 head. Your rebase at fdae7f16 already resolves that conflict and explicitly forces the native route in the fallback fixture. The published positive and missing-pair controls cover the distinction I intended. No repeat requested.

The cross-project complement remains XCL #2940, where a presented blob is stale but native creation succeeds. That should count one native create and keep that pipeline. In Xbox2Windows the forced create failure is a different outcome and the disk-pair recovery is the positive case. Our recorded comparison. If useful on a different open PR, a maintainer or agent can send the PR URL, target SHA and expected behavior in PortBridge #98.

Move the valid manifest into place only when the failed native candidate asks
for its fallback. The fixture now proves the native PSO was attempted before
disk reuse, covers native-only refusal with the pair still pending, and checks
the published files stay unchanged. Drop the test-only forced-native
precedence.
@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 the PSO-failure control now starts with <key>.txt renamed to .pending, so the first draw enters the native path rather than reusing the disk pair. A test-only X2W_TEST_MANIFEST_BEFORE_FALLBACK moves the valid manifest into place only when the failed native candidate asks for its fallback.

The test asserts, in order:

  • the native candidate failed with the injected 0x80004005;
  • the manifest was published before the fallback;
  • the published pair was recovered and drew 16 red pixels;
  • the manifest and both stage blobs kept their bytes and mtimes;
  • native-only mode refused with the pair still pending and left 32 clear pixels;
  • the equivalent RTV-variant control and a missing-manifest refusal.

The test-only forced-native precedence from fdae7f16 is removed; production keeps the disk-first precedence. At b409dc83: 14/14 compiler tests in Debug, 84/84 runtime tests with one WARP capability skip, and 4/4 in Release on WARP and RX 9060 XT. The D3D12 debug layer was unavailable (0x887a002d). AI was used.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independent review of fdae7f1. The PSO fault fixture proves the candidate was attempted and then recovered the published pair. Debug and Release /O2 each had 17 passes and one inbox WARP wave32 skip in the fixed mesh, first native draw, stream, native Dispatch and raw pixel UAV/atomic selection.

The updated RTV flow regresses late manifests. In translation_for_targets, an unavailable variant takes the state != 1 branch on every draw. The following else if (entry->manifest_retry.due(...)) is therefore unreachable in the missing state. With no native worker it republishes the marker and never reads the valid manifest when it appears. The existing startup_mrt_dxc_warp and startup_mrt_dxc_hardware both reproduce this on the exact head: the first and second draws both log no RTV translation after the fixture has published the disk marker and waited 1.1 s. Windows 11 26200.9974, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled.

Please retain the ordinary retry before the native decision, and keep native compilation one attempt per RTV entry. Keep the new injected-failure controls, and rerun these two existing late-publication controls alongside them.

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

@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

I rechecked b409dc8. The delayed publication inside the fault fixture now proves the intended native-first failure and disk recovery. The normal late RTV publication regression still reproduces separately: both native graphics tests pass, both startup_mrt_dxc tests fail.

A small local resolution passed all four on WARP and RTX. I restored translation_for_targets from #3094 at 97cde4d, kept only entry->rtv_request = request immediately after entry->key = key, and kept the rest of b409dc8's PSO fallback and fixture changes. This leaves initial translation and marker publication inside the new-entry branch and the existing entry's due retry in its reachable else-if. Reproduction: ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_(mrt_dxc|native_graphics_draw)_(warp|hardware)$'.

Restore the manifest_retry.due retry before the native decision for RTV
variants. The retry had moved into an else-if after a state check that is
always taken while the variant is unavailable, so a late published manifest
was never loaded.

Keep one native compilation attempt per RTV entry and preserve the new
PSO-failure controls.
@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 fixed the late-manifest regression on dbca1851: translation_for_targets now performs the ordinary manifest_retry.due() reload before the native decision. The previous else if sat after an entry->state != 1 branch that is always taken while the variant is unavailable, so it was unreachable. Native compilation remains limited to one attempt per RTV entry.

I ran your exact controls:

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_(mrt_dxc|native_graphics_draw)_(warp|hardware)$'
  • Debug: 4/4 passed (startup_mrt_dxc_warp, _hardware, startup_native_graphics_draw_warp, _hardware).
  • Release: 6/6 passed, adding native_rtv_variant_warp and _hardware.
  • Broader runtime suite: 84/84 passed, one WARP capability skip; compiler suite 14/14.

The new injected-failure controls still pass. D3D12 debug layer unavailable (0x887a002d). AI was used.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved after independent review of dbca185 on runtime base 97cde4d. The ordinary late RTV retry runs before the one-shot native attempt. The exact head passed the previously failing late-publication control on both adapters. The fault fixture also proves native PSO creation was attempted before the disk pair was published, and checks successful recovery, native-only refusal, unchanged cache files and the RTV variant.

Debug and Release /O2 each passed all six selected source-built tests, no skips. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, D3D12 debug layer enabled in the graphics fixtures.

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

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for the work on this. One thing blocks merging at dbca185: the last commit moved the RTV publish and its log line out of the new-entry block. Every draw on an unavailable RTV variant now stats req_<key>.rtv under draw_lock and writes an unbudgeted "no RTV translation" line to stderr and the log file. On the base (97cde4d) that happened once per entry. The block sits outside #ifdef X2W_NATIVE_SHADERS, so it hits every build, and a variant that never gets translated floods the log for as long as the title draws.

Could you restore translation_for_targets from the base and keep only entry->rtv_request = request, as R0Y00 suggested at 01:11? Two smaller points: the missing-pair, invalid-pair and invalid-PS cases never reach the fallback (they also pass on the base runtime, and "published disk pair pipeline failed" is asserted 0 times), and revision invalidation is still unpinned by a test (the surviving mutants from the earlier review).

This comment was AI-assisted.

Restore translation_for_targets from 97cde4d and keep only entry->rtv_request = request. The publish, native attempt and no-translation log now run once when the RTV entry is created; an existing entry only reloads on its due retry. Add a PSO fallback control where the disk pair loads but its PSO cannot be created, and assert the published-disk-pair-pipeline-failed diagnostic.
@lambirou

Copy link
Copy Markdown
Contributor Author

Fixed at 4b3a4f9a.

  • translation_for_targets is restored from 97cde4d5, with only entry->rtv_request = request added after entry->key = key. The .rtv publish, native attempt and no RTV translation log are back inside the if (!entry) block; an existing entry only reloads on its else if (manifest_retry.due()) retry. A variant that never translates no longer stats the marker or logs on every draw.
  • Added a PSO fallback control where the native candidate fails, then a valid manifest with an uncreatable PS is made ready before fallback. It asserts published disk pair pipeline failed as well as the native failure and the clear target.

Release and Debug: startup_mrt_dxc_{warp,hardware} and startup_native_graphics_draw_{warp,hardware} pass 4/4 each. The new disk-PSO-failure case passes on WARP and the RX 9060 XT.

The revision-invalidation path is still unpinned by a targeted test; I left that as the remaining smaller gap rather than changing the runtime further.

@lambirou

Copy link
Copy Markdown
Contributor Author

Additional RTV checks on 4b3a4f9a: native_rtv_variant_warp and native_rtv_variant_hardware pass 2/2 in both Debug and Release, alongside the 4/4 MRT/native draw set.

Copy link
Copy Markdown
Contributor

I independently tested 4b3a4f9a1228167a71f19b65020d7747e9470ad8 (tree 34d6209b) on #3094 base 97cde4d5.

Debug and Release each passed 7/7, no skips, on Windows 26300.10075 with the D3D12 debug layer enabled. Adapters were RTX 4070 10de:2786 (driver 32.0.16.2124) and inbox WARP 1414:008c (10.0.26100.10068). DXC was 1.9.2602.17.

  • The forced native PSO failure recovered the disk pair on both adapters and read back 16 red and 16 clear pixels. The RTV-specific pair recovered too. Late manifest publication in the same process still drew.
  • The new control with a valid published manifest and an uncreatable disk PS reported both the injected native failure and published disk pair pipeline failed. It recorded no draw and preserved 32 clear pixels on both adapters.
  • The MRT, native-only, cache preservation and UINT16/SINT16/FLOAT32 variant checks also passed. These results are for the PR's stacked base.
cmake --build --preset <dev-or-release> --target compile_dxil startup_stream_consumer d3d12_xs_shim offscreen_check
ctest --preset <dev-or-release> --no-tests=error -j 1 -V -R '^(startup_native_graphics_draw_(warp|hardware)|startup_mrt_dxc_(warp|hardware)|native_rtv_variant_(controls|warp|hardware))$'

I used Codex to run and verify the local checks.

Add a two-draw fixture and a test-only translation revision bump. The second draw must create a new PSO rather than reuse the first; removing the revision from the PSO cache key makes the test fail (one desktop pipeline instead of two).
Keep the translation revision bump, the pre-fallback geometry flag derivation and the transactional PSO fallback against the base's sampler retirement, fixed mesh sync and shared pipeline creation. Keep the test's mtime snapshots and the fault set while adding the base's key variable. The local rasterizer state now takes the base's self parameter.
@lambirou

Copy link
Copy Markdown
Contributor Author

Refreshed onto the merged native graphics base c23cbc36 (includes #3091/#3094, sampler retirement and fixed-mesh sync). Head: 91d000a9.

  • Kept the translation revision bump and the pre-fallback geometry-flag derivation.
  • Adapted the draw to prepare_draw_sampler_heap(self, ...).
  • Kept the test's byte/mtime snapshots and the full missing/manifest/root PSO fault set.
  • Added a two-draw revision-invalidation control: a test-only revision bump must create a second PSO. Removing the revision from the PSO cache key makes it fail with one pipeline instead of two.

Debug and Release: startup_native_graphics_draw_{warp,hardware}, startup_mrt_dxc_{warp,hardware} and native_rtv_variant_{warp,hardware} pass 6/6 each. #3139 is CLEAN/MERGEABLE at 91d000a9.

@lambirou

Copy link
Copy Markdown
Contributor Author

Additional sampler regression on 91d000a9: startup_sampler_heap_{warp,hardware} and startup_inline_sampler_{warp,hardware} pass 4/4 in Release after rebuilding offscreen_check. Two other sampler selections (startup_translated_sampler_bindings, startup_sampler_comparison) are separate executables that are not built in this worktree; they are not failures from this branch.

@lambirou

Copy link
Copy Markdown
Contributor Author

Follow-up: I built the two remaining sampler executables. startup_translated_sampler_bindings and startup_sampler_comparison also pass 2/2 in Release. The full available sampler set is now 6/6 on 91d000a9.

@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 #3139 is refreshed on the merged native graphics base c23cbc36 at 91d000a9. It is CLEAN/MERGEABLE and approved. Validation: 6/6 native draw/MRT/RTV in Debug and Release, plus 6/6 sampler checks in Release; the revision-invalidation mutant is pinned and killed. Ready to merge.

@R0Y00
R0Y00 merged commit 7291aef into R0Y00:codex/native-graphics-integration 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.

8 participants