From b799c1c6ef7843dd803e4d2756e5df14cadec600 Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 21 Nov 2022 02:36:37 -0500 Subject: [PATCH] gl: initialize history and feedback fbos before drawing --- librashader-runtime-gl/src/filter_chain.rs | 32 +++++++++++++------- librashader-runtime-gl/src/filter_pass.rs | 22 +++++++------- librashader-runtime-gl/src/hello_triangle.rs | 6 ++-- librashader-runtime-gl/src/lib.rs | 2 +- test/basic.slangp | 2 -- 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index dcc6cf8..0ea1060 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -634,21 +634,29 @@ impl FilterChain { let mut source = original; + // rescale render buffers to ensure all bindings are valid. + for (index, pass) in self.passes.iter_mut().enumerate() { + self.output_framebuffers[index].scale( + pass.config.scaling.clone(), + pass.get_format(), + viewport, + &original, + &source, + ); + + self.feedback_framebuffers[index].scale( + pass.config.scaling.clone(), + pass.get_format(), + viewport, + &original, + &source, + ); + } + let passes_len = self.passes.len(); let (pass, last) = self.passes.split_at_mut(passes_len - 1); for (index, pass) in pass.iter_mut().enumerate() { - { - let target = &mut self.output_framebuffers[index]; - let _framebuffer_size = target.scale( - pass.config.scaling.clone(), - pass.get_format(), - viewport, - &original, - &source, - ); - } - let target = &self.output_framebuffers[index]; pass.draw( index, @@ -675,6 +683,7 @@ impl FilterChain { for pass in last { source.filter = pass.config.filter; source.mip_filter = pass.config.filter; + pass.draw( passes_len - 1, &self.common, @@ -689,6 +698,7 @@ impl FilterChain { &source, RenderTarget::new(viewport.output, viewport.mvp), ); + } // swap feedback framebuffers with output diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 8331d8a..8ec56f0 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -93,11 +93,8 @@ impl FilterPass { Self::build_uniform(location, buffer, value, gl::Uniform1f) } - fn bind_texture(binding: &TextureImage, texture: &Texture, semantic: TextureSemantics) { + fn bind_texture(binding: &TextureImage, texture: &Texture) { unsafe { - if texture.image.handle == 0 { - eprintln!("[WARNING] trying to bind {semantic:?} texture 0 to slot {} ", binding.binding) - } // eprintln!("setting {} to texunit {}", texture.image.handle, binding.binding); gl::ActiveTexture(gl::TEXTURE0 + binding.binding); gl::BindTexture(gl::TEXTURE_2D, texture.image.handle); @@ -347,7 +344,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::Original.semantics(0)) { - FilterPass::bind_texture(binding, original, TextureSemantics::Original); + FilterPass::bind_texture(binding, original); } // bind OriginalSize @@ -374,7 +371,7 @@ impl FilterPass { .get(&TextureSemantics::Source.semantics(0)) { // eprintln!("setting source binding to {}", binding.binding); - FilterPass::bind_texture(binding, source, TextureSemantics::Source); + FilterPass::bind_texture(binding, source); } // bind SourceSize @@ -395,7 +392,7 @@ impl FilterPass { if let Some(binding) = self.reflection.meta.texture_meta.get(&TextureSemantics::OriginalHistory.semantics(0)) { - FilterPass::bind_texture(binding, original, TextureSemantics::OriginalHistory); + FilterPass::bind_texture(binding, original); } if let Some((location, offset)) = self .variable_bindings @@ -419,7 +416,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::OriginalHistory.semantics(index + 1)) { - FilterPass::bind_texture(binding, output, TextureSemantics::OriginalHistory); + FilterPass::bind_texture(binding, output); } if let Some((location, offset)) = self @@ -446,7 +443,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::PassOutput.semantics(index)) { - FilterPass::bind_texture(binding, output, TextureSemantics::PassOutput); + FilterPass::bind_texture(binding, output); } if let Some((location, offset)) = self @@ -473,7 +470,10 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::PassFeedback.semantics(index)) { - FilterPass::bind_texture(binding, feedback, TextureSemantics::PassFeedback); + if feedback.image.handle == 0 { + eprintln!("[WARNING] trying to bind PassFeedback: {index} which has texture 0 to slot {} in pass {pass_index}", binding.binding) + } + FilterPass::bind_texture(binding, feedback); } if let Some((location, offset)) = self @@ -535,7 +535,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::User.semantics(*index)) { - FilterPass::bind_texture(binding, lut, TextureSemantics::User); + FilterPass::bind_texture(binding, lut); } if let Some((location, offset)) = self diff --git a/librashader-runtime-gl/src/hello_triangle.rs b/librashader-runtime-gl/src/hello_triangle.rs index 12592c9..ebebf58 100644 --- a/librashader-runtime-gl/src/hello_triangle.rs +++ b/librashader-runtime-gl/src/hello_triangle.rs @@ -10,8 +10,8 @@ use crate::filter_chain::FilterChain; use crate::framebuffer::Framebuffer; use crate::util::{GlImage, Size, Viewport}; -const WIDTH: u32 = 1920; -const HEIGHT: u32 = 1080; +const WIDTH: u32 = 900; +const HEIGHT: u32 = 700; const TITLE: &str = "Hello From OpenGL World!"; pub fn compile_program(vertex: &str, fragment: &str) -> GLuint { @@ -113,7 +113,7 @@ pub fn setup() -> (Glfw, Window, Receiver<(f64, WindowEvent)>, GLuint, GLuint) { glfw::OpenGlProfileHint::Core, )); glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true)); - glfw.window_hint(glfw::WindowHint::Resizable(false)); + glfw.window_hint(glfw::WindowHint::Resizable(true)); glfw.window_hint(glfw::WindowHint::OpenGlDebugContext(true)); let (mut window, events) = glfw diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index 42ff537..174ae83 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -18,7 +18,7 @@ mod tests { #[test] fn triangle() { let (glfw, window, events, shader, vao) = hello_triangle::setup(); - let mut filter = FilterChain::load("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV-GLASS.slangp").unwrap(); + let mut filter = FilterChain::load("../test/slang-shaders/crt/crt-royale-fake-bloom.slangp").unwrap(); // FilterChain::load("../test/slang-shaders/crt/crt-royale.slangp").unwrap(); diff --git a/test/basic.slangp b/test/basic.slangp index 8bdc133..6e3cb6c 100644 --- a/test/basic.slangp +++ b/test/basic.slangp @@ -6,5 +6,3 @@ alias0 = "" float_framebuffer0 = "false" srgb_framebuffer0 = "false" ColorMod = "1.700000" -textures = "BORDER;" -BORDER = "agb.png" \ No newline at end of file