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
+5
-9
@@ -51,7 +51,7 @@ type GPU interface {
|
||||
}
|
||||
|
||||
type gpu struct {
|
||||
cache *resourceCache
|
||||
cache *textureCache
|
||||
|
||||
profile string
|
||||
timers *timers
|
||||
@@ -359,7 +359,7 @@ func NewWithDevice(d driver.Device) (GPU, error) {
|
||||
|
||||
func newGPU(ctx driver.Device) (*gpu, error) {
|
||||
g := &gpu{
|
||||
cache: newResourceCache(),
|
||||
cache: newTextureCache(),
|
||||
}
|
||||
g.drawOps.pathCache = newOpCache()
|
||||
if err := g.init(ctx); err != nil {
|
||||
@@ -460,12 +460,8 @@ func (g *gpu) Profile() string {
|
||||
return g.profile
|
||||
}
|
||||
|
||||
func (r *renderer) texHandle(cache *resourceCache, data imageOpData) driver.Texture {
|
||||
type cachekey struct {
|
||||
filter byte
|
||||
handle any
|
||||
}
|
||||
key := cachekey{
|
||||
func (r *renderer) texHandle(cache *textureCache, data imageOpData) driver.Texture {
|
||||
key := textureCacheKey{
|
||||
filter: data.filter,
|
||||
handle: data.handle,
|
||||
}
|
||||
@@ -1211,7 +1207,7 @@ func (d *drawState) materialFor(rect f32.Rectangle, off f32.Point, partTrans f32
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *renderer) uploadImages(cache *resourceCache, ops []imageOp) {
|
||||
func (r *renderer) uploadImages(cache *textureCache, ops []imageOp) {
|
||||
for i := range ops {
|
||||
img := &ops[i]
|
||||
m := img.material
|
||||
|
||||
Reference in New Issue
Block a user