2020-05-11 17:19:42 +02:00
|
|
|
// Copyright 2020 The Ebiten Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package shaderir_test
|
|
|
|
|
|
|
|
import (
|
2020-06-20 18:22:30 +02:00
|
|
|
"go/constant"
|
2020-05-11 17:19:42 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
2020-10-03 19:35:13 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/glsl"
|
2022-03-09 16:08:36 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir/msl"
|
2020-05-11 17:19:42 +02:00
|
|
|
)
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func block(localVars []shaderir.Type, offset int, stmts ...shaderir.Stmt) *shaderir.Block {
|
|
|
|
return &shaderir.Block{
|
2020-08-09 16:40:41 +02:00
|
|
|
LocalVars: localVars,
|
|
|
|
LocalVarIndexOffset: offset,
|
|
|
|
Stmts: stmts,
|
2020-05-14 20:33:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func exprStmt(expr shaderir.Expr) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.ExprStmt,
|
|
|
|
Exprs: []shaderir.Expr{expr},
|
2020-05-16 12:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func blockStmt(block *shaderir.Block) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.BlockStmt,
|
|
|
|
Blocks: []*shaderir.Block{block},
|
2020-05-14 20:33:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func returnStmt(expr shaderir.Expr) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.Return,
|
|
|
|
Exprs: []shaderir.Expr{expr},
|
2020-05-16 13:16:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func assignStmt(lhs shaderir.Expr, rhs shaderir.Expr) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.Assign,
|
|
|
|
Exprs: []shaderir.Expr{lhs, rhs},
|
2020-05-14 16:47:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func ifStmt(cond shaderir.Expr, block *shaderir.Block, elseBlock *shaderir.Block) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.If,
|
|
|
|
Exprs: []shaderir.Expr{cond},
|
|
|
|
Blocks: []*shaderir.Block{block, elseBlock},
|
2020-05-14 19:10:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func forStmt(t shaderir.Type, index, init, end int, op shaderir.Op, delta int, block *shaderir.Block) shaderir.Stmt {
|
|
|
|
return shaderir.Stmt{
|
|
|
|
Type: shaderir.For,
|
|
|
|
Blocks: []*shaderir.Block{block},
|
2020-08-09 14:44:06 +02:00
|
|
|
ForVarType: t,
|
2020-07-12 14:53:18 +02:00
|
|
|
ForVarIndex: index,
|
2020-07-12 15:22:22 +02:00
|
|
|
ForInit: constant.MakeInt64(int64(init)),
|
|
|
|
ForEnd: constant.MakeInt64(int64(end)),
|
2020-07-12 14:53:18 +02:00
|
|
|
ForOp: op,
|
2020-07-12 15:22:22 +02:00
|
|
|
ForDelta: constant.MakeInt64(int64(delta)),
|
2020-05-15 20:10:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func floatExpr(value float32) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.NumberExpr,
|
2020-06-20 18:22:30 +02:00
|
|
|
Const: constant.MakeFloat64(float64(value)),
|
2020-05-14 19:10:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func uniformVariableExpr(index int) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.UniformVariable,
|
2020-05-16 21:28:03 +02:00
|
|
|
Index: index,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func localVariableExpr(index int) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.LocalVariable,
|
2020-05-16 21:28:03 +02:00
|
|
|
Index: index,
|
2020-05-14 16:47:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func builtinFuncExpr(f shaderir.BuiltinFunc) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.BuiltinFuncExpr,
|
2020-05-16 17:25:31 +02:00
|
|
|
BuiltinFunc: f,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func swizzlingExpr(swizzling string) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.SwizzlingExpr,
|
2020-05-16 20:00:57 +02:00
|
|
|
Swizzling: swizzling,
|
2020-05-16 19:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func functionExpr(index int) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.FunctionExpr,
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: index,
|
2020-05-16 11:09:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func binaryExpr(op shaderir.Op, exprs ...shaderir.Expr) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.Binary,
|
2020-05-14 16:47:15 +02:00
|
|
|
Op: op,
|
|
|
|
Exprs: exprs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func selectionExpr(cond, a, b shaderir.Expr) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.Selection,
|
|
|
|
Exprs: []shaderir.Expr{cond, a, b},
|
2020-05-16 10:22:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func callExpr(callee shaderir.Expr, args ...shaderir.Expr) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.Call,
|
|
|
|
Exprs: append([]shaderir.Expr{callee}, args...),
|
2020-05-16 12:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 12:58:48 +02:00
|
|
|
func fieldSelectorExpr(a, b shaderir.Expr) shaderir.Expr {
|
|
|
|
return shaderir.Expr{
|
|
|
|
Type: shaderir.FieldSelector,
|
|
|
|
Exprs: []shaderir.Expr{a, b},
|
2020-05-16 11:09:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:19:42 +02:00
|
|
|
func TestOutput(t *testing.T) {
|
2022-01-11 17:56:09 +01:00
|
|
|
glslVertexPrelude := glsl.VertexPrelude(glsl.GLSLVersionDefault) + "\n"
|
|
|
|
glslFragmentPrelude := glsl.FragmentPrelude(glsl.GLSLVersionDefault) + "\n"
|
2020-08-01 17:09:12 +02:00
|
|
|
|
2020-05-11 17:19:42 +02:00
|
|
|
tests := []struct {
|
|
|
|
Name string
|
2021-10-02 12:58:48 +02:00
|
|
|
Program shaderir.Program
|
2020-05-21 16:58:08 +02:00
|
|
|
GlslVS string
|
|
|
|
GlslFS string
|
2020-08-09 12:36:45 +02:00
|
|
|
Metal string
|
2020-05-11 17:19:42 +02:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "Empty",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glsl.VertexPrelude(glsl.GLSLVersionDefault),
|
2020-11-21 11:17:24 +01:00
|
|
|
GlslFS: glsl.FragmentPrelude(glsl.GLSLVersionDefault),
|
2020-05-11 17:19:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Uniform",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Uniforms: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-11 17:19:42 +02:00
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
uniform float U0;`,
|
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
uniform float U0;`,
|
2020-05-11 17:19:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "UniformStruct",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Uniforms: []shaderir.Type{
|
2020-05-11 17:19:42 +02:00
|
|
|
{
|
2021-10-02 12:58:48 +02:00
|
|
|
Main: shaderir.Struct,
|
|
|
|
Sub: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-11 17:19:42 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
struct S0 {
|
2020-05-21 16:58:08 +02:00
|
|
|
float M0;
|
|
|
|
};
|
2020-08-01 17:09:12 +02:00
|
|
|
|
2020-05-21 16:58:08 +02:00
|
|
|
uniform S0 U0;`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
struct S0 {
|
2020-05-11 17:19:42 +02:00
|
|
|
float M0;
|
|
|
|
};
|
2020-08-01 17:09:12 +02:00
|
|
|
|
2020-05-12 16:32:32 +02:00
|
|
|
uniform S0 U0;`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Vars",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Uniforms: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-12 16:32:32 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Attributes: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-12 16:32:32 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Varyings: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec3},
|
2020-05-12 16:32:32 +02:00
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
uniform float U0;
|
2020-05-21 16:58:08 +02:00
|
|
|
attribute vec2 A0;
|
|
|
|
varying vec3 V0;`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
uniform float U0;
|
2020-05-12 16:32:32 +02:00
|
|
|
varying vec3 V0;`,
|
|
|
|
},
|
|
|
|
{
|
2020-05-13 16:31:17 +02:00
|
|
|
Name: "Func",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-12 16:32:32 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2020-05-12 16:32:32 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(void);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(void) {
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(void);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(void) {
|
2020-05-13 16:31:17 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FuncParams",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-13 16:31:17 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
|
|
|
{Main: shaderir.Vec4},
|
2020-05-13 16:31:17 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Mat4},
|
2020-05-13 16:31:17 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in vec2 l1, in vec4 l2, out mat4 l3) {
|
2020-05-16 13:16:04 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FuncReturn",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-16 13:16:04 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 13:16:04 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Return: shaderir.Type{Main: shaderir.Float},
|
2020-05-16 13:16:04 +02:00
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
1,
|
2020-05-16 13:16:04 +02:00
|
|
|
returnStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-16 13:16:04 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
float F0(in float l0);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
float F0(in float l0) {
|
2020-05-21 16:58:08 +02:00
|
|
|
return l0;
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
float F0(in float l0);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
float F0(in float l0) {
|
2020-05-16 13:16:04 +02:00
|
|
|
return l0;
|
2020-05-13 17:46:36 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FuncLocals",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-13 17:46:36 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 17:46:36 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 17:46:36 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Block: block([]shaderir.Type{
|
|
|
|
{Main: shaderir.Mat4},
|
|
|
|
{Main: shaderir.Mat4},
|
2020-08-09 16:40:41 +02:00
|
|
|
}, 2),
|
2020-05-13 17:46:36 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, out float l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, out float l1) {
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l2 = mat4(0);
|
|
|
|
mat4 l3 = mat4(0);
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, out float l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, out float l1) {
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l2 = mat4(0);
|
|
|
|
mat4 l3 = mat4(0);
|
2020-05-13 20:52:36 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FuncBlocks",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-13 20:52:36 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 20:52:36 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 20:52:36 +02:00
|
|
|
},
|
2020-05-14 20:33:07 +02:00
|
|
|
Block: block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Mat4},
|
|
|
|
{Main: shaderir.Mat4},
|
2020-05-13 20:52:36 +02:00
|
|
|
},
|
2020-08-09 16:40:41 +02:00
|
|
|
2,
|
2020-05-14 20:33:07 +02:00
|
|
|
blockStmt(
|
|
|
|
block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Mat4},
|
|
|
|
{Main: shaderir.Mat4},
|
2020-05-13 20:52:36 +02:00
|
|
|
},
|
2020-08-09 16:40:41 +02:00
|
|
|
4,
|
2020-05-14 20:33:07 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-05-13 20:52:36 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, out float l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, out float l1) {
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l2 = mat4(0);
|
|
|
|
mat4 l3 = mat4(0);
|
2020-05-21 16:58:08 +02:00
|
|
|
{
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l4 = mat4(0);
|
|
|
|
mat4 l5 = mat4(0);
|
2020-05-21 16:58:08 +02:00
|
|
|
}
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, out float l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, out float l1) {
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l2 = mat4(0);
|
|
|
|
mat4 l3 = mat4(0);
|
2020-05-13 20:52:36 +02:00
|
|
|
{
|
2020-06-16 18:53:41 +02:00
|
|
|
mat4 l4 = mat4(0);
|
|
|
|
mat4 l5 = mat4(0);
|
2020-05-13 20:52:36 +02:00
|
|
|
}
|
2020-05-13 18:45:33 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 10:22:17 +02:00
|
|
|
Name: "Add",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-13 18:45:33 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 18:45:33 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-13 18:45:33 +02:00
|
|
|
},
|
2020-05-14 20:33:07 +02:00
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-14 20:33:07 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-14 20:33:07 +02:00
|
|
|
binaryExpr(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.Add,
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
|
|
|
localVariableExpr(1),
|
2020-05-14 16:47:15 +02:00
|
|
|
),
|
2020-05-14 20:33:07 +02:00
|
|
|
),
|
|
|
|
),
|
2020-05-13 18:45:33 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-21 16:58:08 +02:00
|
|
|
l2 = (l0) + (l1);
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-13 18:45:33 +02:00
|
|
|
l2 = (l0) + (l1);
|
2020-05-14 19:10:07 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 10:22:17 +02:00
|
|
|
Name: "Selection",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-16 10:22:17 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Bool},
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 10:22:17 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 10:22:17 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
4,
|
2020-05-16 10:22:17 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(3),
|
2020-05-16 10:22:17 +02:00
|
|
|
selectionExpr(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
|
|
|
localVariableExpr(1),
|
|
|
|
localVariableExpr(2),
|
2020-05-16 10:22:17 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in bool l0, in float l1, in float l2, out float l3);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in bool l0, in float l1, in float l2, out float l3) {
|
2020-05-21 16:58:08 +02:00
|
|
|
l3 = (l0) ? (l1) : (l2);
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in bool l0, in float l1, in float l2, out float l3);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in bool l0, in float l1, in float l2, out float l3) {
|
2020-05-16 10:22:17 +02:00
|
|
|
l3 = (l0) ? (l1) : (l2);
|
2020-05-16 12:10:12 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "Call",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-16 12:10:12 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 12:10:12 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 12:10:12 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-16 12:10:12 +02:00
|
|
|
exprStmt(
|
|
|
|
callExpr(
|
2020-05-16 20:00:57 +02:00
|
|
|
functionExpr(1),
|
2020-05-16 12:10:12 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-16 12:10:12 +02:00
|
|
|
callExpr(
|
2020-05-16 20:00:57 +02:00
|
|
|
functionExpr(2),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
|
|
|
localVariableExpr(1),
|
2020-05-16 12:10:12 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out vec2 l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out vec2 l2) {
|
2020-05-23 11:06:50 +02:00
|
|
|
F1();
|
|
|
|
l2 = F2(l0, l1);
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in float l1, out vec2 l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out vec2 l2) {
|
2020-05-23 11:06:50 +02:00
|
|
|
F1();
|
|
|
|
l2 = F2(l0, l1);
|
2020-05-16 17:25:31 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "BuiltinFunc",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-16 17:25:31 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 17:25:31 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 17:25:31 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-16 17:25:31 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-16 17:25:31 +02:00
|
|
|
callExpr(
|
2021-10-02 12:58:48 +02:00
|
|
|
builtinFuncExpr(shaderir.Min),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
|
|
|
localVariableExpr(1),
|
2020-05-16 17:25:31 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-23 11:06:50 +02:00
|
|
|
l2 = min(l0, l1);
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-23 11:06:50 +02:00
|
|
|
l2 = min(l0, l1);
|
2020-05-16 11:09:04 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FieldSelector",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-16 11:09:04 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec4},
|
2020-05-16 11:09:04 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 11:09:04 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
2,
|
2020-05-16 11:09:04 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(1),
|
2020-05-16 11:09:04 +02:00
|
|
|
fieldSelectorExpr(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-16 19:24:35 +02:00
|
|
|
swizzlingExpr("xz"),
|
2020-05-16 11:09:04 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in vec4 l0, out vec2 l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in vec4 l0, out vec2 l1) {
|
2020-05-21 16:58:08 +02:00
|
|
|
l1 = (l0).xz;
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in vec4 l0, out vec2 l1);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in vec4 l0, out vec2 l1) {
|
2020-05-16 19:24:35 +02:00
|
|
|
l1 = (l0).xz;
|
2020-05-16 10:22:17 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "If",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-14 19:10:07 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-14 19:10:07 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-14 19:10:07 +02:00
|
|
|
},
|
2020-05-14 20:33:07 +02:00
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-14 20:33:07 +02:00
|
|
|
ifStmt(
|
|
|
|
binaryExpr(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.EqualOp,
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-15 20:40:33 +02:00
|
|
|
floatExpr(0),
|
2020-05-14 20:33:07 +02:00
|
|
|
),
|
|
|
|
block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-14 20:33:07 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
|
|
|
localVariableExpr(0),
|
2020-05-14 19:10:07 +02:00
|
|
|
),
|
|
|
|
),
|
2020-05-14 20:33:07 +02:00
|
|
|
block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-14 20:33:07 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
|
|
|
localVariableExpr(1),
|
2020-05-14 20:33:07 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2020-05-14 19:10:07 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-06-20 18:22:30 +02:00
|
|
|
if ((l0) == (0.0)) {
|
2020-05-21 16:58:08 +02:00
|
|
|
l2 = l0;
|
|
|
|
} else {
|
|
|
|
l2 = l1;
|
|
|
|
}
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-06-20 18:22:30 +02:00
|
|
|
if ((l0) == (0.0)) {
|
2020-05-14 19:10:07 +02:00
|
|
|
l2 = l0;
|
|
|
|
} else {
|
|
|
|
l2 = l1;
|
|
|
|
}
|
2020-05-15 20:10:03 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
2020-05-16 10:22:17 +02:00
|
|
|
Name: "For",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-05-15 20:10:03 +02:00
|
|
|
{
|
2020-05-16 20:00:57 +02:00
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-05-15 20:10:03 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-15 20:10:03 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
2020-08-09 15:03:04 +02:00
|
|
|
{},
|
|
|
|
},
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-15 20:10:03 +02:00
|
|
|
forStmt(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.Type{Main: shaderir.Int},
|
2020-07-12 14:53:18 +02:00
|
|
|
3,
|
2020-05-15 20:10:03 +02:00
|
|
|
0,
|
|
|
|
100,
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.LessThanOp,
|
2020-05-15 20:10:03 +02:00
|
|
|
1,
|
|
|
|
block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-05-15 20:10:03 +02:00
|
|
|
assignStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
|
|
|
localVariableExpr(0),
|
2020-05-15 20:10:03 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-21 16:58:08 +02:00
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
|
|
|
l2 = l0;
|
|
|
|
}
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-07-27 16:51:05 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
2020-05-15 20:10:03 +02:00
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
|
|
|
l2 = l0;
|
|
|
|
}
|
2020-08-09 12:36:45 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "For2",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-08-09 12:36:45 +02:00
|
|
|
{
|
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-08-09 12:36:45 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-08-09 12:36:45 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
2020-08-09 15:03:04 +02:00
|
|
|
{},
|
|
|
|
},
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-08-09 12:36:45 +02:00
|
|
|
forStmt(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.Type{Main: shaderir.Int},
|
2020-08-09 12:36:45 +02:00
|
|
|
3,
|
|
|
|
0,
|
|
|
|
100,
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.LessThanOp,
|
2020-08-09 12:36:45 +02:00
|
|
|
1,
|
|
|
|
block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Int},
|
2020-08-09 12:36:45 +02:00
|
|
|
},
|
2020-08-09 16:40:41 +02:00
|
|
|
4,
|
2020-08-09 12:36:45 +02:00
|
|
|
assignStmt(
|
|
|
|
localVariableExpr(2),
|
|
|
|
localVariableExpr(4),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-08-09 12:36:45 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
|
|
|
}
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-09 12:36:45 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
|
|
|
}
|
|
|
|
}`,
|
2022-03-10 08:24:56 +01:00
|
|
|
Metal: msl.Prelude + `
|
2020-08-09 12:36:45 +02:00
|
|
|
|
|
|
|
void F0(float l0, float l1, thread float& l2);
|
|
|
|
|
|
|
|
void F0(float l0, float l1, thread float& l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
|
|
|
}
|
2020-08-09 13:12:56 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "For3",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Funcs: []shaderir.Func{
|
2020-08-09 13:12:56 +02:00
|
|
|
{
|
|
|
|
Index: 0,
|
2021-10-02 12:58:48 +02:00
|
|
|
InParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Float},
|
2020-08-09 13:12:56 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
OutParams: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-08-09 13:12:56 +02:00
|
|
|
},
|
|
|
|
Block: block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
2020-08-09 15:03:04 +02:00
|
|
|
{},
|
|
|
|
{},
|
|
|
|
},
|
2020-09-07 20:01:27 +02:00
|
|
|
3,
|
2020-08-09 13:12:56 +02:00
|
|
|
forStmt(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.Type{Main: shaderir.Int},
|
2020-08-09 13:12:56 +02:00
|
|
|
3,
|
|
|
|
0,
|
|
|
|
100,
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.LessThanOp,
|
2020-08-09 13:12:56 +02:00
|
|
|
1,
|
|
|
|
block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Int},
|
2020-08-09 13:12:56 +02:00
|
|
|
},
|
2020-08-09 16:40:41 +02:00
|
|
|
4,
|
2020-08-09 13:12:56 +02:00
|
|
|
assignStmt(
|
|
|
|
localVariableExpr(2),
|
2020-08-09 16:40:41 +02:00
|
|
|
localVariableExpr(4),
|
2020-08-09 13:12:56 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
forStmt(
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.Type{Main: shaderir.Float},
|
2020-08-09 15:03:04 +02:00
|
|
|
4,
|
2020-08-09 13:12:56 +02:00
|
|
|
0,
|
|
|
|
100,
|
2021-10-02 12:58:48 +02:00
|
|
|
shaderir.LessThanOp,
|
2020-08-09 13:12:56 +02:00
|
|
|
1,
|
|
|
|
block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Int},
|
2020-08-09 13:12:56 +02:00
|
|
|
},
|
2020-08-09 16:40:41 +02:00
|
|
|
5,
|
2020-08-09 13:12:56 +02:00
|
|
|
assignStmt(
|
|
|
|
localVariableExpr(2),
|
2020-08-09 15:03:04 +02:00
|
|
|
localVariableExpr(5),
|
2020-08-09 13:12:56 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
void F0(in float l0, in float l1, out float l2);
|
2020-08-09 13:12:56 +02:00
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
2020-08-09 16:40:41 +02:00
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
2020-08-09 15:03:04 +02:00
|
|
|
for (float l4 = 0.0; l4 < 100.0; l4++) {
|
|
|
|
int l5 = 0;
|
|
|
|
l2 = l5;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-09 13:12:56 +02:00
|
|
|
void F0(in float l0, in float l1, out float l2);
|
|
|
|
|
|
|
|
void F0(in float l0, in float l1, out float l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
2020-08-09 16:40:41 +02:00
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
2020-08-09 15:03:04 +02:00
|
|
|
for (float l4 = 0.0; l4 < 100.0; l4++) {
|
|
|
|
int l5 = 0;
|
|
|
|
l2 = l5;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
|
|
|
}`,
|
2022-03-10 08:24:56 +01:00
|
|
|
Metal: msl.Prelude + `
|
2020-08-09 13:12:56 +02:00
|
|
|
|
|
|
|
void F0(float l0, float l1, thread float& l2);
|
|
|
|
|
|
|
|
void F0(float l0, float l1, thread float& l2) {
|
|
|
|
for (int l3 = 0; l3 < 100; l3++) {
|
2020-08-09 16:40:41 +02:00
|
|
|
int l4 = 0;
|
|
|
|
l2 = l4;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
2020-08-09 15:03:04 +02:00
|
|
|
for (float l4 = 0.0; l4 < 100.0; l4++) {
|
|
|
|
int l5 = 0;
|
|
|
|
l2 = l5;
|
2020-08-09 13:12:56 +02:00
|
|
|
}
|
2020-05-16 15:18:58 +02:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "VertexFunc",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Uniforms: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 15:18:58 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Attributes: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec4},
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 15:18:58 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Varyings: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 15:18:58 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
VertexFunc: shaderir.VertexFunc{
|
2020-05-16 15:18:58 +02:00
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:51:29 +02:00
|
|
|
4+1,
|
2020-05-16 15:18:58 +02:00
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(3),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-16 15:18:58 +02:00
|
|
|
),
|
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(4),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(1),
|
2020-05-16 15:18:58 +02:00
|
|
|
),
|
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(5),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-16 15:18:58 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
uniform float U0;
|
2020-05-16 15:18:58 +02:00
|
|
|
attribute vec4 A0;
|
|
|
|
attribute float A1;
|
|
|
|
attribute vec2 A2;
|
|
|
|
varying float V0;
|
|
|
|
varying vec2 V1;
|
2020-05-17 10:06:21 +02:00
|
|
|
|
2020-05-16 15:18:58 +02:00
|
|
|
void main(void) {
|
|
|
|
gl_Position = A0;
|
|
|
|
V0 = A1;
|
|
|
|
V1 = A2;
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
uniform float U0;
|
2020-05-21 16:58:08 +02:00
|
|
|
varying float V0;
|
|
|
|
varying vec2 V1;`,
|
2020-05-16 16:07:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "FragmentFunc",
|
2021-10-02 12:58:48 +02:00
|
|
|
Program: shaderir.Program{
|
|
|
|
Uniforms: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
2020-05-16 16:07:24 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Attributes: []shaderir.Type{
|
|
|
|
{Main: shaderir.Vec4},
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 16:07:24 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
Varyings: []shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 16:07:24 +02:00
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
VertexFunc: shaderir.VertexFunc{
|
2020-05-16 16:07:24 +02:00
|
|
|
Block: block(
|
|
|
|
nil,
|
2020-09-07 20:01:27 +02:00
|
|
|
5+1,
|
2020-05-16 16:07:24 +02:00
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(3),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(4),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(1),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
|
|
|
assignStmt(
|
2020-06-02 17:46:52 +02:00
|
|
|
localVariableExpr(5),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
2021-10-02 12:58:48 +02:00
|
|
|
FragmentFunc: shaderir.FragmentFunc{
|
2020-05-16 16:07:24 +02:00
|
|
|
Block: block(
|
2021-10-02 12:58:48 +02:00
|
|
|
[]shaderir.Type{
|
|
|
|
{Main: shaderir.Float},
|
|
|
|
{Main: shaderir.Vec2},
|
2020-05-16 16:07:24 +02:00
|
|
|
},
|
2022-08-16 18:01:23 +02:00
|
|
|
3,
|
2020-05-16 16:07:24 +02:00
|
|
|
assignStmt(
|
2020-06-02 19:01:50 +02:00
|
|
|
localVariableExpr(3),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(0),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
|
|
|
assignStmt(
|
2020-06-02 19:01:50 +02:00
|
|
|
localVariableExpr(4),
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(1),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
2022-08-16 18:01:23 +02:00
|
|
|
returnStmt(
|
2020-05-16 21:28:03 +02:00
|
|
|
localVariableExpr(2),
|
2020-05-16 16:07:24 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslVS: glslVertexPrelude + `
|
|
|
|
uniform float U0;
|
2020-05-16 16:07:24 +02:00
|
|
|
attribute vec4 A0;
|
|
|
|
attribute float A1;
|
|
|
|
attribute vec2 A2;
|
|
|
|
varying float V0;
|
|
|
|
varying vec2 V1;
|
2020-05-17 10:06:21 +02:00
|
|
|
|
2020-05-16 16:07:24 +02:00
|
|
|
void main(void) {
|
|
|
|
gl_Position = A0;
|
|
|
|
V0 = A1;
|
|
|
|
V1 = A2;
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2022-01-11 17:56:09 +01:00
|
|
|
GlslFS: glslFragmentPrelude + `
|
2020-08-01 11:19:06 +02:00
|
|
|
uniform float U0;
|
2020-05-21 16:58:08 +02:00
|
|
|
varying float V0;
|
|
|
|
varying vec2 V1;
|
2020-05-17 10:06:21 +02:00
|
|
|
|
2022-08-16 18:01:23 +02:00
|
|
|
vec4 F0(in vec4 l0, in float l1, in vec2 l2);
|
2022-08-16 18:01:23 +02:00
|
|
|
|
2022-08-16 18:01:23 +02:00
|
|
|
vec4 F0(in vec4 l0, in float l1, in vec2 l2) {
|
|
|
|
float l3 = float(0);
|
|
|
|
vec2 l4 = vec2(0);
|
2022-08-16 18:01:23 +02:00
|
|
|
l3 = l0;
|
|
|
|
l4 = l1;
|
2022-08-16 18:01:23 +02:00
|
|
|
return l2;
|
2022-08-16 18:01:23 +02:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:07:24 +02:00
|
|
|
void main(void) {
|
2022-08-16 18:01:23 +02:00
|
|
|
gl_FragColor = F0(gl_FragCoord, V0, V1);
|
2020-05-21 16:58:08 +02:00
|
|
|
}`,
|
2020-05-11 17:19:42 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range tests {
|
2020-08-01 17:09:12 +02:00
|
|
|
tc := tc
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
2020-11-21 11:17:24 +01:00
|
|
|
vs, fs := glsl.Compile(&tc.Program, glsl.GLSLVersionDefault)
|
2020-08-01 17:09:12 +02:00
|
|
|
{
|
|
|
|
got := vs
|
|
|
|
want := tc.GlslVS + "\n"
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("%s vertex: got: %s, want: %s", tc.Name, got, want)
|
|
|
|
}
|
2020-05-21 16:58:08 +02:00
|
|
|
}
|
2020-08-01 17:09:12 +02:00
|
|
|
{
|
|
|
|
got := fs
|
|
|
|
want := tc.GlslFS + "\n"
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("%s fragment: got: %s, want: %s", tc.Name, got, want)
|
|
|
|
}
|
2020-05-21 16:58:08 +02:00
|
|
|
}
|
2022-03-10 08:24:56 +01:00
|
|
|
m := msl.Compile(&tc.Program, "Vertex", "Fragment")
|
2020-08-09 12:36:45 +02:00
|
|
|
if tc.Metal != "" {
|
|
|
|
got := m
|
|
|
|
want := tc.Metal + "\n"
|
|
|
|
if got != want {
|
|
|
|
t.Errorf("%s metal: got: %s, want: %s", tc.Name, got, want)
|
|
|
|
}
|
|
|
|
}
|
2020-08-01 17:09:12 +02:00
|
|
|
})
|
2020-05-11 17:19:42 +02:00
|
|
|
}
|
|
|
|
}
|