startup: persist and reuse translated PSO recipes #2919
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2919"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-26T20:33:35Z.
What changed
The translated draw path builds each desktop graphics PSO on its first draw, from state the shader cache does not store: the effective blend state after export write masks, depth-stencil state, rasterizer state, target formats, DSV format, sample mask and topology. A run therefore reconstructs that state and creates the PSO at the first draw.
This adds an opt-in persistent recipe cache:
X2W_PSO_RECIPE_DIR=<dir>, off by default.pipeline_forappends the exact state after a successfulCreateGraphicsPipelineState.load_translationreads the matching file and the firstpipeline_forreplays records whose target formats and DSV match the pass. A malformed record, an unknown version, a corrupt state key or a target-format mismatch is ignored and the unchanged creation path runs.This is state reconstruction, not a D3D12 pipeline library. A replayed record still calls
CreateGraphicsPipelineState; the driver may compile or find the PSO in its own cache. The change moves the state reconstruction and first-use creation earlier; it does not claim to eliminate driver compilation.Tests
startup_pso_recipepassed: 29 checks, 0 failed. It covers the serializer/parser round trip, two appended records, a corrupt state key, an unknown version, an oversized file, target-format and DSV mismatches, the recreated blend/depth/rasterizer/sample/topology fields, the 63/64/65 record boundary (63 accepts one more, 64 refuses a 65th, and the parser rejects a 65th), and a parseable record without its final LF (append refused, earlier record still readable).startup_stream_draw_warpandstartup_stream_draw_hardwareexercise the full path: the first translated stream draw writes a recipe, a second process with the same directory loads it, reports precreated records, and produces the same 32 RGBA bytes. They also hold the recipe file exclusively during a draw and check that the draw still renders with exact pixels while the file size stays unchanged. The runtime boundary control seeds 63 valid records for another translation key, checks that the next draw appends the matching record as number 64 and the following process logsprecreated 1, then seeds 64 records and checks that the draw still renders while the file stays at 64. It removes the final LF from that file, checks that the draw leaves it byte-for-byte unchanged, and checks that the next draw still reads it. The test found and fixed a real serializer/parser gap: an unused depth-stencil block was written as a zero-filledD3D12_DEPTH_STENCIL_DESC, whose zero stencil ops the parser rejects. The serializer now writes a valid default for an unused block, and the parser normalizes it back for the state key.Passed on
360a9dff, dev and release, on WARP (1414:008c, driver10.0.26100.10068) and on an AMD Radeon RX 9060 XT (1002:7590, driver32.0.32029.2010). The branch is merged with currentmaine1ea515d.Limits
The replay still calls
CreateGraphicsPipelineState; it does not serialize a driver PSO or use a D3D12 pipeline library. No game files or captures are included.Refs #870.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-26T21:04:03Z.
Strengthened the coverage in
560c075a:startup_stream_draw_warpnow writes a recipe on the first translated draw, runs the same draw in a second process with the same directory, checks that the recipe is precreated, and compares all 32 RGBA bytes. This found a real serializer gap: an unused depth-stencil block was written as a zero-filled struct whose stencil ops are invalid; the serializer now writes a valid default and the parser normalizes it back for the state key. CI is green on the new head.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:30:29Z.
Review: COMMENTED
PR #2919 by @lambirou -- startup: persist and reuse translated PSO recipes
What works
Issues
Recommendations
Overall
A well-researched, well-tested implementation. The linear layout extension is cleanly separated from tiled modes. Minor concern about BC format handling in linear mode, but the existing refusal behavior is safe. Ready for merge.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:30:29Z.
Review: COMMENTED
PR #2919 by @lambirou -- startup: persist and reuse translated PSO recipes
What works
Issues
Recommendations
Overall
A well-researched, well-tested implementation. The linear layout extension is cleanly separated from tiled modes. Minor concern about BC format handling in linear mode, but the existing refusal behavior is safe. Ready for merge.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T08:59:37Z.
The two
COMMENTEDreviews on this PR describegfx10_layout.h,linear_modeandstartup_address_console_check.py, which are not part of this change. #2919 is the translated-PSO recipe cache (pso_recipe.h,d3d12_draw.inl,startup_stream_draw_check.py). Could a reviewer take another look at the actual diff? The current heada891727fis green and the two-process replay test passes.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T09:49:19Z.
@R0Y00 the two
COMMENTEDreviews here describegfx10_layout.handlinear_mode, not this PSO-recipe change. The current heada92a0f97is rebased onmain, green, and the two-process PSO replay test passes. Could you review the actual diff?Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T10:29:09Z.
Windows dev + release receipt on
711e7d95:The two-process replay is the requested end-to-end control: first process writes the recipe, second process loads and precreates it, and the 32 RGBA bytes match.
Imported from R0Y00/Xbox2Windows. Originally posted by sydney-0o on 2026-11-27T12:12:46Z.
Could you share when you expect this PR to merge, and whether the record-limit behavior below should be addressed here?
On head
711e7d95, I ranctest --preset dev --no-tests=error -R '^(startup_pso_recipe|startup_stream_draw_(warp|hardware))$' -V: all three passed on Windows 10 build 19045, WARP10.0.19041.5794and NVIDIA GTX 1080 Ti driver32.0.15.8278; the debug layer was disabled for the draw fixtures.I also checked the 64-record boundary with the existing serializer and parser. A source-built file containing 64 valid records and a 65th with a different state key was 30,484 bytes, below the 65,536-byte file limit. The parser accepted 64, rejected the last with
recipe record limit reached, and did not return the 65th key.append_pso_recipechecks file size but not the record count, so such a record can be appended and then ignored on later loads. The regular PSO creation path still handles a miss. A 64/65-record test and a matching append policy would make this boundary explicit.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T12:28:25Z.
Review: CHANGES_REQUESTED
Please address the writer/reader record boundary in this PR. On
711e7d95plusmain1ec2c938(tree117604d5), I reproduced the effect through the ordinary draw entry point with a source-built VS/PS. At 63 valid seed records, the writer appended the live record as number 64 and the next process loggedprecreated 1. At 64 valid seed records, it appended number 65 at 30,810 bytes, well below 64 KiB. The next process loggedrecipe record limit reached, fell back and appended number 66. The pixels still matched on both WARP and RTX. This is a persistent cache miss after a successful write, so please align the append policy with the parser and cover the 64/65 boundary.The implementation also opens the recipe file with
FILE_SHARE_WRITEand seeks to the observed end. Two processes can both choose the same offset. Please make the count/size check and publication one writer transaction or document and enforce exclusive ownership, and keep a contending draw on the regular fallback path. I noted this from the code and did not fault-inject a concurrent interleaving.Independent
ctest --preset <dev|release> --no-tests=error -V -R '^(startup_pso_recipe|startup_stream_draw_(warp|hardware)|startup_compute_dispatch_native_(warp|hardware))$'gave four passes and one native-compute WARP 77 skip per preset. The normal two-process draw, manifest retry and exact red/green readbacks pass. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818 and RTX 4060 Laptop driver 32.0.16.1656. The standard stream test leaves the debug layer off; the boundary probe enabled it.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T14:14:04Z.
Merged
mainate1ea515d. Head isab23bcf4.Record boundary:
recipe record limit reached;The device-free check now covers 63 records (append allowed), 64 records (append refused), 65 records (parser rejects the extra record), and a malformed existing file. All 26 checks pass.
Concurrency:
append_pso_recipeopens the file withdwShareMode = 0and holds that handle across the read, count/size check and append;read_pso_recipe_textnow shares read only, so it denies a writer for the whole read;startup_stream_draw_check.pynow takes an exclusiveCreateFileWhandle on the recipe file, runs another draw, and checks that the draw still produces the exact 32 RGBA pixels while the file size stays unchanged. That control passes for both the red and green recipes.Windows receipt on
ab23bcf4, dev and release,ctest --preset <dev|release> --no-tests=error -R '^startup_(pso_recipe|stream_draw_(warp|hardware))$':startup_pso_recipe: pass, 26 checks.startup_stream_draw_warp: pass, including the exclusive-ownership fallback.startup_stream_draw_hardware: pass on AMD Radeon RX 9060 XT1002:7590, driver32.0.32029.2010.Windows checks #8169 is still running on this head; I will report the result when it finishes.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T14:16:48Z.
Windows checks #8169 completed successfully on
ab23bcf4.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T14:22:47Z.
Added the runtime boundary control on head
708416f3, so the writer path itself is covered rather than only the policy helper.startup_stream_draw_check.pynow seeds the recipe file with 63 valid records for another translation key. The next draw appends the matching record as number 64, and the following process logsprecreated 1and reproduces the exact pixels. Seeding 64 records then leaves the file at 64 after another successful draw: the 65th record is not written. Both controls pass in dev and release on WARP and on the RX 9060 XT.Windows checks are running on the new head; the previous head
ab23bcf4was green in #8169.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T14:26:30Z.
Windows checks #8172 completed successfully on
708416f3.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T14:29:20Z.
@R0Y00 the two CHANGES_REQUESTED points are addressed on
708416f3and Windows checks #8172 are green. The runtime control now seeds 63 records (the next draw appends number 64 and the following process logsprecreated 1) and 64 records (no 65th is written), and the exclusive handle spans the read, count/size check and append. Could you re-review when you have a moment?Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:00:42Z.
Review: CHANGES_REQUESTED
The revised code holds one exclusive handle across the count and append, and the 63/64 controls cover the earlier record-limit issue. I found one remaining reader/writer boundary at
708416f3. Using the shipped C++ serializer, I removed only the last LF from one valid record.parse_pso_recipe_filestill accepted that record (one accepted, zero rejected), andpso_recipe_append_allowedreturned true. Appending the next serialized record producesendx2w-pso-recipe 1on one line. The next read accepted zero records, including the previously valid one. With the separator restored, both records parse.Please ensure a successful append preserves a line boundary. Rejecting the append without changing the file is sufficient. If the writer inserts a separator instead, include it in the 64 KiB cap. Add a control starting from a parseable record without a final LF and verify that the earlier record remains readable.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T15:06:29Z.
Fixed on
360a9dff.pso_recipe_append_allowednow refuses a non-empty file whose last byte is not LF, so the writer leaves the file unchanged instead of joiningendto the next header.Controls:
Passes in dev and release on WARP and the RX 9060 XT:
startup_pso_recipe,startup_stream_draw_warp,startup_stream_draw_hardware. Windows checks are running on the new head.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-27T15:09:39Z.
Windows checks #8191 completed successfully on
360a9dff.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:17:58Z.
Review: APPROVED
Retested
360a9dffonmaina9fd1488(treebcfaa9376a0cd5ee21944a5a42b5a41b075f2f38). The writer now refuses the append before changing a parseable file with no final LF. Besides the submitted unit and runtime controls, I seeded 63 valid foreign records with no final LF, a count still eligible for append. On both WARP and RTX the draw produced exact pixels, the file stayed byte-for-byte unchanged, and the next run rendered again. The adjacent 63-record file with a final LF still appended record 64 and precreated it in the following process. The 64-record and exclusive-handle controls also passed.Built
startup_stream_consumer d3d12_xs_shim startup_pso_recipe_check startup_manifest_retry_check compile_dxil. Debug and Release/O2each gave five passes and one native-compute WARP wave32 skip usingctest --test-dir <build> --no-tests=error -j 1 -V -R '^startup_(pso_recipe|stream_draw_(warp|hardware)|compute_dispatch_native_(warp|hardware)|manifest_retry)$'. Windows 11 26200.9974, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656 and SDK 10.0.26100. The stream draw fixture used the debug layer. This addresses both rounds of cache-write findings.