Fix Vulkan initialization on Parallels - #22104
Conversation
|
Parallels currently documents DirectX 11.1 and OpenGL 4.3 as the supported 3D acceleration APIs for Windows 11 on Arm, rather than Vulkan. Avalonia also has established ANGLE/D3D11 and OpenGL paths on Windows. We therefore treat the Parallels Display Adapter as an environment where Vulkan should be skipped rather than attempted and allowed to crash the process. The intention here isn't to change the normal rendering-mode preference on Windows, but to avoid a known crash path on Parallels. We observed a native access violation during Vulkan initialisation in a Windows 11 ARM VM running under Parallels. Because the failure occurs as a native crash, Avalonia's existing rendering-mode fallback cannot take effect. We validated this in the same Parallels VM: with the detection in place, Vulkan returns null and Avalonia successfully proceeds to the next configured rendering mode. Thus, we're making Vulkan gracefully opt out only when the problematic Parallels adapter is detected. |
|
Please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following: Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by AvaloniaUI OÜ and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant AvaloniaUI OÜ, and those who receive the Submission directly b. Patent License. You grant AvaloniaUI OÜ, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to AvaloniaUI OÜ. You agree to notify AvaloniaUI OÜ in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the Republic of Estonia, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and AvaloniaUI OÜ dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
@cla-avalonia agree |
|
You can test this PR using the following package version. |
|
We already have Avalonia/src/Windows/Avalonia.Win32/Win32PlatformOptions.cs Lines 177 to 178 in fc5923a |
|
Thanks, that’s a good point. The current implementation performs a DXGI adapter check directly in VulkanSupport because the immediate issue is that the Parallels Vulkan path can hit a native access violation before the existing rendering-mode fallback can run. I’ll look into extending the existing adapter-selection mechanism to Vulkan instead, while keeping the Parallels case as the validation scenario. |
|
Thanks for pointing out Win32PlatformOptions.GraphicsAdapterSelectionCallback. After testing the suggested approach with the suggested options API, just found a significant difference that’s relevant to this issue. In the Parallels Windows VM, forcing Avalonia.ControlCatalog.Desktop to use Vulkan produces: The native stack is: Logging immediately before and after GraphicsAdapterSelectionCallback shows that neither message is reached before the crash. This might indicate the native crash occurs before the callback is invoked. Although the Vulkan adapters can be enumerated and represented as PlatformGraphicsDeviceAdapterDescription, this does not help with this failure. Vulkan device creation can reach the point of the native access violation before the callback has an opportunity to select or reject an adapter. Avalonia.ControlCatalog.Desktop runs correctly when Vulkan is not selected, so the failure appears specific to the Vulkan initialization path in the affected Parallels environment. Therefore, GraphicsAdapterSelectionCallback still seems appropriate for Vulkan adapter selection in general, but it is too late for this particular failure. The existing rendering-mode fallback appears to be a better fit: detect the affected Parallels environment before VulkanSupport.TryInitialize(), skip Vulkan, and allow the existing fallback to try WGL and then Software. To my knowledge, the original approach based on these diagnostics appears more suitable for this particular failure mode. It avoids entering the Vulkan initialisation path responsible for the native crash. The diagnostics appear to support this. |
|
You can test this PR using the following package version. |
|
You can test this PR using the following package version. |
|
Can you use https://docs.vulkan.org/refpages/latest/refpages/source/vkEnumeratePhysicalDevices.html to enumerate devices and blacklist the Parallels gpu? That avoids having a dependency on DirectX |
Many thanks for the suggestion. This version uses vkEnumeratePhysicalDevices to detect the Parallels adapter rather than relying on DXGI. The Parallels device is therefore skipped during Vulkan device selection based on the name returned by vkGetPhysicalDeviceProperties. This happens before vkCreateDevice which is where the native crash in the Parallels VM occurs. If no other usable Vulkan device is found the normal Vulkan initialisation failure path is followed allowing the configured fallback rendering mode to be selected. This was tested on the Parallels VM with Vulkan forced as the first rendering mode and the application started without the previous native crash. |
|
You can test this PR using the following package version. |
| }); | ||
| } | ||
|
|
||
| private static unsafe bool IsParallelsDisplayAdapter() |
There was a problem hiding this comment.
This is now redundant, isn't it?
There was a problem hiding this comment.
Aww, my bad. I removed IsParallelsDisplayAdapter() in the working tree earlier, but then I suppose when I run git rebase later, it just effectively restored the old version from the remote PR branch. Get it fixed now.
4403043 to
6f6a4a7
Compare
|
You can test this PR using the following package version. |
| instance.GetPhysicalDeviceProperties(physicalDevice, out var properties); | ||
|
|
||
| var deviceName = Marshal.PtrToStringAnsi((IntPtr)properties.deviceName); | ||
| if (deviceName?.StartsWith("Parallels Display Adapter", StringComparison.OrdinalIgnoreCase) == true) |
There was a problem hiding this comment.
Can we check for vid/pid instead? Should also introduce some kind of configurable blacklist like we do with glx.
Also, please, post vulkaninfo output from your VM. If it's missing from system, get one from Vulkan SDK
There was a problem hiding this comment.
I’m afraid that I doubt if VID/PID is workable here. Parallels doesn’t provide a native Vulkan driver; the Vulkan path in this VM appears to go through Microsoft’s D3D mapping/DZN implementation, which fails during initialization. vulkaninfoSDK reports VK_ERROR_INITIALIZATION_FAILED from DZN, and doesn’t successfully enumerate a usable Vulkan device. The output looks like this:
...> vulkaninfoSDK.exe --summary
ERROR: [Loader Message] Code 0 : loader_get_json: Failed to open JSON file C:\Program Files (x86)\Steam\SteamOverlayVulkanLayer64.json
ERROR: [Loader Message] Code 0 : loader_get_json: Failed to open JSON file C:\Program Files (x86)\Steam\SteamFossilizeVulkanLayer64.json
WARNING: [Loader Message] Code 0 : Removing layer VK_LAYER_MSFT_driver_sorting (C:\Program Files\WindowsApps\Microsoft.D3DMappingLayers_1.2608.1.0_arm64__8wekyb3d8bbwe\dzn_layer.x64.json) because it is a duplicate of VK_LAYER_MSFT_driver_sorting (C:\Program Files\WindowsApps\Microsoft.D3DMappingLayers_1.2608.1.0_arm64__8wekyb3d8bbwe\dzn_layer.arm64.json)
ERROR: [Loader Message] Code 0 : windows_read_data_files_in_registry: Registry lookup failed to get ICD manifest files. Possibly missing Vulkan driver?
WARNING: [Loader Message] Code 0 : Layer VK_LAYER_MSFT_driver_sorting uses API version 1.3 which is older than the application specified API version of 1.4. May cause issues.
MESA: warning: C:\__w\1\s\mesa\src\microsoft\vulkan\dzn_meta.c:220: VK_ERROR_INITIALIZATION_FAILED
WARNING: [C:\__w\1\s\mesa\src\microsoft\vulkan\dzn_meta.c:220] Code 0 : VK_ERROR_INITIALIZATION_FAILED
So I’m not sure there is a reliable Vulkan VID/PID we can use for the blacklist. The Parallels device itself is exposed through WDDM/DXGI rather than a native Vulkan ICD.
|
You can test this PR using the following package version. |
What does the pull request do?
Detects the Parallels Display Adapter on Windows before initializing
Vulkan and skips Vulkan initialization when the adapter is present. This is to solve the bug: #22096.
This allows Avalonia to continue with its existing rendering-mode
fallback mechanism instead of crashing during Vulkan initialization.
What is the current behavior?
When running an Avalonia application with Vulkan enabled inside a
Parallels Desktop Windows VM, Vulkan initialization can result in a
native access violation, thus crashing the program and not invoking the fallback mechanism.
Investigation of the crash dump showed that the failure occurs during
Vulkan initialization. Because this is a native crash rather than a
normal Vulkan initialization failure, control does not return to
Avalonia's rendering-mode selection logic, so the configured fallback
renderer is never reached and the application terminates.
What is the updated/expected behavior with this PR?
When the Parallels Display Adapter is detected, Vulkan initialization
returns
nullbefore entering the failing Vulkan initialization path.Avalonia can therefore continue through its existing rendering-mode
selection and use the next configured rendering mode.
This does not change the normal rendering-mode ordering. It only prevents Vulkan from being attempted on
the affected Parallels configuration.
The change was validated in a Parallels Desktop Windows VM:
initialization.
launches using the fallback rendering mode.
Avalonia.Win32builds successfully for bothnet8.0andnet10.0.git diff --checkpasses.How was the solution implemented (if it's not obvious)?
The Parallels virtual GPU is exposed to Windows as the
Parallels Display Adapter.The implementation uses DXGI to enumerate the available display
adapters and checks the adapter description for
Parallels Display Adapter.The existing
DirectXUnmanagedMethods.CreateDXGIFactory1and MicroCominterfaces are reused for adapter enumeration. If the adapter is
detected,
VulkanSupport.TryInitializereturnsnull, allowing theexisting rendering-mode fallback mechanism to proceed.
Checklist
Breaking changes
None.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #22096