internal/graphicsdriver/metal: Change the order of GCed buffers

As a big buffer is likely reused, we should remove smaller buffers
first.

Updates #1196
This commit is contained in:
Hajime Hoshi 2021-07-06 21:56:25 +09:00
parent 09bd8b6f4a
commit bd3f16dbba

View File

@ -425,14 +425,14 @@ func (g *Graphics) availableBuffer(length uintptr) mtl.Buffer {
} }
// GC unused buffers. // GC unused buffers.
const maxUnusedBuffers = 20 const maxUnusedBuffers = 10
if len(g.unusedBuffers) > maxUnusedBuffers { if len(g.unusedBuffers) > maxUnusedBuffers {
bufs := make([]mtl.Buffer, 0, len(g.unusedBuffers)) bufs := make([]mtl.Buffer, 0, len(g.unusedBuffers))
for b := range g.unusedBuffers { for b := range g.unusedBuffers {
bufs = append(bufs, b) bufs = append(bufs, b)
} }
sort.Slice(bufs, func(a, b int) bool { sort.Slice(bufs, func(a, b int) bool {
return bufs[a].Length() < bufs[b].Length() return bufs[a].Length() > bufs[b].Length()
}) })
for _, b := range bufs[maxUnusedBuffers:] { for _, b := range bufs[maxUnusedBuffers:] {
delete(g.unusedBuffers, b) delete(g.unusedBuffers, b)