presets: allow presets to be serializable with serde

This commit is contained in:
chyyran 2024-09-26 01:27:50 -04:00 committed by Ronny Chan
parent eeda0d02d0
commit 1676150858
9 changed files with 44 additions and 3 deletions

7
Cargo.lock generated
View file

@ -1237,6 +1237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8588661a8607108a5ca69cab034063441a0413a0b041c13618a7dd348021ef6f" checksum = "8588661a8607108a5ca69cab034063441a0413a0b041c13618a7dd348021ef6f"
dependencies = [ dependencies = [
"hashbrown 0.14.5", "hashbrown 0.14.5",
"serde",
] ]
[[package]] [[package]]
@ -1561,6 +1562,7 @@ dependencies = [
"objc2 0.5.2", "objc2 0.5.2",
"objc2-metal", "objc2-metal",
"rustc-hash 2.0.0", "rustc-hash 2.0.0",
"serde",
"smartstring", "smartstring",
"wgpu-types", "wgpu-types",
"windows 0.58.0", "windows 0.58.0",
@ -1589,6 +1591,7 @@ dependencies = [
"num-traits", "num-traits",
"once_cell", "once_cell",
"regex", "regex",
"serde",
"thiserror", "thiserror",
"vec_extract_if_polyfill", "vec_extract_if_polyfill",
] ]
@ -1783,6 +1786,7 @@ dependencies = [
"anyhow", "anyhow",
"ash", "ash",
"bitvec", "bitvec",
"clap",
"d3d12-descriptor-heap", "d3d12-descriptor-heap",
"gfx-maths", "gfx-maths",
"glfw", "glfw",
@ -1796,6 +1800,8 @@ dependencies = [
"objc2-metal", "objc2-metal",
"parking_lot", "parking_lot",
"pollster", "pollster",
"serde",
"serde_json",
"wgpu", "wgpu",
"wgpu-types", "wgpu-types",
"windows 0.58.0", "windows 0.58.0",
@ -2863,6 +2869,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"serde",
"static_assertions", "static_assertions",
"version_check", "version_check",
] ]

View file

@ -29,6 +29,8 @@ glfw = { version = "0.58.0"}
wgpu = { version = "22", default-features = false } wgpu = { version = "22", default-features = false }
wgpu-types = { version = "22" } wgpu-types = { version = "22" }
clap = { version = "=4.3.0", features = ["derive"] }
[workspace.metadata.release] [workspace.metadata.release]
[profile.optimized] [profile.optimized]

View file

@ -7,7 +7,7 @@ publish = false
[dependencies] [dependencies]
cbindgen = "0.27.0" cbindgen = "0.27.0"
clap = { version = "=4.3.0", features = ["derive"] } clap = { workspace = true }
carlog = "0.1.0" carlog = "0.1.0"
[package.metadata.release] [package.metadata.release]

View file

@ -21,7 +21,7 @@ dxgi = ["windows"]
vulkan = ["ash"] vulkan = ["ash"]
wgpu = ["wgpu-types"] wgpu = ["wgpu-types"]
metal = ["objc2", "objc2-metal"] metal = ["objc2", "objc2-metal"]
serde = ["dep:serde", "serde/derive", "smartstring/serde", "halfbrown/serde"]
[dependencies] [dependencies]
num-traits = "0.2.15" num-traits = "0.2.15"
rustc-hash = "2.0.0" rustc-hash = "2.0.0"
@ -32,6 +32,8 @@ glow = { workspace = true, optional = true }
ash = { workspace = true, optional = true } ash = { workspace = true, optional = true }
wgpu-types = { workspace = true, optional = true } wgpu-types = { workspace = true, optional = true }
serde = { version = "1.0", optional = true }
[target.'cfg(windows)'.dependencies.windows] [target.'cfg(windows)'.dependencies.windows]
optional = true optional = true
workspace = true workspace = true

View file

@ -45,6 +45,7 @@ use std::str::FromStr;
#[repr(u32)] #[repr(u32)]
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Supported image formats for textures. /// Supported image formats for textures.
pub enum ImageFormat { pub enum ImageFormat {
#[default] #[default]
@ -91,6 +92,7 @@ pub enum ImageFormat {
#[repr(i32)] #[repr(i32)]
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// The filtering mode for a texture sampler. /// The filtering mode for a texture sampler.
pub enum FilterMode { pub enum FilterMode {
/// Linear filtering. /// Linear filtering.
@ -129,6 +131,7 @@ impl FromStr for FilterMode {
#[repr(i32)] #[repr(i32)]
#[derive(Copy, Clone, Default, Debug, Eq, PartialEq, Hash)] #[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. /// The wrapping (address) mode for a texture sampler.
pub enum WrapMode { pub enum WrapMode {
#[default] #[default]
@ -189,6 +192,7 @@ impl FromStr for ImageFormat {
/// A size with a width and height. /// A size with a width and height.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Size<T> { pub struct Size<T> {
pub width: T, pub width: T,
pub height: T, pub height: T,

View file

@ -22,8 +22,11 @@ once_cell = "1"
regex = { version = "1", default-features = false, features = ["perf"] } regex = { version = "1", default-features = false, features = ["perf"] }
vec_extract_if_polyfill = "0.1.0" vec_extract_if_polyfill = "0.1.0"
serde = { version = "1.0", optional = true }
[features] [features]
parse_legacy_glsl = [] parse_legacy_glsl = []
serde = ["dep:serde", "serde/derive", "librashader-common/serde"]
[dev-dependencies] [dev-dependencies]
glob = "0.3.1" glob = "0.3.1"

View file

@ -7,6 +7,7 @@ use std::str::FromStr;
/// The configuration for a single shader pass. /// The configuration for a single shader pass.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ShaderPassConfig { pub struct ShaderPassConfig {
/// The index of the shader pass relative to its parent preset. /// The index of the shader pass relative to its parent preset.
pub id: i32, pub id: i32,
@ -55,6 +56,7 @@ impl ShaderPassConfig {
#[repr(i32)] #[repr(i32)]
#[derive(Default, Copy, Clone, Debug)] #[derive(Default, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// The scaling type for the shader pass. /// The scaling type for the shader pass.
pub enum ScaleType { pub enum ScaleType {
#[default] #[default]
@ -70,6 +72,7 @@ pub enum ScaleType {
/// The scaling factor for framebuffer scaling. /// The scaling factor for framebuffer scaling.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ScaleFactor { pub enum ScaleFactor {
/// Scale by a fractional float factor. /// Scale by a fractional float factor.
Float(f32), Float(f32),
@ -130,6 +133,7 @@ impl FromStr for ScaleType {
/// Framebuffer scaling parameters. /// Framebuffer scaling parameters.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Scaling { pub struct Scaling {
/// The method to scale the framebuffer with. /// The method to scale the framebuffer with.
pub scale_type: ScaleType, pub scale_type: ScaleType,
@ -139,6 +143,7 @@ pub struct Scaling {
/// 2D quad scaling parameters. /// 2D quad scaling parameters.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Scale2D { pub struct Scale2D {
/// Whether or not this combination of scaling factors is valid. /// Whether or not this combination of scaling factors is valid.
pub valid: bool, pub valid: bool,
@ -150,6 +155,7 @@ pub struct Scale2D {
/// Configuration options for a lookup texture used in the shader. /// Configuration options for a lookup texture used in the shader.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextureConfig { pub struct TextureConfig {
/// The name of the texture. /// The name of the texture.
pub name: ShortString, pub name: ShortString,
@ -165,6 +171,7 @@ pub struct TextureConfig {
/// Configuration options for a shader parameter. /// Configuration options for a shader parameter.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParameterConfig { pub struct ParameterConfig {
/// The name of the parameter. /// The name of the parameter.
pub name: ShortString, 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 /// A shader preset can be used to create a filter chain runtime instance, or reflected to get
/// parameter metadata. /// parameter metadata.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ShaderPreset { pub struct ShaderPreset {
/// Used in legacy GLSL shader semantics. If < 0, no feedback pass is used. /// 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 /// Otherwise, the FBO after pass #N is passed a texture to next frame

View file

@ -3,8 +3,15 @@ name = "librashader-test"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[lib]
path = "src/lib.rs"
[[bin]]
name = "librashader-cli"
path = "src/cli/main.rs"
[dependencies] [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"} librashader-runtime = { version = "0.4.5", path = "../librashader-runtime"}
wgpu = { version = "22", default-features = false, optional = true } wgpu = { version = "22", default-features = false, optional = true }
wgpu-types = { version = "22", optional = true } wgpu-types = { version = "22", optional = true }
@ -22,6 +29,10 @@ glow = { workspace = true, optional = true }
glfw = { workspace = true, optional = true } glfw = { workspace = true, optional = true }
ash = { workspace = true, optional = true } ash = { workspace = true, optional = true }
clap = { workspace = true }
serde = "1.0"
serde_json = "1.0"
[features] [features]
default = ["full"] default = ["full"]
@ -36,6 +47,8 @@ d3d9 = ["librashader/runtime-d3d9", "dep:windows"]
metal = ["librashader/runtime-metal", "dep:objc2", "dep:objc2-metal"] metal = ["librashader/runtime-metal", "dep:objc2", "dep:objc2-metal"]
vulkan-debug = ["vulkan"]
[target.'cfg(windows)'.dependencies.windows] [target.'cfg(windows)'.dependencies.windows]
workspace = true workspace = true
optional = true optional = true

View file

@ -84,6 +84,8 @@ full = ["runtime-all", "reflect-all", "preprocess", "presets"]
# cache hack # cache hack
docsrs = ["librashader-cache/docsrs"] docsrs = ["librashader-cache/docsrs"]
serde = ["librashader-presets/serde"]
# emits warning messages in tests # emits warning messages in tests
github-ci = [] github-ci = []