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

Add ExtensionMeta traits #913

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Neo-Zhixing
Copy link
Contributor

@Neo-Zhixing Neo-Zhixing commented Apr 25, 2024

Supersedes #912

Create new marker traits ExtensionMeta as defined below:

pub enum PromotionStatus {
   None,
   PromotedToCore(u32),
   PromotedToExtension(&'static core::ffi::CStr),
}

pub trait ExtensionMeta {
   const NAME: &'static core::ffi::CStr;
   const SPEC_VERSION: u32;
   const PROMOTION_STATUS: PromotionStatus;

   type Device;
   fn new_device(instance: &crate::Instance, device: &crate::Device) -> Self::Device;
   type Instance;
   fn new_instance(entry: &crate::Entry, instance: &crate::Instance) -> Self::Instance;
}

Add marker struct Meta in all extension mod root. ExtensionMeta trait is automatically implemented for all Meta marker structs.

When an extension does not have Instance or Device fp, the corresponding associated types on the trait will be defined as the unit type ().

Why is this useful?

Higher level abstractions may want to offer a way for users to enable extensions during application startup. Instead of asking for a &'static CStr extension name, we could instead ask for an impl ExtensionMeta which is significantly more idiomatic. This also gives us the promotion status of an extension, which allows the framework to behave differently depending on the core Vulkan version.

// During application startup
app.enable_extension<ash::khr::acceleration_structure::Meta>();

Unfortunately, we cannot implement traits for modules. That's why we need the extra Meta type that we added on module roots. These types give us a way to refer to the whole extension as a type.

@Neo-Zhixing
Copy link
Contributor Author

One additional thing we can do: Exposing the meta types directly on ash::khr::*. So instead of ash::khr::acceleration_structure::Meta you can write ash::khr::AccelerationStructure. And as long as the ExtensionMeta trait is in scope, you can also write ash::khr::AccelerationStructure::Device

let vk_parse::Extension {
name: full_extension_name,
children: items,
promotedto,
Copy link
Contributor

Choose a reason for hiding this comment

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

promoted_to ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is defined in vk_parse. We can probably rename it to promoted_to in our code if that makes you happy

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.

None yet

2 participants