diff --git a/Cargo.lock b/Cargo.lock index 4d32659..f849163 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1138,6 +1138,7 @@ dependencies = [ "librashader-reflect", "librashader-runtime", "librashader-spirv-cross", + "rayon", "rustc-hash", "thiserror", ] diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 82091da..c6c2cde 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -7,7 +7,7 @@ use librashader_reflect::back::{CompileReflectShader, CompileShader}; use librashader_reflect::front::GlslangCompilation; use librashader_reflect::reflect::semantics::ShaderSemantics; use librashader_reflect::reflect::ReflectShader; -use librashader_runtime::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, ImageError, UVDirection}; use rustc_hash::FxHashMap; use std::collections::VecDeque; @@ -317,9 +317,11 @@ impl FilterChainD3D11 { textures: &[TextureConfig], ) -> error::Result> { let mut luts = FxHashMap::default(); + let images = textures.par_iter() + .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) + .collect::, ImageError>>()?; - for (index, texture) in textures.iter().enumerate() { - let image = Image::load(&texture.path, UVDirection::TopLeft)?; + for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let desc = D3D11_TEXTURE2D_DESC { Width: image.size.width, Height: image.size.height, diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index d5fdf40..89626e1 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -38,7 +38,7 @@ mod tests { // "../test/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp"; // "../test/null.slangp", const FILTER_PATH: &str = - "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV-GLASS.slangp"; + "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV-GLASS.slangp"; // const FILTER_PATH: &str = "../test/slang-shaders/test/history.slangp"; // const FILTER_PATH: &str = "../test/slang-shaders/test/feedback.slangp"; diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index d3521e6..4c4ff74 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -23,7 +23,7 @@ use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtif use librashader_reflect::reflect::semantics::{ShaderSemantics, MAX_BINDINGS_COUNT}; use librashader_reflect::reflect::ReflectShader; use librashader_runtime::binding::{BindingUtil, TextureInput}; -use librashader_runtime::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, ImageError, UVDirection}; use librashader_runtime::quad::QuadType; use librashader_runtime::uniforms::UniformStorage; use rustc_hash::FxHashMap; @@ -327,10 +327,11 @@ impl FilterChainD3D12 { let mipmap_gen = D3D12MipmapGen::new(device, true)?; let mut luts = FxHashMap::default(); + let images = textures.par_iter() + .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) + .collect::, ImageError>>()?; - for (index, texture) in textures.iter().enumerate() { - let image = Image::load(&texture.path, UVDirection::TopLeft)?; - + for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let texture = LutTexture::new( device, staging_heap, diff --git a/librashader-runtime-gl/Cargo.toml b/librashader-runtime-gl/Cargo.toml index c6075a4..d700843 100644 --- a/librashader-runtime-gl/Cargo.toml +++ b/librashader-runtime-gl/Cargo.toml @@ -22,6 +22,7 @@ rustc-hash = "1.1.0" gl = "0.14.0" bytemuck = "1.12.3" thiserror = "1.0.37" +rayon = "1.6.1" [dev-dependencies] glfw = "0.47.0" diff --git a/librashader-runtime-gl/src/gl/gl3/lut_load.rs b/librashader-runtime-gl/src/gl/gl3/lut_load.rs index 730ccd0..1676c35 100644 --- a/librashader-runtime-gl/src/gl/gl3/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl3/lut_load.rs @@ -4,9 +4,10 @@ use crate::gl::LoadLut; use crate::texture::InputTexture; use gl::types::{GLsizei, GLuint}; use librashader_presets::TextureConfig; -use librashader_runtime::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, ImageError, UVDirection}; use librashader_runtime::scaling::MipmapSize; use rustc_hash::FxHashMap; +use rayon::prelude::*; pub struct Gl3LutLoad; impl LoadLut for Gl3LutLoad { @@ -18,8 +19,11 @@ impl LoadLut for Gl3LutLoad { binding }; - for (index, texture) in textures.iter().enumerate() { - let image: Image = Image::load(&texture.path, UVDirection::BottomLeft)?; + let images = textures.par_iter() + .map(|texture| Image::load(&texture.path, UVDirection::BottomLeft)) + .collect::, ImageError>>()?; + + for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let levels = if texture.mipmap { image.size.calculate_miplevels() } else { diff --git a/librashader-runtime-gl/src/gl/gl46/lut_load.rs b/librashader-runtime-gl/src/gl/gl46/lut_load.rs index a9e4f59..131ef52 100644 --- a/librashader-runtime-gl/src/gl/gl46/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl46/lut_load.rs @@ -4,9 +4,10 @@ use crate::gl::LoadLut; use crate::texture::InputTexture; use gl::types::{GLsizei, GLuint}; use librashader_presets::TextureConfig; -use librashader_runtime::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, ImageError, UVDirection}; use librashader_runtime::scaling::MipmapSize; use rustc_hash::FxHashMap; +use rayon::prelude::*; pub struct Gl46LutLoad; impl LoadLut for Gl46LutLoad { @@ -22,8 +23,11 @@ impl LoadLut for Gl46LutLoad { gl::BindBuffer(gl::PIXEL_UNPACK_BUFFER, 0); } - for (index, texture) in textures.iter().enumerate() { - let image: Image = Image::load(&texture.path, UVDirection::BottomLeft)?; + let images = textures.par_iter() + .map(|texture| Image::load(&texture.path, UVDirection::BottomLeft)) + .collect::, ImageError>>()?; + + for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let levels = if texture.mipmap { image.size.calculate_miplevels() } else { diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index b2c1183..c9002d0 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -22,7 +22,7 @@ use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtif use librashader_reflect::reflect::semantics::ShaderSemantics; use librashader_reflect::reflect::ReflectShader; use librashader_runtime::binding::BindingUtil; -use librashader_runtime::image::{Image, UVDirection}; +use librashader_runtime::image::{BGRA8, Image, ImageError, UVDirection}; use librashader_runtime::quad::QuadType; use librashader_runtime::uniforms::UniformStorage; use parking_lot::RwLock; @@ -470,9 +470,10 @@ impl FilterChainVulkan { textures: &[TextureConfig], ) -> error::Result> { let mut luts = FxHashMap::default(); - - for (index, texture) in textures.iter().enumerate() { - let image = Image::load(&texture.path, UVDirection::TopLeft)?; + let images = textures.par_iter() + .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) + .collect::>, ImageError>>()?; + for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let texture = LutTexture::new(vulkan, command_buffer, image, texture)?; luts.insert(index, texture); }