mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
gpu: rename resourceCache to textureCache and use concrete key
The only remaining use of the cache is mapping handles to textures. Using a concrete type for the key avoids the allocation caused by convT. If we need more caches again in the future we can copy the type, or make it generic. Instead of updating the benchmark, we removed it outright. It suffered from several flaws: - The amount of work for each iteration of b.N wasn't constant, because the same cache was reused, growing ever larger in size. - It only tested the cost of insertions. The comment "half are the same and half updated" wasn't true, as calling 'put' with the same key twice would've resulted in a panic. - It didn't simulate any particular workload or cache size, making the benchmark useless for comparing different cache implementations. The cost of insertions isn't particularly interesting. Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
committed by
Elias Naur
parent
4eca2c7d26
commit
fe2a164d30
+15
-10
@@ -8,8 +8,13 @@ import (
|
||||
"gioui.org/internal/f32"
|
||||
)
|
||||
|
||||
type resourceCache struct {
|
||||
res map[interface{}]resourceCacheValue
|
||||
type textureCacheKey struct {
|
||||
filter byte
|
||||
handle any
|
||||
}
|
||||
|
||||
type textureCache struct {
|
||||
res map[textureCacheKey]resourceCacheValue
|
||||
}
|
||||
|
||||
type resourceCacheValue struct {
|
||||
@@ -37,13 +42,13 @@ type opCacheValue struct {
|
||||
keep bool
|
||||
}
|
||||
|
||||
func newResourceCache() *resourceCache {
|
||||
return &resourceCache{
|
||||
res: make(map[interface{}]resourceCacheValue),
|
||||
func newTextureCache() *textureCache {
|
||||
return &textureCache{
|
||||
res: make(map[textureCacheKey]resourceCacheValue),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceCache) get(key interface{}) (resource, bool) {
|
||||
func (r *textureCache) get(key textureCacheKey) (resource, bool) {
|
||||
v, exists := r.res[key]
|
||||
if !exists {
|
||||
return nil, false
|
||||
@@ -55,17 +60,17 @@ func (r *resourceCache) get(key interface{}) (resource, bool) {
|
||||
return v.resource, exists
|
||||
}
|
||||
|
||||
func (r *resourceCache) put(key interface{}, val resource) {
|
||||
func (r *textureCache) put(key textureCacheKey, val resource) {
|
||||
v, exists := r.res[key]
|
||||
if exists && v.used {
|
||||
panic(fmt.Errorf("key exists, %p", key))
|
||||
panic(fmt.Errorf("key exists, %v", key))
|
||||
}
|
||||
v.used = true
|
||||
v.resource = val
|
||||
r.res[key] = v
|
||||
}
|
||||
|
||||
func (r *resourceCache) frame() {
|
||||
func (r *textureCache) frame() {
|
||||
for k, v := range r.res {
|
||||
if v.used {
|
||||
v.used = false
|
||||
@@ -77,7 +82,7 @@ func (r *resourceCache) frame() {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resourceCache) release() {
|
||||
func (r *textureCache) release() {
|
||||
for _, v := range r.res {
|
||||
v.resource.release()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user