diff --git a/internal/shader/shader.go b/internal/shader/shader.go index 58c4487eb..91054fb0d 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -685,6 +685,7 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt, if fname == cs.fragmentEntry { offset-- // position offset -= len(cs.ir.Varyings) + offset-- // color } } diff --git a/internal/shader/testdata/for5.expected.fs b/internal/shader/testdata/for5.expected.fs new file mode 100644 index 000000000..440fe11b6 --- /dev/null +++ b/internal/shader/testdata/for5.expected.fs @@ -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; +} diff --git a/internal/shader/testdata/for5.go b/internal/shader/testdata/for5.go index f3a5e9fe9..3006c333a 100644 --- a/internal/shader/testdata/for5.go +++ b/internal/shader/testdata/for5.go @@ -24,3 +24,18 @@ func Vertex(pos vec2) vec4 { sum += y 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) +}