internal/restoring: avoid using staleRegions when alwaysReadPixelsFromGPU is true

Updates #2582
This commit is contained in:
Hajime Hoshi 2023-02-25 23:24:09 +09:00
parent 965fd4cac8
commit f04d9d6925

View File

@ -121,6 +121,7 @@ type Image struct {
// staleRegions indicates the regions to restore.
// staleRegions is valid only when stale is true.
// staleRegions is not used when alwaysReadPixelsFromGPU() returns true.
staleRegions []image.Rectangle
imageType ImageType
@ -261,6 +262,11 @@ func (i *Image) BasePixelsForTesting() *Pixels {
func (i *Image) makeStale(rect image.Rectangle) {
i.stale = true
// If ReadPixels always reads pixels from GPU, staleRegions are never used.
if alwaysReadPixelsFromGPU() {
return
}
i.staleRegions = i.appendRegionsForDrawTriangles(i.staleRegions)
if !rect.Empty() {
i.staleRegions = append(i.staleRegions, rect)
@ -402,6 +408,9 @@ func (i *Image) appendDrawTrianglesHistory(srcs [graphics.ShaderImageCount]*Imag
if i.stale || !i.needsRestoring() {
panic("restorable: an image must not be stale or need restoring at appendDrawTrianglesHistory")
}
if alwaysReadPixelsFromGPU() {
panic("restorable: appendDrawTrianglesHistory must not be called when alwaysReadPixelsFromGPU() returns true")
}
// TODO: Would it be possible to merge draw image history items?
const maxDrawTrianglesHistoryCount = 1024