all: remove unused conditions

Now Kage shaders are always used.

The situtation is different from when we fixed for #1355, so we removed
the fast path for #1335. We have to re-check the current performance.

Updates #1355
This commit is contained in:
Hajime Hoshi 2022-10-02 23:49:07 +09:00
parent 534d82c17d
commit 72983d966b
5 changed files with 35 additions and 72 deletions

View File

@ -455,31 +455,24 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
} }
var offsets [graphics.ShaderImageCount - 1][2]float32 var offsets [graphics.ShaderImageCount - 1][2]float32
var s *restorable.Shader
var imgs [graphics.ShaderImageCount]*restorable.Image var imgs [graphics.ShaderImageCount]*restorable.Image
if shader == nil { for i, subimageOffset := range subimageOffsets {
// Fast path for rendering without a shader (#1355). src := srcs[i+1]
imgs[0] = srcs[0].backend.restorable if src == nil {
} else { continue
for i, subimageOffset := range subimageOffsets {
src := srcs[i+1]
if src == nil {
continue
}
ox, oy, _, _ := src.regionWithPadding()
offsets[i][0] = float32(ox+src.paddingSize()) - oxf + subimageOffset[0]
offsets[i][1] = float32(oy+src.paddingSize()) - oyf + subimageOffset[1]
} }
s = shader.shader ox, oy, _, _ := src.regionWithPadding()
for i, src := range srcs { offsets[i][0] = float32(ox+src.paddingSize()) - oxf + subimageOffset[0]
if src == nil { offsets[i][1] = float32(oy+src.paddingSize()) - oyf + subimageOffset[1]
continue }
} for i, src := range srcs {
imgs[i] = src.backend.restorable if src == nil {
continue
} }
imgs[i] = src.backend.restorable
} }
i.backend.restorable.DrawTriangles(imgs, offsets, vertices, indices, mode, dstRegion, srcRegion, s, uniforms, evenOdd) i.backend.restorable.DrawTriangles(imgs, offsets, vertices, indices, mode, dstRegion, srcRegion, shader.shader, uniforms, evenOdd)
for _, src := range srcs { for _, src := range srcs {
if src == nil { if src == nil {

View File

@ -156,24 +156,16 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [
} }
} }
var s *atlas.Shader
var imgs [graphics.ShaderImageCount]*atlas.Image var imgs [graphics.ShaderImageCount]*atlas.Image
if shader == nil { for i, img := range srcs {
// Fast path for rendering without a shader (#1355). if img == nil {
img := srcs[0] continue
imgs[0] = img.img
} else {
for i, img := range srcs {
if img == nil {
continue
}
imgs[i] = img.img
} }
s = shader.shader imgs[i] = img.img
} }
i.invalidatePixels() i.invalidatePixels()
i.img.DrawTriangles(imgs, vertices, indices, mode, dstRegion, srcRegion, subimageOffsets, s, uniforms, evenOdd) i.img.DrawTriangles(imgs, vertices, indices, mode, dstRegion, srcRegion, subimageOffsets, shader.shader, uniforms, evenOdd)
} }
type Shader struct { type Shader struct {

View File

@ -328,22 +328,16 @@ func (c *drawTrianglesCommand) Exec(graphicsDriver graphicsdriver.Graphics, inde
return nil return nil
} }
var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID
var imgs [graphics.ShaderImageCount]graphicsdriver.ImageID var imgs [graphics.ShaderImageCount]graphicsdriver.ImageID
if c.shader != nil { for i, src := range c.srcs {
shaderID = c.shader.shader.ID() if src == nil {
for i, src := range c.srcs { imgs[i] = graphicsdriver.InvalidImageID
if src == nil { continue
imgs[i] = graphicsdriver.InvalidImageID
continue
}
imgs[i] = src.image.ID()
} }
} else { imgs[i] = src.image.ID()
imgs[0] = c.srcs[0].image.ID()
} }
return graphicsDriver.DrawTriangles(c.dst.image.ID(), imgs, c.offsets, shaderID, c.nindices, indexOffset, c.mode, c.dstRegion, c.srcRegion, c.uniforms, c.evenOdd) return graphicsDriver.DrawTriangles(c.dst.image.ID(), imgs, c.offsets, c.shader.shader.ID(), c.nindices, indexOffset, c.mode, c.dstRegion, c.srcRegion, c.uniforms, c.evenOdd)
} }
func (c *drawTrianglesCommand) numVertices() int { func (c *drawTrianglesCommand) numVertices() int {

View File

@ -128,23 +128,14 @@ func (i *Image) InternalSize() (int, int) {
// If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the // If the source image is not specified, i.e., src is nil and there is no image in the uniform variables, the
// elements for the source image are not used. // elements for the source image are not used.
func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, mode graphicsdriver.CompositeMode, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) { func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, mode graphicsdriver.CompositeMode, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) {
if shader == nil { for _, src := range srcs {
// Fast path for rendering without a shader (#1355). if src == nil {
img := srcs[0] continue
if img.screen { }
if src.screen {
panic("graphicscommand: the screen image cannot be the rendering source") panic("graphicscommand: the screen image cannot be the rendering source")
} }
img.resolveBufferedWritePixels() src.resolveBufferedWritePixels()
} else {
for _, src := range srcs {
if src == nil {
continue
}
if src.screen {
panic("graphicscommand: the screen image cannot be the rendering source")
}
src.resolveBufferedWritePixels()
}
} }
i.resolveBufferedWritePixels() i.resolveBufferedWritePixels()

View File

@ -387,21 +387,14 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, offsets [g
i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, mode, dstRegion, srcRegion, shader, uniforms, evenOdd) i.appendDrawTrianglesHistory(srcs, offsets, vertices, indices, mode, dstRegion, srcRegion, shader, uniforms, evenOdd)
} }
var s *graphicscommand.Shader
var imgs [graphics.ShaderImageCount]*graphicscommand.Image var imgs [graphics.ShaderImageCount]*graphicscommand.Image
if shader == nil { for i, src := range srcs {
// Fast path for rendering without a shader (#1355). if src == nil {
imgs[0] = srcs[0].image continue
} else {
for i, src := range srcs {
if src == nil {
continue
}
imgs[i] = src.image
} }
s = shader.shader imgs[i] = src.image
} }
i.image.DrawTriangles(imgs, offsets, vertices, indices, mode, dstRegion, srcRegion, s, uniforms, evenOdd) i.image.DrawTriangles(imgs, offsets, vertices, indices, mode, dstRegion, srcRegion, shader.shader, uniforms, evenOdd)
} }
// appendDrawTrianglesHistory appends a draw-image history item to the image. // appendDrawTrianglesHistory appends a draw-image history item to the image.