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