From 5acf70e362f7ee9d09464b7e0b38f0a60090c415 Mon Sep 17 00:00:00 2001 From: chyyran Date: Thu, 12 Jan 2023 01:20:13 -0500 Subject: [PATCH] vk: try to fix feedback (but its not working..) --- .../src/gl/gl3/hello_triangle.rs | 4 ++-- .../src/gl/gl46/hello_triangle.rs | 4 ++-- librashader-runtime-gl/src/lib.rs | 4 ++-- librashader-runtime-vk/src/filter_chain.rs | 20 +++++++++------- librashader-runtime-vk/src/filter_pass.rs | 2 +- librashader-runtime-vk/src/texture.rs | 24 ++++++++++++++++++- 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs index 2f5ed6e..7df8ee2 100644 --- a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs @@ -13,8 +13,8 @@ use crate::gl::gl3::CompatibilityGL; use crate::gl::{FramebufferInterface, GLInterface}; use crate::viewport::Viewport; -const WIDTH: u32 = 1920; -const HEIGHT: u32 = 1080; +const WIDTH: u32 = 800; +const HEIGHT: u32 = 600; const TITLE: &str = "librashader OpenGL"; pub fn compile_program(vertex: &str, fragment: &str) -> GLuint { diff --git a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs index 7187c7d..7b89075 100644 --- a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs @@ -13,8 +13,8 @@ use crate::gl::gl46::DirectStateAccessGL; use crate::gl::{FramebufferInterface, GLInterface}; use crate::viewport::Viewport; -const WIDTH: u32 = 1920; -const HEIGHT: u32 = 1080; +const WIDTH: u32 = 800; +const HEIGHT: u32 = 600; const TITLE: &str = "librashader OpenGL 4.6"; pub fn compile_program(vertex: &str, fragment: &str) -> GLuint { diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 1a5443b..ca49b20 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -32,7 +32,7 @@ mod tests { fn triangle_gl() { let (glfw, window, events, shader, vao) = gl::gl3::hello_triangle::setup(); let mut filter = FilterChainGL::load_from_path( - "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", + "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: false, @@ -49,7 +49,7 @@ mod tests { let (glfw, window, events, shader, vao) = gl::gl46::hello_triangle::setup(); let mut filter = FilterChainGL::load_from_path( // "../test/slang-shaders/vhs/VHSPro.slangp", - "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", + "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: true, diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 0462d65..10b95e4 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -3,7 +3,7 @@ use crate::{error, util}; use crate::filter_pass::FilterPass; use crate::luts::LutTexture; use crate::samplers::SamplerSet; -use crate::texture::{OwnedImage, InputImage, VulkanImage}; +use crate::texture::{OwnedImage, InputImage, VulkanImage, OwnedImageLayout}; use crate::ubo_ring::VkUboRing; use crate::vulkan_state::VulkanGraphicsPipeline; use ash::vk::{CommandPoolCreateFlags, PFN_vkGetInstanceProcAddr, Queue, StaticFn}; @@ -631,7 +631,8 @@ impl FilterChainVulkan { &original, &source, // todo: need to check **next** - pass.config.mipmap_input + pass.config.mipmap_input, + None, )?; self.feedback_framebuffers[index].scale( @@ -641,10 +642,15 @@ impl FilterChainVulkan { &original, &source, // todo: need to check **next** - pass.config.mipmap_input + pass.config.mipmap_input, + None )?; - } + if self.common.feedback_textures[index].is_none() { + self.common.feedback_textures[index] = + Some(source.clone()); + } + } let passes_len = passes.len(); let (pass, last) = passes.split_at_mut(passes_len - 1); @@ -673,7 +679,7 @@ impl FilterChainVulkan { source = target.as_input(pass.config.filter, pass.config.wrap_mode)?; - self.common.output_textures[index] = Some(source.clone()); + let feedback = self.common.output_textures[index].replace(source.clone()); intermediates.dispose_outputs(out.output); } @@ -696,10 +702,6 @@ impl FilterChainVulkan { count as u32, 0, viewport, &original, &source, &out)?; - std::mem::swap( - &mut self.output_framebuffers, - &mut self.feedback_framebuffers, - ); intermediates.dispose_outputs(out.output); } diff --git a/librashader-runtime-vk/src/filter_pass.rs b/librashader-runtime-vk/src/filter_pass.rs index c655f9a..bada238 100644 --- a/librashader-runtime-vk/src/filter_pass.rs +++ b/librashader-runtime-vk/src/filter_pass.rs @@ -312,7 +312,7 @@ impl FilterPass { } // PassOutput - for (index, output) in parent.output_textures[0..pass_index].iter().enumerate() { + for (index, output) in parent.output_textures.iter().enumerate() { let Some(output) = output else { continue; }; diff --git a/librashader-runtime-vk/src/texture.rs b/librashader-runtime-vk/src/texture.rs index eb56581..eb3ea01 100644 --- a/librashader-runtime-vk/src/texture.rs +++ b/librashader-runtime-vk/src/texture.rs @@ -18,6 +18,14 @@ pub struct OwnedImage { pub levels: u32, } +pub struct OwnedImageLayout { + pub(crate) dst_layout: vk::ImageLayout, + pub(crate) dst_access: vk::AccessFlags, + pub(crate) src_stage: vk::PipelineStageFlags, + pub(crate) dst_stage: vk::PipelineStageFlags, + pub(crate) cmd: vk::CommandBuffer +} + impl OwnedImage { fn new_internal( device: ash::Device, @@ -122,6 +130,7 @@ impl OwnedImage { _original: &InputImage, source: &InputImage, mipmap: bool, + layout: Option ) -> error::Result> { let size = source.image.size.scale_viewport(scaling, *viewport_size); if self.image.size != size || (mipmap && self.max_miplevels == 1) || (!mipmap && self.max_miplevels != 1) { @@ -138,7 +147,20 @@ impl OwnedImage { }, max_levels)?; let old = std::mem::replace(self, new); - drop(old) + drop(old); + + if let Some(layout) = layout { + unsafe { + util::vulkan_image_layout_transition_levels(&self.device, layout.cmd, + self.image.image, + self.levels, + vk::ImageLayout::UNDEFINED, + layout.dst_layout, vk::AccessFlags::empty(), + layout.dst_access, layout.src_stage, layout.dst_stage, vk::QUEUE_FAMILY_IGNORED, + vk::QUEUE_FAMILY_IGNORED) + + } + } } Ok(size) }