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

match_in/out_struct for finding a predeclared list of types. #850

Open
i509VCB opened this issue Dec 9, 2023 · 0 comments
Open

match_in/out_struct for finding a predeclared list of types. #850

i509VCB opened this issue Dec 9, 2023 · 0 comments

Comments

@i509VCB
Copy link
Contributor

i509VCB commented Dec 9, 2023

I was looking at something similar to match_out_struct/match_in_struct, but it returns a tuple of Option values if some type of structure was found.

The idea is largely inspired by the vk_find_struct(_const) macros in Mesa.

I'd think the macro could look like this:

fn do_something(info: &mut DeviceCreateInfo<'_>)
    // Returns Option<&mut PhysicalDeviceVulkan11Features>
    let vulkan_1_1 = ash::find_in_struct::<&mut PhysicalDeviceVulkan11Features>(info); 

    if let Some(vulkan_1_1) = vulkan_1_1 {
        ...
    }
}

Although there are a few questions worth asking:

  • Accessing multiple extension types: you would have to declare all things you want to access at the same time otherwise you would have borrow checking issues.
  • If multiple instances of extensions can be accessed, we need to forbid accessing the same extension type twice. I believe this would have to be done at compile time to make sense to do. Foe example you would need to forbid (&mut T, &T) and (&mut T, &mut T). (&T, &T) would technically be valid under borrowing rules but it is definitely not optimal.
  • Should find_in/out_struct even support multiple elements? While this is a valid option, I find that finding a struct can be neater: https://gitlab.freedesktop.org/asahi/mesa/-/blob/c5d9a3a5a9ab57b22ae5f17d911a3b00935a4437/src/asahi/vulkan/agxv_device_memory.c#L38-39
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

No branches or pull requests

1 participant