diff --git a/internal/shader/shader.go b/internal/shader/shader.go index d89069135..918413227 100644 --- a/internal/shader/shader.go +++ b/internal/shader/shader.go @@ -695,27 +695,11 @@ func (cs *compileState) parseBlock(outer *block, fname string, stmts []ast.Stmt, } var offset int - switch { - case outer.outer == nil && fname == cs.vertexEntry: - offset = 0 - case outer.outer == nil && fname == cs.fragmentEntry: - offset = 0 - case outer.outer == nil: - offset = len(inParams) + len(outParams) - default: - 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) - offset-- // color - } + for b := outer; b != nil; b = b.outer { + offset += len(b.vars) + } + if outer == &cs.global { + offset += len(inParams) + len(outParams) } block := &block{ diff --git a/internal/shaderir/glsl/glsl.go b/internal/shaderir/glsl/glsl.go index 05ab4cc15..0d1ef1cd6 100644 --- a/internal/shaderir/glsl/glsl.go +++ b/internal/shaderir/glsl/glsl.go @@ -346,8 +346,8 @@ func (c *compileContext) glslBlock(p *shaderir.Program, topBlock, block *shaderi idt := strings.Repeat("\t", level+1) var lines []string - for i, t := range block.LocalVars { - name := fmt.Sprintf("l%d", block.LocalVarIndexOffset+i) + for i := range block.LocalVars { + name, t := localVariable(p, topBlock, block, block.LocalVarIndexOffset+i) switch t.Main { case shaderir.Array: lines = append(lines, fmt.Sprintf("%s%s;", idt, c.glslVarDecl(p, &t, name))) diff --git a/internal/shaderir/metal/metal.go b/internal/shaderir/metal/metal.go index 6136ab226..9c06232ef 100644 --- a/internal/shaderir/metal/metal.go +++ b/internal/shaderir/metal/metal.go @@ -321,8 +321,9 @@ func (c *compileContext) metalBlock(p *shaderir.Program, topBlock, block *shader var lines []string for i, t := range block.LocalVars { // The type is None e.g., when the variable is a for-loop counter. + name := localVariableName(p, topBlock, block.LocalVarIndexOffset+i) if t.Main != shaderir.None { - lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.metalVarDecl(p, &t, fmt.Sprintf("l%d", block.LocalVarIndexOffset+i), false, false), c.metalVarInit(p, &t))) + lines = append(lines, fmt.Sprintf("%s%s = %s;", idt, c.metalVarDecl(p, &t, name, false, false), c.metalVarInit(p, &t))) } }