mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
internal/atlas: replace a global map with a struct member
This should be a pure performance improvement. Updates #2586 Updates #2601
This commit is contained in:
parent
77fd15145b
commit
e1041ea20e
@ -67,9 +67,11 @@ const baseCountToPutOnSourceBackend = 10
|
|||||||
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) {
|
func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) {
|
||||||
// The counter usedAsDestinationCount is updated at most once per frame (#2676).
|
// The counter usedAsDestinationCount is updated at most once per frame (#2676).
|
||||||
for i := range imagesUsedAsDestination {
|
for i := range imagesUsedAsDestination {
|
||||||
if i.usedAsDestinationCount < math.MaxInt {
|
// This counter is not updated when the backend is created in this frame.
|
||||||
|
if !i.backendJustCreated && i.usedAsDestinationCount < math.MaxInt {
|
||||||
i.usedAsDestinationCount++
|
i.usedAsDestinationCount++
|
||||||
}
|
}
|
||||||
|
i.backendJustCreated = false
|
||||||
delete(imagesUsedAsDestination, i)
|
delete(imagesUsedAsDestination, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,10 +85,6 @@ func putImagesOnSourceBackend(graphicsDriver graphicsdriver.Graphics) {
|
|||||||
}
|
}
|
||||||
delete(imagesToPutOnSourceBackend, i)
|
delete(imagesToPutOnSourceBackend, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range imagesBackendJustCreated {
|
|
||||||
delete(imagesBackendJustCreated, i)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type backend struct {
|
type backend struct {
|
||||||
@ -132,8 +130,6 @@ var (
|
|||||||
|
|
||||||
imagesUsedAsDestination = map[*Image]struct{}{}
|
imagesUsedAsDestination = map[*Image]struct{}{}
|
||||||
|
|
||||||
imagesBackendJustCreated = map[*Image]struct{}{}
|
|
||||||
|
|
||||||
deferred []func()
|
deferred []func()
|
||||||
|
|
||||||
// deferredM is a mutex for the slice operations. This must not be used for other usages.
|
// deferredM is a mutex for the slice operations. This must not be used for other usages.
|
||||||
@ -169,6 +165,7 @@ type Image struct {
|
|||||||
disposed bool
|
disposed bool
|
||||||
|
|
||||||
backend *backend
|
backend *backend
|
||||||
|
backendJustCreated bool
|
||||||
|
|
||||||
node *packing.Node
|
node *packing.Node
|
||||||
|
|
||||||
@ -229,6 +226,10 @@ func (i *Image) paddingSize() int {
|
|||||||
func (i *Image) ensureIsolatedFromSource(backends []*backend) {
|
func (i *Image) ensureIsolatedFromSource(backends []*backend) {
|
||||||
i.resetUsedAsSourceCount()
|
i.resetUsedAsSourceCount()
|
||||||
|
|
||||||
|
// imagesUsedAsDestination affects the counter usedAsDestination.
|
||||||
|
// The larger this counter is, the harder it is for the image to be transferred to the source backend.
|
||||||
|
imagesUsedAsDestination[i] = struct{}{}
|
||||||
|
|
||||||
if i.backend == nil {
|
if i.backend == nil {
|
||||||
// `theSourceBackendsForOneFrame` already includes `backends`.
|
// `theSourceBackendsForOneFrame` already includes `backends`.
|
||||||
bs := make([]*backend, 0, len(theSourceBackendsForOneFrame))
|
bs := make([]*backend, 0, len(theSourceBackendsForOneFrame))
|
||||||
@ -236,17 +237,10 @@ func (i *Image) ensureIsolatedFromSource(backends []*backend) {
|
|||||||
bs = append(bs, b)
|
bs = append(bs, b)
|
||||||
}
|
}
|
||||||
i.allocate(bs, false)
|
i.allocate(bs, false)
|
||||||
imagesBackendJustCreated[i] = struct{}{}
|
i.backendJustCreated = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// imagesUsedAsDestination affects the counter usedAsDestination.
|
|
||||||
// The larger this counter is, the harder it is for the image to be transferred to the source backend.
|
|
||||||
// This counter is not updated when the backend is created in this frame.
|
|
||||||
if _, ok := imagesBackendJustCreated[i]; !ok {
|
|
||||||
imagesUsedAsDestination[i] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !i.isOnAtlas() {
|
if !i.isOnAtlas() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user