2022-12-07 02:05:10 -05:00
|
|
|
use crate::error;
|
2023-01-09 22:54:54 -05:00
|
|
|
use crate::filter_chain::Vulkan;
|
2022-12-11 01:06:28 -05:00
|
|
|
use crate::renderpass::VulkanRenderPass;
|
2023-01-09 22:54:54 -05:00
|
|
|
use crate::texture::OwnedTexture;
|
2022-12-21 21:39:31 -05:00
|
|
|
use ash::vk;
|
2023-01-09 22:54:54 -05:00
|
|
|
use ash::vk::{ImageAspectFlags, ImageViewType};
|
2022-12-21 21:39:31 -05:00
|
|
|
use librashader_common::Size;
|
2022-12-07 02:05:10 -05:00
|
|
|
|
|
|
|
pub struct VulkanFramebuffer {
|
|
|
|
pub device: ash::Device,
|
|
|
|
pub framebuffer: vk::Framebuffer,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for VulkanFramebuffer {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
if self.framebuffer != vk::Framebuffer::null() {
|
|
|
|
self.device.destroy_framebuffer(self.framebuffer, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 22:53:28 -05:00
|
|
|
//
|
2023-01-10 00:11:05 -05:00
|
|
|
// pub struct OwnedFramebuffer {
|
2023-01-09 22:53:28 -05:00
|
|
|
// pub size: Size<u32>,
|
2023-01-10 00:11:05 -05:00
|
|
|
// pub image: OwnedTexture,
|
|
|
|
// pub render_pass: VulkanRenderPass,
|
|
|
|
// pub framebuffer: VulkanFramebuffer,
|
|
|
|
// pub view: vk::ImageView,
|
2023-01-09 22:53:28 -05:00
|
|
|
// }
|
|
|
|
//
|
2023-01-10 00:11:05 -05:00
|
|
|
// impl OwnedFramebuffer {
|
|
|
|
// pub fn new(
|
|
|
|
// vulkan: &Vulkan,
|
|
|
|
// size: Size<u32>,
|
|
|
|
// render_pass: VulkanRenderPass,
|
|
|
|
// max_miplevels: u32,
|
|
|
|
// ) -> error::Result<Self> {
|
|
|
|
// let image = OwnedTexture::new(vulkan, size, render_pass.format, max_miplevels)?;
|
|
|
|
// let fb_view = image.create_texture_view()?;
|
2023-01-09 22:53:28 -05:00
|
|
|
// let framebuffer = unsafe {
|
|
|
|
// vulkan.device.create_framebuffer(
|
|
|
|
// &vk::FramebufferCreateInfo::builder()
|
|
|
|
// .render_pass(render_pass.handle)
|
2023-01-10 00:11:05 -05:00
|
|
|
// .attachments(&[image.image_view])
|
|
|
|
// .width(image.image.size.width)
|
|
|
|
// .height(image.image.size.height)
|
2023-01-09 22:53:28 -05:00
|
|
|
// .layers(1)
|
|
|
|
// .build(),
|
|
|
|
// None,
|
|
|
|
// )?
|
|
|
|
// };
|
|
|
|
//
|
2023-01-10 00:11:05 -05:00
|
|
|
// Ok(OwnedFramebuffer {
|
|
|
|
// size,
|
2023-01-09 22:53:28 -05:00
|
|
|
// image,
|
2023-01-10 00:11:05 -05:00
|
|
|
// view: fb_view,
|
2023-01-09 22:53:28 -05:00
|
|
|
// render_pass,
|
2023-01-10 00:11:05 -05:00
|
|
|
// framebuffer: VulkanFramebuffer {
|
|
|
|
// device: vulkan.device.clone(),
|
|
|
|
// framebuffer,
|
|
|
|
// },
|
2023-01-09 22:53:28 -05:00
|
|
|
// })
|
|
|
|
// }
|
2023-01-10 00:11:05 -05:00
|
|
|
// }
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub(crate) struct OutputFramebuffer {
|
|
|
|
pub framebuffer: vk::Framebuffer,
|
|
|
|
pub size: Size<u32>,
|
|
|
|
device: ash::Device,
|
|
|
|
image_view: vk::ImageView,
|
|
|
|
}
|
|
|
|
|
2023-01-09 22:53:28 -05:00
|
|
|
//
|
2023-01-10 00:11:05 -05:00
|
|
|
// pub struct OutputFramebuffer<'a> {
|
|
|
|
// device: ash::Device,
|
|
|
|
// render_pass: &'a VulkanRenderPass,
|
|
|
|
// pub handle: vk::Framebuffer,
|
|
|
|
// pub size: Size<u32>,
|
|
|
|
// pub image: vk::Image,
|
|
|
|
// pub image_view: vk::ImageView,
|
2023-01-09 22:54:54 -05:00
|
|
|
// }
|
2023-01-10 00:11:05 -05:00
|
|
|
//
|
|
|
|
impl OutputFramebuffer {
|
|
|
|
pub fn new(vulkan: &Vulkan, render_pass: &VulkanRenderPass, image: vk::Image, size: Size<u32>) -> error::Result<OutputFramebuffer> {
|
|
|
|
let image_subresource = vk::ImageSubresourceRange::builder()
|
|
|
|
.base_mip_level(0)
|
|
|
|
.base_array_layer(0)
|
|
|
|
.level_count(1)
|
|
|
|
.layer_count(1)
|
|
|
|
.aspect_mask(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 mut view_info = vk::ImageViewCreateInfo::builder()
|
|
|
|
.view_type(ImageViewType::TYPE_2D)
|
|
|
|
.format(render_pass.format.into())
|
|
|
|
.image(image.clone())
|
|
|
|
.subresource_range(image_subresource)
|
|
|
|
.components(swizzle_components)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let image_view = unsafe { vulkan.device.create_image_view(&view_info, None)? };
|
|
|
|
|
|
|
|
let framebuffer = unsafe {
|
|
|
|
vulkan.device.create_framebuffer(
|
|
|
|
&vk::FramebufferCreateInfo::builder()
|
|
|
|
.render_pass(render_pass.handle)
|
|
|
|
.attachments(&[image_view])
|
|
|
|
.width(size.width)
|
|
|
|
.height(size.height)
|
|
|
|
.layers(1)
|
|
|
|
.build(),
|
|
|
|
None,
|
|
|
|
)?
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(OutputFramebuffer {
|
|
|
|
device: vulkan.device.clone(),
|
|
|
|
size,
|
|
|
|
framebuffer,
|
|
|
|
image_view,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// pub fn get_renderpass_begin_info(&self, area: vk::Rect2D, clear: Option<&[vk::ClearValue]>) -> vk::RenderPassBeginInfo {
|
|
|
|
// let mut builder = vk::RenderPassBeginInfo::builder()
|
|
|
|
// .render_pass(self.render_pass.handle)
|
|
|
|
// .framebuffer(self.handle)
|
|
|
|
// .render_area(area);
|
|
|
|
//
|
|
|
|
// if let Some(clear) = clear {
|
|
|
|
// builder = builder.clear_values(clear)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// builder.build()
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for OutputFramebuffer {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
|
|
|
if self.framebuffer != vk::Framebuffer::null() {
|
|
|
|
self.device.destroy_framebuffer(self.framebuffer, None);
|
|
|
|
}
|
|
|
|
if self.image_view != vk::ImageView::null() {
|
|
|
|
self.device.destroy_image_view(self.image_view, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|