vk: remove unneeded device arcs

This commit is contained in:
chyyran 2024-02-26 00:21:51 -05:00 committed by Ronny Chan
parent 4ef4b8762b
commit f61bed3a22
4 changed files with 20 additions and 35 deletions

View file

@ -49,7 +49,6 @@ static VBO_DATA: &[VertexInput; 8] = &concat_arrays!(OFFSCREEN_VBO_DATA, FINAL_V
pub struct DrawQuad {
buffer: VulkanBuffer,
device: Arc<ash::Device>,
}
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);
}
}
}

View file

@ -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(

View file

@ -23,15 +23,12 @@ use librashader_runtime::uniforms::{NoUniformBinder, UniformStorage, UniformStor
use std::sync::Arc;
pub struct FilterPass {
pub device: Arc<ash::Device>,
pub reflection: ShaderReflection,
// pub(crate) compiled: ShaderCompilerOutput<Vec<u32>>,
pub(crate) uniform_storage: UniformStorage<NoUniformBinder, Option<()>, RawVulkanBuffer>,
pub uniform_bindings: FastHashMap<UniformBinding, MemberOffset>,
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,

View file

@ -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<u32>,
pub image_view: vk::ImageView,
device: Arc<ash::Device>,
image: vk::Image,
}
impl OutputImage {
pub fn new(vulkan: &VulkanObjects, image: VulkanImage) -> error::Result<OutputImage> {
pub fn new(device: &ash::Device, image: VulkanImage) -> error::Result<OutputImage> {
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,