shaderir/glsl: Bug fix: Calculate local variable indices correctly

Fixes #1339
This commit is contained in:
Hajime Hoshi 2020-09-07 23:36:05 +09:00
parent 4308bbbc31
commit f61a916e4a
3 changed files with 35 additions and 1 deletions

View File

@ -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;
}

11
internal/shader/testdata/array2.go vendored Normal file
View File

@ -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
}

View File

@ -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
}