rt: load luts with multiple threads

This commit is contained in:
chyyran 2023-02-14 02:56:06 -05:00
parent e2e6357cfb
commit 07fac4d1e9
8 changed files with 32 additions and 18 deletions

1
Cargo.lock generated
View file

@ -1138,6 +1138,7 @@ dependencies = [
"librashader-reflect", "librashader-reflect",
"librashader-runtime", "librashader-runtime",
"librashader-spirv-cross", "librashader-spirv-cross",
"rayon",
"rustc-hash", "rustc-hash",
"thiserror", "thiserror",
] ]

View file

@ -7,7 +7,7 @@ use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation; use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::reflect::semantics::ShaderSemantics; use librashader_reflect::reflect::semantics::ShaderSemantics;
use librashader_reflect::reflect::ReflectShader; use librashader_reflect::reflect::ReflectShader;
use librashader_runtime::image::{Image, UVDirection}; use librashader_runtime::image::{Image, ImageError, UVDirection};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -317,9 +317,11 @@ impl FilterChainD3D11 {
textures: &[TextureConfig], textures: &[TextureConfig],
) -> error::Result<FxHashMap<usize, LutTexture>> { ) -> error::Result<FxHashMap<usize, LutTexture>> {
let mut luts = FxHashMap::default(); let mut luts = FxHashMap::default();
let images = textures.par_iter()
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image>, ImageError>>()?;
for (index, texture) in textures.iter().enumerate() { for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let image = Image::load(&texture.path, UVDirection::TopLeft)?;
let desc = D3D11_TEXTURE2D_DESC { let desc = D3D11_TEXTURE2D_DESC {
Width: image.size.width, Width: image.size.width,
Height: image.size.height, Height: image.size.height,

View file

@ -38,7 +38,7 @@ mod tests {
// "../test/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp"; // "../test/slang-shaders/handheld/console-border/gbc-lcd-grid-v2.slangp";
// "../test/null.slangp", // "../test/null.slangp",
const FILTER_PATH: &str = 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/history.slangp";
// const FILTER_PATH: &str = "../test/slang-shaders/test/feedback.slangp"; // const FILTER_PATH: &str = "../test/slang-shaders/test/feedback.slangp";

View file

@ -23,7 +23,7 @@ use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtif
use librashader_reflect::reflect::semantics::{ShaderSemantics, MAX_BINDINGS_COUNT}; use librashader_reflect::reflect::semantics::{ShaderSemantics, MAX_BINDINGS_COUNT};
use librashader_reflect::reflect::ReflectShader; use librashader_reflect::reflect::ReflectShader;
use librashader_runtime::binding::{BindingUtil, TextureInput}; 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::quad::QuadType;
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -327,10 +327,11 @@ impl FilterChainD3D12 {
let mipmap_gen = D3D12MipmapGen::new(device, true)?; let mipmap_gen = D3D12MipmapGen::new(device, true)?;
let mut luts = FxHashMap::default(); let mut luts = FxHashMap::default();
let images = textures.par_iter()
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image>, ImageError>>()?;
for (index, texture) in textures.iter().enumerate() { for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let image = Image::load(&texture.path, UVDirection::TopLeft)?;
let texture = LutTexture::new( let texture = LutTexture::new(
device, device,
staging_heap, staging_heap,

View file

@ -22,6 +22,7 @@ rustc-hash = "1.1.0"
gl = "0.14.0" gl = "0.14.0"
bytemuck = "1.12.3" bytemuck = "1.12.3"
thiserror = "1.0.37" thiserror = "1.0.37"
rayon = "1.6.1"
[dev-dependencies] [dev-dependencies]
glfw = "0.47.0" glfw = "0.47.0"

View file

@ -4,9 +4,10 @@ use crate::gl::LoadLut;
use crate::texture::InputTexture; use crate::texture::InputTexture;
use gl::types::{GLsizei, GLuint}; use gl::types::{GLsizei, GLuint};
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use librashader_runtime::image::{Image, UVDirection}; use librashader_runtime::image::{Image, ImageError, UVDirection};
use librashader_runtime::scaling::MipmapSize; use librashader_runtime::scaling::MipmapSize;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use rayon::prelude::*;
pub struct Gl3LutLoad; pub struct Gl3LutLoad;
impl LoadLut for Gl3LutLoad { impl LoadLut for Gl3LutLoad {
@ -18,8 +19,11 @@ impl LoadLut for Gl3LutLoad {
binding binding
}; };
for (index, texture) in textures.iter().enumerate() { let images = textures.par_iter()
let image: Image = Image::load(&texture.path, UVDirection::BottomLeft)?; .map(|texture| Image::load(&texture.path, UVDirection::BottomLeft))
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap { let levels = if texture.mipmap {
image.size.calculate_miplevels() image.size.calculate_miplevels()
} else { } else {

View file

@ -4,9 +4,10 @@ use crate::gl::LoadLut;
use crate::texture::InputTexture; use crate::texture::InputTexture;
use gl::types::{GLsizei, GLuint}; use gl::types::{GLsizei, GLuint};
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use librashader_runtime::image::{Image, UVDirection}; use librashader_runtime::image::{Image, ImageError, UVDirection};
use librashader_runtime::scaling::MipmapSize; use librashader_runtime::scaling::MipmapSize;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use rayon::prelude::*;
pub struct Gl46LutLoad; pub struct Gl46LutLoad;
impl LoadLut for Gl46LutLoad { impl LoadLut for Gl46LutLoad {
@ -22,8 +23,11 @@ impl LoadLut for Gl46LutLoad {
gl::BindBuffer(gl::PIXEL_UNPACK_BUFFER, 0); gl::BindBuffer(gl::PIXEL_UNPACK_BUFFER, 0);
} }
for (index, texture) in textures.iter().enumerate() { let images = textures.par_iter()
let image: Image = Image::load(&texture.path, UVDirection::BottomLeft)?; .map(|texture| Image::load(&texture.path, UVDirection::BottomLeft))
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap { let levels = if texture.mipmap {
image.size.calculate_miplevels() image.size.calculate_miplevels()
} else { } else {

View file

@ -22,7 +22,7 @@ use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtif
use librashader_reflect::reflect::semantics::ShaderSemantics; use librashader_reflect::reflect::semantics::ShaderSemantics;
use librashader_reflect::reflect::ReflectShader; use librashader_reflect::reflect::ReflectShader;
use librashader_runtime::binding::BindingUtil; 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::quad::QuadType;
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use parking_lot::RwLock; use parking_lot::RwLock;
@ -470,9 +470,10 @@ impl FilterChainVulkan {
textures: &[TextureConfig], textures: &[TextureConfig],
) -> error::Result<FxHashMap<usize, LutTexture>> { ) -> error::Result<FxHashMap<usize, LutTexture>> {
let mut luts = FxHashMap::default(); let mut luts = FxHashMap::default();
let images = textures.par_iter()
for (index, texture) in textures.iter().enumerate() { .map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
let image = Image::load(&texture.path, UVDirection::TopLeft)?; .collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(vulkan, command_buffer, image, texture)?; let texture = LutTexture::new(vulkan, command_buffer, image, texture)?;
luts.insert(index, texture); luts.insert(index, texture);
} }