Skip to content

Commit

Permalink
yakui-vulkan: Update ash, ash-window, raw-window-handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith authored Apr 1, 2024
1 parent ab36b38 commit 8fedd8e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 53 deletions.
9 changes: 5 additions & 4 deletions crates/yakui-vulkan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ edition = "2021"
yakui = { path = "../yakui" }
yakui-core = { path = "../yakui-core" }

ash = "0.37.2"
ash = { version = "0.38", default-features = false, features = ["std"] }
bytemuck = "1.13.0"
thunderdome = "0.6.0"

[dev-dependencies]
ash-window = "0.12.0"
ash = { version = "0.38", default-features = false, features = ["loaded"] }
ash-window = "0.13"
image = "0.24.5"
raw-window-handle = "0.5.0"
winit = { version = "0.29.2", features = ["rwh_05"] }
raw-window-handle = "0.6.0"
winit = "0.29.2"
54 changes: 27 additions & 27 deletions crates/yakui-vulkan/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ struct VulkanTest {
device: ash::Device,
physical_device: vk::PhysicalDevice,
instance: ash::Instance,
surface_loader: ash::extensions::khr::Surface,
surface_loader: ash::khr::surface::Instance,
device_memory_properties: vk::PhysicalDeviceMemoryProperties,

present_queue: vk::Queue,
Expand Down Expand Up @@ -264,25 +264,25 @@ impl VulkanTest {
/// Bring up all the Vulkan pomp and ceremony required to render things.
/// Vulkan Broadly lifted from: https://github.com/ash-rs/ash/blob/0.37.2/examples/src/lib.rs
pub fn new(window_width: u32, window_height: u32, window: &winit::window::Window) -> Self {
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use std::ffi::CStr;

let entry = unsafe { ash::Entry::load().expect("failed to load Vulkan") };
let app_name = unsafe { CStr::from_bytes_with_nul_unchecked(b"Yakui Vulkan Test\0") };

let appinfo = vk::ApplicationInfo::builder()
let appinfo = 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));

let extension_names =
ash_window::enumerate_required_extensions(window.raw_display_handle())
ash_window::enumerate_required_extensions(window.display_handle().unwrap().as_raw())
.unwrap()
.to_vec();

let create_info = vk::InstanceCreateInfo::builder()
let create_info = vk::InstanceCreateInfo::default()
.application_info(&appinfo)
.enabled_extension_names(&extension_names);

Expand All @@ -296,8 +296,8 @@ impl VulkanTest {
ash_window::create_surface(
&entry,
&instance,
window.raw_display_handle(),
window.raw_window_handle(),
window.display_handle().unwrap().as_raw(),
window.window_handle().unwrap().as_raw(),
None,
)
.unwrap()
Expand All @@ -308,7 +308,7 @@ impl VulkanTest {
.enumerate_physical_devices()
.expect("Physical device error")
};
let surface_loader = ash::extensions::khr::Surface::new(&entry, &instance);
let surface_loader = ash::khr::surface::Instance::new(&entry, &instance);
let (physical_device, queue_family_index) = unsafe {
pdevices
.iter()
Expand Down Expand Up @@ -337,18 +337,18 @@ impl VulkanTest {
.expect("Couldn't find suitable device.")
};
let queue_family_index = queue_family_index as u32;
let device_extension_names_raw = [ash::extensions::khr::Swapchain::name().as_ptr()];
let device_extension_names_raw = [ash::khr::swapchain::NAME.as_ptr()];
let priorities = [1.0];

let queue_info = vk::DeviceQueueCreateInfo::builder()
let queue_info = vk::DeviceQueueCreateInfo::default()
.queue_family_index(queue_family_index)
.queue_priorities(&priorities);

let mut descriptor_indexing_features =
vk::PhysicalDeviceDescriptorIndexingFeatures::builder()
vk::PhysicalDeviceDescriptorIndexingFeatures::default()
.descriptor_binding_partially_bound(true);

let device_create_info = vk::DeviceCreateInfo::builder()
let device_create_info = vk::DeviceCreateInfo::default()
.queue_create_infos(std::slice::from_ref(&queue_info))
.enabled_extension_names(&device_extension_names_raw)
.push_next(&mut descriptor_indexing_features);
Expand Down Expand Up @@ -395,7 +395,7 @@ impl VulkanTest {
.cloned()
.find(|&mode| mode == vk::PresentModeKHR::MAILBOX)
.unwrap_or(vk::PresentModeKHR::FIFO);
let swapchain_loader = ash::extensions::khr::Swapchain::new(&instance, &device);
let swapchain_loader = ash::khr::swapchain::Device::new(&instance, &device);

let swapchain_info = SwapchainInfo::new(
swapchain_loader,
Expand Down Expand Up @@ -429,11 +429,11 @@ impl VulkanTest {
..Default::default()
}];

let subpass = vk::SubpassDescription::builder()
let subpass = vk::SubpassDescription::default()
.color_attachments(&color_attachment_refs)
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS);

let renderpass_create_info = vk::RenderPassCreateInfo::builder()
let renderpass_create_info = vk::RenderPassCreateInfo::default()
.attachments(&renderpass_attachments)
.subpasses(std::slice::from_ref(&subpass))
.dependencies(&dependencies);
Expand All @@ -451,13 +451,13 @@ impl VulkanTest {
&device,
);

let pool_create_info = vk::CommandPoolCreateInfo::builder()
let pool_create_info = vk::CommandPoolCreateInfo::default()
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
.queue_family_index(queue_family_index);

let pool = unsafe { device.create_command_pool(&pool_create_info, None).unwrap() };

let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder()
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::default()
.command_buffer_count(1)
.command_pool(pool)
.level(vk::CommandBufferLevel::PRIMARY);
Expand All @@ -470,7 +470,7 @@ impl VulkanTest {
let draw_command_buffer = command_buffers[0];

let fence_create_info =
vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED);
vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED);

let draw_commands_reuse_fence = unsafe {
device
Expand Down Expand Up @@ -600,7 +600,7 @@ impl VulkanTest {
device
.begin_command_buffer(
self.draw_command_buffer,
&vk::CommandBufferBeginInfo::builder()
&vk::CommandBufferBeginInfo::default()
.flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT),
)
.unwrap();
Expand Down Expand Up @@ -633,7 +633,7 @@ impl VulkanTest {
max_depth: 1.0,
}];

let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
let render_pass_begin_info = vk::RenderPassBeginInfo::default()
.render_pass(self.render_pass)
.framebuffer(self.framebuffers[present_index as usize])
.render_area(self.swapchain_info.surface_resolution.into())
Expand Down Expand Up @@ -661,7 +661,7 @@ impl VulkanTest {
device.end_command_buffer(self.draw_command_buffer).unwrap();
let swapchains = [self.swapchain];
let image_indices = [present_index];
let submit_info = vk::SubmitInfo::builder()
let submit_info = vk::SubmitInfo::default()
.wait_semaphores(std::slice::from_ref(&self.present_complete_semaphore))
.wait_dst_stage_mask(&[vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT])
.command_buffers(std::slice::from_ref(&self.draw_command_buffer))
Expand All @@ -677,7 +677,7 @@ impl VulkanTest {

match self.swapchain_info.swapchain_loader.queue_present(
self.present_queue,
&vk::PresentInfoKHR::builder()
&vk::PresentInfoKHR::default()
.image_indices(&image_indices)
.wait_semaphores(std::slice::from_ref(&self.rendering_complete_semaphore))
.swapchains(&swapchains),
Expand Down Expand Up @@ -725,7 +725,7 @@ fn create_swapchain(
desired_image_count,
} = swapchain_info;

let mut swapchain_create_info = vk::SwapchainCreateInfoKHR::builder()
let mut swapchain_create_info = vk::SwapchainCreateInfoKHR::default()
.surface(*surface)
.min_image_count(*desired_image_count)
.image_color_space(surface_format.color_space)
Expand Down Expand Up @@ -753,7 +753,7 @@ fn create_swapchain(
let present_image_views: Vec<vk::ImageView> = present_images
.iter()
.map(|&image| {
let create_view_info = vk::ImageViewCreateInfo::builder()
let create_view_info = vk::ImageViewCreateInfo::default()
.view_type(vk::ImageViewType::TYPE_2D)
.format(surface_format.format)
.components(vk::ComponentMapping {
Expand Down Expand Up @@ -800,7 +800,7 @@ impl Drop for VulkanTest {
}

struct SwapchainInfo {
pub swapchain_loader: ash::extensions::khr::Swapchain,
pub swapchain_loader: ash::khr::swapchain::Device,
pub surface_format: vk::SurfaceFormatKHR,
pub surface_resolution: vk::Extent2D,
pub present_mode: vk::PresentModeKHR,
Expand All @@ -810,7 +810,7 @@ struct SwapchainInfo {

impl SwapchainInfo {
pub fn new(
swapchain_loader: ash::extensions::khr::Swapchain,
swapchain_loader: ash::khr::swapchain::Device,
surface_format: vk::SurfaceFormatKHR,
surface_resolution: vk::Extent2D,
present_mode: vk::PresentModeKHR,
Expand Down Expand Up @@ -838,7 +838,7 @@ fn create_framebuffers(
.iter()
.map(|&present_image_view| {
let framebuffer_attachments = [present_image_view];
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
let frame_buffer_create_info = vk::FramebufferCreateInfo::default()
.render_pass(render_pass)
.attachments(&framebuffer_attachments)
.width(extent.width)
Expand Down
2 changes: 1 addition & 1 deletion crates/yakui-vulkan/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: Copy> Buffer<T> {
let device = vulkan_context.device;
let device_memory_properties = &vulkan_context.memory_properties;

let buffer_info = vk::BufferCreateInfo::builder()
let buffer_info = vk::BufferCreateInfo::default()
.size(((std::mem::size_of::<T>() * elements) as vk::DeviceSize).max(MIN_BUFFER_SIZE))
.usage(usage)
.sharing_mode(vk::SharingMode::EXCLUSIVE);
Expand Down
12 changes: 6 additions & 6 deletions crates/yakui-vulkan/src/descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Descriptors {

let pool = unsafe {
device.create_descriptor_pool(
&vk::DescriptorPoolCreateInfo::builder()
&vk::DescriptorPoolCreateInfo::default()
.max_sets(1)
.pool_sizes(&[vk::DescriptorPoolSize {
ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
Expand All @@ -29,11 +29,11 @@ impl Descriptors {

let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND];
let mut binding_flags =
vk::DescriptorSetLayoutBindingFlagsCreateInfo::builder().binding_flags(&flags);
vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&flags);

let layout = unsafe {
device.create_descriptor_set_layout(
&vk::DescriptorSetLayoutCreateInfo::builder()
&vk::DescriptorSetLayoutCreateInfo::default()
.bindings(&[vk::DescriptorSetLayoutBinding {
binding: 0,
descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
Expand All @@ -49,7 +49,7 @@ impl Descriptors {

let set = unsafe {
device.allocate_descriptor_sets(
&vk::DescriptorSetAllocateInfo::builder()
&vk::DescriptorSetAllocateInfo::default()
.descriptor_pool(pool)
.set_layouts(std::slice::from_ref(&layout)),
)
Expand All @@ -73,9 +73,9 @@ impl Descriptors {
let texture_id = self.texture_count;
vulkan_context.device.update_descriptor_sets(
std::slice::from_ref(
&vk::WriteDescriptorSet::builder()
&vk::WriteDescriptorSet::default()
.image_info(std::slice::from_ref(
&vk::DescriptorImageInfo::builder()
&vk::DescriptorImageInfo::default()
.sampler(sampler)
.image_view(image_view)
.image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL),
Expand Down
22 changes: 11 additions & 11 deletions crates/yakui-vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ impl YakuiVulkan {

let vertex_code =
read_spv(&mut vertex_spv_file).expect("Failed to read vertex shader spv file");
let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code);
let vertex_shader_info = vk::ShaderModuleCreateInfo::default().code(&vertex_code);

let frag_code =
read_spv(&mut frag_spv_file).expect("Failed to read fragment shader spv file");
let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code);
let frag_shader_info = vk::ShaderModuleCreateInfo::default().code(&frag_code);

let vertex_shader_module = unsafe {
device
Expand All @@ -182,9 +182,9 @@ impl YakuiVulkan {
let pipeline_layout = unsafe {
device
.create_pipeline_layout(
&vk::PipelineLayoutCreateInfo::builder()
&vk::PipelineLayoutCreateInfo::default()
.push_constant_ranges(std::slice::from_ref(
&vk::PushConstantRange::builder()
&vk::PushConstantRange::default()
.stage_flags(vk::ShaderStageFlags::FRAGMENT)
.size(std::mem::size_of::<PushConstant>() as _),
))
Expand Down Expand Up @@ -240,14 +240,14 @@ impl YakuiVulkan {
},
];

let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder()
let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default()
.vertex_attribute_descriptions(&vertex_input_attribute_descriptions)
.vertex_binding_descriptions(&vertex_input_binding_descriptions);
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
topology: vk::PrimitiveTopology::TRIANGLE_LIST,
..Default::default()
};
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
let viewport_state_info = vk::PipelineViewportStateCreateInfo::default()
.scissor_count(1)
.viewport_count(1);

Expand Down Expand Up @@ -287,15 +287,15 @@ impl YakuiVulkan {
alpha_blend_op: vk::BlendOp::ADD,
color_write_mask: vk::ColorComponentFlags::RGBA,
}];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder()
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::default()
.logic_op(vk::LogicOp::CLEAR)
.attachments(&color_blend_attachment_states);

let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
let dynamic_state_info =
vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state);
vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_state);

let mut graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder()
let mut graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::default()
.stages(&shader_stage_create_infos)
.vertex_input_state(&vertex_input_state_info)
.input_assembly_state(&vertex_input_assembly_state_info)
Expand All @@ -315,7 +315,7 @@ impl YakuiVulkan {
);
if let Some(format) = options.dynamic_rendering_format {
rendering_info_formats = [format];
rendering_info = vk::PipelineRenderingCreateInfo::builder()
rendering_info = vk::PipelineRenderingCreateInfo::default()
.color_attachment_formats(&rendering_info_formats);
graphic_pipeline_info = graphic_pipeline_info.push_next(&mut rendering_info);
} else {
Expand All @@ -326,7 +326,7 @@ impl YakuiVulkan {
device
.create_graphics_pipelines(
vk::PipelineCache::null(),
&[graphic_pipeline_info.build()],
&[graphic_pipeline_info],
None,
)
.expect("Unable to create graphics pipeline")
Expand Down
8 changes: 4 additions & 4 deletions crates/yakui-vulkan/src/vulkan_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl VulkanTexture {
vulkan_context
.device
.create_sampler(
&vk::SamplerCreateInfo::builder()
&vk::SamplerCreateInfo::default()
.address_mode_u(address_mode)
.address_mode_v(address_mode)
.address_mode_w(address_mode)
Expand Down Expand Up @@ -111,7 +111,7 @@ impl VulkanTexture {
vulkan_context
.device
.create_sampler(
&vk::SamplerCreateInfo::builder()
&vk::SamplerCreateInfo::default()
.address_mode_u(address_mode)
.address_mode_v(address_mode)
.address_mode_w(address_mode)
Expand Down Expand Up @@ -186,8 +186,8 @@ pub(crate) struct UploadQueue {
phase: UploadPhase,
in_flight: VecDeque<UploadPhase>,
textures: Vec<(vk::Image, vk::Extent2D, vk::Buffer, usize)>,
pre_barriers: Vec<vk::ImageMemoryBarrier>,
post_barriers: Vec<vk::ImageMemoryBarrier>,
pre_barriers: Vec<vk::ImageMemoryBarrier<'static>>,
post_barriers: Vec<vk::ImageMemoryBarrier<'static>>,
}

impl UploadQueue {
Expand Down

0 comments on commit 8fedd8e

Please sign in to comment.