-
Notifications
You must be signed in to change notification settings - Fork 73
Rewrite the ash runner #419
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
Open
Firestar99
wants to merge
12
commits into
main
Choose a base branch
from
simplify-ash-runner2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7dd1dc2
ash runner: make debug msgs easier to read
Firestar99 85ce837
ash runner: constant window updates, don't wait for new events
Firestar99 29bd939
ash runner: remove multimodule, simplify pipeline creation
Firestar99 ed00a3b
ash runner: use bytemuck
Firestar99 12b87f7
ash runner: general code cleanup
Firestar99 c0aebde
ash runner: rewrite
Firestar99 0ebe9dd
ash runner: split it into different modules
Firestar99 def7735
ash runner: fix lints
Firestar99 c1d2b48
ash & wgpu runner: remove build script forwarding `PROFILE` env var
Firestar99 71c6330
ash runner: remove `ash-molten`, require vulkan sdk on macos
Firestar99 3007d25
ash runner: switch Vulkan Memory Model from extension to core feature
Firestar99 fb61b79
ash runner: cleanup debug callback
Firestar99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
use crate::Options; | ||
use anyhow::{Context, anyhow}; | ||
use ash::{ext, khr, vk}; | ||
use std::borrow::Cow; | ||
use std::ffi::{CStr, c_char}; | ||
use std::ops::Deref; | ||
use std::sync::Arc; | ||
|
||
/// Central struct containing the Vulkan instance and device, among others | ||
pub struct MyDevice { | ||
pub entry: ash::Entry, | ||
pub instance: ash::Instance, | ||
pub physical_device: vk::PhysicalDevice, | ||
pub device: ash::Device, | ||
pub main_queue_family: u32, | ||
pub main_queue: vk::Queue, | ||
pub debug_ext_instance: ext::debug_utils::Instance, | ||
pub debug_ext_device: ext::debug_utils::Device, | ||
pub surface_ext: khr::surface::Instance, | ||
pub swapchain_ext: khr::swapchain::Device, | ||
debug_callback: vk::DebugUtilsMessengerEXT, | ||
} | ||
|
||
impl Deref for MyDevice { | ||
type Target = ash::Device; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.device | ||
} | ||
} | ||
|
||
impl MyDevice { | ||
pub fn new(extension_names: &[*const c_char], options: &Options) -> anyhow::Result<Arc<Self>> { | ||
unsafe { | ||
let entry = ash::Entry::load()?; | ||
|
||
let instance = { | ||
let layer_names: &'static [_] = if options.debug_layer { | ||
const { &[c"VK_LAYER_KHRONOS_validation".as_ptr()] } | ||
} else { | ||
&[] | ||
}; | ||
|
||
let mut extension_names_raw = extension_names.to_vec(); | ||
extension_names_raw.push(ext::debug_utils::NAME.as_ptr()); | ||
|
||
let app_name = c"VulkanTriangle"; | ||
entry | ||
.create_instance( | ||
&vk::InstanceCreateInfo::default() | ||
.application_info( | ||
&vk::ApplicationInfo::default() | ||
.application_name(app_name) | ||
.application_version(0) | ||
.engine_name(app_name) | ||
.engine_version(0) | ||
.api_version(vk::make_api_version(0, 1, 3, 0)), | ||
) | ||
.enabled_layer_names(layer_names) | ||
.enabled_extension_names(&extension_names_raw), | ||
None, | ||
) | ||
.context("create_instance")? | ||
}; | ||
|
||
let debug_instance = ext::debug_utils::Instance::new(&entry, &instance); | ||
let debug_callback = { | ||
debug_instance.create_debug_utils_messenger( | ||
&vk::DebugUtilsMessengerCreateInfoEXT::default() | ||
.message_severity( | ||
vk::DebugUtilsMessageSeverityFlagsEXT::ERROR | ||
| vk::DebugUtilsMessageSeverityFlagsEXT::WARNING | ||
| vk::DebugUtilsMessageSeverityFlagsEXT::INFO, | ||
) | ||
.message_type( | ||
vk::DebugUtilsMessageTypeFlagsEXT::GENERAL | ||
| vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION | ||
| vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE, | ||
) | ||
.pfn_user_callback(Some(vulkan_debug_callback)), | ||
None, | ||
)? | ||
}; | ||
|
||
let physical_device = { | ||
instance | ||
.enumerate_physical_devices()? | ||
.into_iter() | ||
.min_by_key(|phy| { | ||
match instance.get_physical_device_properties(*phy).device_type { | ||
vk::PhysicalDeviceType::DISCRETE_GPU => 1, | ||
vk::PhysicalDeviceType::VIRTUAL_GPU => 2, | ||
vk::PhysicalDeviceType::INTEGRATED_GPU => 3, | ||
vk::PhysicalDeviceType::CPU => 4, | ||
_ => 5, | ||
} | ||
}) | ||
.ok_or(anyhow!("No physical devices available"))? | ||
}; | ||
|
||
let main_queue_family = { | ||
instance | ||
.get_physical_device_queue_family_properties(physical_device) | ||
.into_iter() | ||
.enumerate() | ||
.find(|(_, prop)| prop.queue_flags.contains(vk::QueueFlags::GRAPHICS)) | ||
.ok_or(anyhow!( | ||
"No graphics + compute queues on physical device available" | ||
))? | ||
.0 as u32 | ||
}; | ||
|
||
let device = instance | ||
.create_device( | ||
physical_device, | ||
&vk::DeviceCreateInfo::default() | ||
.push_next( | ||
&mut vk::PhysicalDeviceVulkan12Features::default() | ||
.vulkan_memory_model(true), | ||
) | ||
.push_next( | ||
&mut vk::PhysicalDeviceVulkan13Features::default() | ||
.synchronization2(true) | ||
.dynamic_rendering(true), | ||
) | ||
.queue_create_infos(&[vk::DeviceQueueCreateInfo::default() | ||
.queue_family_index(main_queue_family) | ||
.queue_priorities(&[1.0])]) | ||
.enabled_extension_names(&[ | ||
khr::swapchain::NAME.as_ptr(), | ||
khr::shader_non_semantic_info::NAME.as_ptr(), | ||
]), | ||
None, | ||
) | ||
.context("create_device")?; | ||
let main_queue = device.get_device_queue(main_queue_family, 0); | ||
|
||
Ok(Arc::new(Self { | ||
debug_ext_device: ext::debug_utils::Device::new(&instance, &device), | ||
surface_ext: khr::surface::Instance::new(&entry, &instance), | ||
swapchain_ext: khr::swapchain::Device::new(&instance, &device), | ||
entry, | ||
instance, | ||
physical_device, | ||
device, | ||
main_queue_family, | ||
main_queue, | ||
debug_ext_instance: debug_instance, | ||
debug_callback, | ||
})) | ||
} | ||
} | ||
} | ||
|
||
impl Drop for MyDevice { | ||
fn drop(&mut self) { | ||
unsafe { | ||
self.debug_ext_instance | ||
.destroy_debug_utils_messenger(self.debug_callback, None); | ||
self.device.destroy_device(None); | ||
self.instance.destroy_instance(None); | ||
} | ||
} | ||
} | ||
|
||
unsafe extern "system" fn vulkan_debug_callback( | ||
message_severity: vk::DebugUtilsMessageSeverityFlagsEXT, | ||
_message_type: vk::DebugUtilsMessageTypeFlagsEXT, | ||
p_callback_data: *const vk::DebugUtilsMessengerCallbackDataEXT<'_>, | ||
_user_data: *mut std::os::raw::c_void, | ||
) -> vk::Bool32 { | ||
let callback_data = unsafe { *p_callback_data }; | ||
let message_id_name = if callback_data.p_message_id_name.is_null() { | ||
Cow::from("") | ||
} else { | ||
unsafe { CStr::from_ptr(callback_data.p_message_id_name).to_string_lossy() } | ||
}; | ||
let message = if callback_data.p_message.is_null() { | ||
Cow::from("") | ||
} else { | ||
unsafe { CStr::from_ptr(callback_data.p_message).to_string_lossy() } | ||
}; | ||
println!("{message_severity:?}: [{message_id_name}] : {message}"); | ||
vk::FALSE | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/ash/0.38.0/ash/vk/struct.DebugUtilsMessengerCallbackDataEXT.html#method.message_id_name_as_c_str would this help?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I very much would! I think that section is just copied from the old runner :D