Rust-GPU / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://rust-gpu.github.io
Apache License 2.0
980 stars 27 forks source link

Error compiling and running example `runners/ash` #31

Open utensil opened 1 month ago

utensil commented 1 month ago

Expected Behaviour

Example runners/ash compiles and runs.

Example & Steps To Reproduce

  1. git clone https://github.com/Rust-GPU/rust-gpu
  2. cd rust-gpu/yard-rs/example-xp/rust-gpu/examples/runners/ash
  3. cargo run --release
  4. error:
thread 'main' panicked at examples/runners/ash/src/main.rs:255:10:
called `Result::unwrap()` on an `Err` value: CratePathDoesntExist("examples/shaders/sky-shader")

Following the working example multibuilder, one can change the error line from

SpirvBuilder::new("examples/shaders/sky-shader", "spirv-unknown-vulkan1.1")

to

SpirvBuilder::new(concat!(env!("CARGO_MANIFEST_DIR"), "/../../shaders/sky-shader"), "spirv-unknown-vulkan1.1")

Now the example and the shader crate compiles, but running it gives an error

[mvk-error] VK_ERROR_EXTENSION_NOT_PRESENT: Vulkan extension VK_KHR_shader_non_semantic_info is not supported.
thread 'main' panicked at examples/runners/ash/src/main.rs:441:22:
called `Result::unwrap()` on an `Err` value: ERROR_EXTENSION_NOT_PRESENT

This might be fixable by updating ash, or might not be fixable at the moment. In the latter case, an explicit "support matrix"-ish table would be nice.

System Info

Backtrace

N/A

Backtrace

``` ```

Firestar99 commented 1 month ago

CratePathDoesntExist("examples/shaders/sky-shader")

It can also be worked around by doing cargo run --bin example-runner-ash in the root of the repo, but ideally your way should also work

VK_ERROR_EXTENSION_NOT_PRESENT: Vulkan extension VK_KHR_shader_non_semantic_info is not supported

That is your device / driver not supporting the VK_KHR_shader_non_semantic_info extension, which should be available on literally all platforms. As you're on MacOS: The MoltenVK driver also lists this extension as supported, so could you try updating it?

utensil commented 1 month ago

Thanks for the reply!

For the path issue, it's better to make it robust despite the working directory.

For the Vulkan extension issue, the version of MoltenVK in use seems to be determined by

[target.'cfg(target_os = "macos")'.dependencies]
ash-molten = { version = "0.13.1", features = ["pre-built"] }

so I tried bumping this, unfortunately none worked, the results per version are:

v0.14.0+1.1.10:  VK_ERROR_EXTENSION_NOT_PRESENT: Vulkan extension VK_KHR_shader_non_semantic_info is not supported

v0.15.0+1.2.2:
[mvk-error] VK_ERROR_EXTENSION_NOT_PRESENT: Vulkan extension VK_KHR_shader_non_semantic_info is not supported.
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested feature is not available on this device.
[mvk-info] Created VkDevice to run on GPU Apple M1 Pro with the following 1 Vulkan extensions enabled:
                VK_KHR_swapchain v70
thread 'main' panicked at examples/runners/ash/src/main.rs:441:22:

v0.16.0+1.2.6:

[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested physical device feature specified by the 1st flag in VkPhysicalDeviceVulkanMemoryModelFeatures is not available on this device.
[mvk-info] Created VkDevice to run on GPU Apple M1 Pro with the following 2 Vulkan extensions enabled:
                VK_KHR_shader_non_semantic_info v1
                VK_KHR_swapchain v70
[mvk-info] Destroyed VkDevice on GPU Apple M1 Pro with 2 Vulkan extensions enabled.

v0.17.0+1.2.7:
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested physical device feature specified by the 1st flag in VkPhysicalDeviceVulkanMemoryModelFeatures is not available on this device.

v0.18.0+1.2.8:
[mvk-error] VK_ERROR_FEATURE_NOT_PRESENT: vkCreateDevice(): Requested physical device feature specified by the 1st flag in VkPhysicalDeviceVulkanMemoryModelFeatures is not available on this device.
[mvk-info] Created VkDevice to run on GPU Apple M1 Pro with the following 2 Vulkan extensions enabled:
                VK_KHR_shader_non_semantic_info v1
                VK_KHR_swapchain v70

v0.19.0+1.2.8:

compilation error:
error[E0308]: mismatched types
   --> examples/runners/ash/src/main.rs:338:38
    |
338 |                     .create_instance(&instance_create_info, None)
    |                      --------------- ^^^^^^^^^^^^^^^^^^^^^ expected `&InstanceCreateInfo<'_>`, found `&InstanceCreateInfoBuilder<'_>`
    |                      |
    |                      arguments to this method are incorrect
    |
    = note: expected reference `&ash::vk::definitions::InstanceCreateInfo<'_>`
               found reference `&InstanceCreateInfoBuilder<'_>`

...omitted...
utensil commented 1 month ago

Per MoltenVK's changelog, the support for VK_KHR_shader_non_semantic_info is added in MoltenVK 1.2.5, so at least not present in the version v0.13.1+1.1.10 of ash-molten in use by the example.

From the error log above, one can see that indeed after v0.16.0+1.2.6, it starts to complain about another feature: "Requested physical device feature specified by the 1st flag in VkPhysicalDeviceVulkanMemoryModelFeatures is not available on this device" and the VK_KHR_shader_non_semantic_info v1 is successfully enabled.

Firestar99 commented 1 month ago

Afaik rust-gpu always writes it's shaders as requiring the VulkanMemoryModel to make sure it's atomic intrinsics work correctly (as before the vulkan memory model atomics were very vague about how they should actually work), even if the shaders themselves don't use atomics. And again it was assumed every major vendor has implemented it, given how critical it is. So I'm very surprised to be unable to even find a mention of that extension in MoltenVK's docs. https://vulkan.gpuinfo.org/listdevicescoverage.php?platform=macos&extension=VK_KHR_vulkan_memory_model

And I would guess most devs using apple have been using it via wgpu, so noone noticed the regression.

I'll be forwarding this issue.