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.
82 lines
3.1 KiB
82 lines
3.1 KiB
use crate::parser::{tokenize, parse};
|
|
|
|
#[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 mut ast = parse(tokenize(src));
|
|
println!("{:#?}", ast);
|
|
let module = meta_compile(&mut ast);
|
|
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(vec![
|
|
Ast::List(vec![
|
|
Ast::Symbol("store-ptr".to_string()),
|
|
Ast::List(vec![Ast::Symbol("out-color".to_string())]),
|
|
Ast::List(vec![
|
|
Ast::Symbol("v4f32i".to_string()),
|
|
Ast::List(vec![
|
|
Ast::Symbol("/".to_string()),
|
|
Ast::List(vec![
|
|
Ast::Symbol(".xy".to_string()),
|
|
Ast::List(vec![Ast::Symbol("load-ptr".to_string()), Ast::Symbol("frag-coord".to_string())]),
|
|
]),
|
|
Ast::List(vec![Ast::Symbol("v2f32".to_string()), Ast::Symbol("1920.0".to_string()), Ast::Symbol("1080.0".to_string())]),
|
|
]),
|
|
Ast::Symbol("1.0".to_string()),
|
|
Ast::Symbol("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(),
|
|
}],
|
|
};
|
|
assert_eq!(module, test_module);
|
|
} |