shader: Bug fix: Wrong local variable index in a block in an entry point

This commit is contained in:
Hajime Hoshi 2020-08-10 01:39:41 +09:00
parent 4d20da9bc0
commit 9b6b306ca3
3 changed files with 70 additions and 0 deletions

View File

@ -677,6 +677,15 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt,
for b := outer; b != nil; b = b.outer {
offset += len(b.vars)
}
if fname == cs.vertexEntry {
offset -= len(cs.ir.Attributes)
offset-- // position
offset -= len(cs.ir.Varyings)
}
if fname == cs.fragmentEntry {
offset-- // position
offset -= len(cs.ir.Varyings)
}
}
block := &block{

View File

@ -0,0 +1,35 @@
uniform float U0;
uniform float U1;
uniform float U2;
attribute vec2 A0;
void F0(in int l0, out int l1);
void F0(in int l0, out int l1) {
l1 = l0;
return;
}
void main(void) {
int l0 = 0;
int l2 = 0;
l0 = 0;
for (int l1 = 0; l1 < 10; l1++) {
int l2 = 0;
int l3 = 0;
F0(l1, l2);
l3 = l2;
l0 = (l0) + (l3);
for (int l4 = 0; l4 < 10; l4++) {
int l5 = 0;
int l6 = 0;
F0(l4, l5);
l6 = l5;
l0 = (l0) + (l6);
}
}
l2 = 0;
l0 = (l0) + (l2);
gl_Position = vec4(l0);
return;
}

26
internal/shader/testdata/for5.go vendored Normal file
View File

@ -0,0 +1,26 @@
package main
var (
U0 float
U1 float
U2 float
)
func Ident(x int) int {
return x
}
func Vertex(pos vec2) vec4 {
sum := 0
for i := 0; i < 10; i++ {
x := Ident(i)
sum += x
for j := 0; j < 10; j++ {
x := Ident(j)
sum += x
}
}
y := 0
sum += y
return vec4(sum)
}