From 1bbbd784d8778ff09e1aaad65411dc760000a898 Mon Sep 17 00:00:00 2001 From: chyyran Date: Tue, 1 Oct 2024 01:20:40 -0400 Subject: [PATCH] preset: make ShaderPassConfig and TextureConfig type aliases to PathReference --- Cargo.lock | 212 ++++++++++++++++++++- librashader-cli/src/cli/main.rs | 2 +- librashader-presets/src/parse/preset.rs | 2 +- librashader-presets/src/preset.rs | 27 ++- librashader-reflect/src/reflect/presets.rs | 6 +- librashader-runtime-d3d9/src/luts.rs | 2 +- librashader-runtime-vk/src/luts.rs | 2 +- librashader-runtime-wgpu/src/luts.rs | 2 +- librashader-runtime/src/image.rs | 1 + librashader/src/lib.rs | 2 +- librashader/tests/reflect.rs | 4 +- 11 files changed, 229 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1da00aa..4e22f6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,6 +90,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -245,6 +251,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bincode" version = "2.0.0-rc.3" @@ -461,7 +473,7 @@ checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb" dependencies = [ "clap", "heck", - "indexmap", + "indexmap 2.5.0", "log", "proc-macro2", "quote", @@ -501,6 +513,19 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets 0.52.6", +] + [[package]] name = "clap" version = "4.3.0" @@ -522,7 +547,7 @@ dependencies = [ "anstyle", "bitflags 1.3.2", "clap_lex", - "strsim", + "strsim 0.10.0", ] [[package]] @@ -833,12 +858,57 @@ dependencies = [ "windows 0.58.0", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.11.1", + "syn 2.0.79", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.79", +] + [[package]] name = "data-encoding" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + [[package]] name = "digest" version = "0.10.7" @@ -1307,6 +1377,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "hexf-parse" version = "0.2.1" @@ -1319,6 +1395,29 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core 0.52.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icrate" version = "0.0.4" @@ -1330,6 +1429,12 @@ dependencies = [ "objc2 0.4.1", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "image" version = "0.25.2" @@ -1370,6 +1475,17 @@ dependencies = [ "quick-error", ] +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + [[package]] name = "indexmap" version = "2.5.0" @@ -1378,6 +1494,7 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", + "serde", ] [[package]] @@ -1628,6 +1745,7 @@ dependencies = [ name = "librashader-pack" version = "0.4.5" dependencies = [ + "anyhow", "image", "librashader-preprocess", "librashader-presets", @@ -1635,6 +1753,7 @@ dependencies = [ "rayon", "serde", "serde_json", + "serde_with", "thiserror", ] @@ -1981,7 +2100,7 @@ dependencies = [ "cfg_aliases", "codespan-reporting", "hexf-parse", - "indexmap", + "indexmap 2.5.0", "log", "petgraph", "pp-rs", @@ -2076,6 +2195,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-derive" version = "0.4.2" @@ -2442,7 +2567,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap", + "indexmap 2.5.0", ] [[package]] @@ -2506,6 +2631,12 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "pp-rs" version = "0.2.1" @@ -2737,7 +2868,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" dependencies = [ - "base64", + "base64 0.13.1", "bitflags 1.3.2", "serde", ] @@ -2868,6 +2999,36 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.5.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "sha2" version = "0.10.8" @@ -3101,6 +3262,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "1.0.109" @@ -3182,6 +3349,37 @@ dependencies = [ "weezl", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-skia" version = "0.11.4" @@ -3243,7 +3441,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", @@ -3602,7 +3800,7 @@ dependencies = [ "bitflags 2.6.0", "cfg_aliases", "document-features", - "indexmap", + "indexmap 2.5.0", "log", "naga", "once_cell", diff --git a/librashader-cli/src/cli/main.rs b/librashader-cli/src/cli/main.rs index 24b86f9..5c779ce 100644 --- a/librashader-cli/src/cli/main.rs +++ b/librashader-cli/src/cli/main.rs @@ -490,7 +490,7 @@ pub fn main() -> Result<(), anyhow::Error> { return Err(anyhow!("Invalid pass index for the preset")); }; - let source = librashader::preprocess::ShaderSource::load(shader.name.as_path())?; + let source = librashader::preprocess::ShaderSource::load(shader.path.as_path())?; let compilation = SpirvCompilation::try_from(&source)?; let semantics = diff --git a/librashader-presets/src/parse/preset.rs b/librashader-presets/src/parse/preset.rs index 6c3e52e..9dd227b 100644 --- a/librashader-presets/src/parse/preset.rs +++ b/librashader-presets/src/parse/preset.rs @@ -119,7 +119,7 @@ pub fn resolve_values(mut values: Vec) -> ShaderPreset { } let shader = ShaderPassConfig { - name, + path: name, meta: ShaderPassMeta { id, alias: shader_values.iter().find_map(|f| match f { diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index 24e27cf..a3512ee 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -6,15 +6,22 @@ use std::path::PathBuf; use std::str::FromStr; /// The configuration for a single shader pass. +pub type ShaderPassConfig = PathReference; + +/// Configuration options for a lookup texture used in the shader. +pub type TextureConfig = PathReference; + +/// A reference to a resource on desk. #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct ShaderPassConfig { - /// The fully qualified path to the shader pass source file. - pub name: PathBuf, - /// Meta information about the shader pass - pub meta: ShaderPassMeta, +pub struct PathReference { + /// The fully qualified path to the resource, often a shader source file or a texture. + pub path: PathBuf, + /// Meta information about the resource. + pub meta: M, } +/// Meta information about a shader pass. #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ShaderPassMeta { @@ -160,16 +167,6 @@ pub struct Scale2D { pub y: Scaling, } -/// Configuration options for a lookup texture used in the shader. -#[derive(Debug, Clone)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct TextureConfig { - /// The fully qualified path to the texture. - pub path: PathBuf, - /// Meta information about the texture. - pub meta: TextureMeta, -} - /// Configuration options for a lookup texture used in the shader. #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/librashader-reflect/src/reflect/presets.rs b/librashader-reflect/src/reflect/presets.rs index 9f3f6e3..309cb4e 100644 --- a/librashader-reflect/src/reflect/presets.rs +++ b/librashader-reflect/src/reflect/presets.rs @@ -8,7 +8,7 @@ use crate::reflect::semantics::{ use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::{PreprocessError, ShaderSource}; use librashader_presets::{ - ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig, TextureMeta, + ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig, }; /// Artifacts of a reflected and compiled shader pass. @@ -89,7 +89,7 @@ where let passes = passes .into_iter() .map(|shader| { - let source: ShaderSource = ShaderSource::load(&shader.name)?; + let source: ShaderSource = ShaderSource::load(&shader.path)?; let compiled = I::Compiler::compile(&source)?; let reflect = T::from_compilation(compiled)?; @@ -238,7 +238,7 @@ impl ShaderSemantics { .get(index) .ok_or_else(|| PreprocessError::InvalidStage)?; - let source = ShaderSource::load(&config.name)?; + let source = ShaderSource::load(&config.path)?; for parameter in source.parameters.values() { uniform_semantics.insert( diff --git a/librashader-runtime-d3d9/src/luts.rs b/librashader-runtime-d3d9/src/luts.rs index 0c67da0..a2490f4 100644 --- a/librashader-runtime-d3d9/src/luts.rs +++ b/librashader-runtime-d3d9/src/luts.rs @@ -2,7 +2,7 @@ use crate::error; use crate::error::assume_d3d_init; use crate::texture::D3D9InputTexture; -use librashader_presets::{TextureConfig, TextureMeta}; +use librashader_presets::TextureMeta; use librashader_runtime::image::{Image, BGRA8}; use windows::Win32::Graphics::Direct3D9::{ diff --git a/librashader-runtime-vk/src/luts.rs b/librashader-runtime-vk/src/luts.rs index c5d2ef5..b7af137 100644 --- a/librashader-runtime-vk/src/luts.rs +++ b/librashader-runtime-vk/src/luts.rs @@ -3,7 +3,7 @@ use crate::memory::{VulkanBuffer, VulkanImageMemory}; use crate::texture::{InputImage, VulkanImage}; use crate::{error, util}; use ash::vk; -use librashader_presets::{TextureConfig, TextureMeta}; +use librashader_presets::TextureMeta; use librashader_runtime::image::{Image, BGRA8}; use librashader_runtime::scaling::MipmapSize; diff --git a/librashader-runtime-wgpu/src/luts.rs b/librashader-runtime-wgpu/src/luts.rs index 3b30790..84ae875 100644 --- a/librashader-runtime-wgpu/src/luts.rs +++ b/librashader-runtime-wgpu/src/luts.rs @@ -2,7 +2,7 @@ use crate::mipmap::MipmapGen; use crate::samplers::SamplerSet; use crate::texture::InputImage; use librashader_common::{Size, WrapMode}; -use librashader_presets::{TextureConfig, TextureMeta}; +use librashader_presets::TextureMeta; use librashader_runtime::image::Image; use librashader_runtime::scaling::MipmapSize; use std::sync::Arc; diff --git a/librashader-runtime/src/image.rs b/librashader-runtime/src/image.rs index 9794a40..9514f1e 100644 --- a/librashader-runtime/src/image.rs +++ b/librashader-runtime/src/image.rs @@ -2,6 +2,7 @@ pub use image::ImageError; use librashader_common::Size; use std::marker::PhantomData; +use image::RgbaImage; use std::path::Path; /// An uncompressed raw image ready to upload to GPU buffers. diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index e7d2857..d4e7e3e 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -77,7 +77,7 @@ pub mod presets { .shaders .iter() .map(|s| { - ShaderSource::load(&s.name) + ShaderSource::load(&s.path) .map(|s| s.parameters.into_iter().map(|(_, v)| v).collect()) }) .collect(); diff --git a/librashader/tests/reflect.rs b/librashader/tests/reflect.rs index 7a4ad5a..357d89f 100644 --- a/librashader/tests/reflect.rs +++ b/librashader/tests/reflect.rs @@ -55,7 +55,7 @@ fn collect_all_loadable_slang_presets() -> Vec<(PathBuf, ShaderPreset)> { !preset .shaders .par_iter() - .any(|shader| ShaderSource::load(&shader.name).is_err()) + .any(|shader| ShaderSource::load(&shader.path).is_err()) }); presets @@ -67,7 +67,7 @@ pub fn preprocess_all_slang_presets_parsed() { for (path, preset) in presets { preset.shaders.into_par_iter().for_each(|shader| { - if let Err(e) = ShaderSource::load(&shader.name) { + if let Err(e) = ShaderSource::load(&shader.path) { #[cfg(not(feature = "github-ci"))] eprintln!( "[ERROR] Failed to preprocess shader {} from preset {}: {:?}",