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;
+ struct svga_winsys_surface *handle = NULL;
boolean validated;
+ boolean needCopyResource;
SVGA_DBG(DEBUG_PERF,
"svga: Create surface view: layer %d zslice %d mips %d..%d\n",
layer_pick, zslice_pick, start_mip, start_mip+num_mip-1);
+ SVGA_STATS_TIME_PUSH(ss->sws, SVGA_STATS_TIME_EMULATESURFACEVIEW);
+
key->flags = flags;
key->format = format;
key->numMipLevels = num_mip;
if (key->format == SVGA3D_FORMAT_INVALID) {
key->cachable = 0;
- return NULL;
+ goto done;
+ }
+
+ 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);
+ }
}
- SVGA_DBG(DEBUG_DMA, "surface_create for texture view\n");
- handle = svga_screen_surface_create(ss, bind_flags, PIPE_USAGE_DEFAULT,
- &validated, key);
if (!handle) {
key->cachable = 0;
- return NULL;
+ goto done;
}
SVGA_DBG(DEBUG_DMA, " --> got sid %p (texture view)\n", handle);
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;
+ }
+
+done:
+ SVGA_STATS_TIME_POP(ss->sws);
return handle;
}
bind = PIPE_BIND_RENDER_TARGET;
}
- if (tex->imported)
+ if (tex->imported) {
+ /* imported resource (a window) */
format = tex->key.format;
- else
+ if (util_format_is_srgb(surf_tmpl->format)) {
+ /* sRGB rendering to window */
+ format = svga_linear_to_srgb(format);
+ }
+ }
+ else {
format = svga_translate_format(ss, surf_tmpl->format, bind);
+ }
assert(format != SVGA3D_FORMAT_INVALID);
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;
{
struct svga_texture *tex = svga_texture(s->base.texture);
- SVGA_STATS_TIME_PUSH(svga_sws(svga),
- SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW);
-
if (!s->backed) {
struct pipe_surface *backed_view;
+ SVGA_STATS_TIME_PUSH(svga_sws(svga),
+ SVGA_STATS_TIME_CREATEBACKEDSURFACEVIEW);
+
backed_view = svga_create_surface_view(&svga->pipe,
&tex->b.b,
&s->base,
TRUE);
if (!backed_view)
- return NULL;
+ goto done;
s->backed = svga_surface(backed_view);
+
+ SVGA_STATS_TIME_POP(svga_sws(svga));
}
- else {
+ else if (s->backed->age < tex->age) {
/*
* There is already an existing backing surface, but we still need to
- * sync the handles.
+ * sync the backing resource if the original resource has been modified
+ * since the last copy.
*/
struct svga_surface *bs = s->backed;
unsigned int layer, zslice;
}
svga_mark_surface_dirty(&s->backed->base);
+ s->backed->age = tex->age;
- SVGA_STATS_TIME_POP(svga_sws(svga));
-
+done:
return s->backed;
}
* need to update the host-side copy with the invalid
* content when the associated mob is first bound to the surface.
*/
- ret = SVGA3D_InvalidateGBSurface(svga->swc, stex->handle);
- if (ret != PIPE_OK) {
- s = NULL;
- goto done;
+ if (svga->swc->surface_invalidate(svga->swc, stex->handle) != PIPE_OK) {
+ svga_context_flush(svga, NULL);
+ ret = svga->swc->surface_invalidate(svga->swc, stex->handle);
+ assert(ret == PIPE_OK);
}
stex->validated = TRUE;
}
}
}
-done:
SVGA_STATS_TIME_POP(svga_sws(svga));
return s ? &s->base : NULL;
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);
}
/* Increment the view_age and texture age for this surface's mipmap
* level so that any sampler views into the texture are re-validated too.
+ * Note: we age the texture for backed surface view only when the
+ * backed surface is propagated to the original surface.
*/
- svga_age_texture_view(tex, surf->u.tex.level);
+ if (s->handle == tex->handle)
+ svga_age_texture_view(tex, surf->u.tex.level);
}
1);
svga_define_texture_level(tex, layer + i, surf->u.tex.level);
}
+
+ /* 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);