mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
shader: Bug fix: Wrong local variable index in a block
This commit is contained in:
parent
eacc9fac6a
commit
a0494210c3
@ -240,7 +240,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
|
||||
var outParams []int
|
||||
for _, p := range f.ir.OutParams {
|
||||
idx := len(block.vars)
|
||||
idx := block.totalLocalVariableNum()
|
||||
block.vars = append(block.vars, variable{
|
||||
typ: p,
|
||||
})
|
||||
@ -257,7 +257,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
|
||||
idx := len(block.vars)
|
||||
idx := block.totalLocalVariableNum()
|
||||
block.vars = append(block.vars, variable{
|
||||
typ: t,
|
||||
})
|
||||
@ -453,7 +453,7 @@ func (cs *compileState) parseExpr(block *block, expr ast.Expr) ([]shaderir.Expr,
|
||||
return nil, nil, nil, false
|
||||
}
|
||||
|
||||
idx := len(block.vars)
|
||||
idx := block.totalLocalVariableNum()
|
||||
block.vars = append(block.vars, variable{
|
||||
typ: t,
|
||||
})
|
||||
|
@ -95,6 +95,14 @@ type block struct {
|
||||
ir *shaderir.Block
|
||||
}
|
||||
|
||||
func (b *block) totalLocalVariableNum() int {
|
||||
c := len(b.vars)
|
||||
if b.outer != nil {
|
||||
c += b.outer.totalLocalVariableNum()
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (b *block) findLocalVariable(name string) (int, shaderir.Type, bool) {
|
||||
idx := 0
|
||||
for outer := b.outer; outer != nil; outer = outer.outer {
|
||||
|
21
internal/shader/testdata/for4.expected.vs
vendored
Normal file
21
internal/shader/testdata/for4.expected.vs
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
void F0(in int l0, out int l1);
|
||||
void F1(out int l0);
|
||||
|
||||
void F0(in int l0, out int l1) {
|
||||
l1 = l0;
|
||||
return;
|
||||
}
|
||||
|
||||
void F1(out int l0) {
|
||||
int l1 = 0;
|
||||
l1 = 0;
|
||||
for (int l2 = 0; l2 < 10; l2++) {
|
||||
int l3 = 0;
|
||||
int l4 = 0;
|
||||
F0(l2, l3);
|
||||
l4 = l3;
|
||||
l1 = (l1) + (l4);
|
||||
}
|
||||
l0 = l1;
|
||||
return;
|
||||
}
|
14
internal/shader/testdata/for4.go
vendored
Normal file
14
internal/shader/testdata/for4.go
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
func Ident(x int) int {
|
||||
return x
|
||||
}
|
||||
|
||||
func Foo() int {
|
||||
sum := 0
|
||||
for i := 0; i < 10; i++ {
|
||||
x := Ident(i)
|
||||
sum += x
|
||||
}
|
||||
return sum
|
||||
}
|
Loading…
Reference in New Issue
Block a user