Performance optimization for the path without a shader

Fixes #1355
This commit is contained in:
Hajime Hoshi 2020-09-21 05:36:47 +09:00
parent cb73230301
commit f3ef2e2af5
4 changed files with 60 additions and 49 deletions

View File

@ -265,26 +265,24 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
}
}
for _, src := range srcs {
if src == nil {
continue
}
src.resolvePendingPixels(true)
}
i.resolvePendingPixels(false)
var s *shareable.Shader
if shader != nil {
s = shader.shader
}
var imgs [graphics.ShaderImageNum]*shareable.Image
if shader == nil {
// Fast path for rendering without a shader (#1355).
img := srcs[0]
img.resolvePendingPixels(true)
imgs[0] = img.img
} else {
for i, img := range srcs {
if img == nil {
continue
}
img.resolvePendingPixels(true)
imgs[i] = img.img
}
s = shader.shader
}
i.resolvePendingPixels(false)
i.img.DrawTriangles(imgs, vertices, indices, colorm, mode, filter, address, sourceRegion, subimageOffsets, s, uniforms)
i.invalidatePendingPixels()

View File

@ -157,6 +157,14 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
}
}
if shader == nil {
// Fast path for rendering without a shader (#1355).
img := srcs[0]
if img.screen {
panic("graphicscommand: the screen image cannot be the rendering source")
}
img.resolveBufferedReplacePixels()
} else {
for _, src := range srcs {
if src == nil {
continue
@ -166,6 +174,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
}
src.resolveBufferedReplacePixels()
}
}
i.resolveBufferedReplacePixels()
theCommandQueue.EnqueueDrawTrianglesCommand(i, srcs, offsets, vertices, indices, clr, mode, filter, address, sourceRegion, shader, uniforms)

View File

@ -389,18 +389,21 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
} else {
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, colorm, mode, filter, address, sourceRegion, shader, uniforms)
}
var s *graphicscommand.Shader
if shader != nil {
s = shader.shader
}
var s *graphicscommand.Shader
var imgs [graphics.ShaderImageNum]*graphicscommand.Image
if shader == nil {
// Fast path for rendering without a shader (#1355).
imgs[0] = srcs[0].image
} else {
for i, src := range srcs {
if src == nil {
continue
}
imgs[i] = src.image
}
s = shader.shader
}
i.image.DrawTriangles(imgs, offsets, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms)
}

View File

@ -354,6 +354,12 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
}
var offsets [graphics.ShaderImageNum - 1][2]float32
var s *restorable.Shader
var imgs [graphics.ShaderImageNum]*restorable.Image
if shader == nil {
// Fast path for rendering without a shader (#1355).
imgs[0] = srcs[0].backend.restorable
} else {
for i, subimageOffset := range subimageOffsets {
src := srcs[i+1]
if src == nil {
@ -363,19 +369,14 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
offsets[i][0] = float32(ox) + paddingSize - oxf + subimageOffset[0]
offsets[i][1] = float32(oy) + paddingSize - oyf + subimageOffset[1]
}
var s *restorable.Shader
if shader != nil {
s = shader.shader
}
var imgs [graphics.ShaderImageNum]*restorable.Image
for i, src := range srcs {
if src == nil {
continue
}
imgs[i] = src.backend.restorable
}
}
i.backend.restorable.DrawTriangles(imgs, offsets, vertices, indices, colorm, mode, filter, address, sourceRegion, s, uniforms)