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"
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",
]

View file

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

View file

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

View file

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

View file

@ -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<T> {
pub width: T,
pub height: T,

View file

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

View file

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

View file

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

View file

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