Skip to content

Commit

Permalink
bump ash to 0.38
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-ben committed Apr 2, 2024
1 parent 79e81d9 commit a0755e5
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 169 deletions.
15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage = "https://github.com/adrien-ben/egui-ash-renderer"
repository = "https://github.com/adrien-ben/egui-ash-renderer"
documentation = "https://docs.rs/egui-ash-renderer"
license = "MIT"
version = "0.2.0"
version = "0.3.0"
authors = ["Adrien Bennadji <[email protected]>"]
edition = "2021"

Expand All @@ -20,11 +20,10 @@ exclude = [
thiserror = "1.0"
log = "0.4"
egui = { version = ">=0.26, <=0.27", default-features = false }
ash = { version = ">=0.34, <=0.37", default-features = false, features = ["debug"] }
ultraviolet = "0.9"
ash = { version = "0.38", default-features = false, features = ["std"] }

gpu-allocator = { version = "0.25", default-features = false, features = ["vulkan"], optional = true }
vk-mem = { version = "0.3", optional = true }
vk-mem = { version = "0.3", default-features = false, optional = true }

[features]
default = []
Expand All @@ -34,10 +33,10 @@ vk-mem = ["dep:vk-mem"]

[dev-dependencies]
simple_logger = "4.0"
winit = { version = "0.29", default-features = false, features = ["rwh_05", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]}
ash = { version = "0.37", default-features = false, features = ["debug", "linked"] }
ash-window = "0.12"
raw-window-handle = "0.5"
winit = "0.29"
ash = { version = "0.38", default-features = false, features = ["debug", "linked", "std"] }
ash-window = "0.13"
raw-window-handle = "0.6"
image = "0.24"
egui = "0.27"
egui-winit = "0.27"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This is meant to add support for egui in your existing Vulkan/ash applications.

| crate | egui | ash | gpu-allocator (feature) | vk-mem (feature) |
|--------|--------------|--------------|-------------------------|------------------|
| 0.3.0 | [0.26, 0.27] | 0.38 | 0.25 | 0.3.0 |
| 0.2.0 | [0.26, 0.27] | [0.34, 0.37] | 0.25 | 0.3.0 |

## How it works
Expand Down
113 changes: 52 additions & 61 deletions examples/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
pub mod vulkan;

use ash::{
extensions::{
ext::DebugUtils,
khr::{Surface, Swapchain as SwapchainLoader},
},
ext::debug_utils,
khr::{surface, swapchain},
vk, Device, Entry, Instance,
};
#[cfg(any(target_os = "macos", target_os = "ios"))]
use ash::vk::{
KhrGetPhysicalDeviceProperties2Fn, KhrPortabilityEnumerationFn,
};
use egui::{ClippedPrimitive, Context, TextureId, ViewportId};
use egui_ash_renderer::{Options, Renderer};
use egui_winit::State;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use std::{
error::Error,
ffi::{CStr, CString},
Expand Down Expand Up @@ -64,7 +58,7 @@ impl App {
let vulkan_context = VulkanContext::new(&window, title)?;

let command_buffer = {
let allocate_info = vk::CommandBufferAllocateInfo::builder()
let allocate_info = vk::CommandBufferAllocateInfo::default()
.command_pool(vulkan_context.command_pool)
.level(vk::CommandBufferLevel::PRIMARY)
.command_buffer_count(1);
Expand All @@ -80,23 +74,23 @@ impl App {

// Semaphore use for presentation
let image_available_semaphore = {
let semaphore_info = vk::SemaphoreCreateInfo::builder();
let semaphore_info = vk::SemaphoreCreateInfo::default();
unsafe {
vulkan_context
.device
.create_semaphore(&semaphore_info, None)?
}
};
let render_finished_semaphore = {
let semaphore_info = vk::SemaphoreCreateInfo::builder();
let semaphore_info = vk::SemaphoreCreateInfo::default();
unsafe {
vulkan_context
.device
.create_semaphore(&semaphore_info, None)?
}
};
let fence = {
let fence_info = vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED);
let fence_info = vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED);
unsafe { vulkan_context.device.create_fence(&fence_info, None)? }
};

Expand Down Expand Up @@ -313,12 +307,11 @@ impl App {
.expect("Failed to record command buffer");

let command_buffers = [command_buffer];
let submit_info = [vk::SubmitInfo::builder()
let submit_info = [vk::SubmitInfo::default()
.wait_semaphores(&wait_semaphores)
.wait_dst_stage_mask(&wait_stages)
.command_buffers(&command_buffers)
.signal_semaphores(&signal_semaphores)
.build()];
.signal_semaphores(&signal_semaphores)];
unsafe {
vulkan_context
.device
Expand All @@ -328,7 +321,7 @@ impl App {

let swapchains = [swapchain.khr];
let images_indices = [image_index];
let present_info = vk::PresentInfoKHR::builder()
let present_info = vk::PresentInfoKHR::default()
.wait_semaphores(&signal_semaphores)
.swapchains(&swapchains)
.image_indices(&images_indices);
Expand Down Expand Up @@ -405,9 +398,9 @@ impl App {
pub struct VulkanContext {
_entry: Entry,
pub instance: Instance,
debug_utils: DebugUtils,
debug_utils: debug_utils::Instance,
debug_utils_messenger: vk::DebugUtilsMessengerEXT,
surface: Surface,
surface: surface::Instance,
surface_khr: vk::SurfaceKHR,
pub physical_device: vk::PhysicalDevice,
graphics_q_index: u32,
Expand All @@ -426,13 +419,13 @@ impl VulkanContext {
create_vulkan_instance(&entry, window, name)?;

// Vulkan surface
let surface = Surface::new(&entry, &instance);
let surface = surface::Instance::new(&entry, &instance);
let surface_khr = unsafe {
ash_window::create_surface(
&entry,
&instance,
window.raw_display_handle(),
window.raw_window_handle(),
window.display_handle()?.as_raw(),
window.window_handle()?.as_raw(),
None,
)?
};
Expand All @@ -456,7 +449,7 @@ impl VulkanContext {

// Command pool & buffer
let command_pool = {
let command_pool_info = vk::CommandPoolCreateInfo::builder()
let command_pool_info = vk::CommandPoolCreateInfo::default()
.queue_family_index(graphics_q_index)
.flags(vk::CommandPoolCreateFlags::empty());
unsafe { device.create_command_pool(&command_pool_info, None)? }
Expand Down Expand Up @@ -495,7 +488,7 @@ impl Drop for VulkanContext {
}

struct Swapchain {
loader: SwapchainLoader,
loader: swapchain::Device,
extent: vk::Extent2D,
khr: vk::SwapchainKHR,
images: Vec<vk::Image>,
Expand Down Expand Up @@ -592,26 +585,25 @@ fn create_vulkan_instance(
entry: &Entry,
window: &Window,
title: &str,
) -> Result<(Instance, DebugUtils, vk::DebugUtilsMessengerEXT), Box<dyn Error>> {
) -> Result<(Instance, debug_utils::Instance, vk::DebugUtilsMessengerEXT), Box<dyn Error>> {
log::debug!("Creating vulkan instance");
// Vulkan instance
let app_name = CString::new(title)?;
let engine_name = CString::new("No Engine")?;
let app_info = vk::ApplicationInfo::builder()
let app_info = vk::ApplicationInfo::default()
.application_name(app_name.as_c_str())
.application_version(vk::make_api_version(0, 0, 1, 0))
.engine_name(engine_name.as_c_str())
.engine_name(c"No Engine")
.engine_version(vk::make_api_version(0, 0, 1, 0))
.api_version(vk::make_api_version(0, 1, 0, 0));

let mut extension_names =
ash_window::enumerate_required_extensions(window.raw_display_handle())?.to_vec();
extension_names.push(DebugUtils::name().as_ptr());
ash_window::enumerate_required_extensions(window.display_handle()?.as_raw())?.to_vec();
extension_names.push(debug_utils::NAME.as_ptr());

#[cfg(any(target_os = "macos", target_os = "ios"))]
{
extension_names.push(KhrPortabilityEnumerationFn::name().as_ptr());
extension_names.push(KhrGetPhysicalDeviceProperties2Fn::name().as_ptr());
extension_names.push(ash::khr::portability_enumeration::NAME.as_ptr());
extension_names.push(ash::khr::get_physical_device_properties2::NAME.as_ptr());
}

let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) {
Expand All @@ -620,15 +612,15 @@ fn create_vulkan_instance(
vk::InstanceCreateFlags::default()
};

let instance_create_info = vk::InstanceCreateInfo::builder()
let instance_create_info = vk::InstanceCreateInfo::default()
.application_info(&app_info)
.flags(create_flags)
.enabled_extension_names(&extension_names);

let instance = unsafe { entry.create_instance(&instance_create_info, None)? };

// Vulkan debug report
let create_info = vk::DebugUtilsMessengerCreateInfoEXT::builder()
let create_info = vk::DebugUtilsMessengerCreateInfoEXT::default()
.flags(vk::DebugUtilsMessengerCreateFlagsEXT::empty())
.message_severity(
vk::DebugUtilsMessageSeverityFlagsEXT::INFO
Expand All @@ -641,7 +633,7 @@ fn create_vulkan_instance(
| vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION,
)
.pfn_user_callback(Some(vulkan_debug_callback));
let debug_utils = DebugUtils::new(entry, &instance);
let debug_utils = debug_utils::Instance::new(entry, &instance);
let debug_utils_messenger =
unsafe { debug_utils.create_debug_utils_messenger(&create_info, None)? };

Expand All @@ -668,7 +660,7 @@ unsafe extern "system" fn vulkan_debug_callback(

fn create_vulkan_physical_device_and_get_graphics_and_present_qs_indices(
instance: &Instance,
surface: &Surface,
surface: &surface::Instance,
surface_khr: vk::SurfaceKHR,
) -> Result<(vk::PhysicalDevice, u32, u32), Box<dyn Error>> {
log::debug!("Creating vulkan physical device");
Expand Down Expand Up @@ -716,7 +708,7 @@ fn create_vulkan_physical_device_and_get_graphics_and_present_qs_indices(
};
let extention_support = extension_props.iter().any(|ext| {
let name = unsafe { CStr::from_ptr(ext.extension_name.as_ptr()) };
SwapchainLoader::name() == name
swapchain::NAME == name
});

// Does the device have available formats for the given surface
Expand Down Expand Up @@ -765,17 +757,20 @@ fn create_vulkan_device_and_graphics_and_present_qs(
indices
.iter()
.map(|index| {
vk::DeviceQueueCreateInfo::builder()
vk::DeviceQueueCreateInfo::default()
.queue_family_index(*index)
.queue_priorities(&queue_priorities)
.build()
})
.collect::<Vec<_>>()
};

let device_extensions_ptrs = [SwapchainLoader::name().as_ptr()];
let device_extensions_ptrs = [
swapchain::NAME.as_ptr(),
#[cfg(any(target_os = "macos", target_os = "ios"))]
ash::khr::portability_subset::NAME.as_ptr(),
];

let device_create_info = vk::DeviceCreateInfo::builder()
let device_create_info = vk::DeviceCreateInfo::default()
.queue_create_infos(&queue_create_infos)
.enabled_extension_names(&device_extensions_ptrs);

Expand All @@ -790,7 +785,7 @@ fn create_vulkan_swapchain(
vulkan_context: &VulkanContext,
) -> Result<
(
SwapchainLoader,
swapchain::Device,
vk::SwapchainKHR,
vk::Extent2D,
vk::Format,
Expand Down Expand Up @@ -876,7 +871,7 @@ fn create_vulkan_swapchain(
vulkan_context.present_q_index,
];
let create_info = {
let mut builder = vk::SwapchainCreateInfoKHR::builder()
let mut builder = vk::SwapchainCreateInfoKHR::default()
.surface(vulkan_context.surface_khr)
.min_image_count(image_count)
.image_format(format.format)
Expand All @@ -900,15 +895,15 @@ fn create_vulkan_swapchain(
.clipped(true)
};

let swapchain = SwapchainLoader::new(&vulkan_context.instance, &vulkan_context.device);
let swapchain = swapchain::Device::new(&vulkan_context.instance, &vulkan_context.device);
let swapchain_khr = unsafe { swapchain.create_swapchain(&create_info, None)? };

// Swapchain images and image views
let images = unsafe { swapchain.get_swapchain_images(swapchain_khr)? };
let views = images
.iter()
.map(|image| {
let create_info = vk::ImageViewCreateInfo::builder()
let create_info = vk::ImageViewCreateInfo::default()
.image(*image)
.view_type(vk::ImageViewType::TYPE_2D)
.format(format.format)
Expand Down Expand Up @@ -939,37 +934,33 @@ fn create_vulkan_render_pass(
format: vk::Format,
) -> Result<vk::RenderPass, Box<dyn Error>> {
log::debug!("Creating vulkan render pass");
let attachment_descs = [vk::AttachmentDescription::builder()
let attachment_descs = [vk::AttachmentDescription::default()
.format(format)
.samples(vk::SampleCountFlags::TYPE_1)
.load_op(vk::AttachmentLoadOp::CLEAR)
.store_op(vk::AttachmentStoreOp::STORE)
.initial_layout(vk::ImageLayout::UNDEFINED)
.final_layout(vk::ImageLayout::PRESENT_SRC_KHR)
.build()];
.final_layout(vk::ImageLayout::PRESENT_SRC_KHR)];

let color_attachment_refs = [vk::AttachmentReference::builder()
let color_attachment_refs = [vk::AttachmentReference::default()
.attachment(0)
.layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL)
.build()];
.layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL)];

let subpass_descs = [vk::SubpassDescription::builder()
let subpass_descs = [vk::SubpassDescription::default()
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS)
.color_attachments(&color_attachment_refs)
.build()];
.color_attachments(&color_attachment_refs)];

let subpass_deps = [vk::SubpassDependency::builder()
let subpass_deps = [vk::SubpassDependency::default()
.src_subpass(vk::SUBPASS_EXTERNAL)
.dst_subpass(0)
.src_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT)
.src_access_mask(vk::AccessFlags::empty())
.dst_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT)
.dst_access_mask(
vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
)
.build()];
)];

let render_pass_info = vk::RenderPassCreateInfo::builder()
let render_pass_info = vk::RenderPassCreateInfo::default()
.attachments(&attachment_descs)
.subpasses(&subpass_descs)
.dependencies(&subpass_deps);
Expand All @@ -988,7 +979,7 @@ fn create_vulkan_framebuffers(
.iter()
.map(|view| [*view])
.map(|attachments| {
let framebuffer_info = vk::FramebufferCreateInfo::builder()
let framebuffer_info = vk::FramebufferCreateInfo::default()
.render_pass(render_pass)
.attachments(&attachments)
.width(extent.width)
Expand All @@ -1014,10 +1005,10 @@ fn record_command_buffers(
unsafe { device.reset_command_pool(command_pool, vk::CommandPoolResetFlags::empty())? };

let command_buffer_begin_info =
vk::CommandBufferBeginInfo::builder().flags(vk::CommandBufferUsageFlags::SIMULTANEOUS_USE);
vk::CommandBufferBeginInfo::default().flags(vk::CommandBufferUsageFlags::SIMULTANEOUS_USE);
unsafe { device.begin_command_buffer(command_buffer, &command_buffer_begin_info)? };

let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
let render_pass_begin_info = vk::RenderPassBeginInfo::default()
.render_pass(render_pass)
.framebuffer(framebuffer)
.render_area(vk::Rect2D {
Expand Down
Loading

0 comments on commit a0755e5

Please sign in to comment.