From 0d173834a6f09def3feb51df7ab800f9cd549da5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 3 Dec 2022 23:09:41 +0900 Subject: [PATCH] all: speed optimization --- internal/graphics/vertex.go | 9 +++++++++ internal/graphicscommand/command.go | 9 ++------- internal/shaderir/program.go | 13 ++++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/internal/graphics/vertex.go b/internal/graphics/vertex.go index 8667c30d6..cd5809fe5 100644 --- a/internal/graphics/vertex.go +++ b/internal/graphics/vertex.go @@ -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 ( diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 7c5ff447a..a77ea50aa 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -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 diff --git a/internal/shaderir/program.go b/internal/shaderir/program.go index 99bff0629..8040df413 100644 --- a/internal/shaderir/program.go +++ b/internal/shaderir/program.go @@ -32,7 +32,8 @@ type Program struct { VertexFunc VertexFunc FragmentFunc FragmentFunc - reachableUniforms []bool + reachableUniforms []bool + uniformUint32Counts []int } type Func struct { @@ -473,9 +474,15 @@ func (p *Program) FilterUniformVariables(uniforms []uint32) { } } + if p.uniformUint32Counts == nil { + p.uniformUint32Counts = make([]int, len(p.Uniforms)) + for i, typ := range p.Uniforms { + p.uniformUint32Counts[i] = typ.Uint32Count() + } + } + var idx int - for i, typ := range p.Uniforms { - n := typ.Uint32Count() + for i, n := range p.uniformUint32Counts { if !p.reachableUniforms[i] { for j := 0; j < n; j++ { uniforms[idx+j] = 0