From f61a916e4a4494b33adb651526bc52afd123c4c3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 7 Sep 2020 23:36:05 +0900 Subject: [PATCH] shaderir/glsl: Bug fix: Calculate local variable indices correctly Fixes #1339 --- internal/shader/testdata/array2.expected.vs | 22 +++++++++++++++++++++ internal/shader/testdata/array2.go | 11 +++++++++++ internal/shaderir/glsl/glsl.go | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 internal/shader/testdata/array2.expected.vs create mode 100644 internal/shader/testdata/array2.go diff --git a/internal/shader/testdata/array2.expected.vs b/internal/shader/testdata/array2.expected.vs new file mode 100644 index 000000000..1c89be5ea --- /dev/null +++ b/internal/shader/testdata/array2.expected.vs @@ -0,0 +1,22 @@ +void F0(out vec2 l0[3]); + +void F0(out vec2 l0[3]) { + vec2 l1[2]; + l1[0] = vec2(0); + l1[1] = vec2(0); + vec2 l2[3]; + l2[0] = vec2(0); + l2[1] = vec2(0); + l2[2] = vec2(0); + { + vec2 l2[2]; + l2[0] = vec2(0); + l2[1] = vec2(0); + l2[0] = l1[0]; + l2[1] = l1[1]; + } + l0[0] = l2[0]; + l0[1] = l2[1]; + l0[2] = l2[2]; + return; +} diff --git a/internal/shader/testdata/array2.go b/internal/shader/testdata/array2.go new file mode 100644 index 000000000..c5c3ce17d --- /dev/null +++ b/internal/shader/testdata/array2.go @@ -0,0 +1,11 @@ +package main + +func Foo() [3]vec2 { + var a [2]vec2 + { + var b [2]vec2 + b = a + } + var c [3]vec2 + return c +} diff --git a/internal/shaderir/glsl/glsl.go b/internal/shaderir/glsl/glsl.go index 2855b0109..05ab4cc15 100644 --- a/internal/shaderir/glsl/glsl.go +++ b/internal/shaderir/glsl/glsl.go @@ -282,7 +282,8 @@ func descendantLocalVars(block, target *shaderir.Block) ([]shaderir.Type, bool) for _, s := range block.Stmts { for _, b := range s.Blocks { if ts2, found := descendantLocalVars(b, target); found { - ts = append(ts, block.LocalVars...) + n := b.LocalVarIndexOffset - block.LocalVarIndexOffset + ts = append(ts, block.LocalVars[:n]...) ts = append(ts, ts2...) return ts, true }