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-runtime",
"librashader-spirv-cross",
"rayon",
"rustc-hash",
"thiserror",
]

View file

@ -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<FxHashMap<usize, LutTexture>> {
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() {
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,

View file

@ -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";

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::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::<Result<Vec<Image>, 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,

View file

@ -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"

View file

@ -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::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap {
image.size.calculate_miplevels()
} else {

View file

@ -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::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap {
image.size.calculate_miplevels()
} else {

View file

@ -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<FxHashMap<usize, LutTexture>> {
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::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(vulkan, command_buffer, image, texture)?;
luts.insert(index, texture);
}