reflect/preprocess/presets: use SmallString where it makes sense

Most use cases are internal so at least for the runtime consumers there's no API change, but preset parsing
and reflection items are public API so might as well put this as part of 0.4.0
This commit is contained in:
chyyran 2024-09-04 01:53:48 -04:00 committed by Ronny Chan
parent c447e40583
commit 40a56bf165
19 changed files with 182 additions and 167 deletions

168
Cargo.lock generated
View file

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

View file

@ -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)))?;

View file

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

View file

@ -2,4 +2,7 @@
pub type FastHashMap<K, V> =
halfbrown::SizedHashMap<K, V, core::hash::BuildHasherDefault<rustc_hash::FxHasher>, 32>;
/// A string with small string optimizations up to 23 bytes.
pub type ShortString = smartstring::SmartString<smartstring::LazyCompact>;
pub use halfbrown;

View file

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

View file

@ -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<String>,
pub name: Option<ShortString>,
/// The list of shader parameters found in the shader source.
pub parameters: FastHashMap<String, ShaderParameter>,
pub parameters: FastHashMap<ShortString, ShaderParameter>,
/// 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.

View file

@ -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<ShaderParameter>,
pub(crate) name: Option<String>,
pub(crate) name: Option<ShortString>,
}
fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessError> {
@ -40,7 +41,7 @@ fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessErro
Ok((
input,
ShaderParameter {
id: name.to_string(),
id: name.into(),
description: description.to_string(),
initial,
minimum,
@ -60,7 +61,7 @@ fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessErro
Ok(param)
} else {
Ok(ShaderParameter {
id: name.to_string(),
id: name.into(),
description: description.to_string(),
initial: 0f32,
minimum: 0f32,
@ -89,7 +90,7 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
if let Some(format_string) = line.strip_prefix("#pragma format ") {
if format != ImageFormat::Unknown {
return Err(PreprocessError::DuplicatePragmaError(line.to_string()));
return Err(PreprocessError::DuplicatePragmaError(line.into()));
}
let format_string = format_string.trim();
@ -102,10 +103,10 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
if line.starts_with("#pragma name ") {
if name.is_some() {
return Err(PreprocessError::DuplicatePragmaError(line.to_string()));
return Err(PreprocessError::DuplicatePragmaError(line.into()));
}
name = Some(line.trim().to_string())
name = Some(ShortString::from(line.trim()))
}
}
@ -124,7 +125,7 @@ mod test {
#[test]
fn parses_parameter_pragma() {
assert_eq!(ShaderParameter {
id: "exc".to_string(),
id: "exc".into(),
description: "orizontal correction hack (games where players stay at center)".to_string(),
initial: 0.0,
minimum: -10.0,
@ -136,7 +137,7 @@ mod test {
#[test]
fn parses_parameter_pragma_test() {
assert_eq!(ShaderParameter {
id: "HSM_CORE_RES_SAMPLING_MULT_SCANLINE_DIR".to_string(),
id: "HSM_CORE_RES_SAMPLING_MULT_SCANLINE_DIR".into(),
description: " Scanline Dir Multiplier".to_string(),
initial: 100.0,
minimum: 25.0,

View file

@ -117,7 +117,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> 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

View file

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

View file

@ -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<String>,
pub alias: Option<ShortString>,
/// 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,
}

View file

@ -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<String, UniformSemantic> = Default::default();
let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert(

View file

@ -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 &parameter.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::<str>(&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<String, UniformSemantic> = Default::default();
let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert(

View file

@ -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<String, UniformSemantic> = Default::default();
let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert(

View file

@ -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 &parameter.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::<str>(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),
},
);
}

View file

@ -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<String, UniformSemantic> = Default::default();
let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();
for (_index, param) in result.parameters.iter().enumerate() {
uniform_semantics.insert(

View file

@ -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<ShaderReflectError>,
E: From<ShaderCompileError>,
{
let mut uniform_semantics: FastHashMap<String, UniformSemantic> = Default::default();
let mut texture_semantics: FastHashMap<String, Semantic<TextureSemantics>> = Default::default();
let mut uniform_semantics: FastHashMap<ShortString, UniformSemantic> = Default::default();
let mut texture_semantics: FastHashMap<ShortString, Semantic<TextureSemantics>> =
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<String, UniformSemantic>,
texture_semantics: &mut FastHashMap<String, Semantic<TextureSemantics>>,
uniform_semantics: &mut FastHashMap<ShortString, UniformSemantic>,
texture_semantics: &mut FastHashMap<ShortString, Semantic<TextureSemantics>>,
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<String, UniformSemantic>,
texture_semantics: &mut FastHashMap<String, Semantic<TextureSemantics>>,
uniform_semantics: &mut FastHashMap<ShortString, UniformSemantic>,
texture_semantics: &mut FastHashMap<ShortString, Semantic<TextureSemantics>>,
) {
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,

View file

@ -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<Semantic<TextureSemantics>>;
}
impl TextureSemanticMap for FastHashMap<String, UniformSemantic> {
impl TextureSemanticMap for FastHashMap<ShortString, UniformSemantic> {
fn get_texture_semantic(&self, name: &str) -> Option<Semantic<TextureSemantics>> {
match self.get(name) {
None => {
@ -353,7 +353,7 @@ impl TextureSemanticMap for FastHashMap<String, UniformSemantic> {
}
}
impl TextureSemanticMap for FastHashMap<String, Semantic<TextureSemantics>> {
impl TextureSemanticMap for FastHashMap<ShortString, Semantic<TextureSemantics>> {
fn get_texture_semantic(&self, name: &str) -> Option<Semantic<TextureSemantics>> {
match self.get(name) {
None => {
@ -390,7 +390,7 @@ pub trait UniqueSemanticMap {
fn get_unique_semantic(&self, name: &str) -> Option<Semantic<UniqueSemantics, ()>>;
}
impl UniqueSemanticMap for FastHashMap<String, UniformSemantic> {
impl UniqueSemanticMap for FastHashMap<ShortString, UniformSemantic> {
fn get_unique_semantic(&self, name: &str) -> Option<Semantic<UniqueSemantics, ()>> {
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<String, UniformSemantic>,
pub uniform_semantics: FastHashMap<ShortString, UniformSemantic>,
/// A map of texture names to filter chain semantics.
pub texture_semantics: FastHashMap<String, Semantic<TextureSemantics>>,
pub texture_semantics: FastHashMap<ShortString, Semantic<TextureSemantics>>,
}
/// 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<Semantic<TextureSemantics>> for UniformBinding {
#[derive(Debug, Default)]
pub struct BindingMeta {
/// A map of parameter names to uniform binding metadata.
pub parameter_meta: FastHashMap<String, VariableMeta>,
pub parameter_meta: FastHashMap<ShortString, VariableMeta>,
/// A map of unique semantics to uniform binding metadata.
pub unique_meta: FastHashMap<UniqueSemantics, VariableMeta>,
/// A map of texture semantics to texture binding points.

View file

@ -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<Item = Option<impl AsRef<Self::InputTexture>>>,
original_history: impl Iterator<Item = Option<impl AsRef<Self::InputTexture>>>,
lookup_textures: impl Iterator<Item = (usize, impl AsRef<Self::InputTexture>)>,
parameter_defaults: &FastHashMap<String, ShaderParameter>,
parameter_defaults: &FastHashMap<ShortString, ShaderParameter>,
runtime_parameters: &RuntimeParameters,
) {
let runtime_parameters = runtime_parameters.parameters.load();

View file

@ -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<FastHashMap<String, f32>>,
pub(crate) parameters: ArcSwap<FastHashMap<ShortString, f32>>,
}
impl RuntimeParameters {
@ -59,7 +58,7 @@ impl RuntimeParameters {
}
/// Get a reference to the runtime parameters.
pub fn parameters(&self) -> Arc<FastHashMap<String, f32>> {
pub fn parameters(&self) -> Arc<FastHashMap<ShortString, f32>> {
self.parameters.load_full()
}