Skip to content

Add ExtensionMeta traits#913

Closed
PixelDust22 wants to merge 1 commit into
ash-rs:masterfrom
PixelDust22:meta
Closed

Add ExtensionMeta traits#913
PixelDust22 wants to merge 1 commit into
ash-rs:masterfrom
PixelDust22:meta

Conversation

@PixelDust22

@PixelDust22 PixelDust22 commented Apr 25, 2024

Copy link
Copy Markdown
Contributor

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.

@PixelDust22

Copy link
Copy Markdown
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

Comment thread generator/src/lib.rs
let vk_parse::Extension {
name: full_extension_name,
children: items,
promotedto,

Copy link
Copy Markdown
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
Copy Markdown
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

@PixelDust22

PixelDust22 commented Jul 11, 2024

Copy link
Copy Markdown
Contributor Author

@Ralith @MarijnS95 any chances for this to be adopted?

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.

2 participants