mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/shaderir: refactoring
This commit is contained in:
parent
ecf07ad09e
commit
e4c9d6705c
@ -40,8 +40,7 @@ type Program struct {
|
|||||||
FragmentFunc FragmentFunc
|
FragmentFunc FragmentFunc
|
||||||
Unit Unit
|
Unit Unit
|
||||||
|
|
||||||
reachableUniforms []bool
|
uniformMask []uint32
|
||||||
uniformUint32Counts []int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Func struct {
|
type Func struct {
|
||||||
@ -472,30 +471,26 @@ func (p *Program) reachableUniformVariablesFromBlock(block *Block) []int {
|
|||||||
// FilterUniformVariables replaces uniform variables with nil when they are not used.
|
// FilterUniformVariables replaces uniform variables with nil when they are not used.
|
||||||
// By minimizing uniform variables, more commands can be merged in the graphicscommand package.
|
// By minimizing uniform variables, more commands can be merged in the graphicscommand package.
|
||||||
func (p *Program) FilterUniformVariables(uniforms []uint32) {
|
func (p *Program) FilterUniformVariables(uniforms []uint32) {
|
||||||
if p.reachableUniforms == nil {
|
if p.uniformMask == nil {
|
||||||
p.reachableUniforms = make([]bool, len(p.Uniforms))
|
reachableUniforms := make([]bool, len(p.Uniforms))
|
||||||
for _, i := range p.reachableUniformVariablesFromBlock(p.VertexFunc.Block) {
|
for _, i := range p.reachableUniformVariablesFromBlock(p.VertexFunc.Block) {
|
||||||
p.reachableUniforms[i] = true
|
reachableUniforms[i] = true
|
||||||
}
|
}
|
||||||
for _, i := range p.reachableUniformVariablesFromBlock(p.FragmentFunc.Block) {
|
for _, i := range p.reachableUniformVariablesFromBlock(p.FragmentFunc.Block) {
|
||||||
p.reachableUniforms[i] = true
|
reachableUniforms[i] = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if p.uniformUint32Counts == nil {
|
|
||||||
p.uniformUint32Counts = make([]int, len(p.Uniforms))
|
|
||||||
for i, typ := range p.Uniforms {
|
for i, typ := range p.Uniforms {
|
||||||
p.uniformUint32Counts[i] = typ.Uint32Count()
|
fs := make([]uint32, typ.Uint32Count())
|
||||||
|
if reachableUniforms[i] {
|
||||||
|
for j := range fs {
|
||||||
|
fs[j] = (1 << 32) - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.uniformMask = append(p.uniformMask, fs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var idx int
|
for i, factor := range p.uniformMask {
|
||||||
for i, n := range p.uniformUint32Counts {
|
uniforms[i] &= factor
|
||||||
if !p.reachableUniforms[i] {
|
|
||||||
for j := 0; j < n; j++ {
|
|
||||||
uniforms[idx+j] = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
idx += n
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user