Repository navigation
d3d12: order timestamp resolves after their writes on MoltenVK - #1947
Merged
ItsNotRexed merged 1 commit intoNov 22, 2026
Merged
Conversation
This was referenced Nov 22, 2026
Jolymmiles
force-pushed
the
mac/d3d12-timestamp-order-moltenvk
branch
from
November 22, 2026 16:27
bcce8ef to
9f8241d
Compare
Contributor
|
Tested 9f8241d on an NVIDIA GeForce RTX 3050 Laptop GPU, driver 32.0.16.2101, Windows 11, native MSVC (VS 2022 Build Tools, Ninja, RelWithDebInfo), with
AI-assisted (Claude Code). |
On Apple GPUs MoltenVK samples a vkCmdWriteTimestamp in a blit pass of its own at the end of the current Metal encoder. Nothing orders the vkCmdCopyQueryPoolResults resolve after that pass. The copy read the old value, or 0 for a timestamp never written, so d3d12_vulkan_device failed under Wine on a Mac (t1 == 0). A minimal Vulkan program reproduces it natively on MoltenVK 1.4.3 and 1.4.2: the copy was right 0 to 43 times in 200, in the same command buffer, the next one or the next submit. KosmicKrisp and llvmpipe were right in every case. Where driverID is MoltenVK, the queue sets and waits for a fresh VkEvent before each timestamp resolve that copies. A submission with such a resolve also waits on the queue's timeline for the submission before it. Both measured 200/200 and 500/500. The timestamps are still the GPU's own. The events go back to a pool after a host reset once their submission completes. d3d12_vulkan_device also checks a resolve in the execution after the write. Documented in docs/d3d12_vulkan.md section 4.6.
Jolymmiles
force-pushed
the
mac/d3d12-timestamp-order-moltenvk
branch
from
November 22, 2026 17:01
9f8241d to
6670b2b
Compare
Contributor
Author
|
Filed upstream: KhronosGroup/MoltenVK#2918. |
Contributor
|
Tested 6670b2b (merged onto main 4947579) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass
AI-assisted (Claude). |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: item 2 of #1745 (comment) (
d3d12_vulkan_devicetimestamp check on a Mac under Wine)What and why
On a Mac,
d3d12_vulkan_devicefailed at its timestamp check (t0 != 0 && t0 != 0xcdcd… && t1 >= t0, now around line 4529):t0was right andt1was 0. The cause is a MoltenVK bug, reproduced natively without Wine or this runtime.What MoltenVK does wrong. On Apple GPUs counters can only be sampled at stage boundaries. MoltenVK defers each
vkCmdWriteTimestampto the end of the current Metal encoder and samples it in a separate pass.vkCmdCopyQueryPoolResultsthen reads the counters with a blit that nothing orders after that pass. So the copy sees 0 for a query never written before, or the previous run's value otherwise.WAIT_BITshould make the copy wait for availability and no barrier is required, so our recording is valid Vulkan.Native reproduction:
vkCmdWriteTimestamp, thenvkCmdCopyBuffer, thenvkCmdWriteTimestamp, thenvkCmdCopyQueryPoolResults(64_BIT|WAIT_BIT), compared withvkGetQueryPoolResults. Apple M3 Max, 200 iterations each:vkQueueSubmit, no waitvkCmdSetEvent+vkCmdWaitEventson a fresh eventI re-ran rows 1, 5 and 6 myself through the loader with Homebrew's MoltenVK 1.4.2 ICD and with a MoltenVK main build: 0/200, 200/200, 200/200. KosmicKrisp gave 200/200 on row 1.
The workaround is active only where
driverID == VK_DRIVER_ID_MOLTENVK; Wine reports the host driver, and the runtime logs it once. Vulkan has no feature or property for this, so the driver ID is the only possible gate.vkCmdSetEvent+vkCmdWaitEventson an event of its own. MoltenVK decides at submit time, from the event's host state, whether the set or wait does anything, so events aren't reused within a submission. Events are reset on the host and returned to a free list once their submission completes.ExecuteCommandLists.docs/d3d12_vulkan.mdsection 4.6 describes this.ExecuteCommandListsand resolved in the next, without a host wait.Reported upstream as KhronosGroup/MoltenVK#2918 (repro source, the table, and pointers to
MVKCommandBuffer.mm/MVKQueryPool.mmon 5189f8de).Tested
Apple M3 Max, macOS 27.3, Wine 11.0 (CrossOver 26.3's loader) with MoltenVK 1.4.3. The Windows build is cross-compiled with clang-cl 23.1.6, lld-link 22.1.8 and the xwin 10.0.26100 SDK.
d3d12_vulkan_deviceunder Wine: before, FAIL in every run. After, PASS 10/10 in the delegate's runs and 3/3 in mine, and the log saystimestamp resolves wait for the timestamps before them (MoltenVK).run_wine_tests.pylist (110 tests, same commit 6a6704d): before 81 passed / 6 failed / 23 skipped, after 82 / 5 / 23. Onlyd3d12_vulkan_devicechanged status. The remaining failures are separate items:d3d12_descriptoris SHADER-268 (Apply the S#'s LOD bias in the shader where samplers take none (SHADER-268) #1845),d3d12_presentis d3d12_present_test: check the presented images through the capture, GDI screen read only where it works #1908, andd3d12_depth_resolveis in progress.d3d12_computeandd3d12_drawalso fail and are not yet looked at;d3d12_computepassed in one earlier run, so it is flaky.ctest(runtime/build/mac): the same 35/36 before and after.xdxr_build_checkfails on plainmaintoo.d3d12_vulkan_devicepasses in a reviewer's run, see the comment below.No game files. AI-assisted.
Checklist
docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code