internal/graphicscommand: refactoring: remove a hard-coded part for ShaderImageCount (#2895)

This change allows increasing ShaderImageCount without breaking the image display.
Simply made the uniform processing dynamic based on ShaderImageCount.
This commit is contained in:
Pedro Tiple 2024-01-26 04:03:04 +00:00 committed by GitHub
parent 8551cd350f
commit 6fafe734da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -333,40 +333,20 @@ func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shade
dw, dh := dst.InternalSize() dw, dh := dst.InternalSize()
uniforms[0] = math.Float32bits(float32(dw)) uniforms[0] = math.Float32bits(float32(dw))
uniforms[1] = math.Float32bits(float32(dh)) uniforms[1] = math.Float32bits(float32(dh))
uniformIndex := 2
// Set the source texture sizes. for i := 0; i < graphics.ShaderImageCount; i++ {
if srcs[0] != nil { var floatW, floatH uint32
w, h := srcs[0].InternalSize() if srcs[i] != nil {
uniforms[2] = math.Float32bits(float32(w)) w, h := srcs[i].InternalSize()
uniforms[3] = math.Float32bits(float32(h)) floatW = math.Float32bits(float32(w))
} else { floatH = math.Float32bits(float32(h))
uniforms[2] = 0
uniforms[3] = 0
} }
if srcs[1] != nil {
w, h := srcs[1].InternalSize() uniforms[uniformIndex+i*2] = floatW
uniforms[4] = math.Float32bits(float32(w)) uniforms[uniformIndex+1+i*2] = floatH
uniforms[5] = math.Float32bits(float32(h))
} else {
uniforms[4] = 0
uniforms[5] = 0
}
if srcs[2] != nil {
w, h := srcs[2].InternalSize()
uniforms[6] = math.Float32bits(float32(w))
uniforms[7] = math.Float32bits(float32(h))
} else {
uniforms[6] = 0
uniforms[7] = 0
}
if srcs[3] != nil {
w, h := srcs[3].InternalSize()
uniforms[8] = math.Float32bits(float32(w))
uniforms[9] = math.Float32bits(float32(h))
} else {
uniforms[8] = 0
uniforms[9] = 0
} }
uniformIndex += graphics.ShaderImageCount * 2
dr := imageRectangleToRectangleF32(dstRegion) dr := imageRectangleToRectangleF32(dstRegion)
if shader.unit() == shaderir.Texels { if shader.unit() == shaderir.Texels {
@ -377,12 +357,14 @@ func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shade
} }
// Set the destination region origin. // Set the destination region origin.
uniforms[10] = math.Float32bits(dr.x) uniforms[uniformIndex] = math.Float32bits(dr.x)
uniforms[11] = math.Float32bits(dr.y) uniforms[uniformIndex+1] = math.Float32bits(dr.y)
uniformIndex += 2
// Set the destination region size. // Set the destination region size.
uniforms[12] = math.Float32bits(dr.width) uniforms[uniformIndex] = math.Float32bits(dr.width)
uniforms[13] = math.Float32bits(dr.height) uniforms[uniformIndex+1] = math.Float32bits(dr.height)
uniformIndex += 2
var srs [graphics.ShaderImageCount]rectangleF32 var srs [graphics.ShaderImageCount]rectangleF32
for i, r := range srcRegions { for i, r := range srcRegions {
@ -402,42 +384,36 @@ func (q *commandQueue) prependPreservedUniforms(uniforms []uint32, shader *Shade
} }
// Set the source region origins. // Set the source region origins.
uniforms[14] = math.Float32bits(srs[0].x) for i := 0; i < graphics.ShaderImageCount; i++ {
uniforms[15] = math.Float32bits(srs[0].y) uniforms[uniformIndex+i*2] = math.Float32bits(srs[i].x)
uniforms[16] = math.Float32bits(srs[1].x) uniforms[uniformIndex+1+i*2] = math.Float32bits(srs[i].y)
uniforms[17] = math.Float32bits(srs[1].y) }
uniforms[18] = math.Float32bits(srs[2].x) uniformIndex += graphics.ShaderImageCount * 2
uniforms[19] = math.Float32bits(srs[2].y)
uniforms[20] = math.Float32bits(srs[3].x)
uniforms[21] = math.Float32bits(srs[3].y)
// Set the source region sizes. // Set the source region sizes.
uniforms[22] = math.Float32bits(srs[0].width) for i := 0; i < graphics.ShaderImageCount; i++ {
uniforms[23] = math.Float32bits(srs[0].height) uniforms[uniformIndex+i*2] = math.Float32bits(srs[i].width)
uniforms[24] = math.Float32bits(srs[1].width) uniforms[uniformIndex+1+i*2] = math.Float32bits(srs[i].height)
uniforms[25] = math.Float32bits(srs[1].height) }
uniforms[26] = math.Float32bits(srs[2].width) uniformIndex += graphics.ShaderImageCount * 2
uniforms[27] = math.Float32bits(srs[2].height)
uniforms[28] = math.Float32bits(srs[3].width)
uniforms[29] = math.Float32bits(srs[3].height)
// Set the projection matrix. // Set the projection matrix.
uniforms[30] = math.Float32bits(2 / float32(dw)) uniforms[uniformIndex] = math.Float32bits(2 / float32(dw))
uniforms[31] = 0 uniforms[uniformIndex+1] = 0
uniforms[32] = 0 uniforms[uniformIndex+2] = 0
uniforms[33] = 0 uniforms[uniformIndex+3] = 0
uniforms[34] = 0 uniforms[uniformIndex+4] = 0
uniforms[35] = math.Float32bits(2 / float32(dh)) uniforms[uniformIndex+5] = math.Float32bits(2 / float32(dh))
uniforms[36] = 0 uniforms[uniformIndex+6] = 0
uniforms[37] = 0 uniforms[uniformIndex+7] = 0
uniforms[38] = 0 uniforms[uniformIndex+8] = 0
uniforms[39] = 0 uniforms[uniformIndex+9] = 0
uniforms[40] = math.Float32bits(1) uniforms[uniformIndex+10] = math.Float32bits(1)
uniforms[41] = 0 uniforms[uniformIndex+11] = 0
uniforms[42] = math.Float32bits(-1) uniforms[uniformIndex+12] = math.Float32bits(-1)
uniforms[43] = math.Float32bits(-1) uniforms[uniformIndex+13] = math.Float32bits(-1)
uniforms[44] = 0 uniforms[uniformIndex+14] = 0
uniforms[45] = math.Float32bits(1) uniforms[uniformIndex+15] = math.Float32bits(1)
return uniforms return uniforms
} }