From 78ed2572913071256f732caceb27102f172d16b5 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 2 Oct 2023 14:41:29 +1100 Subject: [PATCH] update to ash builders --- gb-emu/src/renderer/vulkan/vulkan.rs | 156 ++++++++++++++++----------- 1 file changed, 93 insertions(+), 63 deletions(-) diff --git a/gb-emu/src/renderer/vulkan/vulkan.rs b/gb-emu/src/renderer/vulkan/vulkan.rs index ccc6d08..f78759b 100644 --- a/gb-emu/src/renderer/vulkan/vulkan.rs +++ b/gb-emu/src/renderer/vulkan/vulkan.rs @@ -125,16 +125,17 @@ impl VulkanWindowInner { #[cfg(any(target_os = "macos", target_os = "ios"))] { - extension_names.push(vk::KhrPortabilityEnumerationFn::NAME.as_ptr()); - extension_names.push(vk::KhrGetPhysicalDeviceProperties2Fn::NAME.as_ptr()); + extension_names.push(vk::KhrPortabilityEnumerationFn::name().as_ptr()); + extension_names.push(vk::KhrGetPhysicalDeviceProperties2Fn::name().as_ptr()); } - let appinfo = vk::ApplicationInfo::default() + let appinfo = vk::ApplicationInfo::builder() .application_name(&name) .engine_name(&name) .application_version(0) .engine_version(0) - .api_version(vk::make_api_version(0, 1, 0, 0)); + .api_version(vk::make_api_version(0, 1, 0, 0)) + .build(); let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) { vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR @@ -142,10 +143,11 @@ impl VulkanWindowInner { vk::InstanceCreateFlags::default() }; - let create_info = vk::InstanceCreateInfo::default() + let create_info = vk::InstanceCreateInfo::builder() .application_info(&appinfo) .enabled_extension_names(&extension_names) - .flags(create_flags); + .flags(create_flags) + .build(); let instance = entry.create_instance(&create_info, None).unwrap(); @@ -188,9 +190,9 @@ impl VulkanWindowInner { .expect("Couldn't find suitable device."); let queue_family_index = queue_family_index as u32; let device_extension_names_raw = [ - Swapchain::NAME.as_ptr(), + Swapchain::name().as_ptr(), #[cfg(any(target_os = "macos", target_os = "ios"))] - vk::KhrPortabilitySubsetFn::NAME.as_ptr(), + vk::KhrPortabilitySubsetFn::name().as_ptr(), ]; let features = vk::PhysicalDeviceFeatures { shader_clip_distance: 1, @@ -198,14 +200,16 @@ impl VulkanWindowInner { }; let priorities = [1.0]; - let queue_info = vk::DeviceQueueCreateInfo::default() + let queue_info = vk::DeviceQueueCreateInfo::builder() .queue_family_index(queue_family_index) - .queue_priorities(&priorities); + .queue_priorities(&priorities) + .build(); - let device_create_info = vk::DeviceCreateInfo::default() + let device_create_info = vk::DeviceCreateInfo::builder() .queue_create_infos(std::slice::from_ref(&queue_info)) .enabled_extension_names(&device_extension_names_raw) - .enabled_features(&features); + .enabled_features(&features) + .build(); let device = instance .create_device(pdevice, &device_create_info, None) @@ -251,7 +255,7 @@ impl VulkanWindowInner { .unwrap_or(vk::PresentModeKHR::FIFO); let swapchain_loader = Swapchain::new(&instance, &device); - let swapchain_create_info = vk::SwapchainCreateInfoKHR::default() + let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder() .surface(surface) .min_image_count(desired_image_count) .image_color_space(surface_format.color_space) @@ -263,22 +267,25 @@ impl VulkanWindowInner { .composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE) .present_mode(present_mode) .clipped(true) - .image_array_layers(1); + .image_array_layers(1) + .build(); let swapchain = swapchain_loader .create_swapchain(&swapchain_create_info, None) .unwrap(); - let pool_create_info = vk::CommandPoolCreateInfo::default() + let pool_create_info = vk::CommandPoolCreateInfo::builder() .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) - .queue_family_index(queue_family_index); + .queue_family_index(queue_family_index) + .build(); let pool = device.create_command_pool(&pool_create_info, None).unwrap(); - let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::default() + let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder() .command_buffer_count(2) .command_pool(pool) - .level(vk::CommandBufferLevel::PRIMARY); + .level(vk::CommandBufferLevel::PRIMARY) + .build(); let command_buffers = device .allocate_command_buffers(&command_buffer_allocate_info) @@ -290,7 +297,7 @@ impl VulkanWindowInner { let present_image_views: Vec = present_images .iter() .map(|&image| { - let create_view_info = vk::ImageViewCreateInfo::default() + let create_view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(surface_format.format) .components(vk::ComponentMapping { @@ -306,14 +313,16 @@ impl VulkanWindowInner { base_array_layer: 0, layer_count: 1, }) - .image(image); + .image(image) + .build(); device.create_image_view(&create_view_info, None).unwrap() }) .collect(); let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); - let fence_create_info = - vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED); + let fence_create_info = vk::FenceCreateInfo::builder() + .flags(vk::FenceCreateFlags::SIGNALED) + .build(); let draw_commands_reuse_fence = device .create_fence(&fence_create_info, None) @@ -352,14 +361,16 @@ impl VulkanWindowInner { ..Default::default() }]; - let subpass = vk::SubpassDescription::default() + let subpass = vk::SubpassDescription::builder() .color_attachments(&color_attachment_refs) - .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS); + .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) + .build(); - let renderpass_create_info = vk::RenderPassCreateInfo::default() + let renderpass_create_info = vk::RenderPassCreateInfo::builder() .attachments(&renderpass_attachments) .subpasses(std::slice::from_ref(&subpass)) - .dependencies(&dependencies); + .dependencies(&dependencies) + .build(); let renderpass = device .create_render_pass(&renderpass_create_info, None) @@ -369,12 +380,13 @@ impl VulkanWindowInner { .iter() .map(|&present_image_view| { let framebuffer_attachments = [present_image_view]; - let frame_buffer_create_info = vk::FramebufferCreateInfo::default() + let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() .render_pass(renderpass) .attachments(&framebuffer_attachments) .width(surface_resolution.width) .height(surface_resolution.height) - .layers(1); + .layers(1) + .build(); device .create_framebuffer(&frame_buffer_create_info, None) @@ -530,13 +542,15 @@ impl VulkanWindowInner { &[], &[texture_barrier], ); - let buffer_copy_regions = vk::BufferImageCopy::default() + let buffer_copy_regions = vk::BufferImageCopy::builder() .image_subresource( - vk::ImageSubresourceLayers::default() + vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) - .layer_count(1), + .layer_count(1) + .build(), ) - .image_extent(image_extent.into()); + .image_extent(image_extent.into()) + .build(); device.cmd_copy_buffer_to_image( texture_command_buffer, @@ -617,9 +631,10 @@ impl VulkanWindowInner { descriptor_count: 1, }, ]; - let descriptor_pool_info = vk::DescriptorPoolCreateInfo::default() + let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder() .pool_sizes(&descriptor_sizes) - .max_sets(1); + .max_sets(1) + .build(); let descriptor_pool = device .create_descriptor_pool(&descriptor_pool_info, None) @@ -639,16 +654,19 @@ impl VulkanWindowInner { ..Default::default() }, ]; - let descriptor_info = - vk::DescriptorSetLayoutCreateInfo::default().bindings(&desc_layout_bindings); + let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder() + .bindings(&desc_layout_bindings) + .build(); let desc_set_layouts = [device .create_descriptor_set_layout(&descriptor_info, None) .unwrap()]; - let desc_alloc_info = vk::DescriptorSetAllocateInfo::default() + let desc_alloc_info = vk::DescriptorSetAllocateInfo::builder() .descriptor_pool(descriptor_pool) - .set_layouts(&desc_set_layouts); + .set_layouts(&desc_set_layouts) + .build(); + let descriptor_sets = device.allocate_descriptor_sets(&desc_alloc_info).unwrap(); let tex_descriptor = vk::DescriptorImageInfo { @@ -668,15 +686,16 @@ impl VulkanWindowInner { device.update_descriptor_sets(&write_desc_sets, &[]); let shader = ash::util::read_spv(&mut std::io::Cursor::new(SHADER)).unwrap(); - let shader_info = vk::ShaderModuleCreateInfo::default().code(&shader); + let shader_info = vk::ShaderModuleCreateInfo::builder().code(&shader).build(); println!("shader info: {:#?}", shader_info); let shader_module = device .create_shader_module(&shader_info, None) .expect("Error creating shader module"); - let layout_create_info = - vk::PipelineLayoutCreateInfo::default().set_layouts(&desc_set_layouts); + let layout_create_info = vk::PipelineLayoutCreateInfo::builder() + .set_layouts(&desc_set_layouts) + .build(); let pipeline_layout = device .create_pipeline_layout(&layout_create_info, None) @@ -711,9 +730,10 @@ impl VulkanWindowInner { format: vk::Format::R32G32B32A32_SFLOAT, offset: 0, }]; - let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default() + let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() .vertex_attribute_descriptions(&vertex_input_attribute_descriptions) - .vertex_binding_descriptions(&vertex_input_binding_descriptions); + .vertex_binding_descriptions(&vertex_input_binding_descriptions) + .build(); let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { topology: vk::PrimitiveTopology::TRIANGLE_LIST, @@ -728,9 +748,10 @@ impl VulkanWindowInner { max_depth: 1.0, }]; let scissors = [surface_resolution.into()]; - let viewport_state_info = vk::PipelineViewportStateCreateInfo::default() + let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder() .scissors(&scissors) - .viewports(&viewports); + .viewports(&viewports) + .build(); let rasterization_info = vk::PipelineRasterizationStateCreateInfo { front_face: vk::FrontFace::COUNTER_CLOCKWISE, @@ -739,8 +760,9 @@ impl VulkanWindowInner { ..Default::default() }; - let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::default() - .rasterization_samples(vk::SampleCountFlags::TYPE_1); + let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder() + .rasterization_samples(vk::SampleCountFlags::TYPE_1) + .build(); let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { blend_enable: 0, @@ -752,15 +774,17 @@ impl VulkanWindowInner { alpha_blend_op: vk::BlendOp::ADD, color_write_mask: vk::ColorComponentFlags::RGBA, }]; - let color_blend_state = vk::PipelineColorBlendStateCreateInfo::default() + let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() .logic_op(vk::LogicOp::CLEAR) - .attachments(&color_blend_attachment_states); + .attachments(&color_blend_attachment_states) + .build(); let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; - let dynamic_state_info = - vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_state); + let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder() + .dynamic_states(&dynamic_state) + .build(); - let graphic_pipeline_infos = vk::GraphicsPipelineCreateInfo::default() + let graphic_pipeline_infos = vk::GraphicsPipelineCreateInfo::builder() .stages(&shader_stage_create_infos) .vertex_input_state(&vertex_input_state_info) .input_assembly_state(&vertex_input_assembly_state_info) @@ -770,7 +794,8 @@ impl VulkanWindowInner { .color_blend_state(&color_blend_state) .dynamic_state(&dynamic_state_info) .layout(pipeline_layout) - .render_pass(renderpass); + .render_pass(renderpass) + .build(); let graphics_pipelines = device .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_infos], None) @@ -874,13 +899,15 @@ impl VulkanWindowInner { &[], &[texture_barrier], ); - let buffer_copy_regions = vk::BufferImageCopy::default() + let buffer_copy_regions = vk::BufferImageCopy::builder() .image_subresource( - vk::ImageSubresourceLayers::default() + vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) - .layer_count(1), + .layer_count(1) + .build(), ) - .image_extent(self.image_extent.into()); + .image_extent(self.image_extent.into()) + .build(); device.cmd_copy_buffer_to_image( texture_command_buffer, @@ -934,11 +961,12 @@ impl VulkanWindowInner { }, }]; - let render_pass_begin_info = vk::RenderPassBeginInfo::default() + let render_pass_begin_info = vk::RenderPassBeginInfo::builder() .render_pass(self.renderpass) .framebuffer(self.framebuffers[present_index as usize]) .render_area(self.surface_resolution.into()) - .clear_values(&clear_values); + .clear_values(&clear_values) + .build(); record_submit_commandbuffer( &self.device, @@ -1074,8 +1102,9 @@ fn record_submit_commandbuffer( ) .expect("Reset command buffer failed."); - let command_buffer_begin_info = vk::CommandBufferBeginInfo::default() - .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT); + let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder() + .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT) + .build(); device .begin_command_buffer(command_buffer, &command_buffer_begin_info) @@ -1087,11 +1116,12 @@ fn record_submit_commandbuffer( let command_buffers = vec![command_buffer]; - let submit_info = vk::SubmitInfo::default() + let submit_info = vk::SubmitInfo::builder() .wait_semaphores(wait_semaphores) .wait_dst_stage_mask(wait_mask) .command_buffers(&command_buffers) - .signal_semaphores(signal_semaphores); + .signal_semaphores(signal_semaphores) + .build(); device .queue_submit(submit_queue, &[submit_info], command_buffer_reuse_fence)