From 094d845edd358fc1d7e5c55dd88a4fb87480d99a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 17 May 2020 03:00:57 +0900 Subject: [PATCH] shaderir: Remove Ident --- internal/shaderir/glsl.go | 12 ++++++------ internal/shaderir/ir_test.go | 38 ++++++++++++++++++------------------ internal/shaderir/program.go | 9 ++++----- 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/internal/shaderir/glsl.go b/internal/shaderir/glsl.go index dfdc51c24..b94912705 100644 --- a/internal/shaderir/glsl.go +++ b/internal/shaderir/glsl.go @@ -166,7 +166,7 @@ func (p *Program) glslFunc(f *Func) []string { } var lines []string - lines = append(lines, fmt.Sprintf("%s %s(%s) {", p.glslType(&f.Return), f.Name, argsstr)) + lines = append(lines, fmt.Sprintf("%s F%d(%s) {", p.glslType(&f.Return), f.Index, argsstr)) lines = append(lines, p.glslBlock(&f.Block, 0, idx)...) lines = append(lines, "}") @@ -230,12 +230,12 @@ func (p *Program) glslBlock(b *Block, level int, localVarIndex int) []string { case BuiltinFuncExpr: return string(e.BuiltinFunc) case SwizzlingExpr: - if !isValidSwizzling(e.Ident) { - return fmt.Sprintf("?(unexpected swizzling: %s)", e.Ident) + if !isValidSwizzling(e.Swizzling) { + return fmt.Sprintf("?(unexpected swizzling: %s)", e.Swizzling) } - return e.Ident - case Ident: - return e.Ident + return e.Swizzling + case FunctionExpr: + return fmt.Sprintf("F%d", e.Index) case Unary: var op string switch e.Op { diff --git a/internal/shaderir/ir_test.go b/internal/shaderir/ir_test.go index c14ca9886..1b41a1171 100644 --- a/internal/shaderir/ir_test.go +++ b/internal/shaderir/ir_test.go @@ -100,15 +100,15 @@ func builtinFuncExpr(f BuiltinFunc) Expr { func swizzlingExpr(swizzling string) Expr { return Expr{ - Type: SwizzlingExpr, - Ident: swizzling, + Type: SwizzlingExpr, + Swizzling: swizzling, } } -func identExpr(ident string) Expr { +func functionExpr(index int) Expr { return Expr{ - Type: Ident, - Ident: ident, + Type: FunctionExpr, + Index: index, } } @@ -200,7 +200,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, }, }, }, @@ -212,7 +212,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Vec2}, @@ -235,7 +235,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, }, @@ -258,7 +258,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, }, @@ -285,7 +285,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, }, @@ -326,7 +326,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Float}, @@ -357,7 +357,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Bool}, {Main: Float}, @@ -389,7 +389,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Float}, @@ -401,13 +401,13 @@ varying vec3 V0;`, nil, exprStmt( callExpr( - identExpr("F1"), + functionExpr(1), ), ), assignStmt( varNameExpr(Local, 2), callExpr( - identExpr("F2"), + functionExpr(2), varNameExpr(Local, 0), varNameExpr(Local, 1), ), @@ -426,7 +426,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Float}, @@ -457,7 +457,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Vec4}, }, @@ -486,7 +486,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Float}, @@ -534,7 +534,7 @@ varying vec3 V0;`, Program: Program{ Funcs: []Func{ { - Name: "F0", + Index: 0, InParams: []Type{ {Main: Float}, {Main: Float}, diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index ea04fd396..fa2d8a3c0 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -27,10 +27,8 @@ type Program struct { structTypes []Type } -// TODO: How to avoid the name with existing functions? - type Func struct { - Name string + Index int InParams []Type InOutParams []Type OutParams []Type @@ -89,7 +87,8 @@ type Expr struct { Int int32 Float float32 BuiltinFunc BuiltinFunc - Ident string + Swizzling string + Index int Op Op } @@ -101,7 +100,7 @@ const ( VarName BuiltinFuncExpr SwizzlingExpr - Ident + FunctionExpr Unary Binary Selection