mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
all: speed optimization
This commit is contained in:
parent
760e6b9ebd
commit
0d173834a6
@ -36,6 +36,15 @@ const (
|
|||||||
TextureSourceRegionOriginUniformVariableIndex = 5
|
TextureSourceRegionOriginUniformVariableIndex = 5
|
||||||
TextureSourceRegionSizeUniformVariableIndex = 6
|
TextureSourceRegionSizeUniformVariableIndex = 6
|
||||||
ProjectionMatrixUniformVariableIndex = 7
|
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 (
|
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 {
|
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
|
origUniforms := uniforms
|
||||||
uniforms = q.uint32sBuffer.alloc(len(origUniforms) + n)
|
uniforms = q.uint32sBuffer.alloc(len(origUniforms) + graphics.PreservedUniformUint32Count)
|
||||||
copy(uniforms[n:], origUniforms)
|
copy(uniforms[graphics.PreservedUniformUint32Count:], origUniforms)
|
||||||
|
|
||||||
var idx int
|
var idx int
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ type Program struct {
|
|||||||
VertexFunc VertexFunc
|
VertexFunc VertexFunc
|
||||||
FragmentFunc FragmentFunc
|
FragmentFunc FragmentFunc
|
||||||
|
|
||||||
reachableUniforms []bool
|
reachableUniforms []bool
|
||||||
|
uniformUint32Counts []int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Func struct {
|
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
|
var idx int
|
||||||
for i, typ := range p.Uniforms {
|
for i, n := range p.uniformUint32Counts {
|
||||||
n := typ.Uint32Count()
|
|
||||||
if !p.reachableUniforms[i] {
|
if !p.reachableUniforms[i] {
|
||||||
for j := 0; j < n; j++ {
|
for j := 0; j < n; j++ {
|
||||||
uniforms[idx+j] = 0
|
uniforms[idx+j] = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user