diff --git a/Cargo.lock b/Cargo.lock index 0e666e3..1737fce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1237,6 +1237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8588661a8607108a5ca69cab034063441a0413a0b041c13618a7dd348021ef6f" dependencies = [ "hashbrown 0.14.5", + "serde", ] [[package]] @@ -1561,6 +1562,7 @@ dependencies = [ "objc2 0.5.2", "objc2-metal", "rustc-hash 2.0.0", + "serde", "smartstring", "wgpu-types", "windows 0.58.0", @@ -1589,6 +1591,7 @@ dependencies = [ "num-traits", "once_cell", "regex", + "serde", "thiserror", "vec_extract_if_polyfill", ] @@ -1783,6 +1786,7 @@ dependencies = [ "anyhow", "ash", "bitvec", + "clap", "d3d12-descriptor-heap", "gfx-maths", "glfw", @@ -1796,6 +1800,8 @@ dependencies = [ "objc2-metal", "parking_lot", "pollster", + "serde", + "serde_json", "wgpu", "wgpu-types", "windows 0.58.0", @@ -2863,6 +2869,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" dependencies = [ "autocfg", + "serde", "static_assertions", "version_check", ] diff --git a/Cargo.toml b/Cargo.toml index 57e52cd..34819d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,8 @@ glfw = { version = "0.58.0"} wgpu = { version = "22", default-features = false } wgpu-types = { version = "22" } +clap = { version = "=4.3.0", features = ["derive"] } + [workspace.metadata.release] [profile.optimized] diff --git a/librashader-build-script/Cargo.toml b/librashader-build-script/Cargo.toml index 3d65bea..6dd45fc 100644 --- a/librashader-build-script/Cargo.toml +++ b/librashader-build-script/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] cbindgen = "0.27.0" -clap = { version = "=4.3.0", features = ["derive"] } +clap = { workspace = true } carlog = "0.1.0" [package.metadata.release] diff --git a/librashader-common/Cargo.toml b/librashader-common/Cargo.toml index 0af2428..1a90e9e 100644 --- a/librashader-common/Cargo.toml +++ b/librashader-common/Cargo.toml @@ -21,7 +21,7 @@ dxgi = ["windows"] vulkan = ["ash"] wgpu = ["wgpu-types"] metal = ["objc2", "objc2-metal"] - +serde = ["dep:serde", "serde/derive", "smartstring/serde", "halfbrown/serde"] [dependencies] num-traits = "0.2.15" rustc-hash = "2.0.0" @@ -32,6 +32,8 @@ glow = { workspace = true, optional = true } ash = { workspace = true, optional = true } wgpu-types = { workspace = true, optional = true } +serde = { version = "1.0", optional = true } + [target.'cfg(windows)'.dependencies.windows] optional = true workspace = true diff --git a/librashader-common/src/lib.rs b/librashader-common/src/lib.rs index 2a5593f..226c7f2 100644 --- a/librashader-common/src/lib.rs +++ b/librashader-common/src/lib.rs @@ -45,6 +45,7 @@ use std::str::FromStr; #[repr(u32)] #[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// Supported image formats for textures. pub enum ImageFormat { #[default] @@ -91,6 +92,7 @@ pub enum ImageFormat { #[repr(i32)] #[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// The filtering mode for a texture sampler. pub enum FilterMode { /// Linear filtering. @@ -129,6 +131,7 @@ impl FromStr for FilterMode { #[repr(i32)] #[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// The wrapping (address) mode for a texture sampler. pub enum WrapMode { #[default] @@ -189,6 +192,7 @@ impl FromStr for ImageFormat { /// A size with a width and height. #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Size { pub width: T, pub height: T, diff --git a/librashader-presets/Cargo.toml b/librashader-presets/Cargo.toml index 5a47ac7..34b66ef 100644 --- a/librashader-presets/Cargo.toml +++ b/librashader-presets/Cargo.toml @@ -22,8 +22,11 @@ once_cell = "1" regex = { version = "1", default-features = false, features = ["perf"] } vec_extract_if_polyfill = "0.1.0" +serde = { version = "1.0", optional = true } + [features] parse_legacy_glsl = [] +serde = ["dep:serde", "serde/derive", "librashader-common/serde"] [dev-dependencies] glob = "0.3.1" diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index 8c63c75..09fcb76 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -7,6 +7,7 @@ use std::str::FromStr; /// The configuration for a single shader pass. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ShaderPassConfig { /// The index of the shader pass relative to its parent preset. pub id: i32, @@ -55,6 +56,7 @@ impl ShaderPassConfig { #[repr(i32)] #[derive(Default, Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] /// The scaling type for the shader pass. pub enum ScaleType { #[default] @@ -70,6 +72,7 @@ pub enum ScaleType { /// The scaling factor for framebuffer scaling. #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ScaleFactor { /// Scale by a fractional float factor. Float(f32), @@ -130,6 +133,7 @@ impl FromStr for ScaleType { /// Framebuffer scaling parameters. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Scaling { /// The method to scale the framebuffer with. pub scale_type: ScaleType, @@ -139,6 +143,7 @@ pub struct Scaling { /// 2D quad scaling parameters. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Scale2D { /// Whether or not this combination of scaling factors is valid. pub valid: bool, @@ -150,6 +155,7 @@ pub struct Scale2D { /// 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 name of the texture. pub name: ShortString, @@ -165,6 +171,7 @@ pub struct TextureConfig { /// Configuration options for a shader parameter. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ParameterConfig { /// The name of the parameter. pub name: ShortString, @@ -177,6 +184,7 @@ pub struct ParameterConfig { /// A shader preset can be used to create a filter chain runtime instance, or reflected to get /// parameter metadata. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ShaderPreset { /// Used in legacy GLSL shader semantics. If < 0, no feedback pass is used. /// Otherwise, the FBO after pass #N is passed a texture to next frame diff --git a/librashader-test/Cargo.toml b/librashader-test/Cargo.toml index 4f1db18..4fc0a35 100644 --- a/librashader-test/Cargo.toml +++ b/librashader-test/Cargo.toml @@ -3,8 +3,15 @@ name = "librashader-test" version = "0.1.0" edition = "2021" +[lib] +path = "src/lib.rs" + +[[bin]] +name = "librashader-cli" +path = "src/cli/main.rs" + [dependencies] -librashader = { version = "0.4.5", path = "../librashader", default-features = false } +librashader = { version = "0.4.5", path = "../librashader", features = ["presets", "serde"], default-features = false } librashader-runtime = { version = "0.4.5", path = "../librashader-runtime"} wgpu = { version = "22", default-features = false, optional = true } wgpu-types = { version = "22", optional = true } @@ -22,6 +29,10 @@ glow = { workspace = true, optional = true } glfw = { workspace = true, optional = true } ash = { workspace = true, optional = true } +clap = { workspace = true } +serde = "1.0" +serde_json = "1.0" + [features] default = ["full"] @@ -36,6 +47,8 @@ d3d9 = ["librashader/runtime-d3d9", "dep:windows"] metal = ["librashader/runtime-metal", "dep:objc2", "dep:objc2-metal"] +vulkan-debug = ["vulkan"] + [target.'cfg(windows)'.dependencies.windows] workspace = true optional = true diff --git a/librashader/Cargo.toml b/librashader/Cargo.toml index 6c37405..58d3d21 100644 --- a/librashader/Cargo.toml +++ b/librashader/Cargo.toml @@ -84,6 +84,8 @@ full = ["runtime-all", "reflect-all", "preprocess", "presets"] # cache hack docsrs = ["librashader-cache/docsrs"] +serde = ["librashader-presets/serde"] + # emits warning messages in tests github-ci = []