diff --git a/blade-graphics/Cargo.toml b/blade-graphics/Cargo.toml index a2f3730a..989c1119 100644 --- a/blade-graphics/Cargo.toml +++ b/blade-graphics/Cargo.toml @@ -17,7 +17,7 @@ hidden-trait = "0.1" log = { workspace = true } mint = { workspace = true } naga = { workspace = true, features = ["clone"] } -raw-window-handle = "0.5" +raw-window-handle = "0.6" [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] block = "0.1" @@ -27,10 +27,10 @@ objc = "0.2.5" naga = { workspace = true, features = ["msl-out"] } [target.'cfg(any(vulkan, windows, target_os = "linux", target_os = "android"))'.dependencies] -ash = "0.37" -ash-window = "0.12" +ash = "0.38" +ash-window = "0.13" gpu-alloc = "0.6" -gpu-alloc-ash = "0.6" +gpu-alloc-ash = "0.7" naga = { workspace = true, features = ["spv-out"] } slab = { workspace = true } diff --git a/blade-graphics/src/gles/resource.rs b/blade-graphics/src/gles/resource.rs index c2689da3..0ee1e6cf 100644 --- a/blade-graphics/src/gles/resource.rs +++ b/blade-graphics/src/gles/resource.rs @@ -49,7 +49,7 @@ impl crate::traits::ResourceDevice for super::Context { | glow::MAP_COHERENT_BIT | glow::MAP_READ_BIT | glow::MAP_WRITE_BIT; - glow::STREAM_READ + glow::DYNAMIC_DRAW //TEMP } crate::Memory::Upload => { map_flags = diff --git a/blade-graphics/src/vulkan/command.rs b/blade-graphics/src/vulkan/command.rs index fa64b0d0..07c051c0 100644 --- a/blade-graphics/src/vulkan/command.rs +++ b/blade-graphics/src/vulkan/command.rs @@ -158,8 +158,8 @@ fn make_buffer_image_copy( } } -fn map_render_target(rt: &crate::RenderTarget) -> vk::RenderingAttachmentInfo { - let mut builder = vk::RenderingAttachmentInfo::builder() +fn map_render_target(rt: &crate::RenderTarget) -> vk::RenderingAttachmentInfo<'static> { + let mut vk_info = vk::RenderingAttachmentInfo::default() .image_view(rt.view.raw) .image_layout(vk::ImageLayout::GENERAL) .load_op(vk::AttachmentLoadOp::LOAD); @@ -190,10 +190,11 @@ fn map_render_target(rt: &crate::RenderTarget) -> vk::RenderingAttachmentInfo { }, } }; - builder = builder.load_op(vk::AttachmentLoadOp::CLEAR).clear_value(cv); + vk_info.load_op = vk::AttachmentLoadOp::CLEAR; + vk_info.clear_value = cv; } - builder.build() + vk_info } impl super::CommandEncoder { @@ -201,18 +202,17 @@ impl super::CommandEncoder { if let Some(ref mut ch) = self.crash_handler { let id = ch.add_marker(marker); unsafe { - (self - .device + self.device .buffer_marker .as_ref() .unwrap() - .cmd_write_buffer_marker_amd)( - self.buffers[0].raw, - vk::PipelineStageFlags::ALL_COMMANDS, - ch.marker_buf.raw, - 0, - id, - ); + .cmd_write_buffer_marker( + self.buffers[0].raw, + vk::PipelineStageFlags::ALL_COMMANDS, + ch.marker_buf.raw, + 0, + id, + ); } } } @@ -220,9 +220,10 @@ impl super::CommandEncoder { pub fn start(&mut self) { self.buffers.rotate_left(1); - let vk_info = vk::CommandBufferBeginInfo::builder() - .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT) - .build(); + let vk_info = vk::CommandBufferBeginInfo { + flags: vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT, + ..Default::default() + }; unsafe { self.device .core @@ -248,14 +249,13 @@ impl super::CommandEncoder { fn barrier(&mut self) { let wa = &self.device.workarounds; - let barrier = vk::MemoryBarrier::builder() - .src_access_mask(vk::AccessFlags::MEMORY_WRITE | wa.extra_sync_src_access) - .dst_access_mask( - vk::AccessFlags::MEMORY_READ - | vk::AccessFlags::MEMORY_WRITE - | wa.extra_sync_dst_access, - ) - .build(); + let barrier = vk::MemoryBarrier { + src_access_mask: vk::AccessFlags::MEMORY_WRITE | wa.extra_sync_src_access, + dst_access_mask: vk::AccessFlags::MEMORY_READ + | vk::AccessFlags::MEMORY_WRITE + | wa.extra_sync_dst_access, + ..Default::default() + }; unsafe { self.device.core.cmd_pipeline_barrier( self.buffers[0].raw, @@ -270,18 +270,19 @@ impl super::CommandEncoder { } pub fn init_texture(&mut self, texture: super::Texture) { - let barrier = vk::ImageMemoryBarrier::builder() - .old_layout(vk::ImageLayout::UNDEFINED) - .new_layout(vk::ImageLayout::GENERAL) - .image(texture.raw) - .subresource_range(vk::ImageSubresourceRange { + let barrier = vk::ImageMemoryBarrier { + old_layout: vk::ImageLayout::UNDEFINED, + new_layout: vk::ImageLayout::GENERAL, + image: texture.raw, + subresource_range: vk::ImageSubresourceRange { aspect_mask: super::map_aspects(texture.format.aspects()), base_mip_level: 0, level_count: vk::REMAINING_MIP_LEVELS, base_array_layer: 0, layer_count: vk::REMAINING_ARRAY_LAYERS, - }) - .build(); + }, + ..Default::default() + }; unsafe { self.device.core.cmd_pipeline_barrier( self.buffers[0].raw, @@ -303,19 +304,20 @@ impl super::CommandEncoder { acquire_semaphore: frame.acquire_semaphore, }); - let barrier = vk::ImageMemoryBarrier::builder() - .old_layout(vk::ImageLayout::GENERAL) - .new_layout(vk::ImageLayout::PRESENT_SRC_KHR) - .image(frame.image) - .subresource_range(vk::ImageSubresourceRange { + let barrier = vk::ImageMemoryBarrier { + old_layout: vk::ImageLayout::GENERAL, + new_layout: vk::ImageLayout::PRESENT_SRC_KHR, + image: frame.image, + subresource_range: vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: 1, - }) - .src_access_mask(vk::AccessFlags::MEMORY_WRITE | wa.extra_sync_src_access) - .build(); + }, + src_access_mask: vk::AccessFlags::MEMORY_WRITE | wa.extra_sync_src_access, + ..Default::default() + }; unsafe { self.device.core.cmd_pipeline_barrier( self.buffers[0].raw, @@ -369,9 +371,10 @@ impl super::CommandEncoder { color_attachments.push(map_render_target(rt)); } - let mut rendering_info = vk::RenderingInfoKHR::builder() + let mut rendering_info = vk::RenderingInfoKHR::default() .layer_count(1) .color_attachments(&color_attachments); + if let Some(rt) = targets.depth_stencil { target_size = rt.view.target_size; depth_stencil_attachment = map_render_target(&rt); @@ -398,7 +401,7 @@ impl super::CommandEncoder { min_depth: 0.0, max_depth: 1.0, }; - rendering_info = rendering_info.render_area(render_area); + rendering_info.render_area = render_area; let cmd_buf = self.buffers[0]; unsafe { @@ -584,26 +587,29 @@ impl crate::traits::AccelerationStructureEncoder first_vertex: 0, transform_offset: 0, }; - let geometry = vk::AccelerationStructureGeometryKHR::builder() - .geometry_type(vk::GeometryTypeKHR::INSTANCES) - .geometry(vk::AccelerationStructureGeometryDataKHR { - instances: vk::AccelerationStructureGeometryInstancesDataKHR::builder() - .data(vk::DeviceOrHostAddressConstKHR { + let geometry = vk::AccelerationStructureGeometryKHR { + geometry_type: vk::GeometryTypeKHR::INSTANCES, + geometry: vk::AccelerationStructureGeometryDataKHR { + instances: vk::AccelerationStructureGeometryInstancesDataKHR { + data: vk::DeviceOrHostAddressConstKHR { device_address: self.device.get_device_address(&instance_data), - }) - .build(), - }) - .build(); + }, + ..Default::default() + }, + }, + ..Default::default() + }; let geometries = [geometry]; - let build_info = vk::AccelerationStructureBuildGeometryInfoKHR::builder() - .ty(vk::AccelerationStructureTypeKHR::TOP_LEVEL) - .mode(vk::BuildAccelerationStructureModeKHR::BUILD) - .geometries(&geometries) - .scratch_data(vk::DeviceOrHostAddressKHR { + let build_info = vk::AccelerationStructureBuildGeometryInfoKHR { + ty: vk::AccelerationStructureTypeKHR::TOP_LEVEL, + mode: vk::BuildAccelerationStructureModeKHR::BUILD, + scratch_data: vk::DeviceOrHostAddressKHR { device_address: self.device.get_device_address(&scratch_data), - }) - .dst_acceleration_structure(acceleration_structure.raw) - .build(); + }, + dst_acceleration_structure: acceleration_structure.raw, + ..Default::default() + } + .geometries(&geometries); let rt = self.device.ray_tracing.as_ref().unwrap(); unsafe { @@ -699,9 +705,11 @@ impl crate::traits::PipelineEncoder for super::PipelineEncoder<'_, '_> { }); let descriptor_set_layouts = [dsl.raw]; - let descriptor_set_info = vk::DescriptorSetAllocateInfo::builder() - .descriptor_pool(self.cmd_buf.descriptor_pool) - .set_layouts(&descriptor_set_layouts); + let descriptor_set_info = vk::DescriptorSetAllocateInfo { + descriptor_pool: self.cmd_buf.descriptor_pool, + ..Default::default() + } + .set_layouts(&descriptor_set_layouts); unsafe { let sets = self .device diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 15af0c71..5b452252 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -1,7 +1,4 @@ -use ash::{ - extensions::{ext, khr}, - vk, -}; +use ash::{amd, ext, khr, vk}; use naga::back::spv; use std::{ffi, fs, mem, sync::Mutex}; @@ -19,10 +16,10 @@ mod layer { } const REQUIRED_DEVICE_EXTENSIONS: &[&ffi::CStr] = &[ - vk::ExtInlineUniformBlockFn::name(), - vk::KhrTimelineSemaphoreFn::name(), - vk::KhrDescriptorUpdateTemplateFn::name(), - vk::KhrDynamicRenderingFn::name(), + vk::EXT_INLINE_UNIFORM_BLOCK_NAME, + vk::KHR_TIMELINE_SEMAPHORE_NAME, + vk::KHR_DESCRIPTOR_UPDATE_TEMPLATE_NAME, + vk::KHR_DYNAMIC_RENDERING_NAME, ]; #[derive(Debug)] @@ -85,7 +82,7 @@ unsafe fn inspect_adapter( vk::PhysicalDeviceAccelerationStructurePropertiesKHR::default(); let mut portability_subset_properties = vk::PhysicalDevicePortabilitySubsetPropertiesKHR::default(); - let mut properties2_khr = vk::PhysicalDeviceProperties2KHR::builder() + let mut properties2_khr = vk::PhysicalDeviceProperties2KHR::default() .push_next(&mut inline_uniform_block_properties) .push_next(&mut timeline_semaphore_properties) .push_next(&mut descriptor_indexing_properties) @@ -129,7 +126,7 @@ unsafe fn inspect_adapter( let mut acceleration_structure_features = vk::PhysicalDeviceAccelerationStructureFeaturesKHR::default(); let mut ray_query_features = vk::PhysicalDeviceRayQueryFeaturesKHR::default(); - let mut features2_khr = vk::PhysicalDeviceFeatures2::builder() + let mut features2_khr = vk::PhysicalDeviceFeatures2::default() .push_next(&mut inline_uniform_block_features) .push_next(&mut timeline_semaphore_features) .push_next(&mut dynamic_rendering_features) @@ -175,8 +172,8 @@ unsafe fn inspect_adapter( return None; } - let ray_tracing = if !supported_extensions.contains(&vk::KhrAccelerationStructureFn::name()) - || !supported_extensions.contains(&vk::KhrRayQueryFn::name()) + let ray_tracing = if !supported_extensions.contains(&vk::KHR_ACCELERATION_STRUCTURE_NAME) + || !supported_extensions.contains(&vk::KHR_RAY_QUERY_NAME) { log::info!("No ray tracing extensions are supported"); false @@ -216,8 +213,8 @@ unsafe fn inspect_adapter( true }; - let buffer_marker = supported_extensions.contains(&vk::AmdBufferMarkerFn::name()); - let shader_info = supported_extensions.contains(&vk::AmdShaderInfoFn::name()); + let buffer_marker = supported_extensions.contains(&vk::AMD_BUFFER_MARKER_NAME); + let shader_info = supported_extensions.contains(&vk::AMD_SHADER_INFO_NAME); Some(AdapterCapabilities { api_version, @@ -300,8 +297,8 @@ impl super::Context { let mut create_flags = vk::InstanceCreateFlags::empty(); let mut instance_extensions = vec![ - ext::DebugUtils::name(), - vk::KhrGetPhysicalDeviceProperties2Fn::name(), + vk::EXT_DEBUG_UTILS_NAME, + vk::KHR_GET_PHYSICAL_DEVICE_PROPERTIES2_NAME, ]; if let Some((_, rdh)) = surface_handles { instance_extensions.extend( @@ -318,12 +315,12 @@ impl super::Context { return Err(crate::NotSupportedError); } } - if supported_instance_extensions.contains(&vk::KhrPortabilityEnumerationFn::name()) { - instance_extensions.push(vk::KhrPortabilityEnumerationFn::name()); + if supported_instance_extensions.contains(&vk::KHR_PORTABILITY_ENUMERATION_NAME) { + instance_extensions.push(vk::KHR_PORTABILITY_ENUMERATION_NAME); create_flags |= vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR; } - let app_info = vk::ApplicationInfo::builder() + let app_info = vk::ApplicationInfo::default() .engine_name(ffi::CStr::from_bytes_with_nul(b"blade\0").unwrap()) .engine_version(1) .api_version(vk::HEADER_VERSION_COMPLETE); @@ -333,7 +330,7 @@ impl super::Context { .map(|&s| s.as_ptr()) .collect::>(); let (layer_strings, extension_strings) = str_pointers.split_at(layers.len()); - let create_info = vk::InstanceCreateInfo::builder() + let create_info = vk::InstanceCreateInfo::default() .application_info(&app_info) .flags(create_flags) .enabled_layer_names(layer_strings) @@ -353,19 +350,18 @@ impl super::Context { ash_window::create_surface(&entry, &core_instance, rdh, rwh, None).unwrap() }); - let instance = super::Instance { - debug_utils: ext::DebugUtils::new(&entry, &core_instance), - get_physical_device_properties2: khr::GetPhysicalDeviceProperties2::new( - &entry, - &core_instance, - ), - surface: if surface_handles.is_some() { - Some(khr::Surface::new(&entry, &core_instance)) - } else { - None - }, - core: core_instance, - }; + let instance = + super::Instance { + _debug_utils: ext::debug_utils::Instance::new(&entry, &core_instance), + get_physical_device_properties2: + khr::get_physical_device_properties2::Instance::new(&entry, &core_instance), + surface: if surface_handles.is_some() { + Some(khr::surface::Instance::new(&entry, &core_instance)) + } else { + None + }, + core: core_instance, + }; let physical_devices = instance.core.enumerate_physical_devices().unwrap(); let (physical_device, capabilities) = physical_devices @@ -379,36 +375,35 @@ impl super::Context { log::debug!("Adapter {:#?}", capabilities); let device_core = { - let family_info = vk::DeviceQueueCreateInfo::builder() + let family_info = vk::DeviceQueueCreateInfo::default() .queue_family_index(capabilities.queue_family_index) - .queue_priorities(&[1.0]) - .build(); + .queue_priorities(&[1.0]); let family_infos = [family_info]; let mut device_extensions = REQUIRED_DEVICE_EXTENSIONS.to_vec(); if surface_handles.is_some() { - device_extensions.push(vk::KhrSwapchainFn::name()); + device_extensions.push(vk::KHR_SWAPCHAIN_NAME); } if capabilities.layered { log::info!("Enabling Vulkan Portability"); - device_extensions.push(vk::KhrPortabilitySubsetFn::name()); + device_extensions.push(vk::KHR_PORTABILITY_SUBSET_NAME); } if capabilities.ray_tracing { if capabilities.api_version < vk::API_VERSION_1_2 { - device_extensions.push(vk::ExtDescriptorIndexingFn::name()); - device_extensions.push(vk::KhrBufferDeviceAddressFn::name()); - device_extensions.push(vk::KhrShaderFloatControlsFn::name()); - device_extensions.push(vk::KhrSpirv14Fn::name()); + device_extensions.push(vk::EXT_DESCRIPTOR_INDEXING_NAME); + device_extensions.push(vk::KHR_BUFFER_DEVICE_ADDRESS_NAME); + device_extensions.push(vk::KHR_SHADER_FLOAT_CONTROLS_NAME); + device_extensions.push(vk::KHR_SPIRV_1_4_NAME); } - device_extensions.push(vk::KhrDeferredHostOperationsFn::name()); - device_extensions.push(vk::KhrAccelerationStructureFn::name()); - device_extensions.push(vk::KhrRayQueryFn::name()); + device_extensions.push(vk::KHR_DEFERRED_HOST_OPERATIONS_NAME); + device_extensions.push(vk::KHR_ACCELERATION_STRUCTURE_NAME); + device_extensions.push(vk::KHR_RAY_QUERY_NAME); } if capabilities.buffer_marker { - device_extensions.push(vk::AmdBufferMarkerFn::name()); + device_extensions.push(vk::AMD_BUFFER_MARKER_NAME); } if capabilities.shader_info { - device_extensions.push(vk::AmdShaderInfoFn::name()); + device_extensions.push(vk::AMD_SHADER_INFO_NAME); } let str_pointers = device_extensions @@ -416,14 +411,19 @@ impl super::Context { .map(|&s| s.as_ptr()) .collect::>(); - let mut ext_inline_uniform_block = - vk::PhysicalDeviceInlineUniformBlockFeaturesEXT::builder() - .inline_uniform_block(true); - let mut khr_timeline_semaphore = - vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR::builder().timeline_semaphore(true); - let mut khr_dynamic_rendering = - vk::PhysicalDeviceDynamicRenderingFeaturesKHR::builder().dynamic_rendering(true); - let mut device_create_info = vk::DeviceCreateInfo::builder() + let mut ext_inline_uniform_block = vk::PhysicalDeviceInlineUniformBlockFeaturesEXT { + inline_uniform_block: vk::TRUE, + ..Default::default() + }; + let mut khr_timeline_semaphore = vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR { + timeline_semaphore: vk::TRUE, + ..Default::default() + }; + let mut khr_dynamic_rendering = vk::PhysicalDeviceDynamicRenderingFeaturesKHR { + dynamic_rendering: vk::TRUE, + ..Default::default() + }; + let mut device_create_info = vk::DeviceCreateInfo::default() .queue_create_infos(&family_infos) .enabled_extension_names(&str_pointers) .push_next(&mut ext_inline_uniform_block) @@ -435,18 +435,24 @@ impl super::Context { let mut khr_acceleration_structure; let mut khr_ray_query; if capabilities.ray_tracing { - ext_descriptor_indexing = - vk::PhysicalDeviceDescriptorIndexingFeaturesEXT::builder() - .shader_storage_buffer_array_non_uniform_indexing(true) - .shader_sampled_image_array_non_uniform_indexing(true) - .descriptor_binding_partially_bound(true); - khr_buffer_device_address = - vk::PhysicalDeviceBufferDeviceAddressFeaturesKHR::builder() - .buffer_device_address(true); - khr_acceleration_structure = - vk::PhysicalDeviceAccelerationStructureFeaturesKHR::builder() - .acceleration_structure(true); - khr_ray_query = vk::PhysicalDeviceRayQueryFeaturesKHR::builder().ray_query(true); + ext_descriptor_indexing = vk::PhysicalDeviceDescriptorIndexingFeaturesEXT { + shader_storage_buffer_array_non_uniform_indexing: vk::TRUE, + shader_sampled_image_array_non_uniform_indexing: vk::TRUE, + descriptor_binding_partially_bound: vk::TRUE, + ..Default::default() + }; + khr_buffer_device_address = vk::PhysicalDeviceBufferDeviceAddressFeaturesKHR { + buffer_device_address: vk::TRUE, + ..Default::default() + }; + khr_acceleration_structure = vk::PhysicalDeviceAccelerationStructureFeaturesKHR { + acceleration_structure: vk::TRUE, + ..Default::default() + }; + khr_ray_query = vk::PhysicalDeviceRayQueryFeaturesKHR { + ray_query: vk::TRUE, + ..Default::default() + }; device_create_info = device_create_info .push_next(&mut ext_descriptor_indexing) .push_next(&mut khr_buffer_device_address) @@ -461,11 +467,12 @@ impl super::Context { }; let device = super::Device { - timeline_semaphore: khr::TimelineSemaphore::new(&instance.core, &device_core), - dynamic_rendering: khr::DynamicRendering::new(&instance.core, &device_core), + debug_utils: ext::debug_utils::Device::new(&instance.core, &device_core), + timeline_semaphore: khr::timeline_semaphore::Device::new(&instance.core, &device_core), + dynamic_rendering: khr::dynamic_rendering::Device::new(&instance.core, &device_core), ray_tracing: if capabilities.ray_tracing { Some(super::RayTracingDevice { - acceleration_structure: khr::AccelerationStructure::new( + acceleration_structure: khr::acceleration_structure::Device::new( &instance.core, &device_core, ), @@ -474,25 +481,15 @@ impl super::Context { None }, buffer_marker: if capabilities.buffer_marker && desc.validation { - //TODO: https://github.com/ash-rs/ash/issues/768 - Some(vk::AmdBufferMarkerFn::load(|name| unsafe { - mem::transmute( - instance - .core - .get_device_proc_addr(device_core.handle(), name.as_ptr()), - ) - })) + Some(amd::buffer_marker::Device::new( + &instance.core, + &device_core, + )) } else { None }, shader_info: if capabilities.shader_info { - Some(vk::AmdShaderInfoFn::load(|name| unsafe { - mem::transmute( - instance - .core - .get_device_proc_addr(device_core.handle(), name.as_ptr()), - ) - })) + Some(amd::shader_info::Device::new(&instance.core, &device_core)) } else { None }, @@ -561,18 +558,20 @@ impl super::Context { .core .get_device_queue(capabilities.queue_family_index, 0); let last_progress = 0; - let mut timeline_info = vk::SemaphoreTypeCreateInfo::builder() - .semaphore_type(vk::SemaphoreType::TIMELINE) - .initial_value(last_progress); + let mut timeline_info = vk::SemaphoreTypeCreateInfo { + semaphore_type: vk::SemaphoreType::TIMELINE, + initial_value: last_progress, + ..Default::default() + }; let timeline_semaphore_create_info = - vk::SemaphoreCreateInfo::builder().push_next(&mut timeline_info); + vk::SemaphoreCreateInfo::default().push_next(&mut timeline_info); let timeline_semaphore = unsafe { device .core .create_semaphore(&timeline_semaphore_create_info, None) .unwrap() }; - let present_semaphore_create_info = vk::SemaphoreCreateInfo::builder(); + let present_semaphore_create_info = vk::SemaphoreCreateInfo::default(); let present_semaphore = unsafe { device .core @@ -581,8 +580,8 @@ impl super::Context { }; let surface = vk_surface.map(|raw| { - let extension = khr::Swapchain::new(&instance.core, &device.core); - let semaphore_create_info = vk::SemaphoreCreateInfo::builder(); + let extension = khr::swapchain::Device::new(&instance.core, &device.core); + let semaphore_create_info = vk::SemaphoreCreateInfo::default(); let next_semaphore = unsafe { device .core @@ -631,25 +630,22 @@ impl super::Context { window: &I, desc: crate::ContextDesc, ) -> Result { - let handles = (window.raw_window_handle(), window.raw_display_handle()); + let handles = ( + window.raw_window_handle().unwrap(), + window.raw_display_handle().unwrap(), + ); Self::init_impl(desc, Some(handles)) } - pub(super) fn set_object_name( - &self, - object_type: vk::ObjectType, - object: impl vk::Handle, - name: &str, - ) { + pub(super) fn set_object_name(&self, object: T, name: &str) { let name_cstr = ffi::CString::new(name).unwrap(); - let name_info = vk::DebugUtilsObjectNameInfoEXT::builder() - .object_type(object_type) - .object_handle(object.as_raw()) + let name_info = vk::DebugUtilsObjectNameInfoEXT::default() + .object_handle(object) .object_name(&name_cstr); let _ = unsafe { - self.instance + self.device .debug_utils - .set_debug_utils_object_name(self.device.core.handle(), &name_info) + .set_debug_utils_object_name(&name_info) }; } @@ -718,24 +714,26 @@ impl super::Context { crate::ColorSpace::Srgb => crate::TextureFormat::Bgra8Unorm, }; let vk_format = super::map_texture_format(format); - let create_info = vk::SwapchainCreateInfoKHR::builder() - .surface(surface.raw) - .min_image_count(effective_frame_count) - .image_format(vk_format) - .image_extent(vk::Extent2D { + let create_info = vk::SwapchainCreateInfoKHR { + surface: surface.raw, + min_image_count: effective_frame_count, + image_format: vk_format, + image_extent: vk::Extent2D { width: config.size.width, height: config.size.height, - }) - .image_array_layers(1) - .image_usage(super::resource::map_texture_usage( + }, + image_array_layers: 1, + image_usage: super::resource::map_texture_usage( config.usage, crate::TexelAspects::COLOR, - )) - .queue_family_indices(&queue_families) - .pre_transform(vk::SurfaceTransformFlagsKHR::IDENTITY) - .composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE) - .present_mode(present_mode) - .old_swapchain(surface.swapchain); + ), + pre_transform: vk::SurfaceTransformFlagsKHR::IDENTITY, + composite_alpha: vk::CompositeAlphaFlagsKHR::OPAQUE, + present_mode, + old_swapchain: surface.swapchain, + ..Default::default() + } + .queue_family_indices(&queue_families); let new_swapchain = unsafe { surface .extension @@ -771,18 +769,20 @@ impl super::Context { layer_count: 1, }; for (index, image) in images.into_iter().enumerate() { - let view_create_info = vk::ImageViewCreateInfo::builder() - .image(image) - .view_type(vk::ImageViewType::TYPE_2D) - .format(vk_format) - .subresource_range(subresource_range); + let view_create_info = vk::ImageViewCreateInfo { + image, + view_type: vk::ImageViewType::TYPE_2D, + format: vk_format, + subresource_range, + ..Default::default() + }; let view = unsafe { self.device .core .create_image_view(&view_create_info, None) .unwrap() }; - let semaphore_create_info = vk::SemaphoreCreateInfo::builder(); + let semaphore_create_info = vk::SemaphoreCreateInfo::default(); let acquire_semaphore = unsafe { self.device .core diff --git a/blade-graphics/src/vulkan/mod.rs b/blade-graphics/src/vulkan/mod.rs index c486fd8d..4f814285 100644 --- a/blade-graphics/src/vulkan/mod.rs +++ b/blade-graphics/src/vulkan/mod.rs @@ -1,7 +1,4 @@ -use ash::{ - extensions::{ext, khr}, - vk, -}; +use ash::{khr, vk}; use std::{num::NonZeroU32, ptr, sync::Mutex}; mod command; @@ -11,14 +8,14 @@ mod resource; struct Instance { core: ash::Instance, - debug_utils: ext::DebugUtils, - get_physical_device_properties2: khr::GetPhysicalDeviceProperties2, - surface: Option, + _debug_utils: ash::ext::debug_utils::Instance, + get_physical_device_properties2: khr::get_physical_device_properties2::Instance, + surface: Option, } #[derive(Clone)] struct RayTracingDevice { - acceleration_structure: khr::AccelerationStructure, + acceleration_structure: khr::acceleration_structure::Device, } #[derive(Clone)] @@ -30,11 +27,12 @@ struct Workarounds { #[derive(Clone)] struct Device { core: ash::Device, - timeline_semaphore: khr::TimelineSemaphore, - dynamic_rendering: khr::DynamicRendering, + debug_utils: ash::ext::debug_utils::Device, + timeline_semaphore: khr::timeline_semaphore::Device, + dynamic_rendering: khr::dynamic_rendering::Device, ray_tracing: Option, - buffer_marker: Option, - shader_info: Option, + buffer_marker: Option, + shader_info: Option, workarounds: Workarounds, } @@ -85,7 +83,7 @@ struct Surface { frames: Vec, next_semaphore: vk::Semaphore, swapchain: vk::SwapchainKHR, - extension: khr::Swapchain, + extension: khr::swapchain::Device, } fn map_timeout(millis: u32) -> u64 { @@ -305,17 +303,21 @@ impl crate::traits::CommandDevice for Context { }); } - let pool_info = vk::CommandPoolCreateInfo::builder() - .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER); + let pool_info = vk::CommandPoolCreateInfo { + flags: vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER, + ..Default::default() + }; let pool = unsafe { self.device .core .create_command_pool(&pool_info, None) .unwrap() }; - let cmd_buf_info = vk::CommandBufferAllocateInfo::builder() - .command_pool(pool) - .command_buffer_count(desc.buffer_count); + let cmd_buf_info = vk::CommandBufferAllocateInfo { + command_pool: pool, + command_buffer_count: desc.buffer_count, + ..Default::default() + }; let cmd_buffers = unsafe { self.device .core @@ -327,12 +329,14 @@ impl crate::traits::CommandDevice for Context { .into_iter() .map(|raw| { if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::COMMAND_BUFFER, raw, desc.name); + self.set_object_name(raw, desc.name); }; let mut inline_uniform_block_info = - vk::DescriptorPoolInlineUniformBlockCreateInfoEXT::builder() - .max_inline_uniform_block_bindings(ROUGH_SET_COUNT); - let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder() + vk::DescriptorPoolInlineUniformBlockCreateInfoEXT { + max_inline_uniform_block_bindings: ROUGH_SET_COUNT, + ..Default::default() + }; + let descriptor_pool_info = vk::DescriptorPoolCreateInfo::default() .max_sets(ROUGH_SET_COUNT) .pool_sizes(&descriptor_sizes) .push_next(&mut inline_uniform_block_info); @@ -414,10 +418,10 @@ impl crate::traits::CommandDevice for Context { } None => (0, 1), }; - let mut timeline_info = vk::TimelineSemaphoreSubmitInfo::builder() + let mut timeline_info = vk::TimelineSemaphoreSubmitInfo::default() .wait_semaphore_values(&wait_values_all[..num_wait_semaphores]) .signal_semaphore_values(&signal_values_all[..num_signal_sepahores]); - let vk_info = vk::SubmitInfo::builder() + let vk_info = vk::SubmitInfo::default() .command_buffers(&command_buffers) .wait_semaphores(&wait_semaphores_all[..num_wait_semaphores]) .wait_dst_stage_mask(&wait_stages[..num_wait_semaphores]) @@ -426,7 +430,7 @@ impl crate::traits::CommandDevice for Context { let ret = unsafe { self.device .core - .queue_submit(queue.raw, &[vk_info.build()], vk::Fence::null()) + .queue_submit(queue.raw, &[vk_info], vk::Fence::null()) }; encoder.check_gpu_crash(ret); @@ -435,7 +439,7 @@ impl crate::traits::CommandDevice for Context { let swapchains = [surface.swapchain]; let image_indices = [presentation.image_index]; let wait_semaphores = [queue.present_semaphore]; - let present_info = vk::PresentInfoKHR::builder() + let present_info = vk::PresentInfoKHR::default() .swapchains(&swapchains) .image_indices(&image_indices) .wait_semaphores(&wait_semaphores); @@ -452,7 +456,7 @@ impl crate::traits::CommandDevice for Context { let timeline_semaphore = self.queue.lock().unwrap().timeline_semaphore; let semaphores = [timeline_semaphore]; let semaphore_values = [sp.progress]; - let wait_info = vk::SemaphoreWaitInfoKHR::builder() + let wait_info = vk::SemaphoreWaitInfoKHR::default() .semaphores(&semaphores) .values(&semaphore_values); let timeout_ns = map_timeout(timeout_ms); @@ -576,16 +580,19 @@ fn map_vertex_format(vertex_format: crate::VertexFormat) -> vk::Format { } } -struct BottomLevelAccelerationStructureInput { +struct BottomLevelAccelerationStructureInput<'a> { max_primitive_counts: Box<[u32]>, build_range_infos: Box<[vk::AccelerationStructureBuildRangeInfoKHR]>, - _geometries: Box<[vk::AccelerationStructureGeometryKHR]>, - build_info: vk::AccelerationStructureBuildGeometryInfoKHR, + _geometries: Box<[vk::AccelerationStructureGeometryKHR<'a>]>, + build_info: vk::AccelerationStructureBuildGeometryInfoKHR<'a>, } impl Device { fn get_device_address(&self, piece: &crate::BufferPiece) -> u64 { - let vk_info = vk::BufferDeviceAddressInfo::builder().buffer(piece.buffer.raw); + let vk_info = vk::BufferDeviceAddressInfo { + buffer: piece.buffer.raw, + ..Default::default() + }; let base = unsafe { self.core.get_buffer_device_address(&vk_info) }; base + piece.offset } @@ -608,19 +615,20 @@ impl Device { transform_offset: 0, }); - let mut triangles = vk::AccelerationStructureGeometryTrianglesDataKHR::builder() - .vertex_format(map_vertex_format(mesh.vertex_format)) - .vertex_data({ + let mut triangles = vk::AccelerationStructureGeometryTrianglesDataKHR { + vertex_format: map_vertex_format(mesh.vertex_format), + vertex_data: { let device_address = self.get_device_address(&mesh.vertex_data); assert!( device_address & 0x3 == 0, "Vertex data address {device_address} is not aligned" ); vk::DeviceOrHostAddressConstKHR { device_address } - }) - .vertex_stride(mesh.vertex_stride as u64) - .max_vertex(mesh.vertex_count.saturating_sub(1)) - .build(); + }, + vertex_stride: mesh.vertex_stride as u64, + max_vertex: mesh.vertex_count.saturating_sub(1), + ..Default::default() + }; if let Some(index_type) = mesh.index_type { let device_address = self.get_device_address(&mesh.index_data); assert!( @@ -639,23 +647,26 @@ impl Device { triangles.transform_data = vk::DeviceOrHostAddressConstKHR { device_address }; } - let geometry = vk::AccelerationStructureGeometryKHR::builder() - .geometry_type(vk::GeometryTypeKHR::TRIANGLES) - .geometry(vk::AccelerationStructureGeometryDataKHR { triangles }) - .flags(if mesh.is_opaque { + let geometry = vk::AccelerationStructureGeometryKHR { + geometry_type: vk::GeometryTypeKHR::TRIANGLES, + geometry: vk::AccelerationStructureGeometryDataKHR { triangles }, + flags: if mesh.is_opaque { vk::GeometryFlagsKHR::OPAQUE } else { vk::GeometryFlagsKHR::empty() - }) - .build(); + }, + ..Default::default() + }; geometries.push(geometry); } - let build_info = vk::AccelerationStructureBuildGeometryInfoKHR::builder() - .ty(vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL) - .flags(vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE) - .mode(vk::BuildAccelerationStructureModeKHR::BUILD) - .geometries(&geometries) - .build(); + let build_info = vk::AccelerationStructureBuildGeometryInfoKHR { + ty: vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL, + flags: vk::BuildAccelerationStructureFlagsKHR::PREFER_FAST_TRACE, + mode: vk::BuildAccelerationStructureModeKHR::BUILD, + geometry_count: geometries.len() as u32, + p_geometries: geometries.as_ptr(), + ..Default::default() + }; log::debug!( "BLAS total {} primitives in {} geometries", diff --git a/blade-graphics/src/vulkan/pipeline.rs b/blade-graphics/src/vulkan/pipeline.rs index 64ba46b9..5629c921 100644 --- a/blade-graphics/src/vulkan/pipeline.rs +++ b/blade-graphics/src/vulkan/pipeline.rs @@ -1,13 +1,13 @@ use ash::vk; use naga::back::spv; -use std::{ffi, mem, ptr, str}; +use std::{ffi, mem, str}; const DUMP_PREFIX: Option<&str> = None; -struct CompiledShader { +struct CompiledShader<'a> { vk_module: vk::ShaderModule, _entry_point: ffi::CString, - create_info: vk::PipelineShaderStageCreateInfo, + create_info: vk::PipelineShaderStageCreateInfo<'a>, attribute_mappings: Vec, wg_size: [u32; 3], } @@ -102,7 +102,7 @@ impl super::Context { std::fs::write(file_name, spv_bytes).unwrap(); } - let vk_info = vk::ShaderModuleCreateInfo::builder().code(&spv); + let vk_info = vk::ShaderModuleCreateInfo::default().code(&spv); let vk_module = unsafe { self.device @@ -118,11 +118,12 @@ impl super::Context { }; let entry_point = ffi::CString::new(sf.entry_point).unwrap(); - let create_info = vk::PipelineShaderStageCreateInfo::builder() - .stage(vk_stage) - .module(vk_module) - .name(&entry_point) - .build(); + let create_info = vk::PipelineShaderStageCreateInfo { + stage: vk_stage, + module: vk_module, + p_name: entry_point.as_ptr(), + ..Default::default() + }; CompiledShader { vk_module, @@ -210,7 +211,7 @@ impl super::Context { descriptor_type, descriptor_count, stage_flags, - p_immutable_samplers: ptr::null(), + ..Default::default() }); template_entries.push(vk::DescriptorUpdateTemplateEntryKHR { dst_binding: binding_index as u32, @@ -226,8 +227,8 @@ impl super::Context { } let mut binding_flags_info = - vk::DescriptorSetLayoutBindingFlagsCreateInfo::builder().binding_flags(&binding_flags); - let set_layout_info = vk::DescriptorSetLayoutCreateInfo::builder() + vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&binding_flags); + let set_layout_info = vk::DescriptorSetLayoutCreateInfo::default() .bindings(&vk_bindings) .push_next(&mut binding_flags_info); let raw = unsafe { @@ -237,7 +238,7 @@ impl super::Context { .unwrap() }; - let template_create_info = vk::DescriptorUpdateTemplateCreateInfo::builder() + let template_create_info = vk::DescriptorUpdateTemplateCreateInfo::default() .descriptor_update_entries(&template_entries) .template_type(vk::DescriptorUpdateTemplateTypeKHR::DESCRIPTOR_SET) .descriptor_set_layout(raw); @@ -269,7 +270,7 @@ impl super::Context { descriptor_set_layouts.push(dsl); } - let vk_info = vk::PipelineLayoutCreateInfo::builder().set_layouts(&vk_set_layouts); + let vk_info = vk::PipelineLayoutCreateInfo::default().set_layouts(&vk_set_layouts); let raw = unsafe { self.device .core @@ -304,10 +305,9 @@ impl super::Context { let layout = self.create_pipeline_layout(desc.data_layouts, &group_infos); - let create_info = vk::ComputePipelineCreateInfo::builder() + let create_info = vk::ComputePipelineCreateInfo::default() .layout(layout.raw) - .stage(cs.create_info) - .build(); + .stage(cs.create_info); let mut raw_vec = unsafe { self.device @@ -320,19 +320,8 @@ impl super::Context { unsafe { self.device.core.destroy_shader_module(cs.vk_module, None) }; if let Some(ref ext) = self.device.shader_info { - let mut data_size = mem::size_of::(); - let mut statistics = vk::ShaderStatisticsInfoAMD::default(); - if unsafe { - #[allow(trivial_casts)] - (ext.get_shader_info_amd)( - self.device.core.handle(), - raw, - vk::ShaderStageFlags::COMPUTE, - vk::ShaderInfoTypeAMD::STATISTICS, - &mut data_size, - &mut statistics as *mut _ as *mut _, - ) - } == vk::Result::SUCCESS + if let Ok(statistics) = + unsafe { ext.get_shader_info_statistics(raw, vk::ShaderStageFlags::COMPUTE) } { let ru = &statistics.resource_usage; log::info!( @@ -345,7 +334,7 @@ impl super::Context { } if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::PIPELINE, raw, desc.name); + self.set_object_name(raw, desc.name); } super::ComputePipeline { raw, @@ -410,17 +399,15 @@ impl super::Context { }) .collect::>(); - let vk_vertex_input = vk::PipelineVertexInputStateCreateInfo::builder() + let vk_vertex_input = vk::PipelineVertexInputStateCreateInfo::default() .vertex_binding_descriptions(&vertex_buffers) - .vertex_attribute_descriptions(&vertex_attributes) - .build(); + .vertex_attribute_descriptions(&vertex_attributes); let (raw_topology, supports_restart) = map_primitive_topology(desc.primitive.topology); - let vk_input_assembly = vk::PipelineInputAssemblyStateCreateInfo::builder() + let vk_input_assembly = vk::PipelineInputAssemblyStateCreateInfo::default() .topology(raw_topology) - .primitive_restart_enable(supports_restart) - .build(); + .primitive_restart_enable(supports_restart); - let mut vk_rasterization = vk::PipelineRasterizationStateCreateInfo::builder() + let mut vk_rasterization = vk::PipelineRasterizationStateCreateInfo::default() .polygon_mode(if desc.primitive.wireframe { vk::PolygonMode::LINE } else { @@ -429,9 +416,8 @@ impl super::Context { .front_face(map_front_face(desc.primitive.front_face)) .line_width(1.0); let mut vk_depth_clip_state = - vk::PipelineRasterizationDepthClipStateCreateInfoEXT::builder() - .depth_clip_enable(false) - .build(); + vk::PipelineRasterizationDepthClipStateCreateInfoEXT::default() + .depth_clip_enable(false); if desc.primitive.unclipped_depth { vk_rasterization = vk_rasterization.push_next(&mut vk_depth_clip_state); } @@ -442,24 +428,21 @@ impl super::Context { vk::DynamicState::BLEND_CONSTANTS, vk::DynamicState::STENCIL_REFERENCE, ]; - let vk_dynamic_state = vk::PipelineDynamicStateCreateInfo::builder() - .dynamic_states(&dynamic_states) - .build(); + let vk_dynamic_state = + vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_states); - let vk_viewport = vk::PipelineViewportStateCreateInfo::builder() + let vk_viewport = vk::PipelineViewportStateCreateInfo::default() .flags(vk::PipelineViewportStateCreateFlags::empty()) .scissor_count(1) - .viewport_count(1) - .build(); + .viewport_count(1); let vk_sample_mask = [1u32, 0]; - let vk_multisample = vk::PipelineMultisampleStateCreateInfo::builder() + let vk_multisample = vk::PipelineMultisampleStateCreateInfo::default() .rasterization_samples(vk::SampleCountFlags::TYPE_1) - .sample_mask(&vk_sample_mask) - .build(); + .sample_mask(&vk_sample_mask); let mut ds_format = vk::Format::UNDEFINED; - let mut vk_depth_stencil = vk::PipelineDepthStencilStateCreateInfo::builder(); + let mut vk_depth_stencil = vk::PipelineDepthStencilStateCreateInfo::default(); if let Some(ref ds) = desc.depth_stencil { ds_format = super::map_texture_format(ds.format); @@ -491,7 +474,7 @@ impl super::Context { let mut color_formats = Vec::with_capacity(desc.color_targets.len()); let mut vk_attachments = Vec::with_capacity(desc.color_targets.len()); for ct in desc.color_targets { - let mut vk_attachment = vk::PipelineColorBlendAttachmentState::builder() + let mut vk_attachment = vk::PipelineColorBlendAttachmentState::default() .color_write_mask(vk::ColorComponentFlags::from_raw(ct.write_mask.bits())); if let Some(ref blend) = ct.blend { let (color_op, color_src, color_dst) = map_blend_component(&blend.color); @@ -507,19 +490,17 @@ impl super::Context { } color_formats.push(super::map_texture_format(ct.format)); - vk_attachments.push(vk_attachment.build()); + vk_attachments.push(vk_attachment); } - let vk_color_blend = vk::PipelineColorBlendStateCreateInfo::builder() - .attachments(&vk_attachments) - .build(); + let vk_color_blend = + vk::PipelineColorBlendStateCreateInfo::default().attachments(&vk_attachments); - let mut rendering_info = vk::PipelineRenderingCreateInfo::builder() + let mut rendering_info = vk::PipelineRenderingCreateInfo::default() .color_attachment_formats(&color_formats) .depth_attachment_format(ds_format) - .stencil_attachment_format(ds_format) - .build(); + .stencil_attachment_format(ds_format); - let create_info = vk::GraphicsPipelineCreateInfo::builder() + let create_info = vk::GraphicsPipelineCreateInfo::default() .layout(layout.raw) .stages(&stages) .vertex_input_state(&vk_vertex_input) @@ -530,8 +511,7 @@ impl super::Context { .depth_stencil_state(&vk_depth_stencil) .color_blend_state(&vk_color_blend) .dynamic_state(&vk_dynamic_state) - .push_next(&mut rendering_info) - .build(); + .push_next(&mut rendering_info); let mut raw_vec = unsafe { self.device @@ -545,7 +525,7 @@ impl super::Context { unsafe { self.device.core.destroy_shader_module(fs.vk_module, None) }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::PIPELINE, raw, desc.name); + self.set_object_name(raw, desc.name); } super::RenderPipeline { raw, layout } } diff --git a/blade-graphics/src/vulkan/resource.rs b/blade-graphics/src/vulkan/resource.rs index 47608dfc..e637d381 100644 --- a/blade-graphics/src/vulkan/resource.rs +++ b/blade-graphics/src/vulkan/resource.rs @@ -90,12 +90,14 @@ impl super::Context { ) -> crate::AccelerationStructureSizes { let blas_input = self.device.map_acceleration_structure_meshes(meshes); let rt = self.device.ray_tracing.as_ref().unwrap(); - let sizes_raw = unsafe { + let mut sizes_raw = vk::AccelerationStructureBuildSizesInfoKHR::default(); + unsafe { rt.acceleration_structure .get_acceleration_structure_build_sizes( vk::AccelerationStructureBuildTypeKHR::DEVICE, &blas_input.build_info, &blas_input.max_primitive_counts, + &mut sizes_raw, ) }; crate::AccelerationStructureSizes { @@ -108,26 +110,26 @@ impl super::Context { &self, instance_count: u32, ) -> crate::AccelerationStructureSizes { - let geometry = vk::AccelerationStructureGeometryKHR::builder() + let geometry = vk::AccelerationStructureGeometryKHR::default() .geometry_type(vk::GeometryTypeKHR::INSTANCES) .geometry(vk::AccelerationStructureGeometryDataKHR { - instances: vk::AccelerationStructureGeometryInstancesDataKHR::builder().build(), - }) - .build(); + instances: vk::AccelerationStructureGeometryInstancesDataKHR::default(), + }); let geometries = [geometry]; - let build_info = vk::AccelerationStructureBuildGeometryInfoKHR::builder() + let build_info = vk::AccelerationStructureBuildGeometryInfoKHR::default() .ty(vk::AccelerationStructureTypeKHR::TOP_LEVEL) .mode(vk::BuildAccelerationStructureModeKHR::BUILD) - .geometries(&geometries) - .build(); + .geometries(&geometries); let rt = self.device.ray_tracing.as_ref().unwrap(); - let sizes_raw = unsafe { + let mut sizes_raw = vk::AccelerationStructureBuildSizesInfoKHR::default(); + unsafe { rt.acceleration_structure .get_acceleration_structure_build_sizes( vk::AccelerationStructureBuildTypeKHR::DEVICE, &build_info, &[instance_count], + &mut sizes_raw, ) }; crate::AccelerationStructureSizes { @@ -149,10 +151,12 @@ impl super::Context { }); let rt = self.device.ray_tracing.as_ref().unwrap(); for (i, instance) in instances.iter().enumerate() { - let device_address_info = vk::AccelerationStructureDeviceAddressInfoKHR::builder() - .acceleration_structure( - bottom_level[instance.acceleration_structure_index as usize].raw, - ); + let device_address_info = vk::AccelerationStructureDeviceAddressInfoKHR { + acceleration_structure: bottom_level + [instance.acceleration_structure_index as usize] + .raw, + ..Default::default() + }; let vk_instance = vk::AccelerationStructureInstanceKHR { transform: unsafe { mem::transmute(instance.transform) }, instance_custom_index_and_mask: vk::Packed24_8::new( @@ -188,17 +192,17 @@ impl crate::traits::ResourceDevice for super::Context { fn create_buffer(&self, desc: crate::BufferDesc) -> super::Buffer { use vk::BufferUsageFlags as Buf; - let mut vk_info = vk::BufferCreateInfo::builder() - .size(desc.size) - .usage( - Buf::TRANSFER_SRC - | Buf::TRANSFER_DST - | Buf::STORAGE_BUFFER - | Buf::INDEX_BUFFER - | Buf::VERTEX_BUFFER - | Buf::INDIRECT_BUFFER, - ) - .sharing_mode(vk::SharingMode::EXCLUSIVE); + let mut vk_info = vk::BufferCreateInfo { + size: desc.size, + usage: Buf::TRANSFER_SRC + | Buf::TRANSFER_DST + | Buf::STORAGE_BUFFER + | Buf::INDEX_BUFFER + | Buf::VERTEX_BUFFER + | Buf::INDIRECT_BUFFER, + sharing_mode: vk::SharingMode::EXCLUSIVE, + ..Default::default() + }; if self.device.ray_tracing.is_some() { vk_info.usage |= Buf::SHADER_DEVICE_ADDRESS | Buf::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR; @@ -222,7 +226,7 @@ impl crate::traits::ResourceDevice for super::Context { .unwrap() }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::BUFFER, raw, desc.name); + self.set_object_name(raw, desc.name); } super::Buffer { @@ -254,17 +258,19 @@ impl crate::traits::ResourceDevice for super::Context { create_flags |= vk::ImageCreateFlags::CUBE_COMPATIBLE; } - let vk_info = vk::ImageCreateInfo::builder() - .flags(create_flags) - .image_type(map_texture_dimension(desc.dimension)) - .format(super::map_texture_format(desc.format)) - .extent(super::map_extent_3d(&desc.size)) - .mip_levels(desc.mip_level_count) - .array_layers(desc.array_layer_count) - .samples(vk::SampleCountFlags::from_raw(1)) // desc.sample_count - .tiling(vk::ImageTiling::OPTIMAL) - .usage(map_texture_usage(desc.usage, desc.format.aspects())) - .sharing_mode(vk::SharingMode::EXCLUSIVE); + let vk_info = vk::ImageCreateInfo { + flags: create_flags, + image_type: map_texture_dimension(desc.dimension), + format: super::map_texture_format(desc.format), + extent: super::map_extent_3d(&desc.size), + mip_levels: desc.mip_level_count, + array_layers: desc.array_layer_count, + samples: vk::SampleCountFlags::from_raw(1), // desc.sample_count + tiling: vk::ImageTiling::OPTIMAL, + usage: map_texture_usage(desc.usage, desc.format.aspects()), + sharing_mode: vk::SharingMode::EXCLUSIVE, + ..Default::default() + }; let raw = unsafe { self.device.core.create_image(&vk_info, None).unwrap() }; let requirements = unsafe { self.device.core.get_image_memory_requirements(raw) }; @@ -285,7 +291,7 @@ impl crate::traits::ResourceDevice for super::Context { .unwrap() }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::IMAGE, raw, desc.name); + self.set_object_name(raw, desc.name); } super::Texture { @@ -309,15 +315,17 @@ impl crate::traits::ResourceDevice for super::Context { fn create_texture_view(&self, desc: crate::TextureViewDesc) -> super::TextureView { let aspects = desc.format.aspects(); let subresource_range = super::map_subresource_range(desc.subresources, aspects); - let vk_info = vk::ImageViewCreateInfo::builder() - .image(desc.texture.raw) - .view_type(map_view_dimension(desc.dimension)) - .format(super::map_texture_format(desc.format)) - .subresource_range(subresource_range); + let vk_info = vk::ImageViewCreateInfo { + image: desc.texture.raw, + view_type: map_view_dimension(desc.dimension), + format: super::map_texture_format(desc.format), + subresource_range: subresource_range, + ..Default::default() + }; let raw = unsafe { self.device.core.create_image_view(&vk_info, None).unwrap() }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::IMAGE_VIEW, raw, desc.name); + self.set_object_name(raw, desc.name); } super::TextureView { @@ -335,33 +343,33 @@ impl crate::traits::ResourceDevice for super::Context { } fn create_sampler(&self, desc: crate::SamplerDesc) -> super::Sampler { - let mut vk_info = vk::SamplerCreateInfo::builder() - .mag_filter(map_filter_mode(desc.mag_filter)) - .min_filter(map_filter_mode(desc.min_filter)) - .mipmap_mode(map_mip_filter_mode(desc.mipmap_filter)) - .address_mode_u(map_address_mode(desc.address_modes[0])) - .address_mode_v(map_address_mode(desc.address_modes[1])) - .address_mode_w(map_address_mode(desc.address_modes[2])) - .min_lod(desc.lod_min_clamp) - .max_lod(desc.lod_max_clamp.unwrap_or(vk::LOD_CLAMP_NONE)); + let mut vk_info = vk::SamplerCreateInfo { + mag_filter: map_filter_mode(desc.mag_filter), + min_filter: map_filter_mode(desc.min_filter), + mipmap_mode: map_mip_filter_mode(desc.mipmap_filter), + address_mode_u: map_address_mode(desc.address_modes[0]), + address_mode_v: map_address_mode(desc.address_modes[1]), + address_mode_w: map_address_mode(desc.address_modes[2]), + min_lod: desc.lod_min_clamp, + max_lod: desc.lod_max_clamp.unwrap_or(vk::LOD_CLAMP_NONE), + ..Default::default() + }; if let Some(fun) = desc.compare { - vk_info = vk_info - .compare_enable(true) - .compare_op(super::map_comparison(fun)); + vk_info.compare_enable = vk::TRUE; + vk_info.compare_op = super::map_comparison(fun); } if desc.anisotropy_clamp > 1 { - vk_info = vk_info - .anisotropy_enable(true) - .max_anisotropy(desc.anisotropy_clamp as f32); + vk_info.anisotropy_enable = vk::TRUE; + vk_info.max_anisotropy = desc.anisotropy_clamp as f32; } if let Some(color) = desc.border_color { - vk_info = vk_info.border_color(map_border_color(color)); + vk_info.border_color = map_border_color(color); } let raw = unsafe { self.device.core.create_sampler(&vk_info, None).unwrap() }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::SAMPLER, raw, desc.name); + self.set_object_name(raw, desc.name); } super::Sampler { raw } @@ -375,10 +383,12 @@ impl crate::traits::ResourceDevice for super::Context { &self, desc: crate::AccelerationStructureDesc, ) -> super::AccelerationStructure { - let buffer_info = vk::BufferCreateInfo::builder() - .size(desc.size) - .usage(vk::BufferUsageFlags::ACCELERATION_STRUCTURE_STORAGE_KHR) - .sharing_mode(vk::SharingMode::EXCLUSIVE); + let buffer_info = vk::BufferCreateInfo { + size: desc.size, + usage: vk::BufferUsageFlags::ACCELERATION_STRUCTURE_STORAGE_KHR, + sharing_mode: vk::SharingMode::EXCLUSIVE, + ..Default::default() + }; let buffer = unsafe { self.device.core.create_buffer(&buffer_info, None).unwrap() }; let requirements = unsafe { self.device.core.get_buffer_memory_requirements(buffer) }; @@ -399,10 +409,12 @@ impl crate::traits::ResourceDevice for super::Context { vk::AccelerationStructureTypeKHR::BOTTOM_LEVEL } }; - let vk_info = vk::AccelerationStructureCreateInfoKHR::builder() - .ty(raw_ty) - .buffer(buffer) - .size(desc.size); + let vk_info = vk::AccelerationStructureCreateInfoKHR { + ty: raw_ty, + buffer, + size: desc.size, + ..Default::default() + }; let rt = self.device.ray_tracing.as_ref().unwrap(); let raw = unsafe { @@ -412,8 +424,8 @@ impl crate::traits::ResourceDevice for super::Context { }; if !desc.name.is_empty() { - self.set_object_name(vk::ObjectType::BUFFER, buffer, desc.name); - self.set_object_name(vk::ObjectType::ACCELERATION_STRUCTURE_KHR, raw, desc.name); + self.set_object_name(buffer, desc.name); + self.set_object_name(raw, desc.name); } super::AccelerationStructure { raw,