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

This commit is contained in:
Hajime Hoshi 2020-08-10 02:29:49 +09:00
parent 9b6b306ca3
commit ee049a19ac
3 changed files with 50 additions and 0 deletions

View File

@ -685,6 +685,7 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt,
if fname == cs.fragmentEntry { if fname == cs.fragmentEntry {
offset-- // position offset-- // position
offset -= len(cs.ir.Varyings) offset -= len(cs.ir.Varyings)
offset-- // color
} }
} }

View File

@ -0,0 +1,34 @@
uniform float U0;
uniform float U1;
uniform float U2;
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_FragColor = vec4(l0);
return;
}

View File

@ -24,3 +24,18 @@ func Vertex(pos vec2) vec4 {
sum += y sum += y
return vec4(sum) return vec4(sum)
} }
func Fragment(pos vec4) 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)
}