From f61bed3a22b4ce8f4a33497b5bd08492c6869db9 Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 26 Feb 2024 00:21:51 -0500 Subject: [PATCH] vk: remove unneeded device arcs --- librashader-runtime-vk/src/draw_quad.rs | 19 +++++-------------- librashader-runtime-vk/src/filter_chain.rs | 11 ++++++----- librashader-runtime-vk/src/filter_pass.rs | 9 +++------ librashader-runtime-vk/src/framebuffer.rs | 16 ++++++---------- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/librashader-runtime-vk/src/draw_quad.rs b/librashader-runtime-vk/src/draw_quad.rs index 9b9731a..9f11959 100644 --- a/librashader-runtime-vk/src/draw_quad.rs +++ b/librashader-runtime-vk/src/draw_quad.rs @@ -49,7 +49,6 @@ static VBO_DATA: &[VertexInput; 8] = &concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_V pub struct DrawQuad { buffer: VulkanBuffer, - device: Arc, } impl DrawQuad { @@ -69,31 +68,23 @@ impl DrawQuad { slice.copy_from_slice(bytemuck::cast_slice(VBO_DATA)); } - Ok(DrawQuad { - buffer, - device: device.clone(), - }) + Ok(DrawQuad { buffer }) } - pub fn bind_vbo_for_frame(&self, cmd: vk::CommandBuffer) { + pub fn bind_vbo_for_frame(&self, device: &ash::Device, cmd: vk::CommandBuffer) { unsafe { - self.device.cmd_bind_vertex_buffers( - cmd, - 0, - &[self.buffer.handle], - &[0 as vk::DeviceSize], - ) + device.cmd_bind_vertex_buffers(cmd, 0, &[self.buffer.handle], &[0 as vk::DeviceSize]) } } - pub fn draw_quad(&self, cmd: vk::CommandBuffer, vbo: QuadType) { + pub fn draw_quad(&self, device: &ash::Device, cmd: vk::CommandBuffer, vbo: QuadType) { let offset = match vbo { QuadType::Offscreen => 0, QuadType::Final => 4, }; unsafe { - self.device.cmd_draw(cmd, 4, 1, offset, 0); + device.cmd_draw(cmd, 4, 1, offset, 0); } } } diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 99104fb..c5ac6cd 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -459,7 +459,6 @@ impl FilterChainVulkan { )?; Ok(FilterPass { - device: vulkan.device.clone(), reflection, // compiled: spirv_words, uniform_storage, @@ -670,14 +669,16 @@ impl FilterChainVulkan { let options = options.unwrap_or(&self.default_options); - self.common.draw_quad.bind_vbo_for_frame(cmd); + self.common + .draw_quad + .bind_vbo_for_frame(&self.vulkan.device, cmd); for (index, pass) in pass.iter_mut().enumerate() { let target = &self.output_framebuffers[index]; source.filter_mode = pass.config.filter; source.wrap_mode = pass.config.wrap_mode; source.mip_filter = pass.config.filter; - let output_image = OutputImage::new(&self.vulkan, target.image.clone())?; + let output_image = OutputImage::new(&self.vulkan.device, target.image.clone())?; let out = RenderTarget::identity(&output_image); let residual_fb = pass.draw( @@ -696,7 +697,7 @@ impl FilterChainVulkan { if target.max_miplevels > 1 && !self.disable_mipmaps { target.generate_mipmaps_and_end_pass(cmd); } else { - out.output.end_pass(cmd); + out.output.end_pass(&self.vulkan.device, cmd); } source = self.common.output_textures[index].clone().unwrap(); @@ -722,7 +723,7 @@ impl FilterChainVulkan { source.wrap_mode = pass.config.wrap_mode; source.mip_filter = pass.config.filter; - let output_image = OutputImage::new(&self.vulkan, viewport.output.clone())?; + let output_image = OutputImage::new(&self.vulkan.device, viewport.output.clone())?; let out = RenderTarget::viewport_with_output(&output_image, viewport); let residual_fb = pass.draw( diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index 37f1737..465c818 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -23,15 +23,12 @@ use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage, UniformStor use std::sync::Arc; pub struct FilterPass { - pub device: Arc, pub reflection: ShaderReflection, - // pub(crate) compiled: ShaderCompilerOutput>, pub(crate) uniform_storage: UniformStorage, RawVulkanBuffer>, pub uniform_bindings: FastHashMap, pub source: ShaderSource, pub config: ShaderPassConfig, pub graphics_pipeline: VulkanGraphicsPipeline, - // pub ubo_ring: VkUboRing, pub frames_in_flight: u32, } @@ -123,7 +120,7 @@ impl FilterPass { )?; } - output.output.begin_pass(cmd); + output.output.begin_pass(&parent.device, cmd); let residual = self.graphics_pipeline.begin_rendering(output, cmd)?; @@ -176,7 +173,7 @@ impl FilterPass { parent .device .cmd_set_viewport(cmd, 0, &[output.output.size.into()]); - parent.draw_quad.draw_quad(cmd, vbo_type); + parent.draw_quad.draw_quad(&parent.device, cmd, vbo_type); self.graphics_pipeline.end_rendering(cmd); } Ok(residual) @@ -196,7 +193,7 @@ impl FilterPass { source: &InputImage, ) { Self::bind_semantics( - &self.device, + &parent.device, &parent.samplers, &mut self.uniform_storage, descriptor_set, diff --git a/librashader-runtime-vk/src/framebuffer.rs b/librashader-runtime-vk/src/framebuffer.rs index fca540b..852f860 100644 --- a/librashader-runtime-vk/src/framebuffer.rs +++ b/librashader-runtime-vk/src/framebuffer.rs @@ -1,20 +1,17 @@ -use crate::filter_chain::VulkanObjects; use crate::texture::VulkanImage; use crate::{error, util}; use ash::vk; use librashader_common::Size; -use std::sync::Arc; #[derive(Clone)] pub(crate) struct OutputImage { pub size: Size, pub image_view: vk::ImageView, - device: Arc, image: vk::Image, } impl OutputImage { - pub fn new(vulkan: &VulkanObjects, image: VulkanImage) -> error::Result { + pub fn new(device: &ash::Device, image: VulkanImage) -> error::Result { let image_subresource = vk::ImageSubresourceRange::builder() .base_mip_level(0) .base_array_layer(0) @@ -35,20 +32,19 @@ impl OutputImage { .subresource_range(*image_subresource) .components(*swizzle_components); - let image_view = unsafe { vulkan.device.create_image_view(&view_info, None)? }; + let image_view = unsafe { device.create_image_view(&view_info, None)? }; Ok(OutputImage { - device: vulkan.device.clone(), size: image.size, image: image.image, image_view, }) } - pub fn begin_pass(&self, cmd: vk::CommandBuffer) { + pub fn begin_pass(&self, device: &ash::Device, cmd: vk::CommandBuffer) { unsafe { util::vulkan_image_layout_transition_levels( - &self.device, + device, cmd, self.image, 1, @@ -64,10 +60,10 @@ impl OutputImage { } } - pub fn end_pass(&self, cmd: vk::CommandBuffer) { + pub fn end_pass(&self, device: &ash::Device, cmd: vk::CommandBuffer) { unsafe { util::vulkan_image_layout_transition_levels( - &self.device, + &device, cmd, self.image, vk::REMAINING_MIP_LEVELS,