KyleMayes / vulkanalia

Vulkan bindings for Rust.
Apache License 2.0
267 stars 30 forks source link

Encountering error in the tutorial. #270

Closed Octaeon closed 4 months ago

Octaeon commented 5 months ago

I'm trying to follow along the vulkan tutorial in Rust and I'm at the validation layers chapter. After setting the custom message callback, I get this error:

VUID-VkDebugUtilsMessengerCreateInfoEXT-messageType-parameter(ERROR / SPEC): msgNum: -553000032 - Validation Error: [ VUID-VkDebugUtilsMessengerCreateInfoEXT-messageType-parameter ] Object 0: VK_NULL_HANDLE, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xdf09e3a0 | vkCreateDebugUtilsMessengerEXT: value of pCreateInfo->messageType contains flag bits that are not recognized members of VkDebugUtilsMessageTypeFlagBitsEXT The Vulkan spec states: messageType must be a valid combination of VkDebugUtilsMessageTypeFlagBitsEXT values (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkDebugUtilsMessengerCreateInfoEXT-messageType-parameter)
    Objects: 1
        [0] 0, type: 3, name: NULL

At first, I thought I did something wrong, so I went to the source code of the tutorial and copied the entirety of it, replacing my entire main.rs file (at some points I wrote the code myself instead of simply copy-pasting, so I thought I made an error somewhere), but it's still there.

I didn't want to bother with rewriting the dependencies, so I copied them wholesale from the tutorial, so no possibility of issue there (I checked). I noticed that the Cargo.toml file in the tutorial section of the repo has edition = "2018", while I had 2021, so I changed it to 2018, it didn't fix the issue.

I also have the newest version of Vulkan (installed through apt, I checked, it's up to date), and I'm regularly updating my OS.

Some OS/program info: I'm on Linux, specifically Pop Os 22.04 LTS x86_64. I'm using the newest version of Rust, and this is the output I get from rustc --version:

rustc 1.78.0 (9b00956e5 2024-04-29)

vkcube runs without problems. I will attach the full output of the vulkaninfo command as a file here, since it's way too long for a GitHub issue.

One last relevant fact I can give is that when I ran vulkaninfo, this showed up at the very beginning of the output:

WARNING: [Loader Message] Code 0 : loader_scan_for_direct_drivers: The VK_LUNARG_direct_driver_loading extension was enabled but the pNext chain of VkInstanceCreateInfo did not contain the VkDirectDriverLoadingListLUNARG structure.
WARNING: [Loader Message] Code 0 : terminator_CreateInstance: Received return code -3 from call to vkCreateInstance in ICD /usr/lib/x86_64-linux-gnu/libvulkan_virtio.so. Skipping this driver.

That's all that I was able to gather. I tried to read the vulkan docs, but there's a reason I'm following the tutorial and not them... they're damn near impenetrable.

If there's anything else I should share about what I did, do tell.

Thanks.

KyleMayes commented 4 months ago

Sorry for the long delay in responding.

The error is referring to an unknown bitflag being provided for the message_type field here:

https://github.com/KyleMayes/vulkanalia/blob/b7a91d422ac477ffbde0238f87107c885f809fad/tutorial/src/02_validation_layers.rs#L174-L177

So the issue is that vk::DebugUtilsMessageTypeFlagsEXT::all() is returning one or more bitflags not supported by your Vulkan implementation. Taking a look at the definition provided by vulkanalia:

https://github.com/KyleMayes/vulkanalia/blob/b7a91d422ac477ffbde0238f87107c885f809fad/vulkanalia-sys/src/bitmasks.rs#L397-L407

I imagine the culprit here is DEVICE_ADDRESS_BINDING which is seemingly only provided by this extension: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_device_address_binding_report.html

Despite that, it works on my machine, but perhaps this flag gets rejected by some Vulkan implementations if that extension is not enabled. I think if you replaced the relevant in the code in the tutorial with this so that you avoid using that non-standard flag it should work:

let mut debug_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
    .message_severity(vk::DebugUtilsMessageSeverityFlagsEXT::all())
    .message_type(
        vk::DebugUtilsMessageTypeFlagsEXT::GENERAL
            | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE
            | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION,
    )
    .user_callback(Some(debug_callback));

More generally, this sort of thing is probably a good reason to avoid using ::all() for bitmasks with this library. I'll update the tutorial with this change and add a note about why ::all() can cause problems.

Octaeon commented 4 months ago

Thanks! I did what you suggested and it works fine.