chore: run fmt
This commit is contained in:
parent
3f83e0fcd0
commit
f0ad7ea3c8
|
@ -8,4 +8,8 @@ edition = "2021"
|
|||
[dependencies]
|
||||
thiserror = "1.0.37"
|
||||
nom = "7.1.1"
|
||||
librashader = { path = "../librashader"}
|
||||
librashader = { path = "../librashader" }
|
||||
|
||||
[features]
|
||||
default = [ "line_directives" ]
|
||||
line_directives = []
|
|
@ -1,7 +1,7 @@
|
|||
use librashader::ShaderParameter;
|
||||
use std::convert::Infallible;
|
||||
use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
use librashader::ShaderParameter;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum PreprocessError {
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::io::Read;
|
|||
use std::path::Path;
|
||||
use std::str::Lines;
|
||||
|
||||
#[cfg(feature = "line_directives")]
|
||||
const GL_GOOGLE_CPP_STYLE_LINE_DIRECTIVE: &'static str =
|
||||
"#extension GL_GOOGLE_CPP_STYLE_LINE_DIRECTIVE : require";
|
||||
|
||||
|
@ -33,7 +34,9 @@ pub fn read_source(path: impl AsRef<Path>) -> Result<String, PreprocessError> {
|
|||
return Err(PreprocessError::UnexpectedEof);
|
||||
}
|
||||
|
||||
#[cfg(feature = "line_directives")]
|
||||
output.push_line(GL_GOOGLE_CPP_STYLE_LINE_DIRECTIVE);
|
||||
|
||||
output.mark_line(2, path.file_name().and_then(|f| f.to_str()).unwrap_or(""));
|
||||
preprocess(lines, path, &mut output)?;
|
||||
|
||||
|
|
|
@ -3,15 +3,15 @@ mod include;
|
|||
mod pragma;
|
||||
mod stage;
|
||||
|
||||
use std::path::Path;
|
||||
use crate::include::read_source;
|
||||
pub use error::*;
|
||||
use librashader::ShaderSource;
|
||||
use crate::include::read_source;
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
pub(crate) trait SourceOutput {
|
||||
fn push_line(&mut self, str: &str);
|
||||
fn mark_line(&mut self, line_no: usize, comment: &str) {
|
||||
#[cfg(feature = "line_directives")]
|
||||
self.push_line(&format!("#line {} \"{}\"", line_no, comment))
|
||||
}
|
||||
}
|
||||
|
@ -44,10 +44,11 @@ mod test {
|
|||
|
||||
#[test]
|
||||
pub fn load_file() {
|
||||
let result =
|
||||
load_shader_source("../test/slang-shaders/blurs/shaders/royale/blur3x3-last-pass.slang")
|
||||
let result = load_shader_source(
|
||||
"../test/slang-shaders/blurs/shaders/royale/blur3x3-last-pass.slang",
|
||||
)
|
||||
.unwrap();
|
||||
eprintln!("{result:#?}")
|
||||
eprintln!("{:#}", result.vertex)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -60,12 +61,12 @@ mod test {
|
|||
|
||||
#[test]
|
||||
pub fn get_param_pragmas() {
|
||||
let result =
|
||||
read_source("../test/slang-shaders/crt/shaders/crt-maximus-royale/src/ntsc_pass1.slang")
|
||||
let result = read_source(
|
||||
"../test/slang-shaders/crt/shaders/crt-maximus-royale/src/ntsc_pass1.slang",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let params = pragma::parse_pragma_meta(result)
|
||||
.unwrap();
|
||||
let params = pragma::parse_pragma_meta(result).unwrap();
|
||||
eprintln!("{params:?}")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use std::str::FromStr;
|
||||
use crate::PreprocessError;
|
||||
use librashader::{ShaderFormat, ShaderParameter};
|
||||
use nom::bytes::complete::{is_not, tag, take_until, take_while};
|
||||
use nom::combinator::map_res;
|
||||
use nom::IResult;
|
||||
use nom::number::complete::float;
|
||||
use nom::sequence::delimited;
|
||||
use librashader::{ShaderFormat, ShaderParameter};
|
||||
use crate::PreprocessError;
|
||||
use nom::IResult;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ShaderMeta {
|
||||
pub(crate) format: ShaderFormat,
|
||||
pub(crate) parameters: Vec<ShaderParameter>,
|
||||
pub(crate) name: Option<String>
|
||||
pub(crate) name: Option<String>,
|
||||
}
|
||||
|
||||
fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessError>{
|
||||
fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessError> {
|
||||
fn parse_parameter_string_inner(input: &str) -> IResult<&str, ShaderParameter> {
|
||||
let (input, _) = tag("#pragma parameter ")(input)?;
|
||||
let (input, name) = take_while(|c| c != ' ')(input)?;
|
||||
|
@ -28,14 +28,17 @@ fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessErro
|
|||
let (input, maximum) = float(input)?;
|
||||
let (input, _) = tag(" ")(input)?;
|
||||
let (input, step) = float(input)?;
|
||||
Ok((input, ShaderParameter {
|
||||
Ok((
|
||||
input,
|
||||
ShaderParameter {
|
||||
id: name.to_string(),
|
||||
description: description.to_string(),
|
||||
initial,
|
||||
minimum,
|
||||
maximum,
|
||||
step
|
||||
}))
|
||||
step,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
if let Ok((_, parameter)) = parse_parameter_string_inner(input) {
|
||||
|
@ -55,7 +58,7 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
|
|||
let parameter = parse_parameter_string(line)?;
|
||||
if let Some(existing) = parameters.iter().find(|&p| p.id == parameter.id) {
|
||||
if existing != ¶meter {
|
||||
return Err(PreprocessError::DuplicatePragmaError(parameter.id))
|
||||
return Err(PreprocessError::DuplicatePragmaError(parameter.id));
|
||||
}
|
||||
} else {
|
||||
parameters.push(parameter);
|
||||
|
@ -64,14 +67,14 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
|
|||
|
||||
if line.starts_with("#pragma format ") {
|
||||
if format != ShaderFormat::Unknown {
|
||||
return Err(PreprocessError::DuplicatePragmaError(line.to_string()))
|
||||
return Err(PreprocessError::DuplicatePragmaError(line.to_string()));
|
||||
}
|
||||
|
||||
let format_string = line["#pragma format ".len()..].trim();
|
||||
format = ShaderFormat::from_str(&format_string)?;
|
||||
|
||||
if format == ShaderFormat::Unknown {
|
||||
return Err(PreprocessError::UnknownShaderFormat)
|
||||
return Err(PreprocessError::UnknownShaderFormat);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,13 +87,17 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
|
|||
}
|
||||
}
|
||||
|
||||
Ok(ShaderMeta { name, format, parameters })
|
||||
Ok(ShaderMeta {
|
||||
name,
|
||||
format,
|
||||
parameters,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use librashader::ShaderParameter;
|
||||
use crate::pragma::parse_parameter_string;
|
||||
use librashader::ShaderParameter;
|
||||
|
||||
#[test]
|
||||
fn parses_parameter_pragma() {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use std::str::FromStr;
|
||||
use crate::{PreprocessError, SourceOutput};
|
||||
use std::str::FromStr;
|
||||
|
||||
enum ActiveStage {
|
||||
Both,
|
||||
Fragment,
|
||||
Vertex
|
||||
Vertex,
|
||||
}
|
||||
|
||||
impl FromStr for ActiveStage {
|
||||
|
@ -14,7 +14,7 @@ impl FromStr for ActiveStage {
|
|||
match s {
|
||||
"vertex" => Ok(ActiveStage::Vertex),
|
||||
"fragment" => Ok(ActiveStage::Fragment),
|
||||
_ => Err(PreprocessError::InvalidStage)
|
||||
_ => Err(PreprocessError::InvalidStage),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ impl FromStr for ActiveStage {
|
|||
#[derive(Default)]
|
||||
pub(crate) struct ShaderOutput {
|
||||
pub(crate) fragment: String,
|
||||
pub(crate) vertex: String
|
||||
pub(crate) vertex: String,
|
||||
}
|
||||
|
||||
pub(crate) fn process_stages(source: &str) -> Result<ShaderOutput, PreprocessError> {
|
||||
|
@ -48,9 +48,7 @@ pub(crate) fn process_stages(source: &str) -> Result<ShaderOutput, PreprocessErr
|
|||
ActiveStage::Fragment => {
|
||||
output.fragment.push_line(line);
|
||||
}
|
||||
ActiveStage::Vertex => {
|
||||
output.vertex.push_line(line)
|
||||
}
|
||||
ActiveStage::Vertex => output.vertex.push_line(line),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
mod error;
|
||||
mod parse;
|
||||
mod preset;
|
||||
pub use preset::*;
|
||||
pub use error::*;
|
||||
pub use preset::*;
|
||||
|
|
|
@ -33,8 +33,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
pub fn parse_preset() {
|
||||
let root =
|
||||
PathBuf::from("../test/slang-shaders/ntsc/ntsc-256px-svideo.slangp");
|
||||
let root = PathBuf::from("../test/slang-shaders/ntsc/ntsc-256px-svideo.slangp");
|
||||
let basic = ShaderPreset::try_parse(root);
|
||||
eprintln!("{:#?}", basic);
|
||||
assert!(basic.is_ok());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::parse::remove_if;
|
||||
use crate::parse::value::Value;
|
||||
use crate::{ParameterConfig, ShaderPreset, Scale2D, Scaling, ShaderPassConfig, TextureConfig};
|
||||
use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, TextureConfig};
|
||||
|
||||
pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
||||
let textures: Vec<TextureConfig> = values
|
||||
|
|
Loading…
Reference in a new issue