From 5b69e81bd770ffae3559f6b2096a983355d7c995 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 16 May 2020 18:09:04 +0900 Subject: [PATCH] shaderir: Add more tests --- internal/shaderir/ir_test.go | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index c502acfae..1148bf11f 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -77,6 +77,13 @@ func varNameExpr(vt VariableType, index int) Expr { } } +func identExpr(ident string) Expr { + return Expr{ + Type: Ident, + Ident: ident, + } +} + func binaryExpr(op Op, exprs ...Expr) Expr { return Expr{ Type: Binary, @@ -92,6 +99,13 @@ func selectionExpr(cond, a, b Expr) Expr { } } +func fieldSelectorExpr(a, b Expr) Expr { + return Expr{ + Type: FieldSelector, + Exprs: []Expr{a, b}, + } +} + func TestOutput(t *testing.T) { tests := []struct { Name string @@ -310,6 +324,35 @@ varying vec3 V0;`, }, Glsl: `void F0(in bool l0, in float l1, in float l2, out float l3) { l3 = (l0) ? (l1) : (l2); +}`, + }, + { + Name: "FieldSelector", + Program: Program{ + Funcs: []Func{ + { + Name: "F0", + InParams: []Type{ + {Main: Vec4}, + }, + OutParams: []Type{ + {Main: Float}, + }, + Block: block( + nil, + assignStmt( + varNameExpr(Local, 1), + fieldSelectorExpr( + varNameExpr(Local, 0), + identExpr("x"), + ), + ), + ), + }, + }, + }, + Glsl: `void F0(in vec4 l0, out float l1) { + l1 = (l0).x; }`, }, {