mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/shaderir: improve FilterUniformVariables
``` name old time/op new time/op delta Filter-8 31.7ns ± 1% 29.9ns ± 1% -5.60% (p=0.000 n=9+10) ``` Updates #2601
This commit is contained in:
parent
3b67b91bb2
commit
4f2327536c
34
internal/shaderir/bench_test.go
Normal file
34
internal/shaderir/bench_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2023 The Ebitengine Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package shaderir_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
)
|
||||
|
||||
func BenchmarkFilter(b *testing.B) {
|
||||
src := builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false)
|
||||
s, err := graphics.CompileShader(src)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
uniforms := make([]uint32, graphics.PreservedUniformUint32Count)
|
||||
for i := 0; i < b.N; i++ {
|
||||
s.FilterUniformVariables(uniforms)
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ type Program struct {
|
||||
FragmentFunc FragmentFunc
|
||||
Unit Unit
|
||||
|
||||
uniformMask []uint32
|
||||
uniformFactors []uint32
|
||||
}
|
||||
|
||||
type Func struct {
|
||||
@ -464,7 +464,7 @@ func (p *Program) appendReachableUniformVariablesFromBlock(indices []int, block
|
||||
// FilterUniformVariables replaces uniform variables with nil when they are not used.
|
||||
// By minimizing uniform variables, more commands can be merged in the graphicscommand package.
|
||||
func (p *Program) FilterUniformVariables(uniforms []uint32) {
|
||||
if p.uniformMask == nil {
|
||||
if p.uniformFactors == nil {
|
||||
indices := p.appendReachableUniformVariablesFromBlock(nil, p.VertexFunc.Block)
|
||||
indices = p.appendReachableUniformVariablesFromBlock(indices, p.FragmentFunc.Block)
|
||||
reachableUniforms := make([]bool, len(p.Uniforms))
|
||||
@ -475,14 +475,14 @@ func (p *Program) FilterUniformVariables(uniforms []uint32) {
|
||||
fs := make([]uint32, typ.Uint32Count())
|
||||
if reachableUniforms[i] {
|
||||
for j := range fs {
|
||||
fs[j] = (1 << 32) - 1
|
||||
fs[j] = 1
|
||||
}
|
||||
}
|
||||
p.uniformMask = append(p.uniformMask, fs...)
|
||||
p.uniformFactors = append(p.uniformFactors, fs...)
|
||||
}
|
||||
}
|
||||
|
||||
for i, factor := range p.uniformMask {
|
||||
uniforms[i] &= factor
|
||||
for i, factor := range p.uniformFactors {
|
||||
uniforms[i] *= factor
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user