From b81f415917ea65da1339a67756ad1ec7afeb431a Mon Sep 17 00:00:00 2001 From: chyyran Date: Wed, 15 Feb 2023 22:57:20 -0500 Subject: [PATCH] vk: fix lifetime issues with ash Using `build` everywhere was causing miscompilations because of lifetimes leaking. --- librashader-runtime-vk/src/filter_chain.rs | 21 ++-- librashader-runtime-vk/src/filter_pass.rs | 12 +-- librashader-runtime-vk/src/framebuffer.rs | 10 +- .../src/graphics_pipeline.rs | 100 ++++++++++-------- .../src/hello_triangle/command.rs | 4 +- .../src/hello_triangle/framebuffer.rs | 2 +- .../src/hello_triangle/mod.rs | 10 +- .../src/hello_triangle/pipeline.rs | 37 +++---- .../src/hello_triangle/swapchain.rs | 12 +-- .../src/hello_triangle/syncobjects.rs | 2 +- .../src/hello_triangle/vulkan_base.rs | 14 +-- librashader-runtime-vk/src/luts.rs | 49 ++++----- librashader-runtime-vk/src/memory.rs | 14 +-- librashader-runtime-vk/src/render_pass.rs | 20 ++-- librashader-runtime-vk/src/samplers.rs | 2 +- librashader-runtime-vk/src/texture.rs | 59 +++++------ 16 files changed, 186 insertions(+), 182 deletions(-) diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index a4417ef..c0e297f 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -241,7 +241,7 @@ impl FilterChainVulkan { device.create_command_pool( &vk::CommandPoolCreateInfo::builder() .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) - .build(), + , None, )? }; @@ -253,7 +253,7 @@ impl FilterChainVulkan { .command_pool(command_pool) .level(vk::CommandBufferLevel::PRIMARY) .command_buffer_count(1) - .build(), + , )?[0] }; @@ -262,7 +262,7 @@ impl FilterChainVulkan { command_buffer, &vk::CommandBufferBeginInfo::builder() .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT) - .build(), + , )? } @@ -279,9 +279,10 @@ impl FilterChainVulkan { device.end_command_buffer(command_buffer)?; let buffers = [command_buffer]; - let submits = [vk::SubmitInfo::builder().command_buffers(&buffers).build()]; + let submit_info = vk::SubmitInfo::builder() + .command_buffers(&buffers); - device.queue_submit(queue, &submits, vk::Fence::null())?; + device.queue_submit(queue, &[*submit_info], vk::Fence::null())?; device.queue_wait_idle(queue)?; device.free_command_buffers(command_pool, &buffers); device.destroy_command_pool(command_pool, None); @@ -583,21 +584,19 @@ impl FilterChainVulkan { .format(input.format) .view_type(vk::ImageViewType::TYPE_2D) .subresource_range( - vk::ImageSubresourceRange::builder() + *vk::ImageSubresourceRange::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .level_count(1) .layer_count(1) - .build(), + ) .components( - vk::ComponentMapping::builder() + *vk::ComponentMapping::builder() .r(vk::ComponentSwizzle::R) .g(vk::ComponentSwizzle::G) .b(vk::ComponentSwizzle::B) .a(vk::ComponentSwizzle::A) - .build(), - ) - .build(); + ); self.vulkan.device.create_image_view(&create_info, None)? }; diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 9f59464..0ee49a9 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -57,21 +57,21 @@ impl BindSemantics, RawVulkanBuffer> for FilterPass device: &Self::DeviceContext, ) { let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter); - let image_info = [vk::DescriptorImageInfo::builder() + let image_info = vk::DescriptorImageInfo::builder() .sampler(sampler.handle) .image_view(texture.image_view) .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) - .build()]; + ; - let write_desc = [vk::WriteDescriptorSet::builder() + let image_info = [*image_info]; + let write_desc = vk::WriteDescriptorSet::builder() .dst_set(*descriptors) .dst_binding(binding.binding) .dst_array_element(0) .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&image_info) - .build()]; + .image_info(&image_info); unsafe { - device.update_descriptor_sets(&write_desc, &[]); + device.update_descriptor_sets(&[*write_desc], &[]); } } } diff --git a/librashader-runtime-vk/src/framebuffer.rs b/librashader-runtime-vk/src/framebuffer.rs index 0c89e56..d592a0d 100644 --- a/librashader-runtime-vk/src/framebuffer.rs +++ b/librashader-runtime-vk/src/framebuffer.rs @@ -21,22 +21,22 @@ impl OutputImage { .level_count(1) .layer_count(1) .aspect_mask(vk::ImageAspectFlags::COLOR) - .build(); + ; let swizzle_components = vk::ComponentMapping::builder() .r(vk::ComponentSwizzle::R) .g(vk::ComponentSwizzle::G) .b(vk::ComponentSwizzle::B) .a(vk::ComponentSwizzle::A) - .build(); + ; let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(image.format) .image(image.image) - .subresource_range(image_subresource) - .components(swizzle_components) - .build(); + .subresource_range(*image_subresource) + .components(*swizzle_components) + ; let image_view = unsafe { vulkan.device.create_image_view(&view_info, None)? }; diff --git a/librashader-runtime-vk/src/graphics_pipeline.rs b/librashader-runtime-vk/src/graphics_pipeline.rs index 3e0b258..06ca6e7 100644 --- a/librashader-runtime-vk/src/graphics_pipeline.rs +++ b/librashader-runtime-vk/src/graphics_pipeline.rs @@ -11,6 +11,7 @@ use librashader_reflect::reflect::ShaderReflection; use librashader_runtime::render_target::RenderTarget; use std::ffi::CStr; use std::sync::Arc; +use ash::vk::PushConstantRange; const ENTRY_POINT: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"main\0") }; @@ -77,8 +78,7 @@ impl PipelineDescriptors { unsafe { let layout = device.create_descriptor_set_layout( &vk::DescriptorSetLayoutCreateInfo::builder() - .bindings(self.bindings()) - .build(), + .bindings(self.bindings()), None, )?; Ok(layout) @@ -108,25 +108,39 @@ impl PipelineLayoutObjects { let pipeline_create_info = vk::PipelineLayoutCreateInfo::builder().set_layouts(&descriptor_set_layout); - let pipeline_create_info = if let Some(push_constant) = &reflection.push_constant { - let stage_mask = util::binding_stage_to_vulkan_stage(push_constant.stage_mask); - let push_constant_range = [vk::PushConstantRange::builder() - .stage_flags(stage_mask) - .size(push_constant.size) - .build()]; - pipeline_create_info - .push_constant_ranges(&push_constant_range) - .build() - } else { - pipeline_create_info.build() - }; + let push_constant_range = reflection.push_constant.as_ref() + .map(|push_constant| { + let stage_mask = util::binding_stage_to_vulkan_stage(push_constant.stage_mask); + [*vk::PushConstantRange::builder() + .stage_flags(stage_mask) + .size(push_constant.size)] + }); + + let push_constant_range: &[PushConstantRange] = push_constant_range + .as_ref() + .map_or(&[], |o| o); + + let pipeline_create_info = pipeline_create_info + .push_constant_ranges(push_constant_range); + + // let pipeline_create_info = if let Some(push_constant) = &reflection.push_constant { + // let stage_mask = util::binding_stage_to_vulkan_stage(push_constant.stage_mask); + // let push_constant_range = vk::PushConstantRange::builder() + // .stage_flags(stage_mask) + // .size(push_constant.size); + // let push_constant_range = [*push_constant_range]; + // pipeline_create_info + // .push_constant_ranges(&push_constant_range) + // } else { + // pipeline_create_info + // }; let layout = unsafe { device.create_pipeline_layout(&pipeline_create_info, None)? }; let pool_info = vk::DescriptorPoolCreateInfo::builder() .max_sets(replicas) .pool_sizes(&descriptors.pool_sizes) - .build(); + ; let pool = unsafe { device.create_descriptor_pool(&pool_info, None)? }; @@ -134,7 +148,7 @@ impl PipelineLayoutObjects { let alloc_info = vk::DescriptorSetAllocateInfo::builder() .descriptor_pool(pool) .set_layouts(&descriptor_set_layout) - .build(); + ; for _ in 0..replicas { let set = unsafe { device.allocate_descriptor_sets(&alloc_info)? }; @@ -197,7 +211,7 @@ impl VulkanGraphicsPipeline { ) -> error::Result { let input_assembly = vk::PipelineInputAssemblyStateCreateInfo::builder() .topology(vk::PrimitiveTopology::TRIANGLE_STRIP) - .build(); + ; let vao_state = [ vk::VertexInputAttributeDescription { @@ -214,16 +228,16 @@ impl VulkanGraphicsPipeline { }, ]; - let input_binding = [vk::VertexInputBindingDescription::builder() + let input_binding = vk::VertexInputBindingDescription::builder() .binding(0) .stride(4 * std::mem::size_of::() as u32) - .input_rate(vk::VertexInputRate::VERTEX) - .build()]; + .input_rate(vk::VertexInputRate::VERTEX); + let input_binding = [*input_binding]; let pipeline_input_state = vk::PipelineVertexInputStateCreateInfo::builder() .vertex_binding_descriptions(&input_binding) .vertex_attribute_descriptions(&vao_state) - .build(); + ; let raster_state = vk::PipelineRasterizationStateCreateInfo::builder() .polygon_mode(vk::PolygonMode::FILL) @@ -233,21 +247,21 @@ impl VulkanGraphicsPipeline { .rasterizer_discard_enable(false) .depth_bias_enable(false) .line_width(1.0) - .build(); + ; - let attachments = [vk::PipelineColorBlendAttachmentState::builder() + let attachments = vk::PipelineColorBlendAttachmentState::builder() .blend_enable(false) - .color_write_mask(vk::ColorComponentFlags::from_raw(0xf)) - .build()]; + .color_write_mask(vk::ColorComponentFlags::from_raw(0xf)); + let attachments = [*attachments]; let blend_state = vk::PipelineColorBlendStateCreateInfo::builder() .attachments(&attachments) - .build(); + ; let viewport_state = vk::PipelineViewportStateCreateInfo::builder() .viewport_count(1) .scissor_count(1) - .build(); + ; let depth_stencil_state = vk::PipelineDepthStencilStateCreateInfo::builder() .depth_test_enable(false) @@ -256,30 +270,31 @@ impl VulkanGraphicsPipeline { .depth_bounds_test_enable(false) .min_depth_bounds(1.0) .max_depth_bounds(1.0) - .build(); + ; let multisample_state = vk::PipelineMultisampleStateCreateInfo::builder() .rasterization_samples(vk::SampleCountFlags::TYPE_1) - .build(); + ; let states = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dynamic_state = vk::PipelineDynamicStateCreateInfo::builder() .dynamic_states(&states) - .build(); + ; let shader_stages = [ vk::PipelineShaderStageCreateInfo::builder() .stage(vk::ShaderStageFlags::VERTEX) .name(ENTRY_POINT) .module(vertex_module.shader) - .build(), + , vk::PipelineShaderStageCreateInfo::builder() .stage(vk::ShaderStageFlags::FRAGMENT) .name(ENTRY_POINT) .module(fragment_module.shader) - .build(), + , ]; + let shader_stages = [*shader_stages[0], *shader_stages[1]]; let mut pipeline_info = vk::GraphicsPipelineCreateInfo::builder() .stages(&shader_stages) .vertex_input_state(&pipeline_input_state) @@ -296,12 +311,11 @@ impl VulkanGraphicsPipeline { pipeline_info = pipeline_info.render_pass(render_pass.handle) } - let pipeline_info = [pipeline_info.build()]; let pipeline = unsafe { // panic_safety: if this is successful this should return 1 pipelines. device - .create_graphics_pipelines(*cache, &pipeline_info, None) + .create_graphics_pipelines(*cache, &[*pipeline_info], None) .map_err(|e| e.1)?[0] }; @@ -320,10 +334,10 @@ impl VulkanGraphicsPipeline { let vertex_info = vk::ShaderModuleCreateInfo::builder() .code(shader_assembly.vertex.as_ref()) - .build(); + ; let fragment_info = vk::ShaderModuleCreateInfo::builder() .code(shader_assembly.fragment.as_ref()) - .build(); + ; let vertex_module = VulkanShaderModule::new(device, &vertex_info)?; let fragment_module = VulkanShaderModule::new(device, &fragment_info)?; @@ -344,7 +358,7 @@ impl VulkanGraphicsPipeline { if let Some(pipeline_data) = pipeline_data.as_ref() { cache_info = cache_info.initial_data(pipeline_data); } - let cache_info = cache_info.build(); + let cache_info = cache_info; let pipeline_cache = unsafe { device.create_pipeline_cache(&cache_info, None)? }; @@ -416,7 +430,7 @@ impl VulkanGraphicsPipeline { .width(output.output.size.width) .height(output.output.size.height) .layers(1) - .build(), + , None, )? }; @@ -436,18 +450,18 @@ impl VulkanGraphicsPipeline { offset: vk::Offset2D { x: 0, y: 0 }, extent: output.output.size.into(), }) - .build(); + ; unsafe { device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE); } Ok(Some(framebuffer)) } else { - let attachments = [vk::RenderingAttachmentInfo::builder() + let attachments = vk::RenderingAttachmentInfo::builder() .load_op(vk::AttachmentLoadOp::DONT_CARE) .store_op(vk::AttachmentStoreOp::STORE) .image_layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL) - .image_view(output.output.image_view) - .build()]; + .image_view(output.output.image_view); + let attachments = [*attachments]; let rendering_info = vk::RenderingInfo::builder() .layer_count(1) @@ -456,7 +470,7 @@ impl VulkanGraphicsPipeline { extent: output.output.size.into(), }) .color_attachments(&attachments) - .build(); + ; unsafe { device.cmd_begin_rendering(cmd, &rendering_info); diff --git a/librashader-runtime-vk/src/hello_triangle/command.rs b/librashader-runtime-vk/src/hello_triangle/command.rs index 49472ae..4e7fc52 100644 --- a/librashader-runtime-vk/src/hello_triangle/command.rs +++ b/librashader-runtime-vk/src/hello_triangle/command.rs @@ -17,7 +17,7 @@ impl VulkanCommandPool { let create_info = vk::CommandPoolCreateInfo::builder() .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) .queue_family_index(indices.graphics_family()) - .build(); + ; unsafe { let pool = base.device.create_command_pool(&create_info, None)?; @@ -25,7 +25,7 @@ impl VulkanCommandPool { .command_pool(pool) .level(vk::CommandBufferLevel::PRIMARY) .command_buffer_count(frames_in_flight) - .build(); + ; let buffers = base.device.allocate_command_buffers(&buffer_info)?; Ok(VulkanCommandPool { diff --git a/librashader-runtime-vk/src/hello_triangle/framebuffer.rs b/librashader-runtime-vk/src/hello_triangle/framebuffer.rs index 46dc564..17dc7ef 100644 --- a/librashader-runtime-vk/src/hello_triangle/framebuffer.rs +++ b/librashader-runtime-vk/src/hello_triangle/framebuffer.rs @@ -20,7 +20,7 @@ impl VulkanFramebuffer { .width(width) .height(height) .layers(1) - .build(); + ; unsafe { let framebuffer = device.create_framebuffer(&framebuffer_info, None)?; diff --git a/librashader-runtime-vk/src/hello_triangle/mod.rs b/librashader-runtime-vk/src/hello_triangle/mod.rs index 61db692..a2cc7ea 100644 --- a/librashader-runtime-vk/src/hello_triangle/mod.rs +++ b/librashader-runtime-vk/src/hello_triangle/mod.rs @@ -101,7 +101,7 @@ impl VulkanWindow { ..Default::default() }) .clear_values(&clear_values) - .build(); + ; vulkan.base.device.cmd_begin_render_pass( cmd, @@ -287,7 +287,7 @@ impl VulkanWindow { // let blit_subresource = vk::ImageSubresourceLayers::builder() // .layer_count(1) // .aspect_mask(vk::ImageAspectFlags::COLOR) - // .build(); + // ; // // let src_offsets = [ // vk::Offset3D { x: 0, y: 0, z: 0 }, @@ -344,12 +344,12 @@ impl VulkanWindow { let stage_mask = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]; let cmd = [cmd]; - let submit_info = [vk::SubmitInfo::builder() + let submit_info = [*vk::SubmitInfo::builder() .wait_dst_stage_mask(&stage_mask) .wait_semaphores(&image_available) .signal_semaphores(&render_finished) .command_buffers(&cmd) - .build()]; + ]; vulkan .base @@ -363,7 +363,7 @@ impl VulkanWindow { .wait_semaphores(&render_finished) .swapchains(&swapchain) .image_indices(&swapchain_index) - .build(); + ; vulkan .swapchain diff --git a/librashader-runtime-vk/src/hello_triangle/pipeline.rs b/librashader-runtime-vk/src/hello_triangle/pipeline.rs index 78fb98e..a49e227 100644 --- a/librashader-runtime-vk/src/hello_triangle/pipeline.rs +++ b/librashader-runtime-vk/src/hello_triangle/pipeline.rs @@ -154,7 +154,7 @@ impl VulkanPipeline { .module(vertex_shader_info.module) .stage(vk::ShaderStageFlags::VERTEX) .name(ENTRY_POINT) - .build(); + ; let mut frag_spv_file = Cursor::new(&include_bytes!("../../shader/triangle_simple/frag.spv")[..]); @@ -165,17 +165,17 @@ impl VulkanPipeline { .module(frag_shader_info.module) .stage(vk::ShaderStageFlags::FRAGMENT) .name(ENTRY_POINT) - .build(); + ; let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() .vertex_attribute_descriptions(&[]) .vertex_binding_descriptions(&[]) - .build(); + ; let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo::builder() .primitive_restart_enable(false) .topology(vk::PrimitiveTopology::TRIANGLE_LIST) - .build(); + ; let viewports = [vk::Viewport { x: 0.0, @@ -200,7 +200,7 @@ impl VulkanPipeline { let states = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dynamic_state = vk::PipelineDynamicStateCreateInfo::builder() .dynamic_states(&states) - .build(); + ; let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder() .scissors(&scissors) @@ -214,15 +214,15 @@ impl VulkanPipeline { .line_width(1.0f32) .cull_mode(vk::CullModeFlags::BACK) .front_face(vk::FrontFace::CLOCKWISE) - .build(); + ; let multisample = vk::PipelineMultisampleStateCreateInfo::builder() .rasterization_samples(vk::SampleCountFlags::TYPE_1) .min_sample_shading(1.0f32) .sample_shading_enable(false) - .build(); + ; - let color_blend_attachment = [vk::PipelineColorBlendAttachmentState::builder() + let color_blend_attachment = [*vk::PipelineColorBlendAttachmentState::builder() .blend_enable(false) .color_write_mask(vk::ColorComponentFlags::RGBA) .src_color_blend_factor(vk::BlendFactor::ONE) @@ -231,18 +231,8 @@ impl VulkanPipeline { .src_alpha_blend_factor(vk::BlendFactor::ONE) .dst_alpha_blend_factor(vk::BlendFactor::ZERO) .alpha_blend_op(vk::BlendOp::ADD) - .build()]; - // - // let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { - // blend_enable: 0, - // src_color_blend_factor: vk::BlendFactor::SRC_COLOR, - // dst_color_blend_factor: vk::BlendFactor::ONE_MINUS_DST_COLOR, - // color_blend_op: vk::BlendOp::ADD, - // src_alpha_blend_factor: vk::BlendFactor::ZERO, - // dst_alpha_blend_factor: vk::BlendFactor::ZERO, - // alpha_blend_op: vk::BlendOp::ADD, - // color_write_mask: vk::ColorComponentFlags::RGBA, - // }]; + ]; + let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() .logic_op(vk::LogicOp::COPY) .attachments(&color_blend_attachment); @@ -285,7 +275,7 @@ impl VulkanPipeline { .create_render_pass(&renderpass_create_info, None) .unwrap(); - let infos = [vertex_stage_info, frag_stage_info]; + let infos = [*vertex_stage_info, *frag_stage_info]; let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() .stages(&infos) .vertex_input_state(&vertex_input_state_info) @@ -297,12 +287,13 @@ impl VulkanPipeline { .dynamic_state(&dynamic_state) .layout(pipeline_layout) .render_pass(renderpass); + let graphic_pipeline_info = [*graphic_pipeline_info]; let graphics_pipelines = base .device .create_graphics_pipelines( vk::PipelineCache::null(), - &[graphic_pipeline_info.build()], + &graphic_pipeline_info, None, ) .expect("Unable to create graphics pipeline"); @@ -324,7 +315,7 @@ pub struct ShaderModule { impl ShaderModule { pub fn new(device: &ash::Device, spirv: Vec) -> VkResult { - let create_info = vk::ShaderModuleCreateInfo::builder().code(&spirv).build(); + let create_info = vk::ShaderModuleCreateInfo::builder().code(&spirv); let module = unsafe { device.create_shader_module(&create_info, None)? }; diff --git a/librashader-runtime-vk/src/hello_triangle/swapchain.rs b/librashader-runtime-vk/src/hello_triangle/swapchain.rs index 12d9f11..8d1f6e0 100644 --- a/librashader-runtime-vk/src/hello_triangle/swapchain.rs +++ b/librashader-runtime-vk/src/hello_triangle/swapchain.rs @@ -58,7 +58,7 @@ impl VulkanSwapchain { .image_array_layers(1) // todo: switch to IMAGE_USAGE_TRANSFER_DST .image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT) - .build(); + ; let loader = ash::extensions::khr::Swapchain::new(&base.instance, &base.device); @@ -122,7 +122,7 @@ impl VulkanSwapchain { layer_count: 1, }) .image(*image) - .build(); + ; let view = unsafe { base.device.create_image_view(&create_info, None)? }; // unsafe { @@ -136,7 +136,7 @@ impl VulkanSwapchain { // b"SwapchainImage\0", // )) // .object_type(vk::ObjectType::IMAGE) - // .build(), + // , // ) // .expect("could not set object name"); // base.debug @@ -149,7 +149,7 @@ impl VulkanSwapchain { // b"SwapchainImageView\0", // )) // .object_type(vk::ObjectType::IMAGE_VIEW) - // .build(), + // , // ) // .expect("could not set object name"); // } @@ -177,7 +177,7 @@ impl VulkanSwapchain { layer_count: 1, }) .image(*image) - .build(); + ; let view = unsafe { base.device.create_image_view(&create_info, None)? }; // unsafe { @@ -191,7 +191,7 @@ impl VulkanSwapchain { // b"RenderImageView\0", // )) // .object_type(vk::ObjectType::IMAGE_VIEW) - // .build(), + // , // ) // .expect("could not set object name"); // } diff --git a/librashader-runtime-vk/src/hello_triangle/syncobjects.rs b/librashader-runtime-vk/src/hello_triangle/syncobjects.rs index 9a53ee5..ffbc614 100644 --- a/librashader-runtime-vk/src/hello_triangle/syncobjects.rs +++ b/librashader-runtime-vk/src/hello_triangle/syncobjects.rs @@ -23,7 +23,7 @@ impl SyncObjects { device.create_fence( &vk::FenceCreateInfo::builder() .flags(vk::FenceCreateFlags::SIGNALED) - .build(), + , None, )?, ) diff --git a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs index 0119efd..d6d49bb 100644 --- a/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs +++ b/librashader-runtime-vk/src/hello_triangle/vulkan_base.rs @@ -34,7 +34,7 @@ impl VulkanBase { .engine_version(0) .application_version(0) .api_version(vk::make_api_version(0, 1, 3, 0)) - .build(); + ; dbg!("entry"); // todo: make this xplat @@ -50,7 +50,7 @@ impl VulkanBase { .application_info(&app_info) .enabled_layer_names(&layers) .enabled_extension_names(&extensions) - .build(); + ; let instance = unsafe { entry.create_instance(&create_info, None)? }; @@ -88,20 +88,20 @@ impl VulkanBase { let _debug = [unsafe { CStr::from_bytes_with_nul_unchecked(KHRONOS_VALIDATION).as_ptr() }]; let indices = find_queue_family(instance, *physical_device); - let queue_info = [vk::DeviceQueueCreateInfo::builder() + let queue_info = [*vk::DeviceQueueCreateInfo::builder() .queue_family_index(indices.graphics_family()) .queue_priorities(&[1.0f32]) - .build()]; + ]; // let physical_device_features = vk::PhysicalDeviceFeatures::default(); let mut physical_device_features = vk::PhysicalDeviceVulkan13Features::builder() .dynamic_rendering(true) - .build(); + ; // let mut physical_device_features = // vk::PhysicalDeviceFeatures2::builder().push_next(&mut physical_device_features) - // .build(); + // ; let extensions = [ ash::extensions::khr::Swapchain::name().as_ptr(), @@ -114,7 +114,7 @@ impl VulkanBase { .enabled_extension_names(&extensions) .push_next(&mut physical_device_features) // .enabled_features(&physical_device_features) - .build(); + ; let device = unsafe { instance.create_device(*physical_device, &device_create_info, None)? }; diff --git a/librashader-runtime-vk/src/luts.rs b/librashader-runtime-vk/src/luts.rs index cbc5a0c..8473099 100644 --- a/librashader-runtime-vk/src/luts.rs +++ b/librashader-runtime-vk/src/luts.rs @@ -38,7 +38,7 @@ impl LutTexture { | vk::ImageUsageFlags::TRANSFER_DST, ) .initial_layout(vk::ImageLayout::UNDEFINED) - .build(); + ; let texture = unsafe { vulkan.device.create_image(&image_info, None)? }; @@ -51,22 +51,22 @@ impl LutTexture { .level_count(image_info.mip_levels) .layer_count(1) .aspect_mask(vk::ImageAspectFlags::COLOR) - .build(); + ; let swizzle_components = vk::ComponentMapping::builder() .r(vk::ComponentSwizzle::R) .g(vk::ComponentSwizzle::G) .b(vk::ComponentSwizzle::B) .a(vk::ComponentSwizzle::A) - .build(); + ; let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(vk::Format::B8G8R8A8_UNORM) .image(texture) - .subresource_range(image_subresource) - .components(swizzle_components) - .build(); + .subresource_range(*image_subresource) + .components(*swizzle_components) + ; let texture_view = unsafe { vulkan.device.create_image_view(&view_info, None)? }; @@ -99,6 +99,17 @@ impl LutTexture { vk::QUEUE_FAMILY_IGNORED, ); + let builder = vk::BufferImageCopy::builder() + .image_subresource( + *vk::ImageSubresourceLayers::builder() + .aspect_mask(vk::ImageAspectFlags::COLOR) + .mip_level(0) + .base_array_layer(0) + .layer_count(1) + , + ) + .image_extent(image.size.into()); + vulkan.device.cmd_copy_buffer_to_image( cmd, staging.handle, @@ -108,17 +119,7 @@ impl LutTexture { } else { vk::ImageLayout::TRANSFER_DST_OPTIMAL }, - &[vk::BufferImageCopy::builder() - .image_subresource( - vk::ImageSubresourceLayers::builder() - .aspect_mask(vk::ImageAspectFlags::COLOR) - .mip_level(0) - .base_array_layer(0) - .layer_count(1) - .build(), - ) - .image_extent(image.size.into()) - .build()], + &[*builder], ) } @@ -149,21 +150,21 @@ impl LutTexture { .mip_level(level - 1) .base_array_layer(0) .layer_count(1) - .build(); + ; let dst_subresource = vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(level) .base_array_layer(0) .layer_count(1) - .build(); + ; - let image_blit = [vk::ImageBlit::builder() - .src_subresource(src_subresource) + let image_blit = vk::ImageBlit::builder() + .src_subresource(*src_subresource) .src_offsets(src_offsets) - .dst_subresource(dst_subresource) + .dst_subresource(*dst_subresource) .dst_offsets(dst_offsets) - .build()]; + ; unsafe { util::vulkan_image_layout_transition_levels( @@ -188,7 +189,7 @@ impl LutTexture { vk::ImageLayout::GENERAL, texture, vk::ImageLayout::GENERAL, - &image_blit, + &[*image_blit], config.filter_mode.into(), ); } diff --git a/librashader-runtime-vk/src/memory.rs b/librashader-runtime-vk/src/memory.rs index e97459b..b7425a7 100644 --- a/librashader-runtime-vk/src/memory.rs +++ b/librashader-runtime-vk/src/memory.rs @@ -73,7 +73,7 @@ impl VulkanBuffer { .size(size as vk::DeviceSize) .usage(usage) .sharing_mode(vk::SharingMode::EXCLUSIVE) - .build(); + ; let buffer = device.create_buffer(&buffer_info, None)?; let memory_reqs = device.get_buffer_memory_requirements(buffer); @@ -165,21 +165,21 @@ impl RawVulkanBuffer { storage: &impl UniformStorageAccess, ) -> error::Result<()> { unsafe { - let buffer_info = [vk::DescriptorBufferInfo::builder() + let buffer_info = vk::DescriptorBufferInfo::builder() .buffer(self.buffer.handle) .offset(0) - .range(storage.ubo_slice().len() as vk::DeviceSize) - .build()]; + .range(storage.ubo_slice().len() as vk::DeviceSize); - let write_info = [vk::WriteDescriptorSet::builder() + let buffer_info = [*buffer_info]; + let write_info = vk::WriteDescriptorSet::builder() .descriptor_type(vk::DescriptorType::UNIFORM_BUFFER) .dst_set(descriptor_set) .dst_binding(binding) .dst_array_element(0) .buffer_info(&buffer_info) - .build()]; + ; - self.buffer.device.update_descriptor_sets(&write_info, &[]) + self.buffer.device.update_descriptor_sets(&[*write_info], &[]) } Ok(()) } diff --git a/librashader-runtime-vk/src/render_pass.rs b/librashader-runtime-vk/src/render_pass.rs index 881807f..6a04993 100644 --- a/librashader-runtime-vk/src/render_pass.rs +++ b/librashader-runtime-vk/src/render_pass.rs @@ -12,7 +12,7 @@ pub struct VulkanRenderPass { impl VulkanRenderPass { pub fn create_render_pass(device: &ash::Device, format: vk::Format) -> error::Result { // format should never be undefined. - let attachment = [vk::AttachmentDescription::builder() + let attachment = vk::AttachmentDescription::builder() .flags(vk::AttachmentDescriptionFlags::empty()) .format(format) .samples(SampleCountFlags::TYPE_1) @@ -21,24 +21,24 @@ impl VulkanRenderPass { .stencil_load_op(AttachmentLoadOp::DONT_CARE) .stencil_store_op(AttachmentStoreOp::DONT_CARE) .initial_layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL) - .final_layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL) - .build()]; + .final_layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL); + let attachment = [*attachment]; - let attachment_ref = [vk::AttachmentReference::builder() + let attachment_ref = vk::AttachmentReference::builder() .attachment(0) - .layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL) - .build()]; + .layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL); + let attachment_ref = [*attachment_ref]; - let subpass = [vk::SubpassDescription::builder() + let subpass = vk::SubpassDescription::builder() .pipeline_bind_point(PipelineBindPoint::GRAPHICS) - .color_attachments(&attachment_ref) - .build()]; + .color_attachments(&attachment_ref); + let subpass = [*subpass]; let renderpass_info = vk::RenderPassCreateInfo::builder() .flags(vk::RenderPassCreateFlags::empty()) .attachments(&attachment) .subpasses(&subpass) - .build(); + ; unsafe { let rp = device.create_render_pass(&renderpass_info, None)?; diff --git a/librashader-runtime-vk/src/samplers.rs b/librashader-runtime-vk/src/samplers.rs index 7be35f8..091bf97 100644 --- a/librashader-runtime-vk/src/samplers.rs +++ b/librashader-runtime-vk/src/samplers.rs @@ -30,7 +30,7 @@ impl VulkanSampler { .address_mode_u(wrap.into()) .address_mode_v(wrap.into()) .address_mode_w(wrap.into()) - .build(); + ; let sampler = unsafe { device.create_sampler(&create_info, None)? }; diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index b43c4b0..ba47452 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -59,7 +59,7 @@ impl OwnedImage { ) .sharing_mode(vk::SharingMode::EXCLUSIVE) .initial_layout(vk::ImageLayout::UNDEFINED) - .build(); + ; let image = unsafe { device.create_image(&image_create_info, None)? }; let mem_reqs = unsafe { device.get_image_memory_requirements(image) }; @@ -71,22 +71,22 @@ impl OwnedImage { .level_count(image_create_info.mip_levels) .layer_count(1) .aspect_mask(vk::ImageAspectFlags::COLOR) - .build(); + ; let swizzle_components = vk::ComponentMapping::builder() .r(vk::ComponentSwizzle::R) .g(vk::ComponentSwizzle::G) .b(vk::ComponentSwizzle::B) .a(vk::ComponentSwizzle::A) - .build(); + ; let view_info = vk::ImageViewCreateInfo::builder() .view_type(vk::ImageViewType::TYPE_2D) .format(format.into()) .image(image) - .subresource_range(image_subresource) - .components(swizzle_components) - .build(); + .subresource_range(*image_subresource) + .components(*swizzle_components) + ; let image_view = unsafe { device.create_image_view(&view_info, None)? }; @@ -200,7 +200,7 @@ impl OwnedImage { base_array_layer: 0, layer_count: vk::REMAINING_ARRAY_LAYERS, }) - .build(); + ; let mipchain_barrier = vk::ImageMemoryBarrier::builder() .src_access_mask(vk::AccessFlags::empty()) @@ -217,7 +217,7 @@ impl OwnedImage { level_count: vk::REMAINING_MIP_LEVELS, layer_count: vk::REMAINING_ARRAY_LAYERS, }) - .build(); + ; unsafe { self.device.cmd_pipeline_barrier( @@ -227,7 +227,7 @@ impl OwnedImage { vk::DependencyFlags::empty(), &[], &[], - &[input_barrier, mipchain_barrier], + &[*input_barrier, *mipchain_barrier], ); for level in 1..self.levels { @@ -248,7 +248,7 @@ impl OwnedImage { level_count: 1, layer_count: vk::REMAINING_ARRAY_LAYERS, }) - .build(); + ; self.device.cmd_pipeline_barrier( cmd, @@ -257,7 +257,7 @@ impl OwnedImage { vk::DependencyFlags::empty(), &[], &[], - &[next_barrier], + &[*next_barrier], ); } @@ -287,21 +287,20 @@ impl OwnedImage { .mip_level(level - 1) .base_array_layer(0) .layer_count(1) - .build(); + ; let dst_subresource = vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(level) .base_array_layer(0) .layer_count(1) - .build(); + ; - let image_blit = [vk::ImageBlit::builder() - .src_subresource(src_subresource) + let image_blit = vk::ImageBlit::builder() + .src_subresource(*src_subresource) .src_offsets(src_offsets) - .dst_subresource(dst_subresource) - .dst_offsets(dst_offsets) - .build()]; + .dst_subresource(*dst_subresource) + .dst_offsets(dst_offsets); self.device.cmd_blit_image( cmd, @@ -309,7 +308,7 @@ impl OwnedImage { vk::ImageLayout::TRANSFER_SRC_OPTIMAL, self.image.image, vk::ImageLayout::TRANSFER_DST_OPTIMAL, - &image_blit, + &[*image_blit], vk::Filter::LINEAR, ); } @@ -331,7 +330,7 @@ impl OwnedImage { base_array_layer: 0, layer_count: vk::REMAINING_ARRAY_LAYERS, }) - .build(); + ; let mipchain_barrier = vk::ImageMemoryBarrier::builder() .src_access_mask(vk::AccessFlags::TRANSFER_WRITE) @@ -348,7 +347,7 @@ impl OwnedImage { level_count: 1, layer_count: vk::REMAINING_ARRAY_LAYERS, }) - .build(); + ; // next past waits for ALL_GRAPHICS, use dependency chain and FRAGMENT_SHADER dst stage // to ensure that next pass doesn't start until mipchain is complete. @@ -359,7 +358,7 @@ impl OwnedImage { vk::DependencyFlags::empty(), &[], &[], - &[input_barrier, mipchain_barrier], + &[*input_barrier, *mipchain_barrier], ); } } @@ -373,25 +372,25 @@ impl OwnedImage { ) { let region = vk::ImageCopy::builder() .src_subresource( - vk::ImageSubresourceLayers::builder() + *vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(0) .base_array_layer(0) .layer_count(1) - .build(), + , ) .dst_subresource( - vk::ImageSubresourceLayers::builder() + *vk::ImageSubresourceLayers::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .mip_level(0) .base_array_layer(0) .layer_count(1) - .build(), + , ) .src_offset(Default::default()) .dst_offset(Default::default()) .extent(source.size.into()) - .build(); + ; unsafe { util::vulkan_image_layout_transition_levels( @@ -415,7 +414,7 @@ impl OwnedImage { source_layout, self.image.image, vk::ImageLayout::TRANSFER_DST_OPTIMAL, - &[region], + &[*region], ); util::vulkan_image_layout_transition_levels( &self.device, @@ -457,13 +456,13 @@ impl OwnedImage { &vk::ClearColorValue { float32: [0.0, 0.0, 0.0, 0.0], }, - &[vk::ImageSubresourceRange::builder() + &[*vk::ImageSubresourceRange::builder() .aspect_mask(vk::ImageAspectFlags::COLOR) .base_mip_level(0) .level_count(1) .base_array_layer(0) .layer_count(1) - .build()], + ], ); util::vulkan_image_layout_transition_levels(