mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
shader: Bug fix: Wrong out-params when returning is in a block
This commit is contained in:
parent
ce4732a7dc
commit
8369a4cc15
@ -607,15 +607,22 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
|
||||
}
|
||||
|
||||
func (cs *compileState) parseBlock(outer *block, stmts []ast.Stmt, inParams, outParams []variable) (*block, bool) {
|
||||
vars := make([]variable, 0, len(inParams)+len(outParams))
|
||||
vars = append(vars, inParams...)
|
||||
vars = append(vars, outParams...)
|
||||
var vars []variable
|
||||
if outer == &cs.global {
|
||||
vars = make([]variable, 0, len(inParams)+len(outParams))
|
||||
vars = append(vars, inParams...)
|
||||
vars = append(vars, outParams...)
|
||||
}
|
||||
block := &block{
|
||||
vars: vars,
|
||||
outer: outer,
|
||||
}
|
||||
defer func() {
|
||||
for _, v := range block.vars[len(inParams)+len(outParams):] {
|
||||
var offset int
|
||||
if outer == &cs.global {
|
||||
offset = len(inParams) + len(outParams)
|
||||
}
|
||||
for _, v := range block.vars[offset:] {
|
||||
block.ir.LocalVars = append(block.ir.LocalVars, v.typ)
|
||||
}
|
||||
}()
|
||||
|
@ -96,7 +96,7 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
cs.addError(stmt.Pos(), fmt.Sprintf("unexpected token: %s", stmt.Tok))
|
||||
}
|
||||
case *ast.BlockStmt:
|
||||
b, ok := cs.parseBlock(block, stmt.List, nil, nil)
|
||||
b, ok := cs.parseBlock(block, stmt.List, inParams, nil)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
@ -114,7 +114,7 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
if stmt.Init != nil {
|
||||
init := stmt.Init
|
||||
stmt.Init = nil
|
||||
b, ok := cs.parseBlock(block, []ast.Stmt{init, stmt}, nil, nil)
|
||||
b, ok := cs.parseBlock(block, []ast.Stmt{init, stmt}, inParams, nil)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
@ -143,7 +143,7 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
stmts = append(stmts, ss...)
|
||||
|
||||
var bs []shaderir.Block
|
||||
b, ok := cs.parseBlock(block, stmt.Body.List, nil, nil)
|
||||
b, ok := cs.parseBlock(block, stmt.Body.List, inParams, nil)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
@ -152,13 +152,13 @@ func (cs *compileState) parseStmt(block *block, stmt ast.Stmt, inParams []variab
|
||||
if stmt.Else != nil {
|
||||
switch s := stmt.Else.(type) {
|
||||
case *ast.BlockStmt:
|
||||
b, ok := cs.parseBlock(block, s.List, nil, nil)
|
||||
b, ok := cs.parseBlock(block, s.List, inParams, nil)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
bs = append(bs, b.ir)
|
||||
default:
|
||||
b, ok := cs.parseBlock(block, []ast.Stmt{s}, nil, nil)
|
||||
b, ok := cs.parseBlock(block, []ast.Stmt{s}, inParams, nil)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
16
internal/shader/testdata/if_init.expected.vs
vendored
16
internal/shader/testdata/if_init.expected.vs
vendored
@ -1,14 +1,14 @@
|
||||
void F0(out vec2 l0) {
|
||||
vec2 l1 = vec2(0);
|
||||
l1 = vec2(0.0);
|
||||
void F0(in vec2 l0, out vec2 l1) {
|
||||
vec2 l2 = vec2(0);
|
||||
l2 = vec2(0.0);
|
||||
{
|
||||
vec2 l2 = vec2(0);
|
||||
l2 = vec2(1.0);
|
||||
if (((l2).x) == (1.0)) {
|
||||
l0 = l2;
|
||||
vec2 l3 = vec2(0);
|
||||
l3 = vec2(1.0);
|
||||
if (((l3).x) == (1.0)) {
|
||||
l1 = l3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
l0 = l1;
|
||||
l1 = l2;
|
||||
return;
|
||||
}
|
||||
|
2
internal/shader/testdata/if_init.go
vendored
2
internal/shader/testdata/if_init.go
vendored
@ -1,6 +1,6 @@
|
||||
package main
|
||||
|
||||
func Foo() vec2 {
|
||||
func Foo(x vec2) vec2 {
|
||||
v := vec2(0)
|
||||
if v := vec2(1); v.x == 1 {
|
||||
return v
|
||||
|
Loading…
Reference in New Issue
Block a user