internal/shaderir: rename functions

This commit is contained in:
Hajime Hoshi 2022-11-03 17:14:49 +09:00
parent a118f1d797
commit e2c25dbc6d
2 changed files with 14 additions and 14 deletions

View File

@ -136,7 +136,7 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
var funcs []*shaderir.Func var funcs []*shaderir.Func
if p.VertexFunc.Block != nil { if p.VertexFunc.Block != nil {
indices := p.ReferredFuncIndicesInVertexShader() indices := p.ReachableFuncIndicesFromVertexShader()
sort.Ints(indices) sort.Ints(indices)
funcs = make([]*shaderir.Func, 0, len(indices)) funcs = make([]*shaderir.Func, 0, len(indices))
for _, idx := range indices { for _, idx := range indices {
@ -234,7 +234,7 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
var funcs []*shaderir.Func var funcs []*shaderir.Func
if p.VertexFunc.Block != nil { if p.VertexFunc.Block != nil {
indices := p.ReferredFuncIndicesInFragmentShader() indices := p.ReachableFuncIndicesFromFragmentShader()
sort.Ints(indices) sort.Ints(indices)
funcs = make([]*shaderir.Func, 0, len(indices)) funcs = make([]*shaderir.Func, 0, len(indices))
for _, idx := range indices { for _, idx := range indices {

View File

@ -363,25 +363,25 @@ func IsValidSwizzling(s string) bool {
return false return false
} }
func (p *Program) ReferredFuncIndicesInVertexShader() []int { func (p *Program) ReachableFuncIndicesFromVertexShader() []int {
return p.referredFuncIndicesInBlockEntryPoint(p.VertexFunc.Block) return p.reachableFuncIndicesFromBlockEntryPoint(p.VertexFunc.Block)
} }
func (p *Program) ReferredFuncIndicesInFragmentShader() []int { func (p *Program) ReachableFuncIndicesFromFragmentShader() []int {
return p.referredFuncIndicesInBlockEntryPoint(p.FragmentFunc.Block) return p.reachableFuncIndicesFromBlockEntryPoint(p.FragmentFunc.Block)
} }
func (p *Program) referredFuncIndicesInBlockEntryPoint(b *Block) []int { func (p *Program) reachableFuncIndicesFromBlockEntryPoint(b *Block) []int {
indexToFunc := map[int]*Func{} indexToFunc := map[int]*Func{}
for _, f := range p.Funcs { for _, f := range p.Funcs {
f := f f := f
indexToFunc[f.Index] = &f indexToFunc[f.Index] = &f
} }
visited := map[int]struct{}{} visited := map[int]struct{}{}
return referredFuncIndicesInBlock(b, indexToFunc, visited) return reachableFuncIndicesFromBlock(b, indexToFunc, visited)
} }
func referredFuncIndicesInBlock(b *Block, indexToFunc map[int]*Func, visited map[int]struct{}) []int { func reachableFuncIndicesFromBlock(b *Block, indexToFunc map[int]*Func, visited map[int]struct{}) []int {
if b == nil { if b == nil {
return nil return nil
} }
@ -390,27 +390,27 @@ func referredFuncIndicesInBlock(b *Block, indexToFunc map[int]*Func, visited map
for _, s := range b.Stmts { for _, s := range b.Stmts {
for _, e := range s.Exprs { for _, e := range s.Exprs {
fs = append(fs, referredFuncIndicesInExpr(&e, indexToFunc, visited)...) fs = append(fs, reachableFuncIndicesFromExpr(&e, indexToFunc, visited)...)
} }
for _, bb := range s.Blocks { for _, bb := range s.Blocks {
fs = append(fs, referredFuncIndicesInBlock(bb, indexToFunc, visited)...) fs = append(fs, reachableFuncIndicesFromBlock(bb, indexToFunc, visited)...)
} }
} }
return fs return fs
} }
func referredFuncIndicesInExpr(e *Expr, indexToFunc map[int]*Func, visited map[int]struct{}) []int { func reachableFuncIndicesFromExpr(e *Expr, indexToFunc map[int]*Func, visited map[int]struct{}) []int {
var fs []int var fs []int
if e.Type == FunctionExpr { if e.Type == FunctionExpr {
if _, ok := visited[e.Index]; !ok { if _, ok := visited[e.Index]; !ok {
fs = append(fs, e.Index) fs = append(fs, e.Index)
visited[e.Index] = struct{}{} visited[e.Index] = struct{}{}
fs = append(fs, referredFuncIndicesInBlock(indexToFunc[e.Index].Block, indexToFunc, visited)...) fs = append(fs, reachableFuncIndicesFromBlock(indexToFunc[e.Index].Block, indexToFunc, visited)...)
} }
} }
for _, ee := range e.Exprs { for _, ee := range e.Exprs {
fs = append(fs, referredFuncIndicesInExpr(&ee, indexToFunc, visited)...) fs = append(fs, reachableFuncIndicesFromExpr(&ee, indexToFunc, visited)...)
} }
return fs return fs
} }