mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
all: speed optimization
This commit is contained in:
parent
760e6b9ebd
commit
0d173834a6
@ -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 (
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user