diff --git a/Cargo.lock b/Cargo.lock index d63f2f1..b972b47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -137,7 +137,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -192,13 +192,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -313,9 +313,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitstream-io" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b80895c12b34217892edc4718b2293748796b6570c6ff9f0935df8e10e26534" +checksum = "b81e1519b0d82120d2fd469d5bfb2919a9361c48b02d82d04befc1cdd2002452" [[package]] name = "bitvec" @@ -411,9 +411,9 @@ checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce" [[package]] name = "bytemuck" -version = "1.17.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" +checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2" dependencies = [ "bytemuck_derive", ] @@ -426,7 +426,7 @@ checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -494,9 +494,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.13" +version = "1.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" +checksum = "e9d013ecb737093c0e86b151a7b837993cf9ec6c502946cfb44bedc392421e0b" dependencies = [ "jobserver", "libc", @@ -718,9 +718,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" [[package]] name = "core-foundation" @@ -1006,9 +1006,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fdeflate" @@ -1027,9 +1027,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c0596c1eac1f9e04ed902702e9878208b336edc9d6fddc8a48387349bab3666" +checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" dependencies = [ "crc32fast", "miniz_oxide 0.8.0", @@ -1062,7 +1062,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -1460,9 +1460,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -1476,7 +1476,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -1698,6 +1698,7 @@ dependencies = [ "num-traits", "objc2-metal", "rustc-hash 2.0.0", + "smartstring", "wgpu-types", "windows 0.58.0", ] @@ -1736,7 +1737,7 @@ dependencies = [ "bitflags 2.6.0", "bytemuck", "glslang", - "indexmap 2.4.0", + "indexmap 2.5.0", "librashader-common", "librashader-preprocess", "librashader-presets", @@ -2090,7 +2091,7 @@ dependencies = [ "cfg_aliases", "codespan-reporting", "hexf-parse", - "indexmap 2.4.0", + "indexmap 2.5.0", "log", "petgraph", "pp-rs", @@ -2205,7 +2206,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -2266,7 +2267,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -2468,7 +2469,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -2489,7 +2490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.4.0", + "indexmap 2.5.0", ] [[package]] @@ -2573,11 +2574,11 @@ checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" [[package]] name = "proc-macro-crate" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" dependencies = [ - "toml_edit 0.21.1", + "toml_edit", ] [[package]] @@ -2629,7 +2630,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -2649,18 +2650,18 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f24d770aeca0eacb81ac29dfbc55ebcc09312fdd1f8bbecdc7e4a84e000e3b4" +checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc" dependencies = [ "memchr", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -2884,9 +2885,9 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" [[package]] name = "rgb" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" +checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" dependencies = [ "bytemuck", ] @@ -2936,9 +2937,9 @@ checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags 2.6.0", "errno", @@ -2989,29 +2990,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.208" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.208" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.125" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -3084,6 +3085,17 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + [[package]] name = "smithay-client-toolkit" version = "0.18.1" @@ -3196,9 +3208,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.75" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -3275,7 +3287,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -3347,7 +3359,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.20", + "toml_edit", ] [[package]] @@ -3359,28 +3371,17 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap 2.4.0", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.18", + "winnow", ] [[package]] @@ -3520,7 +3521,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -3554,7 +3555,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3567,9 +3568,9 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wayland-backend" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90e11ce2ca99c97b940ee83edbae9da2d56a08f9ea8158550fd77fa31722993" +checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6" dependencies = [ "cc", "downcast-rs", @@ -3581,9 +3582,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.31.5" +version = "0.31.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e321577a0a165911bdcfb39cf029302479d7527b517ee58ab0f6ad09edf0943" +checksum = "e3f45d1222915ef1fd2057220c1d9d9624b7654443ea35c3877f7a52bd0a5a2d" dependencies = [ "bitflags 2.6.0", "rustix", @@ -3604,9 +3605,9 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.31.5" +version = "0.31.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef9489a8df197ebf3a8ce8a7a7f0a2320035c3743f3c1bd0bdbccf07ce64f95" +checksum = "3a94697e66e76c85923b0d28a0c251e8f0666f58fc47d316c0f4da6da75d37cb" dependencies = [ "rustix", "wayland-client", @@ -3653,9 +3654,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.31.4" +version = "0.31.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7b56f89937f1cf2ee1f1259cf2936a17a1f45d8f0aa1019fae6d470d304cfa6" +checksum = "597f2001b2e5fc1121e3d5b9791d3e78f05ba6bfa4641053846248e3a13661c3" dependencies = [ "proc-macro2", "quick-xml", @@ -3664,9 +3665,9 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.31.4" +version = "0.31.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43676fe2daf68754ecf1d72026e4e6c15483198b5d24e888b74d3f22f887a148" +checksum = "efa8ac0d8e8ed3e3b5c9fc92c7881406a268e11555abe36493efabe649a29e09" dependencies = [ "dlib", "log", @@ -3736,7 +3737,7 @@ dependencies = [ "bitflags 2.6.0", "cfg_aliases", "document-features", - "indexmap 2.4.0", + "indexmap 2.5.0", "log", "naga", "once_cell", @@ -3893,7 +3894,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -3904,7 +3905,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] @@ -4188,15 +4189,6 @@ dependencies = [ "xkbcommon-dl", ] -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.6.18" @@ -4305,7 +4297,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.75", + "syn 2.0.77", ] [[package]] diff --git a/librashader-capi/src/presets.rs b/librashader-capi/src/presets.rs index 30976b5..2c7c8f5 100644 --- a/librashader-capi/src/presets.rs +++ b/librashader-capi/src/presets.rs @@ -205,7 +205,7 @@ extern_fn! { let iter = librashader::presets::get_parameter_meta(preset)?; let mut values = Vec::new(); for param in iter { - let name = CString::new(param.id) + let name = CString::new(param.id.to_string()) .map_err(|err| LibrashaderError::UnknownError(Box::new(err)))?; let description = CString::new(param.description) .map_err(|err| LibrashaderError::UnknownError(Box::new(err)))?; diff --git a/librashader-common/Cargo.toml b/librashader-common/Cargo.toml index c56dddb..c1da3ae 100644 --- a/librashader-common/Cargo.toml +++ b/librashader-common/Cargo.toml @@ -29,6 +29,7 @@ wgpu-types = { version = "22", optional = true } num-traits = "0.2.15" rustc-hash = "2.0.0" halfbrown = "0.2.4" +smartstring = "1.0" [target.'cfg(windows)'.dependencies.windows] optional = true diff --git a/librashader-common/src/map.rs b/librashader-common/src/map.rs index 9179a10..2b1c72b 100644 --- a/librashader-common/src/map.rs +++ b/librashader-common/src/map.rs @@ -2,4 +2,7 @@ pub type FastHashMap = halfbrown::SizedHashMap, 32>; +/// A string with small string optimizations up to 23 bytes. +pub type ShortString = smartstring::SmartString; + pub use halfbrown; diff --git a/librashader-preprocess/src/error.rs b/librashader-preprocess/src/error.rs index 75e04d6..374f1a8 100644 --- a/librashader-preprocess/src/error.rs +++ b/librashader-preprocess/src/error.rs @@ -1,3 +1,4 @@ +use librashader_common::map::ShortString; use std::convert::Infallible; use std::path::PathBuf; use thiserror::Error; @@ -27,7 +28,7 @@ pub enum PreprocessError { PragmaParseError(String), /// The given pragma was declared multiple times with differing values. #[error("duplicate pragma found")] - DuplicatePragmaError(String), + DuplicatePragmaError(ShortString), /// The image format requested by the shader was unknown or not supported. #[error("shader format is unknown or not found")] UnknownImageFormat, diff --git a/librashader-preprocess/src/lib.rs b/librashader-preprocess/src/lib.rs index 45ca4c9..f977cd9 100644 --- a/librashader-preprocess/src/lib.rs +++ b/librashader-preprocess/src/lib.rs @@ -15,7 +15,7 @@ mod stage; use crate::include::read_source; pub use error::*; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use librashader_common::ImageFormat; use std::path::Path; @@ -29,10 +29,10 @@ pub struct ShaderSource { pub fragment: String, /// The alias of the shader if available. - pub name: Option, + pub name: Option, /// The list of shader parameters found in the shader source. - pub parameters: FastHashMap, + pub parameters: FastHashMap, /// The image format the shader expects. pub format: ImageFormat, @@ -42,7 +42,7 @@ pub struct ShaderSource { #[derive(Debug, Clone, PartialEq)] pub struct ShaderParameter { /// The name of the parameter. - pub id: String, + pub id: ShortString, /// The description of the parameter. pub description: String, /// The initial value the parameter is set to. diff --git a/librashader-preprocess/src/pragma.rs b/librashader-preprocess/src/pragma.rs index b5a82b8..708cb46 100644 --- a/librashader-preprocess/src/pragma.rs +++ b/librashader-preprocess/src/pragma.rs @@ -2,6 +2,7 @@ use crate::{PreprocessError, ShaderParameter}; use librashader_common::ImageFormat; use nom::bytes::complete::{is_not, tag, take_while}; +use librashader_common::map::ShortString; use nom::character::complete::multispace1; use nom::number::complete::float; use nom::sequence::delimited; @@ -12,7 +13,7 @@ use std::str::FromStr; pub(crate) struct ShaderMeta { pub(crate) format: ImageFormat, pub(crate) parameters: Vec, - pub(crate) name: Option, + pub(crate) name: Option, } fn parse_parameter_string(input: &str) -> Result { @@ -40,7 +41,7 @@ fn parse_parameter_string(input: &str) -> Result Result) -> Result) -> Result) -> ShaderPreset { id, name, alias: shader_values.iter().find_map(|f| match f { - Value::Alias(_, value) => Some(value.to_string()), + Value::Alias(_, value) => Some(value.clone()), _ => None, }), filter: shader_values diff --git a/librashader-presets/src/parse/value.rs b/librashader-presets/src/parse/value.rs index 4654b74..7a4a680 100644 --- a/librashader-presets/src/parse/value.rs +++ b/librashader-presets/src/parse/value.rs @@ -10,7 +10,7 @@ use nom::IResult; use num_traits::cast::ToPrimitive; use crate::parse::token::do_lex; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use librashader_common::{FilterMode, WrapMode}; use std::fs::File; use std::io::Read; @@ -37,10 +37,10 @@ pub enum Value { FloatFramebuffer(i32, bool), SrgbFramebuffer(i32, bool), MipmapInput(i32, bool), - Alias(i32, String), - Parameter(String, f32), + Alias(i32, ShortString), + Parameter(ShortString, f32), Texture { - name: String, + name: ShortString, filter_mode: FilterMode, wrap_mode: WrapMode, mipmap: bool, @@ -389,7 +389,7 @@ pub fn parse_values( .map_or(None, |(_, v)| Some(FilterMode::from_str(&v.value).unwrap())); values.push(Value::Texture { - name: texture.to_string(), + name: ShortString::from(*texture.fragment()), filter_mode: filter.unwrap_or(if linear { FilterMode::Linear } else { @@ -412,7 +412,7 @@ pub fn parse_values( // params (god help me), it would be pretty bad because we lose texture path fallback. .unwrap_or(0.0); values.push(Value::Parameter( - token.key.fragment().to_string(), + ShortString::from(*token.key.fragment()), param_val, )); continue; @@ -493,7 +493,10 @@ pub fn parse_values( } if let Ok((_, idx)) = parse_indexed_key("alias", token.key) { - values.push(Value::Alias(idx, token.value.to_string())); + values.push(Value::Alias( + idx, + ShortString::from(*token.value.fragment()), + )); continue; } if let Ok((_, idx)) = parse_indexed_key("scale_type", token.key) { @@ -556,7 +559,7 @@ pub fn parse_values( // handle undeclared parameters after parsing everything else as a last resort. if let Ok(param_val) = from_float(token.value) { values.push(Value::Parameter( - token.key.fragment().to_string(), + ShortString::from(*token.key.fragment()), param_val, )); } @@ -605,7 +608,7 @@ pub fn parse_values( }); values.push(Value::Texture { - name: texture.to_string(), + name: ShortString::from(*texture.fragment()), filter_mode: if linear { FilterMode::Linear } else { diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index e287bf9..8c63c75 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -1,4 +1,5 @@ use crate::error::ParsePresetError; +use librashader_common::map::ShortString; use librashader_common::{FilterMode, ImageFormat, WrapMode}; use std::ops::Mul; use std::path::PathBuf; @@ -12,7 +13,7 @@ pub struct ShaderPassConfig { /// The fully qualified path to the shader pass source file. pub name: PathBuf, /// The alias of the shader pass if available. - pub alias: Option, + pub alias: Option, /// The filtering mode that this shader pass should expect. pub filter: FilterMode, /// The texture addressing (wrap) mode that this shader pass expects. @@ -151,7 +152,7 @@ pub struct Scale2D { #[derive(Debug, Clone)] pub struct TextureConfig { /// The name of the texture. - pub name: String, + pub name: ShortString, /// The fully qualified path to the texture. pub path: PathBuf, /// The wrap (addressing) mode to use when sampling the texture. @@ -166,7 +167,7 @@ pub struct TextureConfig { #[derive(Debug, Clone)] pub struct ParameterConfig { /// The name of the parameter. - pub name: String, + pub name: ShortString, /// The value it is set to in the preset. pub value: f32, } diff --git a/librashader-reflect/src/back/wgsl.rs b/librashader-reflect/src/back/wgsl.rs index 1453321..00d5227 100644 --- a/librashader-reflect/src/back/wgsl.rs +++ b/librashader-reflect/src/back/wgsl.rs @@ -36,7 +36,7 @@ mod test { use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; use crate::reflect::ReflectShader; use bitflags::Flags; - use librashader_common::map::FastHashMap; + use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::ShaderSource; #[test] @@ -45,7 +45,7 @@ mod test { // let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap(); let result = ShaderSource::load("../test/basic.slang").unwrap(); - let mut uniform_semantics: FastHashMap = Default::default(); + let mut uniform_semantics: FastHashMap = Default::default(); for (_index, param) in result.parameters.iter().enumerate() { uniform_semantics.insert( diff --git a/librashader-reflect/src/reflect/cross/mod.rs b/librashader-reflect/src/reflect/cross/mod.rs index 688d198..a0214c4 100644 --- a/librashader-reflect/src/reflect/cross/mod.rs +++ b/librashader-reflect/src/reflect/cross/mod.rs @@ -19,11 +19,11 @@ use crate::reflect::{align_uniform_size, ReflectShader}; use std::fmt::Debug; use std::ops::Deref; +use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; +use librashader_common::map::ShortString; use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type}; use spirv_cross::ErrorCode; -use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; - /// Reflect shaders under SPIRV-Cross semantics. /// /// SPIRV-Cross supports GLSL, HLSL, SPIR-V, and MSL targets. @@ -342,7 +342,7 @@ where match ¶meter.semantics { UniqueSemantics::FloatParameter => { let offset = range.offset; - if let Some(meta) = meta.parameter_meta.get_mut(&name) { + if let Some(meta) = meta.parameter_meta.get_mut::(&name.as_ref()) { if let Some(expected) = meta.offset.offset(offset_type) && expected != offset { @@ -365,6 +365,7 @@ where *meta.offset.offset_mut(offset_type) = Some(offset); } else { + let name = ShortString::from(name); meta.parameter_meta.insert( name.clone(), VariableMeta { @@ -403,7 +404,7 @@ where meta.unique_meta.insert( *semantics, VariableMeta { - id: name, + id: name.into(), offset: MemberOffset::new(offset, offset_type), size: typeinfo.size * typeinfo.columns, }, @@ -454,7 +455,7 @@ where SemanticErrorBlame::Vertex => BindingStage::VERTEX, SemanticErrorBlame::Fragment => BindingStage::FRAGMENT, }, - id: name, + id: ShortString::from(name), }, ); } @@ -753,7 +754,7 @@ mod test { use crate::back::{CompileShader, ShaderCompilerOutput}; use crate::front::{Glslang, ShaderInputCompiler}; use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; - use librashader_common::map::FastHashMap; + use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::ShaderSource; use spirv_cross::glsl::{CompilerOptions, Version}; use spirv_cross::hlsl::ShaderModel; @@ -762,7 +763,7 @@ mod test { #[test] pub fn test_into() { let result = ShaderSource::load("../test/basic.slang").unwrap(); - let mut uniform_semantics: FastHashMap = Default::default(); + let mut uniform_semantics: FastHashMap = Default::default(); for (_index, param) in result.parameters.iter().enumerate() { uniform_semantics.insert( diff --git a/librashader-reflect/src/reflect/cross/msl.rs b/librashader-reflect/src/reflect/cross/msl.rs index 60b52de..6c07497 100644 --- a/librashader-reflect/src/reflect/cross/msl.rs +++ b/librashader-reflect/src/reflect/cross/msl.rs @@ -110,7 +110,7 @@ mod test { use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; use crate::reflect::ReflectShader; use bitflags::Flags; - use librashader_common::map::FastHashMap; + use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::ShaderSource; use rustc_hash::FxHashMap; use spirv_cross::msl; @@ -122,7 +122,7 @@ mod test { // let result = ShaderSource::load("../test/shaders_slang/crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang").unwrap(); let result = ShaderSource::load("../test/basic.slang").unwrap(); - let mut uniform_semantics: FastHashMap = Default::default(); + let mut uniform_semantics: FastHashMap = Default::default(); for (_index, param) in result.parameters.iter().enumerate() { uniform_semantics.insert( diff --git a/librashader-reflect/src/reflect/naga/mod.rs b/librashader-reflect/src/reflect/naga/mod.rs index 5dd577e..037fac2 100644 --- a/librashader-reflect/src/reflect/naga/mod.rs +++ b/librashader-reflect/src/reflect/naga/mod.rs @@ -10,16 +10,8 @@ pub mod wgsl; use crate::error::{SemanticsErrorKind, ShaderReflectError}; use std::fmt::Debug; -use crate::front::SpirvCompilation; -use naga::{ - AddressSpace, Binding, Expression, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, - Scalar, ScalarKind, StructMember, TypeInner, VectorSize, -}; -use rspirv::binary::Assemble; -use rspirv::dr::Builder; -use rustc_hash::FxHashSet; - use crate::front::spirv_passes::lower_samplers; +use crate::front::SpirvCompilation; use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData}; use crate::reflect::semantics::{ BindingMeta, BindingStage, BufferReflection, MemberOffset, ShaderSemantics, TextureBinding, @@ -28,6 +20,14 @@ use crate::reflect::semantics::{ MAX_PUSH_BUFFER_SIZE, }; use crate::reflect::{align_uniform_size, ReflectShader, ShaderReflection}; +use librashader_common::map::ShortString; +use naga::{ + AddressSpace, Binding, Expression, GlobalVariable, Handle, ImageClass, Module, ResourceBinding, + Scalar, ScalarKind, StructMember, TypeInner, VectorSize, +}; +use rspirv::binary::Assemble; +use rspirv::dr::Builder; +use rustc_hash::FxHashSet; /// Reflect under Naga semantics /// @@ -678,7 +678,7 @@ impl NagaReflect { match ¶meter.semantics { UniqueSemantics::FloatParameter => { let offset = member.offset; - if let Some(meta) = meta.parameter_meta.get_mut(&name) { + if let Some(meta) = meta.parameter_meta.get_mut::(name.as_ref()) { if let Some(expected) = meta.offset.offset(offset_type) && expected != offset as usize { @@ -701,6 +701,7 @@ impl NagaReflect { *meta.offset.offset_mut(offset_type) = Some(offset as usize); } else { + let name = ShortString::from(name); meta.parameter_meta.insert( name.clone(), VariableMeta { @@ -739,7 +740,7 @@ impl NagaReflect { meta.unique_meta.insert( *semantics, VariableMeta { - id: name, + id: ShortString::from(name), offset: MemberOffset::new(offset as usize, offset_type), size: typeinfo.size * typeinfo.columns, }, @@ -790,7 +791,7 @@ impl NagaReflect { SemanticErrorBlame::Vertex => BindingStage::VERTEX, SemanticErrorBlame::Fragment => BindingStage::FRAGMENT, }, - id: name, + id: ShortString::from(name), }, ); } diff --git a/librashader-reflect/src/reflect/naga/msl.rs b/librashader-reflect/src/reflect/naga/msl.rs index 1f705c8..6794831 100644 --- a/librashader-reflect/src/reflect/naga/msl.rs +++ b/librashader-reflect/src/reflect/naga/msl.rs @@ -166,7 +166,7 @@ mod test { use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics}; use crate::reflect::ReflectShader; use bitflags::Flags; - use librashader_common::map::FastHashMap; + use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::ShaderSource; use spirv_cross::msl; @@ -174,7 +174,7 @@ mod test { pub fn test_into() { let result = ShaderSource::load("../test/basic.slang").unwrap(); - let mut uniform_semantics: FastHashMap = Default::default(); + let mut uniform_semantics: FastHashMap = Default::default(); for (_index, param) in result.parameters.iter().enumerate() { uniform_semantics.insert( diff --git a/librashader-reflect/src/reflect/presets.rs b/librashader-reflect/src/reflect/presets.rs index 1a47e0c..644d8cb 100644 --- a/librashader-reflect/src/reflect/presets.rs +++ b/librashader-reflect/src/reflect/presets.rs @@ -5,7 +5,7 @@ use crate::front::{ShaderInputCompiler, ShaderReflectObject}; use crate::reflect::semantics::{ Semantic, ShaderSemantics, TextureSemantics, UniformSemantic, UniqueSemantics, }; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use librashader_preprocess::{PreprocessError, ShaderSource}; use librashader_presets::{ShaderPassConfig, TextureConfig}; @@ -80,8 +80,9 @@ where E: From, E: From, { - let mut uniform_semantics: FastHashMap = Default::default(); - let mut texture_semantics: FastHashMap> = Default::default(); + let mut uniform_semantics: FastHashMap = Default::default(); + let mut texture_semantics: FastHashMap> = + Default::default(); let passes = passes .into_iter() @@ -119,8 +120,8 @@ where /// Insert the available semantics for the input pass config into the provided semantic maps. fn insert_pass_semantics( - uniform_semantics: &mut FastHashMap, - texture_semantics: &mut FastHashMap>, + uniform_semantics: &mut FastHashMap, + texture_semantics: &mut FastHashMap>, config: &ShaderPassConfig, ) { let Some(alias) = &config.alias else { @@ -142,24 +143,32 @@ fn insert_pass_semantics( index, }, ); + + let mut alias_size = alias.clone(); + alias_size.push_str("Size"); uniform_semantics.insert( - format!("{alias}Size"), + alias_size, UniformSemantic::Texture(Semantic { semantics: TextureSemantics::PassOutput, index, }), ); + let mut alias_feedback = alias.clone(); + alias_feedback.push_str("Feedback"); // PassFeedback texture_semantics.insert( - format!("{alias}Feedback"), + alias_feedback, Semantic { semantics: TextureSemantics::PassFeedback, index, }, ); + + let mut alias_feedback_size = alias.clone(); + alias_feedback_size.push_str("FeedbackSize"); uniform_semantics.insert( - format!("{alias}FeedbackSize"), + alias_feedback_size, UniformSemantic::Texture(Semantic { semantics: TextureSemantics::PassFeedback, index, @@ -170,10 +179,13 @@ fn insert_pass_semantics( /// Insert the available semantics for the input texture config into the provided semantic maps. fn insert_lut_semantics( textures: &[TextureConfig], - uniform_semantics: &mut FastHashMap, - texture_semantics: &mut FastHashMap>, + uniform_semantics: &mut FastHashMap, + texture_semantics: &mut FastHashMap>, ) { for (index, texture) in textures.iter().enumerate() { + let mut size_semantic = texture.name.clone(); + size_semantic.push_str("Size"); + texture_semantics.insert( texture.name.clone(), Semantic { @@ -183,7 +195,7 @@ fn insert_lut_semantics( ); uniform_semantics.insert( - format!("{}Size", texture.name), + size_semantic, UniformSemantic::Texture(Semantic { semantics: TextureSemantics::User, index, diff --git a/librashader-reflect/src/reflect/semantics.rs b/librashader-reflect/src/reflect/semantics.rs index 894c270..278fc89 100644 --- a/librashader-reflect/src/reflect/semantics.rs +++ b/librashader-reflect/src/reflect/semantics.rs @@ -1,5 +1,5 @@ use bitflags::bitflags; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use std::str::FromStr; /// The maximum number of bindings allowed in a shader. @@ -255,7 +255,7 @@ pub struct VariableMeta { /// The size of the uniform. pub size: u32, /// The name of the uniform. - pub id: String, + pub id: ShortString, } /// Reflection information about a texture size uniform variable. @@ -267,7 +267,7 @@ pub struct TextureSizeMeta { /// The mask indicating for which stages the texture size uniform should be bound. pub stage_mask: BindingStage, /// The name of the uniform. - pub id: String, + pub id: ShortString, } /// Reflection information about texture samplers. @@ -321,7 +321,7 @@ pub trait TextureSemanticMap { fn get_texture_semantic(&self, name: &str) -> Option>; } -impl TextureSemanticMap for FastHashMap { +impl TextureSemanticMap for FastHashMap { fn get_texture_semantic(&self, name: &str) -> Option> { match self.get(name) { None => { @@ -353,7 +353,7 @@ impl TextureSemanticMap for FastHashMap { } } -impl TextureSemanticMap for FastHashMap> { +impl TextureSemanticMap for FastHashMap> { fn get_texture_semantic(&self, name: &str) -> Option> { match self.get(name) { None => { @@ -390,7 +390,7 @@ pub trait UniqueSemanticMap { fn get_unique_semantic(&self, name: &str) -> Option>; } -impl UniqueSemanticMap for FastHashMap { +impl UniqueSemanticMap for FastHashMap { fn get_unique_semantic(&self, name: &str) -> Option> { match self.get(name) { // existing uniforms in the semantic map have priority @@ -448,9 +448,9 @@ pub enum UniformSemantic { #[derive(Debug, Clone)] pub struct ShaderSemantics { /// A map of uniform names to filter chain semantics. - pub uniform_semantics: FastHashMap, + pub uniform_semantics: FastHashMap, /// A map of texture names to filter chain semantics. - pub texture_semantics: FastHashMap>, + pub texture_semantics: FastHashMap>, } /// The binding of a uniform after the shader has been linked. @@ -460,7 +460,7 @@ pub struct ShaderSemantics { #[derive(Debug, Clone, Eq, Hash, PartialEq)] pub enum UniformBinding { /// A user parameter (`float`) binding. - Parameter(String), + Parameter(ShortString), /// A known semantic binding. SemanticVariable(UniqueSemantics), /// A texture size (`float4`) binding. @@ -483,7 +483,7 @@ impl From> for UniformBinding { #[derive(Debug, Default)] pub struct BindingMeta { /// A map of parameter names to uniform binding metadata. - pub parameter_meta: FastHashMap, + pub parameter_meta: FastHashMap, /// A map of unique semantics to uniform binding metadata. pub unique_meta: FastHashMap, /// A map of texture semantics to texture binding points. diff --git a/librashader-runtime/src/binding.rs b/librashader-runtime/src/binding.rs index 8848a99..b566121 100644 --- a/librashader-runtime/src/binding.rs +++ b/librashader-runtime/src/binding.rs @@ -1,6 +1,6 @@ use crate::parameters::RuntimeParameters; use crate::uniforms::{BindUniform, NoUniformBinder, UniformStorage}; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use librashader_common::Size; use librashader_preprocess::ShaderParameter; use librashader_reflect::reflect::semantics::{ @@ -120,7 +120,7 @@ where pass_feedback: impl Iterator>>, original_history: impl Iterator>>, lookup_textures: impl Iterator)>, - parameter_defaults: &FastHashMap, + parameter_defaults: &FastHashMap, runtime_parameters: &RuntimeParameters, ) { let runtime_parameters = runtime_parameters.parameters.load(); diff --git a/librashader-runtime/src/parameters.rs b/librashader-runtime/src/parameters.rs index 81c9638..0bdb8ce 100644 --- a/librashader-runtime/src/parameters.rs +++ b/librashader-runtime/src/parameters.rs @@ -1,6 +1,5 @@ -use std::ops::Deref; use arc_swap::ArcSwap; -use librashader_common::map::FastHashMap; +use librashader_common::map::{FastHashMap, ShortString}; use librashader_presets::ParameterConfig; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; @@ -17,7 +16,7 @@ pub trait FilterChainParameters { /// any thread. pub struct RuntimeParameters { passes_enabled: AtomicUsize, - pub(crate) parameters: ArcSwap>, + pub(crate) parameters: ArcSwap>, } impl RuntimeParameters { @@ -59,7 +58,7 @@ impl RuntimeParameters { } /// Get a reference to the runtime parameters. - pub fn parameters(&self) -> Arc> { + pub fn parameters(&self) -> Arc> { self.parameters.load_full() }