Revert "internal/graphicscommand: merge adjacent commands if the same shader and uniform variables are used"

This reverts commit 425ce27976.

Reason: test failures
This commit is contained in:
Hajime Hoshi 2022-04-03 00:11:15 +09:00
parent 425ce27976
commit 651c5693c6
2 changed files with 12 additions and 24 deletions

View File

@ -117,7 +117,7 @@ func mustUseDifferentVertexBuffer(nextNumVertexFloats, nextNumIndices int) bool
} }
// EnqueueDrawTrianglesCommand enqueues a drawing-image command. // EnqueueDrawTrianglesCommand enqueues a drawing-image command.
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) { func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, offsets [graphics.ShaderImageNum - 1][2]float32, vertices []float32, indices []uint16, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms map[string]interface{}, evenOdd bool) {
if len(indices) > graphics.IndicesNum { if len(indices) > graphics.IndicesNum {
panic(fmt.Sprintf("graphicscommand: len(indices) must be <= graphics.IndicesNum but not at EnqueueDrawTrianglesCommand: len(indices): %d, graphics.IndicesNum: %d", len(indices), graphics.IndicesNum)) panic(fmt.Sprintf("graphicscommand: len(indices) must be <= graphics.IndicesNum but not at EnqueueDrawTrianglesCommand: len(indices): %d, graphics.IndicesNum: %d", len(indices), graphics.IndicesNum))
} }
@ -152,7 +152,7 @@ func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.Sh
if !split && 0 < len(q.commands) { if !split && 0 < len(q.commands) {
// TODO: Pass offsets and uniforms when merging considers the shader. // TODO: Pass offsets and uniforms when merging considers the shader.
if last, ok := q.commands[len(q.commands)-1].(*drawTrianglesCommand); ok { if last, ok := q.commands[len(q.commands)-1].(*drawTrianglesCommand); ok {
if last.CanMergeWithDrawTrianglesCommand(dst, srcs, vertices, color, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd) { if last.CanMergeWithDrawTrianglesCommand(dst, srcs, vertices, color, mode, filter, address, dstRegion, srcRegion, shader, evenOdd) {
last.setVertices(q.lastVertices(len(vertices) + last.numVertices())) last.setVertices(q.lastVertices(len(vertices) + last.numVertices()))
last.addNumIndices(len(indices)) last.addNumIndices(len(indices))
return return
@ -295,7 +295,7 @@ type drawTrianglesCommand struct {
dstRegion graphicsdriver.Region dstRegion graphicsdriver.Region
srcRegion graphicsdriver.Region srcRegion graphicsdriver.Region
shader *Shader shader *Shader
uniforms [][]float32 uniforms map[string]interface{}
evenOdd bool evenOdd bool
} }
@ -393,6 +393,7 @@ func (c *drawTrianglesCommand) Exec(graphicsDriver graphicsdriver.Graphics, inde
var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID var shaderID graphicsdriver.ShaderID = graphicsdriver.InvalidShaderID
var imgs [graphics.ShaderImageNum]graphicsdriver.ImageID var imgs [graphics.ShaderImageNum]graphicsdriver.ImageID
var us [][]float32
if c.shader != nil { if c.shader != nil {
shaderID = c.shader.shader.ID() shaderID = c.shader.shader.ID()
for i, src := range c.srcs { for i, src := range c.srcs {
@ -402,11 +403,12 @@ func (c *drawTrianglesCommand) Exec(graphicsDriver graphicsdriver.Graphics, inde
} }
imgs[i] = src.image.ID() imgs[i] = src.image.ID()
} }
us = c.shader.convertUniforms(c.uniforms)
} else { } else {
imgs[0] = c.srcs[0].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.color, c.filter, c.address, c.dstRegion, c.srcRegion, c.uniforms, c.evenOdd) return graphicsDriver.DrawTriangles(c.dst.image.ID(), imgs, c.offsets, shaderID, c.nindices, indexOffset, c.mode, c.color, c.filter, c.address, c.dstRegion, c.srcRegion, us, c.evenOdd)
} }
func (c *drawTrianglesCommand) numVertices() int { func (c *drawTrianglesCommand) numVertices() int {
@ -427,22 +429,13 @@ func (c *drawTrianglesCommand) addNumIndices(n int) {
// CanMergeWithDrawTrianglesCommand returns a boolean value indicating whether the other drawTrianglesCommand can be merged // CanMergeWithDrawTrianglesCommand returns a boolean value indicating whether the other drawTrianglesCommand can be merged
// with the drawTrianglesCommand c. // with the drawTrianglesCommand c.
func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, vertices []float32, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms [][]float32, evenOdd bool) bool { func (c *drawTrianglesCommand) CanMergeWithDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageNum]*Image, vertices []float32, color affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, evenOdd bool) bool {
if c.shader != shader { // If a shader is used, commands are not merged.
//
// TODO: Merge shader commands considering uniform variables.
if c.shader != nil || shader != nil {
return false return false
} }
if c.shader != nil {
if len(c.uniforms) != len(uniforms) {
return false
}
for i, v0 := range c.uniforms {
for j, v1 := range v0 {
if v1 != uniforms[i][j] {
return false
}
}
}
}
if c.dst != dst { if c.dst != dst {
return false return false
} }

View File

@ -162,12 +162,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, offsets [gra
} }
i.resolveBufferedReplacePixels() i.resolveBufferedReplacePixels()
var us [][]float32 theCommandQueue.EnqueueDrawTrianglesCommand(i, srcs, offsets, vertices, indices, clr, mode, filter, address, dstRegion, srcRegion, shader, uniforms, evenOdd)
if shader != nil {
us = shader.convertUniforms(uniforms)
}
theCommandQueue.EnqueueDrawTrianglesCommand(i, srcs, offsets, vertices, indices, clr, mode, filter, address, dstRegion, srcRegion, shader, us, evenOdd)
} }
// ReadPixels reads the image's pixels. // ReadPixels reads the image's pixels.