vk: port to use dynamic rendering
This commit is contained in:
parent
02b3b8baff
commit
b8cfeda08a
|
@ -171,7 +171,7 @@ impl FilterChainFrameIntermediates {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispose_outputs(&mut self, output_framebuffer: OutputFramebuffer) {
|
pub(crate) fn dispose_outputs(&mut self, output_framebuffer: OutputFramebuffer) {
|
||||||
self.framebuffers.push(output_framebuffer.framebuffer);
|
// self.framebuffers.push(output_framebuffer.framebuffer);
|
||||||
self.image_views.push(output_framebuffer.image_view);
|
self.image_views.push(output_framebuffer.image_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ impl FilterChainVulkan {
|
||||||
x: 0.0,
|
x: 0.0,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
mvp: DEFAULT_MVP,
|
mvp: DEFAULT_MVP,
|
||||||
output: OutputFramebuffer::new(&self.vulkan, &pass.graphics_pipeline.render_pass,
|
output: OutputFramebuffer::new(&self.vulkan, /*&pass.graphics_pipeline.render_pass,*/
|
||||||
target.image.clone())?,
|
target.image.clone())?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -560,7 +560,7 @@ impl FilterChainVulkan {
|
||||||
y: viewport.y,
|
y: viewport.y,
|
||||||
mvp: viewport.mvp.unwrap_or(DEFAULT_MVP),
|
mvp: viewport.mvp.unwrap_or(DEFAULT_MVP),
|
||||||
output: OutputFramebuffer::new(&self.vulkan,
|
output: OutputFramebuffer::new(&self.vulkan,
|
||||||
&pass.graphics_pipeline.render_pass,
|
/*&pass.graphics_pipeline.render_pass,*/
|
||||||
viewport.output.clone())?,
|
viewport.output.clone())?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -104,25 +104,44 @@ impl FilterPass {
|
||||||
|
|
||||||
output.output.begin_pass(cmd);
|
output.output.begin_pass(cmd);
|
||||||
|
|
||||||
let render_pass_info = vk::RenderPassBeginInfo::builder()
|
// let render_pass_info = vk::RenderPassBeginInfo::builder()
|
||||||
.framebuffer(output.output.framebuffer)
|
// .framebuffer(output.output.framebuffer)
|
||||||
.render_pass(self.graphics_pipeline.render_pass.handle)
|
// .render_pass(self.graphics_pipeline.render_pass.handle)
|
||||||
.clear_values(&[vk::ClearValue {
|
// .clear_values(&[vk::ClearValue {
|
||||||
color: vk::ClearColorValue {
|
// color: vk::ClearColorValue {
|
||||||
float32: [0.0, 0.0, 0.0, 0.0]
|
// float32: [0.0, 0.0, 0.0, 0.0]
|
||||||
}
|
// }
|
||||||
}])
|
// }])
|
||||||
// always render into the full output, regardless of viewport settings.
|
// // always render into the full output, regardless of viewport settings.
|
||||||
|
// .render_area(vk::Rect2D {
|
||||||
|
// offset: vk::Offset2D {
|
||||||
|
// x: 0,
|
||||||
|
// y: 0,
|
||||||
|
// },
|
||||||
|
// extent: output.output.size.into(),
|
||||||
|
// }).build();
|
||||||
|
|
||||||
|
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()];
|
||||||
|
|
||||||
|
let rendering_info = vk::RenderingInfo::builder()
|
||||||
|
.layer_count(1)
|
||||||
.render_area(vk::Rect2D {
|
.render_area(vk::Rect2D {
|
||||||
offset: vk::Offset2D {
|
offset: vk::Offset2D {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
},
|
},
|
||||||
extent: output.output.size.into(),
|
extent: output.output.size.into(),
|
||||||
}).build();
|
})
|
||||||
|
.color_attachments(&attachments);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
parent.device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE);
|
parent.device.cmd_begin_rendering(cmd, &rendering_info);
|
||||||
|
// parent.device.cmd_begin_render_pass(cmd, &render_pass_info, vk::SubpassContents::INLINE);
|
||||||
parent.device.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.graphics_pipeline.pipeline);
|
parent.device.cmd_bind_pipeline(cmd, vk::PipelineBindPoint::GRAPHICS, self.graphics_pipeline.pipeline);
|
||||||
|
|
||||||
// todo: allow frames in flight.
|
// todo: allow frames in flight.
|
||||||
|
@ -154,7 +173,8 @@ impl FilterPass {
|
||||||
|
|
||||||
parent.device.cmd_set_viewport(cmd, 0, &[output.output.size.into()]);
|
parent.device.cmd_set_viewport(cmd, 0, &[output.output.size.into()]);
|
||||||
parent.device.cmd_draw(cmd, 4, 1, 0, 0);
|
parent.device.cmd_draw(cmd, 4, 1, 0, 0);
|
||||||
parent.device.cmd_end_render_pass(cmd);
|
// parent.device.cmd_end_render_pass(cmd);
|
||||||
|
parent.device.cmd_end_rendering(cmd);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use librashader_common::Size;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct OutputFramebuffer {
|
pub(crate) struct OutputFramebuffer {
|
||||||
pub framebuffer: vk::Framebuffer,
|
|
||||||
pub size: Size<u32>,
|
pub size: Size<u32>,
|
||||||
pub image_view: vk::ImageView,
|
pub image_view: vk::ImageView,
|
||||||
device: ash::Device,
|
device: ash::Device,
|
||||||
|
@ -16,7 +15,7 @@ pub(crate) struct OutputFramebuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputFramebuffer {
|
impl OutputFramebuffer {
|
||||||
pub fn new(vulkan: &Vulkan, render_pass: &VulkanRenderPass,
|
pub fn new(vulkan: &Vulkan,
|
||||||
image: VulkanImage) -> error::Result<OutputFramebuffer> {
|
image: VulkanImage) -> error::Result<OutputFramebuffer> {
|
||||||
let image_subresource = vk::ImageSubresourceRange::builder()
|
let image_subresource = vk::ImageSubresourceRange::builder()
|
||||||
.base_mip_level(0)
|
.base_mip_level(0)
|
||||||
|
@ -44,24 +43,10 @@ impl OutputFramebuffer {
|
||||||
let image_view = unsafe { vulkan.device.create_image_view(
|
let image_view = unsafe { vulkan.device.create_image_view(
|
||||||
&view_info, None)? };
|
&view_info, None)? };
|
||||||
|
|
||||||
let framebuffer = unsafe {
|
|
||||||
vulkan.device.create_framebuffer(
|
|
||||||
&vk::FramebufferCreateInfo::builder()
|
|
||||||
.render_pass(render_pass.handle)
|
|
||||||
.attachments(&[image_view])
|
|
||||||
.width(image.size.width)
|
|
||||||
.height(image.size.height)
|
|
||||||
.layers(1)
|
|
||||||
.build(),
|
|
||||||
None,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(OutputFramebuffer {
|
Ok(OutputFramebuffer {
|
||||||
device: vulkan.device.clone(),
|
device: vulkan.device.clone(),
|
||||||
size: image.size,
|
size: image.size,
|
||||||
image: image.image,
|
image: image.image,
|
||||||
framebuffer,
|
|
||||||
image_view,
|
image_view,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,13 +86,26 @@ impl VulkanBase {
|
||||||
.queue_priorities(&[1.0f32])
|
.queue_priorities(&[1.0f32])
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let physical_device_features = vk::PhysicalDeviceFeatures::default();
|
// 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 device_create_info = vk::DeviceCreateInfo::builder()
|
let device_create_info = vk::DeviceCreateInfo::builder()
|
||||||
.queue_create_infos(&[queue_info])
|
.queue_create_infos(&[queue_info])
|
||||||
.enabled_layer_names(&[debug])
|
.enabled_layer_names(&[debug])
|
||||||
.enabled_extension_names(&[ash::extensions::khr::Swapchain::name().as_ptr()])
|
.enabled_extension_names(&[
|
||||||
.enabled_features(&physical_device_features)
|
ash::extensions::khr::Swapchain::name().as_ptr(),
|
||||||
|
ash::extensions::khr::DynamicRendering::name().as_ptr(),
|
||||||
|
])
|
||||||
|
.push_next(&mut physical_device_features)
|
||||||
|
// .enabled_features(&physical_device_features)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let device =
|
let device =
|
||||||
|
|
|
@ -177,7 +177,6 @@ impl Drop for VulkanShaderModule {
|
||||||
|
|
||||||
pub struct VulkanGraphicsPipeline {
|
pub struct VulkanGraphicsPipeline {
|
||||||
pub layout: PipelineLayoutObjects,
|
pub layout: PipelineLayoutObjects,
|
||||||
pub render_pass: VulkanRenderPass,
|
|
||||||
pub pipeline: vk::Pipeline,
|
pub pipeline: vk::Pipeline,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,8 +289,6 @@ impl VulkanGraphicsPipeline {
|
||||||
.build(),
|
.build(),
|
||||||
];
|
];
|
||||||
|
|
||||||
let render_pass = VulkanRenderPass::create_render_pass(device, format).unwrap();
|
|
||||||
|
|
||||||
let pipeline_info = vk::GraphicsPipelineCreateInfo::builder()
|
let pipeline_info = vk::GraphicsPipelineCreateInfo::builder()
|
||||||
.stages(&shader_stages)
|
.stages(&shader_stages)
|
||||||
.vertex_input_state(&pipeline_input_state)
|
.vertex_input_state(&pipeline_input_state)
|
||||||
|
@ -302,7 +299,7 @@ impl VulkanGraphicsPipeline {
|
||||||
.viewport_state(&viewport_state)
|
.viewport_state(&viewport_state)
|
||||||
.depth_stencil_state(&depth_stencil_state)
|
.depth_stencil_state(&depth_stencil_state)
|
||||||
.dynamic_state(&dynamic_state)
|
.dynamic_state(&dynamic_state)
|
||||||
.render_pass(render_pass.handle.clone())
|
// .render_pass(render_pass.handle.clone())
|
||||||
.layout(pipeline_layout.layout)
|
.layout(pipeline_layout.layout)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -316,7 +313,7 @@ impl VulkanGraphicsPipeline {
|
||||||
|
|
||||||
Ok(VulkanGraphicsPipeline {
|
Ok(VulkanGraphicsPipeline {
|
||||||
layout: pipeline_layout,
|
layout: pipeline_layout,
|
||||||
render_pass,
|
// render_pass,
|
||||||
pipeline,
|
pipeline,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue