Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: macOS - added portability bit and extension when creating vulkan instance #3958

Merged
merged 2 commits into from
Jul 22, 2023

Conversation

schell
Copy link
Contributor

@schell schell commented Jul 21, 2023

Checklist

  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Description
wgpu can't select the vulkan backend on macos. This should at least get us a bit further down the path. Here's the relevant discussion on the wgpu users matrix channel

Testing
Run an example (on macos) with RUST_LOG=trace WGPU_BACKEND=vk VK_LOADER_DEBUG=error cargo run --bin skybox --features=vulkan-portability

@schell
Copy link
Contributor Author

schell commented Jul 21, 2023

This gets me a little further towards wgpu selecting the vulkan backend, but it still cannot find a suitable GPU adapter. Here's the relevant portions of my log:

[2023-07-21T22:50:40Z INFO  wgpu_example::framework] Initializing the surface...
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] Instance version: 0x4030fa
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] Enabling debug utils
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] Enabling device properties2
[2023-07-21T22:50:40Z INFO  wgpu_core::instance] Adapter Vulkan AdapterInfo { name: "Apple M1", vendor: 4203, device: 218366959, device_type: IntegratedGpu, driver: "MoltenVK", driver_info: "1.2.4", backend: Vulkan }
Using Apple M1 (Vulkan)
[2023-07-21T22:50:40Z DEBUG wgpu_hal::vulkan::adapter] Supported extensions: ["VK_KHR_swapchain", "VK_EXT_image_robustness", "VK_KHR_swapchain_mutable_format", "VK_EXT_robustness2", "VK_KHR_portability_subset"]
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
    	Inserted device layer "VK_LAYER_KHRONOS_validation" (/usr/local/share/vulkan/explicit_layer.d/../../../lib/libVkLayer_khronos_validation.dylib)
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] 	objects: (type: INSTANCE, hndl: 0x157846200, name: ?)
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
    	       Using "Apple M1" with driver: "/usr/local/share/vulkan/icd.d/../../../lib/libMoltenVK.dylib"
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] 	objects: (type: INSTANCE, hndl: 0x157846200, name: ?)
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] GENERAL [ (0x0)]
    	Vulkan semaphores using MTLEvent.
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] 	objects: (type: DEVICE, hndl: 0x1579e3c18, name: ?)
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested physical device feature specified by the 1st flag in VkPhysicalDeviceRobustness2FeaturesEXT is not available on this device.
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] VALIDATION [ (0x0)]
    	VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested physical device feature specified by the 1st flag in VkPhysicalDeviceRobustness2FeaturesEXT is not available on this device.
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] 	objects: (type: DEVICE, hndl: 0x1579e3c18, name: ?)
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] GENERAL [ (0x0)]
    	Created VkDevice to run on GPU Apple M1 with the following 5 Vulkan extensions enabled:
    		VK_KHR_portability_subset v1
    		VK_KHR_swapchain v70
    		VK_KHR_swapchain_mutable_format v1
    		VK_EXT_image_robustness v1
    		VK_EXT_robustness2 v1
[2023-07-21T22:50:40Z INFO  wgpu_hal::vulkan::instance] 	objects: (type: DEVICE, hndl: 0x1579e3c18, name: ?)
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
    	terminator_CreateDevice: Failed in ICD /usr/local/share/vulkan/icd.d/../../../lib/libMoltenVK.dylib vkCreateDevice call
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] 	objects: (type: INSTANCE, hndl: 0x157846200, name: ?)
ERROR:            terminator_CreateDevice: Failed in ICD /usr/local/share/vulkan/icd.d/../../../lib/libMoltenVK.dylib vkCreateDevice call
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] GENERAL [Loader Message (0x0)]
    	vkCreateDevice:  Failed to create device chain.
[2023-07-21T22:50:40Z ERROR wgpu_hal::vulkan::instance] 	objects: (type: INSTANCE, hndl: 0x157846200, name: ?)
ERROR:            vkCreateDevice:  Failed to create device chain.
[2023-07-21T22:50:40Z WARN  wgpu_hal::vulkan] Unrecognized device error ERROR_FEATURE_NOT_PRESENT
[2023-07-21T22:50:40Z ERROR wgpu::backend::direct] Error in Adapter::request_device: Connection to device was lost during initialization
thread 'main' panicked at 'Unable to find a suitable GPU adapter!: RequestDeviceError', /Users/schell/code/wgpu/examples/common/src/framework.rs:231:10

@eddyb
Copy link
Contributor

eddyb commented Jul 22, 2023

Looks like the remaining error is from wgpu-hal making some of its own fields ambiguous:

robust_buffer_access: phd_features.core.robust_buffer_access != 0,
robust_image_access: match phd_features.robustness2 {
Some(ref f) => f.robust_image_access2 != 0,
None => phd_features
.image_robustness
.map_or(false, |ext| ext.robust_image_access != 0),
},

robustness2: if enabled_extensions.contains(&vk::ExtRobustness2Fn::name()) {
// Note: enabling `robust_buffer_access2` isn't requires, strictly speaking
// since we can enable `robust_buffer_access` all the time. But it improves
// program portability, so we opt into it anyway.
Some(
vk::PhysicalDeviceRobustness2FeaturesEXT::builder()
.robust_buffer_access2(private_caps.robust_buffer_access)
.robust_image_access2(private_caps.robust_image_access)
.build(),
)
} else {
None
},

That is, private_caps.robust_buffer_access and private_caps.robust_image_access may come from phd_features.robustness2, but they may just as well not.

I suspect what you want to do is duplicate those two fields of PrivateCapabilities to have versions prefixed with robustness2_ and make sure that the robustness2 bits are only requested if the driver reported them as supported.

Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great first step. confirmed getting the same on my m1 as well :)
Let's continue as @eddyb suggests

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.

3 participants