KhronosGroup / MoltenVK

MoltenVK is a Vulkan Portability implementation. It layers a subset of the high-performance, industry-standard Vulkan graphics and compute API over Apple's Metal graphics framework, enabling Vulkan applications to run on macOS, iOS and tvOS.
Apache License 2.0
4.82k stars 428 forks source link

Add support for VK_QUERY_TYPE_PIPELINE_STATISTICS #1907

Open palmerj opened 1 year ago

palmerj commented 1 year ago

Trying to run Red Dead Redemption 2 using Vulkan (directx 12 is the only other option) on a M2Max results in the following error:

[mvk-info] Vulkan semaphores using Metal implicit guarantees within a single queue.
[mvk-info] Created VkDevice to run on GPU Apple M2 Max with the following 10 Vulkan extensions enabled:
        VK_KHR_bind_memory2 v1
        VK_KHR_get_memory_requirements2 v1
        VK_KHR_maintenance2 v1
        VK_KHR_push_descriptor v2
        VK_KHR_swapchain v70
        VK_KHR_timeline_semaphore v2
        VK_KHR_uniform_buffer_standard_layout v1
        VK_EXT_buffer_device_address v2
        VK_EXT_inline_uniform_block v1
        VK_EXT_scalar_block_layout v1
[mvk-info] Created 3 swapchain images with initial size (1280, 720) and contents scale 1.0 for screen U2790B.
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768
[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768
0150:fixme:system:QueryDisplayConfig (00000002 000000000CB5FA28 000000000CB5B1D0 000000000CB5FA38 000000000CB571D0 0000000000000000): semi-stub
0150:fixme:system:QueryDisplayConfig (00000002 000000000CB5FA28 000000000CB5B1D0 000000000CB5FA38 000000000CB571D0 0000000000000000): semi-stub
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateQueryPool: VK_QUERY_TYPE_PIPELINE_STATISTICS is not supported.
0150:fixme:seh:WerRegisterFile (L"C:\\users\\wineskin\\AppData\\Local\\Rockstar Games\\Red Dead Redemption 2\\CrashLogs\\game-20230516-102656-256.crash.log", 2, 1) stub
wine: Unhandled page fault on read access to 0000000000000008 at address 00000001426C155E (thread 0150), starting debugger...
0150:err:seh:start_debugger Couldn't start debugger L"false" (2)
Read the Wine Developers Guide on how to set up winedbg or another debugger
00fc:fixme:kernelbase:AppPolicyGetProcessTerminationMethod FFFFFFFFFFFFFFFA, 000000000021FD70

Game crash log doesn't contain anything:

###### DEBUG INFO ######

###### END OF DEBUG INFO ######

I also tried adding the -ignorepipelinecache command line option to rdr2.exe and that made no difference.

billhollings commented 1 year ago

[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Could not create MTLCounterSampleBuffer for query pool of type VK_QUERY_TYPE_TIMESTAMP. Reverting to emulated behavior. (Error code 1): Invalid sample buffer length: 65536 B. Expected range: 8 -> 32768

PR #1910 fixes the first set of errors involving VK_QUERY_TYPE_TIMESTAMP. It will still output an error to the log, including the max number of timestamp queries that can be supported in a query pool, but it will no longer return an error code to the app, since MoltenVK will fall back to emulation if the number of queries requested is too large for Metal.

To improve accuracy and performance, the app should reduce the number of queries to 4096 (32768 / 8), so that MoltenVK can use native GPU time-stamping.

[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateQueryPool: VK_QUERY_TYPE_PIPELINE_STATISTICS is not supported.

MoltenVK does not currently support VK_QUERY_TYPE_PIPELINE_STATISTICS. The app can check this via vkGetPhysicalDeviceFeatures().

I've changed this issue to a request to add support for VK_QUERY_TYPE_PIPELINE_STATISTICS when we can.