Repository navigation
Conversation
|
Reproduced a test failure on head DefectThe Vulkan layer checks and disk-persistence checks pass on both NVIDIA GeForce RTX 5060 Ti ( Root causeOn Windows 11 without Windows Developer Mode enabled, Microsoft's native D3D12 Steps to reproduce
AI-assisted. |
|
Tested For this change. #8213 could not be put in the same tree: it conflicts with this PR in Setup. Built with MSVC 14.52 (Visual Studio 18), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.1, Ninja RelWithDebInfo on Windows Server 2025 (no Vulkan driver there), then the same binaries run through
Under Wine the tree is test by test the same as Because the four were built together, there is no per-PR negative control in this run: a regression would have shown as a difference from |
|
Tested 7f0d87d merged onto main (5d74c27) on AMD Radeon RX 9070 XT, Adrenalin 26.11.1 (LLPC / Vulkan 1.4.359), Windows 11:
|
|
Tested Why line 184 failsThe Microsoft docs for
So the native refusal is A guard for the testThe guard skips the host side of the @@ -179,9 +179,19 @@ int exercise_shader_cache(ID3D12Device9* dev, const char* label, bool is_vulkan_
{
Ref<ID3D12ShaderCacheSession> s_dis;
EXPECT(SUCCEEDED(dev->CreateShaderCacheSession(&desc, IID_PPV_ARGS(&s_dis.p))) && s_dis.p);
- EXPECT(dev->ShaderCacheControl(D3D12_SHADER_CACHE_KIND_FLAG_APPLICATION_MANAGED,
- D3D12_SHADER_CACHE_CONTROL_FLAG_CLEAR |
- D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE) == S_OK);
+ const HRESULT disable_hr = dev->ShaderCacheControl(
+ D3D12_SHADER_CACHE_KIND_FLAG_APPLICATION_MANAGED,
+ D3D12_SHADER_CACHE_CONTROL_FLAG_CLEAR | D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE);
+ // ShaderCacheControl "may be used only in developer mode" (MS docs); without it the in-box runtime
+ // refuses every valid control with DXGI_ERROR_SDK_COMPONENT_MISSING, so there is no DISABLE to compare.
+ if (!is_vulkan_layer && disable_hr == DXGI_ERROR_SDK_COMPONENT_MISSING) {
+ std::printf("shader cache (%s): validation, StoreValue/FindValue, size queries and sharing OK; "
+ "DISABLE parity SKIP (ShaderCacheControl: DXGI_ERROR_SDK_COMPONENT_MISSING, "
+ "needs Developer Mode)\n",
+ label);
+ return 0;
+ }
+ EXPECT(disable_hr == S_OK);
EXPECT(dev->CreateShaderCacheSession(&desc, __uuidof(ID3D12ShaderCacheSession), nullptr) ==
DXGI_ERROR_NOT_CURRENTLY_AVAILABLE);With the guard, on the same machine, The full suite with the guard gives 237/239, the same as With Developer Mode on, the native device should return Code read of the runtime changes
No problems found. Setup
AI-assisted (Claude Code). |
wavehs
left a comment
There was a problem hiding this comment.
Read-only audit of 7f0d87dc (diff against 867d922f0, clean): I cannot run d3d12_shader_cache_test here — it is an MSVC-only target and this Mac has no Vulkan 1.3 device — so below is the code/test verification, with the one arithmetic claim reproduced against the exact bytes the new test writes.
The DISABLE change is not just host parity — main contradicted the documented contract
The D3D12_SHADER_CACHE_CONTROL_FLAGS page says of D3D12_SHADER_CACHE_CONTROL_FLAG_DISABLE: "Attempts to use/create a cache while it's disabled result in DXGI_ERROR_NOT_CURRENTLY_AVAILABLE" (learn.microsoft.com). FindValue/StoreValue already answer that way in main, so CreateShaderCacheSession returning S_OK (and registering a live session) while disabled was the odd one out; putting the check in after the desc validation and before if (!out) … S_FALSE (d3d12_vulkan_device.cpp:5893-5897) matches both the doc and the "shouldn't be used to create" wording. The redundant re-check in ShaderCacheRegistry::acquire (4280) is harmless.
Disk accounting: the inserted guard is right, including the check's position
val_len > max_file_bytes has to stay outside if (inserted) (4197): it is what bounds the single v allocation, and it is also what keeps max_file_bytes - val_len from wrapping. Inside, emplace consumes k/v either way, and a duplicate keeps the first value — which is what the new test asserts (got_v == v).
I replayed both loops over the exact 64-byte file the test writes (d3d12_shader_cache_test.cpp:424-446, max 12):
| loader | result |
|---|---|
main |
whole file dropped: the pre-read check sees bytes(8) > 12-8 on the second copy and returns, so entries stays empty |
| this branch | {k: v}, total_bytes = 8 |
So at this tight bound the assertion that binds on main is FindValue(k) == S_OK, not the CACHE_FULL one — worth knowing when reading the failure output on an unfixed tree (it will look like "the cache ignored the file", not "it thought the cache was full"). At the 128 MiB default a duplicate only overcounts, so note that this branch is unreachable from this writer at all: entries is a std::map and StoreValue answers DXGI_ERROR_ALREADY_EXISTS for a live key, so only a foreign/hand-edited/corrupt file can contain one. The commit message's "fix ShaderCacheStore disk accounting" reads as if a normal cache hits it; "harden the loader against duplicate keys" would describe it better.
Remaining gap in the same function (pre-existing, but this is the place to fix it): a rejected file is never removed
load_from_disk_locked deletes the file on a version mismatch, but returns from every malformed/oversized case (4190, 4197, 4206) leaving it in place. A file written under a larger MaximumValueFileSizeBytes — the doc calls the field "the maximum file size", so a smaller value on reopen is legal — is therefore re-read and re-dropped on every CreateShaderCacheSession, silently, until the first StoreValue rewrites it. std::filesystem::remove(disk_path, ec) before those returns (or a log_once naming the reason) would make the empty cache observable.
Temp-file cleanup: correct, and the two "no cleanup needed" paths are genuinely clean
write_ok set from out.good() after out.flush(), removal outside the ofstream scope, plus the existing MoveFileExW failure path (4226-4246) — an ENOSPC/ERROR_DISK_FULL surfaces at flush() on MSVC's filebuf, so flush() before the scope end is what makes the check meaningful (a close() error after a successful flush is not reachable in practice). The if (!out) return false path creates nothing, and the PID/TID/write_seq name makes a pre-existing temp for that name impossible after a restart. The new test (:462-483) covers the interesting half: the temp write succeeds (a different path) and only MoveFileExW onto the directory fails, so the rollback and the .tmp scan are both exercised.
Two claims in the new test are asserted for the host runtime as well
exercise_shader_cache also runs against Microsoft's ID3D12Device9 (:416), so :185-186 (E_INVALIDARG wins over the disabled state) and :180-182 (DISABLE wins over the null-output S_FALSE, and S_FALSE for an unsupported IID with a null output) become host expectations. Neither precedence is in the docs, so if the Windows run is not green yet, those are the lines to check; the null-output S_FALSE shape, by contrast, is already asserted by main at :50.
Nits: auto [it, inserted] binds an unused it (no warning on /W4, structured bindings are exempt from C4189); the new FAIL_REGULAR_EXPRESSION (CMakeLists.txt:1807-1808) is consistent with the other thirteen tests and is the only thing that can catch validation output emitted after the in-test d.validation_errors() check, i.e. during static destruction.
AI-assisted. macOS 27.2.1 arm64, Python 3.15.2; diff/loader replay only, the C++ test was not run and no game files were used.
Summary
Fixes two
ShaderCacheStoredisk-persistence bugs and one Windows 11 host-parity mismatch inruntime/shims/d3d12_vulkan_device.cpp:ShaderCacheStore::load_from_disk_lockedduplicate-key byte accounting: Only countval_lentowardbytes(and checkbytes > max_file_bytes - val_len) whenloaded.emplace(...)actually inserts a new key, preventing duplicate keys in an on-disk cache file from inflatingtotal_bytesand causing prematureDXGI_ERROR_CACHE_FULLrejections on subsequentStoreValuecalls.ShaderCacheStore::save_to_disk_lockedtemp-file cleanup on write failure: Flush and checkout.good()inside the stream scope, and remove the.tmpfile after closing the stream if writing fails so temporary files never leak on disk.ID3D12Device9::CreateShaderCacheSessionDISABLEprecedence over null-output capability check: Empirical probing against live Windows 11 WARP and native NVIDIA GeForce RTX 5090 D3D12 runtimes confirmed that whenD3D12_SHADER_CACHE_KIND_FLAG_APPLICATION_MANAGEDis disabled viaShaderCacheControl(..., DISABLE),CreateShaderCacheSession(&valid_desc, riid, nullptr)returnsDXGI_ERROR_NOT_CURRENTLY_AVAILABLE(notS_FALSE), while invalid-argument checks (E_INVALIDARG) still take precedence.Tests
Expanded
runtime/test/d3d12_shader_cache_test.cpp(and addedFAIL_REGULAR_EXPRESSION "Validation Error;VUID-"tod3d12_shader_cacheinruntime/CMakeLists.txt) to cover:MaximumValueFileSizeByteslimits.tmpfile leaks whensave_to_disk_lockedfailsCreateShaderCacheSession(including wrongriidandDISABLEprecedence),MODE_MEMORYwith disk-oriented flags /MaximumValueFileSizeBytes,FindValuemissing-key size queries and zero-sized bufferDXGI_ERROR_MORE_DATA, andShaderCacheControlunknown-kind and combinedCLEAR | DISABLE/CLEAR | ENABLEflagsVerified on NVIDIA GeForce RTX 5090 with
LEONIDA_VK_VALIDATION=1(0 VUIDs):d3d12_shader_cache— Passed (0 validation errors, Vulkan layer + live RTX 5090 D3D12 host parity)d3d12_com— Passed (0 validation errors)Claim: #8868 (comment)
AI-assisted (Gemini 4 Neon).