SVGA_DBG(DEBUG_DMA, "unref sid %p (texture)\n", tex->handle);
svga_screen_surface_destroy(ss, &tex->key, &tex->handle);
+ /* Destroy the backed surface handle if exists */
+ if (tex->backed_handle)
+ svga_screen_surface_destroy(ss, &tex->backed_key, &tex->backed_handle);
+
ss->hud.total_resource_bytes -= tex->size;
FREE(tex->defined);
tex->can_use_upload = svga_texture_transfer_map_can_upload(svgascreen,
&tex->b.b);
+ /* Initialize the backing resource cache */
+ tex->backed_handle = NULL;
+
svgascreen->hud.total_resource_bytes += tex->size;
svgascreen->hud.num_resources++;
int layer_pick,
unsigned num_layers,
int zslice_pick,
+ boolean cacheable,
struct svga_host_surface_cache_key *key) /* OUT */
{
struct svga_screen *ss = svga_screen(svga->pipe.screen);
struct svga_winsys_surface *handle;
boolean validated;
+ boolean needCopyResource;
SVGA_DBG(DEBUG_PERF,
"svga: Create surface view: layer %d zslice %d mips %d..%d\n",
return NULL;
}
- SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
- handle = svga_screen_surface_create(ss, bind_flags, PIPE_USAGE_DEFAULT,
- &validated, key);
+ if (cacheable && tex->backed_handle &&
+ memcmp(key, &tex->backed_key, sizeof *key) == 0) {
+ handle = tex->backed_handle;
+ needCopyResource = tex->backed_age < tex->age;
+ } else {
+ SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
+ handle = svga_screen_surface_create(ss, bind_flags, PIPE_USAGE_DEFAULT,
+ &validated, key);
+ needCopyResource = TRUE;
+
+ if (cacheable && !tex->backed_handle) {
+ tex->backed_handle = handle;
+ memcpy(&tex->backed_key, key, sizeof *key);
+ }
+ }
+
if (!handle) {
key->cachable = 0;
return NULL;
if (layer_pick < 0)
layer_pick = 0;
- svga_texture_copy_handle_resource(svga, tex, handle,
- key->numMipLevels,
- key->numFaces * key->arraySize,
- zslice_pick, start_mip, layer_pick);
+ if (needCopyResource) {
+ svga_texture_copy_handle_resource(svga, tex, handle,
+ key->numMipLevels,
+ key->numFaces * key->arraySize,
+ zslice_pick, start_mip, layer_pick);
+ tex->backed_age = tex->age;
+ }
return handle;
}
s->handle = svga_texture_view_surface(svga, tex, bind, flags,
tex->key.format,
surf_tmpl->u.tex.level, 1,
- layer, nlayers, zslice, &s->key);
+ layer, nlayers, zslice,
+ TRUE, &s->key);
if (!s->handle) {
FREE(s);
goto done;
s->backed = NULL;
}
- if (s->handle != t->handle) {
+ /* Destroy the surface handle if this is a backed handle and
+ * it is not being cached in the texture.
+ */
+ if (s->handle != t->handle && s->handle != t->backed_handle) {
SVGA_DBG(DEBUG_DMA, "unref sid %p (tex surface)\n", s->handle);
svga_screen_surface_destroy(ss, &s->key, &s->handle);
}
/* Sync the surface view age with the texture age */
s->age = tex->age;
+
+ /* If this backed surface is cached in the texture,
+ * update the backed age as well.
+ */
+ if (tex->backed_handle == s->handle) {
+ tex->backed_age = tex->age;
+ }
}
SVGA_STATS_TIME_POP(ss->sws);