From af6f58981e753def2bc9d667cfa039260660834b Mon Sep 17 00:00:00 2001 From: chyyran Date: Thu, 16 Feb 2023 21:16:42 -0500 Subject: [PATCH] vk: move internal frame count to common --- librashader-runtime-d3d11/src/samplers.rs | 4 +--- librashader-runtime-d3d12/src/samplers.rs | 4 +--- .../tests/hello_triangle/mod.rs | 5 ++--- librashader-runtime-gl/src/samplers.rs | 17 ++++++----------- librashader-runtime-gl/tests/triangle.rs | 8 ++++---- librashader-runtime-vk/src/filter_chain.rs | 19 +++++++++---------- librashader-runtime-vk/src/filter_pass.rs | 4 +--- librashader-runtime-vk/src/samplers.rs | 4 +++- 8 files changed, 27 insertions(+), 38 deletions(-) diff --git a/librashader-runtime-d3d11/src/samplers.rs b/librashader-runtime-d3d11/src/samplers.rs index 9ef4afe..5ecf7c9 100644 --- a/librashader-runtime-d3d11/src/samplers.rs +++ b/librashader-runtime-d3d11/src/samplers.rs @@ -14,9 +14,7 @@ impl SamplerSet { pub fn get(&self, wrap: WrapMode, filter: FilterMode) -> &ID3D11SamplerState { // SAFETY: the sampler set is complete for the matrix // wrap x filter - unsafe { - self.samplers.get(&(wrap, filter)).unwrap_unchecked() - } + unsafe { self.samplers.get(&(wrap, filter)).unwrap_unchecked() } } pub fn new(device: &ID3D11Device) -> Result { diff --git a/librashader-runtime-d3d12/src/samplers.rs b/librashader-runtime-d3d12/src/samplers.rs index f92ff99..219fbfe 100644 --- a/librashader-runtime-d3d12/src/samplers.rs +++ b/librashader-runtime-d3d12/src/samplers.rs @@ -22,9 +22,7 @@ impl SamplerSet { ) -> &D3D12DescriptorHeapSlot { // SAFETY: the sampler set is complete for the matrix // wrap x filter - unsafe { - self.samplers.get(&(wrap, filter)).unwrap_unchecked() - } + unsafe { self.samplers.get(&(wrap, filter)).unwrap_unchecked() } } pub fn new(device: &ID3D12Device) -> error::Result { let mut samplers = FxHashMap::default(); diff --git a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs index a0f27c8..7a33dc2 100644 --- a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs +++ b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs @@ -288,9 +288,8 @@ pub mod d3d12_hello_triangle { } } - let filter = unsafe { - FilterChainD3D12::load_from_path(filter, &device, None).unwrap() - }; + let filter = + unsafe { FilterChainD3D12::load_from_path(filter, &device, None).unwrap() }; Ok(Sample { dxgi_factory, diff --git a/librashader-runtime-gl/src/samplers.rs b/librashader-runtime-gl/src/samplers.rs index 2cddc59..cc51d2c 100644 --- a/librashader-runtime-gl/src/samplers.rs +++ b/librashader-runtime-gl/src/samplers.rs @@ -13,7 +13,10 @@ impl SamplerSet { // SAFETY: the sampler set is complete for the matrix // wrap x filter x mipmap unsafe { - *self.samplers.get(&(wrap, filter, mipmap)).unwrap_unchecked() + *self + .samplers + .get(&(wrap, filter, mipmap)) + .unwrap_unchecked() } } @@ -45,17 +48,9 @@ impl SamplerSet { let mut sampler = 0; unsafe { gl::GenSamplers(1, &mut sampler); - SamplerSet::make_sampler( - sampler, - *wrap_mode, - *filter_mode, - *mip_filter, - ); + SamplerSet::make_sampler(sampler, *wrap_mode, *filter_mode, *mip_filter); - samplers.insert( - (*wrap_mode, *filter_mode, *mip_filter), - sampler, - ); + samplers.insert((*wrap_mode, *filter_mode, *mip_filter), sampler); } } } diff --git a/librashader-runtime-gl/tests/triangle.rs b/librashader-runtime-gl/tests/triangle.rs index 0d83ba0..e91b055 100644 --- a/librashader-runtime-gl/tests/triangle.rs +++ b/librashader-runtime-gl/tests/triangle.rs @@ -17,8 +17,8 @@ fn triangle_gl() { disable_cache: false, }), ) - // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) - .unwrap(); + // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) + .unwrap(); hello_triangle::gl3::do_loop(glfw, window, events, shader, vao, &mut filter); } } @@ -39,8 +39,8 @@ fn triangle_gl46() { disable_cache: false, }), ) - // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) - .unwrap(); + // FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None) + .unwrap(); hello_triangle::gl46::do_loop(glfw, window, events, shader, vao, &mut filter); } } diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 3c86ebe..4c4d0f9 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -142,6 +142,7 @@ pub(crate) struct FilterCommon { pub history_textures: Box<[Option]>, pub config: FilterMutable, pub device: Arc, + pub(crate) internal_frame_count: usize, } /// Contains residual intermediate `VkImageView` and `VkImage` objects created @@ -380,6 +381,7 @@ impl FilterChainVulkan { output_textures, feedback_textures, history_textures, + internal_frame_count: 0, }, passes: filters, vulkan: device, @@ -454,7 +456,6 @@ impl FilterChainVulkan { graphics_pipeline, // ubo_ring, frames_in_flight, - internal_frame_count: 0, }) }) .collect(); @@ -482,12 +483,7 @@ impl FilterChainVulkan { } // image must be in SHADER_READ_OPTIMAL - fn push_history( - &mut self, - input: &VulkanImage, - cmd: vk::CommandBuffer, - count: usize, - ) -> error::Result<()> { + fn push_history(&mut self, input: &VulkanImage, cmd: vk::CommandBuffer) -> error::Result<()> { if let Some(mut back) = self.history_framebuffers.pop_back() { if back.image.size != input.size || (input.format != vk::Format::UNDEFINED && input.format != back.image.format) @@ -498,7 +494,8 @@ impl FilterChainVulkan { &mut back, OwnedImage::new(&self.vulkan, input.size, input.format.into(), 1)?, ); - self.residuals[count % self.residuals.len()].dispose_owned(old_back); + self.residuals[self.common.internal_frame_count % self.residuals.len()] + .dispose_owned(old_back); } unsafe { @@ -556,7 +553,8 @@ impl FilterChainVulkan { frame_count: usize, options: Option<&FrameOptionsVulkan>, ) -> error::Result<()> { - let intermediates = &mut self.residuals[frame_count % self.residuals.len()]; + let intermediates = + &mut self.residuals[self.common.internal_frame_count % self.residuals.len()]; intermediates.dispose(); // limit number of passes to those enabled. @@ -725,7 +723,8 @@ impl FilterChainVulkan { intermediates.dispose_framebuffers(residual_fb); } - self.push_history(input, cmd, frame_count)?; + self.push_history(input, cmd)?; + self.common.internal_frame_count = self.common.internal_frame_count.wrapping_add(1); Ok(()) } } diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index b8bc741..67dcb92 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -32,7 +32,6 @@ pub struct FilterPass { pub graphics_pipeline: VulkanGraphicsPipeline, // pub ubo_ring: VkUboRing, pub frames_in_flight: u32, - pub internal_frame_count: usize, } impl TextureInput for InputImage { @@ -100,7 +99,7 @@ impl FilterPass { vbo_type: QuadType, ) -> error::Result> { let mut descriptor = self.graphics_pipeline.layout.descriptor_sets - [self.internal_frame_count % self.frames_in_flight as usize]; + [parent.internal_frame_count % self.frames_in_flight as usize]; self.build_semantics( pass_index, @@ -181,7 +180,6 @@ impl FilterPass { parent.draw_quad.draw_quad(cmd, vbo_type); self.graphics_pipeline.end_rendering(&parent.device, cmd); } - self.internal_frame_count = self.internal_frame_count.wrapping_add(1); Ok(residual) } diff --git a/librashader-runtime-vk/src/samplers.rs b/librashader-runtime-vk/src/samplers.rs index 6102594..8f93dbb 100644 --- a/librashader-runtime-vk/src/samplers.rs +++ b/librashader-runtime-vk/src/samplers.rs @@ -62,7 +62,9 @@ impl SamplerSet { // SAFETY: the sampler set is complete for the matrix // wrap x filter x mipmap unsafe { - self.samplers.get(&(wrap, filter, mipmap)).unwrap_unchecked() + self.samplers + .get(&(wrap, filter, mipmap)) + .unwrap_unchecked() } }