You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
4.0 KiB
97 lines
4.0 KiB
use crate::parser::{parse, tokenize};
|
|
|
|
#[test]
|
|
fn test_compile() {
|
|
use crate::compiler::*;
|
|
let src = "
|
|
(module Shader Logical GLSL450)
|
|
(import :std GLSL.std.450)
|
|
(bind (frag-coord:*v4f32i) (BuiltIn FragCoord))
|
|
(bind (out-color:*v4f32o) (Location 0))
|
|
(dec frag-coord:*v4f32i Input)
|
|
(dec out-color:*v4f32o Output)
|
|
(entry main Fragment OriginUpperLeft (:frag-coord :out-color))
|
|
(fun (main)
|
|
(store-ptr (out-color)
|
|
(v4f32i (/ (.xy (load-ptr frag-coord))
|
|
(v2f32 1920.0 1080.0))
|
|
1.0
|
|
1.0)))
|
|
";
|
|
let ast = parse(tokenize(src));
|
|
println!("{:#?}", ast);
|
|
let module = meta_compile(&mut ast.unwrap());
|
|
println!("{:#?}", module);
|
|
let test_module = Module {
|
|
capabilities: vec![Capability::Shader],
|
|
entry_points: vec![EntryPoint {
|
|
execution_model: ExecutionModel::Fragment,
|
|
execution_mode: ExecutionMode::OriginUpperLeft,
|
|
name: "main".to_string(),
|
|
interface: vec!["frag-coord".to_string(), "out-color".to_string()],
|
|
}],
|
|
globals: vec![
|
|
GlobalVariable {
|
|
name: "frag-coord".to_string(),
|
|
typ: "*v4f32i".to_string(),
|
|
storage_class: StorageClass::Input,
|
|
decorations: vec![Decoration::BuiltIn(BuiltinDecoration::FragCoord)],
|
|
},
|
|
GlobalVariable {
|
|
name: "out-color".to_string(),
|
|
typ: "*v4f32o".to_string(),
|
|
storage_class: StorageClass::Output,
|
|
decorations: vec![Decoration::Location(0)],
|
|
},
|
|
],
|
|
functions: vec![Function {
|
|
name: "main".to_string(),
|
|
return_type: "void".to_string(),
|
|
arguments: vec![],
|
|
body: Some(vec![]),
|
|
ast: Some(Ast::List(Localised::dummy_location(vec![Ast::List(
|
|
Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location("store-ptr".to_string())),
|
|
Ast::List(Localised::dummy_location(vec![Ast::Symbol(
|
|
Localised::dummy_location("out-color".to_string()),
|
|
)])),
|
|
Ast::List(Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location("v4f32i".to_string())),
|
|
Ast::List(Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location("/".to_string())),
|
|
Ast::List(Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location(".xy".to_string())),
|
|
Ast::List(Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location("load-ptr".to_string())),
|
|
Ast::Symbol(Localised::dummy_location(
|
|
"frag-coord".to_string(),
|
|
)),
|
|
])),
|
|
])),
|
|
Ast::List(Localised::dummy_location(vec![
|
|
Ast::Symbol(Localised::dummy_location("v2f32".to_string())),
|
|
Ast::Symbol(Localised::dummy_location("1920.0".to_string())),
|
|
Ast::Symbol(Localised::dummy_location("1080.0".to_string())),
|
|
])),
|
|
])),
|
|
Ast::Symbol(Localised::dummy_location("1.0".to_string())),
|
|
Ast::Symbol(Localised::dummy_location("1.0".to_string())),
|
|
])),
|
|
]),
|
|
)]))),
|
|
}],
|
|
memory_model: Memory {
|
|
addressing_model: AddressingModel::Logical,
|
|
memory_model: MemoryModel::GLSL450,
|
|
},
|
|
imports: vec![Import {
|
|
name: ":std".to_string(),
|
|
value: "GLSL.std.450".to_string(),
|
|
}],
|
|
};
|
|
dbg!(&module);
|
|
dbg!(&test_module);
|
|
assert_eq!(module, test_module);
|
|
}
|
|
|