vk: remove renderpass stuff

This commit is contained in:
chyyran 2023-01-11 18:04:35 -05:00
parent b8cfeda08a
commit dd16dbd5d2
7 changed files with 11 additions and 151 deletions

View file

@ -2,15 +2,6 @@ use crate::error;
use crate::vulkan_primitives::VulkanBuffer; use crate::vulkan_primitives::VulkanBuffer;
use ash::vk; use ash::vk;
#[rustfmt::skip]
pub(crate) static VBO_OFFSCREEN: &[f32; 16] = &[
// Offscreen
-1.0, -1.0, 0.0, 0.0,
-1.0, 1.0, 0.0, 1.0,
1.0, -1.0, 1.0, 0.0,
1.0, 1.0, 1.0, 1.0,
];
#[rustfmt::skip] #[rustfmt::skip]
pub(crate) static VBO_DEFAULT_FINAL: &[f32; 16] = &[ pub(crate) static VBO_DEFAULT_FINAL: &[f32; 16] = &[
// Final // Final
@ -39,17 +30,13 @@ impl DrawQuad {
device, device,
mem_props, mem_props,
vk::BufferUsageFlags::VERTEX_BUFFER, vk::BufferUsageFlags::VERTEX_BUFFER,
2 * std::mem::size_of::<[f32; 16]>(), std::mem::size_of::<[f32; 16]>(),
)?; )?;
{ {
let mut map = buffer.map()?; let mut map = buffer.map()?;
unsafe { unsafe {
map.copy_from(0, bytemuck::cast_slice(VBO_OFFSCREEN)); map.copy_from(0, bytemuck::cast_slice(VBO_DEFAULT_FINAL));
map.copy_from(
std::mem::size_of::<[f32; 16]>(),
bytemuck::cast_slice(VBO_DEFAULT_FINAL),
);
} }
} }
Ok(DrawQuad { Ok(DrawQuad {
@ -59,17 +46,12 @@ impl DrawQuad {
} }
pub fn bind_vbo(&self, cmd: vk::CommandBuffer, vbo: VboType) { pub fn bind_vbo(&self, cmd: vk::CommandBuffer, vbo: VboType) {
let offset = match vbo {
VboType::Offscreen => 0,
VboType::Final => std::mem::size_of::<[f32; 16]>(),
};
unsafe { unsafe {
self.device.cmd_bind_vertex_buffers( self.device.cmd_bind_vertex_buffers(
cmd, cmd,
0, 0,
&[self.buffer.handle], &[self.buffer.handle],
&[offset as vk::DeviceSize], &[0],
) )
} }
} }

View file

@ -22,7 +22,7 @@ use librashader_runtime::uniforms::UniformStorage;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::error::Error; use std::error::Error;
use std::path::Path; use std::path::Path;
use crate::draw_quad::{DrawQuad, VBO_DEFAULT_FINAL, VBO_OFFSCREEN}; use crate::draw_quad::DrawQuad;
use crate::framebuffer::OutputFramebuffer; use crate::framebuffer::OutputFramebuffer;
use crate::render_target::{DEFAULT_MVP, RenderTarget}; use crate::render_target::{DEFAULT_MVP, RenderTarget};
use crate::viewport::Viewport; use crate::viewport::Viewport;
@ -362,22 +362,11 @@ impl FilterChainVulkan {
uniform_bindings.insert(UniformBinding::TextureSize(*semantics), param.offset); uniform_bindings.insert(UniformBinding::TextureSize(*semantics), param.offset);
} }
// default to something sane
if source.format == ImageFormat::Unknown {
source.format = ImageFormat::R8G8B8A8Unorm
}
// preset overrides shader
if let Some(format) = config.get_format_override() {
source.format = format;
}
let graphics_pipeline = VulkanGraphicsPipeline::new( let graphics_pipeline = VulkanGraphicsPipeline::new(
&vulkan.device, &vulkan.device,
&vulkan.pipeline_cache, &vulkan.pipeline_cache,
&spirv_words, &spirv_words,
&reflection, &reflection,
source.format,
images, images,
)?; )?;
@ -535,7 +524,8 @@ impl FilterChainVulkan {
target.image.clone())?, target.image.clone())?,
}; };
pass.draw(cmd, index, &self.common, count as u32, 0, viewport, &original, &source, &out)?; pass.draw(cmd, index, &self.common, count as u32, 0,
viewport, &original, &source, &out)?;
// for second to last pass, we want to transition to copy instead. // for second to last pass, we want to transition to copy instead.
out.output.end_pass(cmd); out.output.end_pass(cmd);
@ -560,7 +550,6 @@ 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,*/
viewport.output.clone())?, viewport.output.clone())?,
}; };

View file

@ -104,23 +104,6 @@ impl FilterPass {
output.output.begin_pass(cmd); output.output.begin_pass(cmd);
// let render_pass_info = vk::RenderPassBeginInfo::builder()
// .framebuffer(output.output.framebuffer)
// .render_pass(self.graphics_pipeline.render_pass.handle)
// .clear_values(&[vk::ClearValue {
// color: vk::ClearColorValue {
// float32: [0.0, 0.0, 0.0, 0.0]
// }
// }])
// // 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() 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)
@ -173,7 +156,6 @@ 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_rendering(cmd); parent.device.cmd_end_rendering(cmd);
} }
Ok(()) Ok(())

View file

@ -1,7 +1,6 @@
use crate::{error, util}; use crate::{error, util};
use crate::filter_chain::Vulkan; use crate::filter_chain::Vulkan;
use crate::renderpass::VulkanRenderPass; use crate::texture::{VulkanImage};
use crate::texture::{OwnedTexture, VulkanImage};
use ash::vk; use ash::vk;
use ash::vk::{ImageAspectFlags, ImageViewType}; use ash::vk::{ImageAspectFlags, ImageViewType};
use librashader_common::Size; use librashader_common::Size;
@ -81,30 +80,4 @@ impl OutputFramebuffer {
vk::QUEUE_FAMILY_IGNORED) vk::QUEUE_FAMILY_IGNORED)
} }
} }
// 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);
// }
}
}
} }

View file

@ -9,7 +9,6 @@ mod filter_pass;
mod framebuffer; mod framebuffer;
mod hello_triangle; mod hello_triangle;
mod luts; mod luts;
mod renderpass;
mod render_target; mod render_target;
mod samplers; mod samplers;
mod texture; mod texture;

View file

@ -1,56 +0,0 @@
use crate::error;
use ash::vk;
use ash::vk::{
AttachmentLoadOp, AttachmentStoreOp, ImageLayout, PipelineBindPoint, SampleCountFlags,
};
use librashader_common::ImageFormat;
pub struct VulkanRenderPass {
pub handle: vk::RenderPass,
pub format: ImageFormat,
}
impl VulkanRenderPass {
pub fn create_render_pass(
device: &ash::Device,
mut format: ImageFormat,
) -> error::Result<Self> {
// default to reasonable choice if unknown
if format == ImageFormat::Unknown {
format = ImageFormat::R8G8B8A8Unorm;
}
let attachment = vk::AttachmentDescription::builder()
.flags(vk::AttachmentDescriptionFlags::empty())
.format(format.into())
.samples(SampleCountFlags::TYPE_1)
.load_op(AttachmentLoadOp::DONT_CARE)
.store_op(AttachmentStoreOp::STORE)
.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();
let attachment_ref = vk::AttachmentReference::builder()
.attachment(0)
.layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL)
.build();
let subpass = vk::SubpassDescription::builder()
.pipeline_bind_point(PipelineBindPoint::GRAPHICS)
.color_attachments(&[attachment_ref])
.build();
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)?;
Ok(Self { handle: rp, format })
}
}
}

View file

@ -1,4 +1,3 @@
use crate::renderpass::VulkanRenderPass;
use crate::{error, util}; use crate::{error, util};
use ash::vk; use ash::vk;
use librashader_common::ImageFormat; use librashader_common::ImageFormat;
@ -24,7 +23,7 @@ impl PipelineDescriptors {
pub fn add_ubo_binding(&mut self, ubo_meta: Option<&UboReflection>) { pub fn add_ubo_binding(&mut self, ubo_meta: Option<&UboReflection>) {
if let Some(ubo_meta) = ubo_meta && !ubo_meta.stage_mask.is_empty() { if let Some(ubo_meta) = ubo_meta && !ubo_meta.stage_mask.is_empty() {
let mut ubo_mask = util::binding_stage_to_vulkan_stage(ubo_meta.stage_mask); let ubo_mask = util::binding_stage_to_vulkan_stage(ubo_meta.stage_mask);
self.layout_bindings.push(vk::DescriptorSetLayoutBinding { self.layout_bindings.push(vk::DescriptorSetLayoutBinding {
binding: ubo_meta.binding, binding: ubo_meta.binding,
@ -42,7 +41,7 @@ impl PipelineDescriptors {
} }
pub fn add_texture_bindings<'a>(&mut self, textures: impl Iterator<Item = &'a TextureBinding>) { pub fn add_texture_bindings<'a>(&mut self, textures: impl Iterator<Item = &'a TextureBinding>) {
let mut texture_mask = vk::ShaderStageFlags::FRAGMENT; let texture_mask = vk::ShaderStageFlags::FRAGMENT;
for texture in textures { for texture in textures {
self.layout_bindings.push(vk::DescriptorSetLayoutBinding { self.layout_bindings.push(vk::DescriptorSetLayoutBinding {
binding: texture.binding, binding: texture.binding,
@ -102,11 +101,11 @@ impl PipelineLayoutObjects {
let mut descriptor_set_layout = [descriptors.create_descriptor_set_layout(device)?]; let mut descriptor_set_layout = [descriptors.create_descriptor_set_layout(device)?];
let mut 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 pipeline_create_info = if let Some(push_constant) = &reflection.push_constant {
let mut stage_mask = util::binding_stage_to_vulkan_stage(push_constant.stage_mask); let stage_mask = util::binding_stage_to_vulkan_stage(push_constant.stage_mask);
let push_constant_range = [vk::PushConstantRange::builder() let push_constant_range = [vk::PushConstantRange::builder()
.stage_flags(stage_mask) .stage_flags(stage_mask)
.size(push_constant.size) .size(push_constant.size)
@ -186,14 +185,8 @@ impl VulkanGraphicsPipeline {
cache: &vk::PipelineCache, cache: &vk::PipelineCache,
shader_assembly: &ShaderCompilerOutput<Vec<u32>>, shader_assembly: &ShaderCompilerOutput<Vec<u32>>,
reflection: &ShaderReflection, reflection: &ShaderReflection,
mut format: ImageFormat,
replicas: u32, replicas: u32,
) -> error::Result<VulkanGraphicsPipeline> { ) -> error::Result<VulkanGraphicsPipeline> {
// default to something sane
if format == ImageFormat::Unknown {
format = ImageFormat::R8G8B8A8Unorm
}
// shader_vulkan 1927 (init_pipeline_layout) // shader_vulkan 1927 (init_pipeline_layout)
let pipeline_layout = PipelineLayoutObjects::new(&reflection, replicas, device)?; let pipeline_layout = PipelineLayoutObjects::new(&reflection, replicas, device)?;
@ -299,7 +292,6 @@ 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())
.layout(pipeline_layout.layout) .layout(pipeline_layout.layout)
.build(); .build();
@ -313,7 +305,6 @@ impl VulkanGraphicsPipeline {
Ok(VulkanGraphicsPipeline { Ok(VulkanGraphicsPipeline {
layout: pipeline_layout, layout: pipeline_layout,
// render_pass,
pipeline, pipeline,
}) })
} }