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