all: speed optimization

This commit is contained in:
Hajime Hoshi 2022-12-03 23:09:41 +09:00
parent 760e6b9ebd
commit 0d173834a6
3 changed files with 21 additions and 10 deletions

View File

@ -36,6 +36,15 @@ const (
TextureSourceRegionOriginUniformVariableIndex = 5
TextureSourceRegionSizeUniformVariableIndex = 6
ProjectionMatrixUniformVariableIndex = 7
PreservedUniformUint32Count = 2 + // the destination texture size
2*ShaderImageCount + // the texture sizes array
2 + // the texture destination region's origin
2 + // the texture destination region's size
2*(ShaderImageCount-1) + // the offsets array of the second and the following images
2 + // the texture source region's origin
2 + // the texture source region's size
16 // the projection matrix
)
const (

View File

@ -580,14 +580,9 @@ func roundUpPower2(x int) int {
}
func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shader, dst *Image, srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, dstRegion, srcRegion graphicsdriver.Region) []uint32 {
var n int
for _, typ := range shader.ir.Uniforms[:graphics.PreservedUniformVariablesCount] {
n += typ.Uint32Count()
}
origUniforms := uniforms
uniforms = q.uint32sBuffer.alloc(len(origUniforms) + n)
copy(uniforms[n:], origUniforms)
uniforms = q.uint32sBuffer.alloc(len(origUniforms) + graphics.PreservedUniformUint32Count)
copy(uniforms[graphics.PreservedUniformUint32Count:], origUniforms)
var idx int

View File

@ -33,6 +33,7 @@ type Program struct {
FragmentFunc FragmentFunc
reachableUniforms []bool
uniformUint32Counts []int
}
type Func struct {
@ -473,9 +474,15 @@ func (p *Program) FilterUniformVariables(uniforms []uint32) {
}
}
var idx int
if p.uniformUint32Counts == nil {
p.uniformUint32Counts = make([]int, len(p.Uniforms))
for i, typ := range p.Uniforms {
n := typ.Uint32Count()
p.uniformUint32Counts[i] = typ.Uint32Count()
}
}
var idx int
for i, n := range p.uniformUint32Counts {
if !p.reachableUniforms[i] {
for j := 0; j < n; j++ {
uniforms[idx+j] = 0