Skip to content

Runtime: GetCachedBlob and CachedPSO checks like the host runtime - #1683

Merged
ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
requiemsnkrp:d3d-cached-pso
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
requiemsnkrp:d3d-cached-pso

Conversation

@requiemsnkrp

Copy link
Copy Markdown

What and why

New D3D item, claim: ID3D12PipelineState::GetCachedBlob was a generated stub (E_NOTIMPL) and CachedPSO in CreateComputePipelineState/CreateGraphicsPipelineState was ignored. A title that saves its PSO blobs and passes them back on the next run got a failure from the first call and no validation on the second.

  • runtime/src/cached_pso.h: the blob. It holds no pipeline (the PSO is still rebuilt from its descriptors, and D3D-34 / Runtime: use the Vulkan pipeline cache produced by the build (D3D-34) #367 keeps the VkPipelineCache side): magic, version, vendorID, deviceID, driverVersion, pipelineCacheUUID, a SHA-256 of the description, and an FNV-1a checksum over everything before it.
  • d3d12_vulkan_device.cpp: GetCachedBlob on PipelineState, a description key per PSO type (shaders, root signature content, stream output, blend, sample mask, rasterizer, depth-stencil, input layout, strip cut, topology type, RTV/DSV formats, sample desc, node mask; not Flags), the root signature now keeps the SHA-256 of its serialized blob, and the CachedPSO check runs before the PSO is created.
  • docs/d3d12_vulkan.md §3.6: replaces "CachedPSO blobs are ignored" with what the layer does now.

Host behaviour it follows

Measured with the PC runtime on an RTX 3060 (driver 32.0.16.1714, Windows 11) and WARP, compute and graphics:

CachedPSO Host Layer
blob from the same description S_OK S_OK
same description, other Flags S_OK S_OK
an equal root signature object S_OK S_OK
root signature with other content, another shader, any other graphics state tried (RTV formats, DSV, input layout, cull mode, write mask, sample mask, strip cut, sRGB RTV) E_INVALIDARG E_INVALIDARG
any byte changed, truncated, junk E_INVALIDARG E_INVALIDARG
pointer with CachedBlobSizeInBytes 0 E_INVALIDARG E_INVALIDARG
null pointer with a size S_OK (ignored) S_OK
blob from another adapter (GPU blob on WARP) D3D12_ERROR_ADAPTER_NOT_FOUND same for another vendor/device ID
GetCachedBlob(nullptr) S_OK S_OK

Another driver gives D3D12_ERROR_DRIVER_VERSION_MISMATCH per the DirectX docs; not measured (needs a driver change), the layer returns it for a different driverVersion or pipelineCacheUUID.

Tested

  • d3d12_compute_test: the 11 cases above run on the layer and on the host (default adapter and WARP, empty cs_5_0 shader from d3dcompiler_47), and the answers must be equal (prints cached PSO: 2 host adapter(s) gave the same 11 answers; skips the host half without a host device or compiler). Then every byte of the blob flipped one at a time gives E_INVALIDARG, and resealed vendor/device/driver/UUID/version changes give the errors above.
  • d3d12_draw_test: GetCachedBlob on the graphics PSO and the graphics rows of the table.
  • Full ctest (without the window tests d3d12_present, xbox_present, dxgi_swapchain, frame_pacer): 88/88 pass (package-gated tests skip), MSVC 19.51, Windows SDK 10.0.26100, Windows 11, NVIDIA GeForce RTX 3060, driver 32.0.16.1714. Not run under the Vulkan validation layers (not installed on this machine).

No game files used.

AI-assisted (Claude).

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested 3105f65 on RTX 4070 SUPER (NVIDIA 616.64) and Intel UHD 770 (101.7092), Windows 11, MSVC 19.44: pass

  • d3d12_compute_test and d3d12_draw_test pass with the layer on each GPU (LEONIDA_VK_DEVICE). Both print "cached PSO: 2 host adapter(s) gave the same 11 answers".
  • Same two tests under VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0, confirmed loaded): 0 validation messages on both GPUs. The PR body says these were not run before.
  • Full ctest on the 4070 SUPER: 92/92 pass. The package-gated tests skip.

@SpositoDouglas

Copy link
Copy Markdown
Contributor

Tested 3105f656 on AMD Radeon RX 9060 XT (RDNA4), AMD Software 26.11.2 (32.0.32029.2010, Vulkan 1.4.359), Windows 11 Pro 26H2 (26300.9974), MSVC 19.44, Vulkan SDK 1.4.363.0: pass. This adds AMD's D3D12 driver as a host next to the NVIDIA and Intel runs.

  • Build (scripts/build_runtime.ps1, RelWithDebInfo): no warnings.
  • d3d12_compute_test: pass. The host half ran on AMD's D3D12 driver and WARP: cached PSO: 2 host adapter(s) gave the same 11 answers.
  • d3d12_draw_test: pass.
  • Both again with LEONIDA_VK_VALIDATION=1 (implicit layers off): pass, 0 validation errors.
  • ctest -C RelWithDebInfo: 92/92 (gameinput disabled, no SDL3), the same with LEONIDA_VK_VALIDATION=1.

AI-assisted (Claude Code). Synthetic tests only, no game data.

@x2Tweek

x2Tweek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

{"body": "## Independent code review and test of PR #1683 (D3D-191)\n\nCommit tested: 3105f65 (head of PR #1683, branch d3d-cached-pso)\nEnvironment: Windows 11 Pro 10.0.26300, MSVC 19.51.36248 (VS 18 Community), CMake 4.4.4, Ninja 1.13.2, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5090, driver 621.24\n\n### What was verified\n\nStatic code review of the 4 modified + 1 new files:\n\n- runtime/src/cached_pso.h (new): Identity (vendor/device/driver/pipelineCacheUUID), Key (SHA-256 hex of description fields), encode() builds the blob (magic "LPSO", version, vendor, device, driver, UUID, key, FNV-1a checksum), check() validates magic/version/checksum/adapter/driver/description and returns accepted/invalid/other_adapter/other_driver/other_description. KeyBuilder assembles key bytes with length-prefixed fields. Matches the measured PC runtime behavior from the PR description.\n- runtime/shims/d3d12_vulkan_device.cpp: DeviceState.pso_identity populated from VkPhysicalDeviceProperties (vendorID, deviceID, driverVersion, pipelineCacheUUID). RootSignature now stores content_ (SHA-256 of serialized blob). pipeline_key() for compute and graphics descriptions keys all fields the PC runtime matches (root signature, shaders via DXBC checksum/FNV-1a, stream output, blend, rasterizer, depth-stencil, input layout, RTV/DSV formats, sample desc, node mask; not Flags). GetCachedBlob() returns encode(identity, cache_key_). check_cached_pso() runs before PSO creation in both CreateComputePipelineState and CreateGraphicsPipelineState.\n- runtime/test/d3d12_compute_test.cpp: 11 CachedPSO cases (same desc, other Flags, equal root sig, other root sig, truncated, junk, byte x3, size-0 ptr, null ptr with size) on layer + host (default adapter and WARP), plus per-byte flip and resealed adapter/driver/version checks. Host half skips gracefully without d3d12.dll/compiler.\n- runtime/test/d3d12_draw_test.cpp: CachedPSO on graphics PSO — same desc S_OK, other Flags S_OK, changed mrt/instance/cull/write mask/sample mask/strip cut/RTV format all E_INVALIDARG.\n- docs/d3d12_vulkan.md §3.6: documents the new behavior, replacing "CachedPSO blobs are ignored".\n- No game data, keys, or decryption: synthetic shaders only. Compliant with CONTRIBUTING.md.\n\nCPU/GPU tests executed:\n\nBuilt with MSVC x64, CMake Ninja, Release:\ncmd\ncmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLEONIDA_VULKAN_HEADERS_FETCH=OFF ../runtime\ncmake --build . --target d3d12_compute_test d3d12_draw_test gta6rt_d3d12_com\n\n\nBuild: 19/19 steps OK (one warning C4456 shadowing in test, pre-existing).\n\nRuntime:\n- d3d12_compute_test.exe: device: NVIDIA GeForce RTX 5090; cached PSO: 2 host adapter(s) gave the same 11 answers — layer matches host on default adapter and WARP; per-byte flip gives E_INVALIDARG; resealed adapter/driver/version fields give the runtime's own errors.\n- d3d12_draw_test.exe: device: NVIDIA GeForce RTX 5090; all CachedPSO graphics cases match expected (S_OK/E_INVALIDARG); M1: five draws and culled triangle, 4096/4096 pixels matched.\n\n### Conclusion\n\nStatic review found no correctness issues. The implementation matches the measured host runtime behavior documented in the PR. Both GPU tests pass on RTX 5090, with the CachedPSO comparison against the host (default adapter + WARP) producing identical answers on all 11 cases. AI-assisted (Claude Code). GPU test logged on disk."}

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 3105f65 on AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1) and NVIDIA RTX 5080 (616.92), Windows 11, MSVC 19.4x + Ninja (RelWithDebInfo): pass

Full runtime build of the PR head, VK_LOADER_LAYERS_DISABLE=~implicit~, one device at a time:

LEONIDA_VK_DEVICE=radeon  d3d12_compute_test.exe ; d3d12_draw_test.exe
LEONIDA_VK_DEVICE=5080    d3d12_compute_test.exe ; d3d12_draw_test.exe
d3d12_compute_test d3d12_draw_test
Radeon iGPU exit 0, "cached PSO: 2 host adapter(s) gave the same 11 answers" exit 0, M1 draws 4096/4096 pixels
RTX 5080 exit 0, same "11 answers" line exit 0, M1 draws 4096/4096 pixels

Remarks:

  • Red on main not run: GetCachedBlob is a stub on main, so the new test cases do not apply there.
  • Not run: the Vulkan validation layers, and the full ctest. Only the two tests this PR changes.
  • If glslangValidator is missing (current Vulkan SDK ships glslang), CMake silently skips d3d12_compute_test and d3d12_draw_test; pass -DVulkan_GLSLANG_VALIDATOR_EXECUTABLE=<path to glslang> to build them.

AI-assisted.

@Rossrocha

Copy link
Copy Markdown

Tested 3105f65 merged onto main a0acd33 on AMD Radeon RX 6600 (RDNA2, Navi 23, discrete), AMD proprietary 26.11.2 (Vulkan 1.4.315), Windows 11 Pro 10.0.26300: pass.

  • d3d12_compute_test run directly, exit 0 with and without LEONIDA_VK_VALIDATION=1: "cached PSO: 2 host adapter(s) gave the same 11 answers", then the compute dispatch check (64 elements in each of two dispatches)
  • d3d12_draw_test directly, exit 0 both ways (strip cut 4096/4096, M1 all 4096 pixels)
  • ctest --test-dir runtime\build: 95/95 (gameinput disabled); with LEONIDA_VK_VALIDATION=1: 95/95
  • python -I scripts/run_gpu_tests.py: 155/163, 8 skipped (the M1.5/M2/M3 cases ctest runs), 0 failed; same with LEONIDA_W64_EMULATE=1

Nit: MSVC 19.44 gives one new warning from this PR, runtime/test/d3d12_compute_test.cpp(357): warning C4456: declaration of 'bytes' hides previous local declaration. The std::vector<std::uint8_t> bytes(...) at 357 shadows constexpr UINT elements = 64, bytes = elements * 4; at 282 in main(). Renaming the vector to blob_bytes would silence it; main builds without it.

AI-assisted (Claude Code): it merged the PR, built it, ran the suites and wrote this comment.

ID3D12PipelineState::GetCachedBlob returns a blob with the adapter, driver, pipelineCacheUUID and a SHA-256 of the description (without Flags; shaders keyed by their DXBC checksum), sealed by a checksum. Create{Compute,Graphics}PipelineState check a supplied CachedPSO before creating the PSO and answer as the PC runtime does, measured on an RTX 3060 and WARP. Rebased onto main (one commit). AI-assisted.
@requiemsnkrp

Copy link
Copy Markdown
Author

Rebased onto main (conflicts with the slot-67 native compute PSO and SubgroupRequest changes; both kept), now one commit 9cc95bff. Retested on the RTX 3060: d3d12_compute_test passes with cached PSO: 2 host adapter(s) gave the same 11 answers; full ctest without the window tests: the only failures are d3d12_com (segfault), d3d12_debug_markers, d3d12_indirect_rt, d3d12_draw, which fail the same way on main without this PR.

@ItsNotRexed
ItsNotRexed merged commit fc2ee62 into ProjectLeonida:main Nov 22, 2026
Jolymmiles added a commit to Jolymmiles/Leonida that referenced this pull request Nov 22, 2026
ProjectLeonida#1683's comparison expected Wine to have no host D3D12 device or no compiler. Wine has
both (vkd3d and its d3dcompiler_47), but vkd3d's GetCachedBlob is a stub, so
cached_pso_cases returned no answers for each host adapter and `host == layer` failed
on every run (line 388; Apple M3 Max, CrossOver 26.3 / Wine 11 with MoltenVK 1.4.3).
Like the other host comparisons (host_wine.h), it now skips under Wine and says why;
the layer's own 11 answers are still checked against the expected list.
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.

7 participants