+ /* determine the layer bounds */
+ if (strb->rtt_layered) {
+ first_layer = 0;
+ last_layer = util_max_layer(strb->texture, level);
+ }
+ else {
+ first_layer =
+ last_layer = strb->rtt_face + strb->rtt_slice;
+ }
+
+ /* Adjust for texture views */
+ if (strb->is_rtt && resource->array_size > 1 &&
+ strb->Base.TexImage->TexObject->Immutable) {
+ struct gl_texture_object *tex = strb->Base.TexImage->TexObject;
+ first_layer += tex->MinLayer;
+ if (!strb->rtt_layered)
+ last_layer += tex->MinLayer;
+ else
+ last_layer = MIN2(first_layer + tex->NumLayers - 1, last_layer);
+ }
+
+ if (!strb->surface ||
+ strb->surface->texture->nr_samples != strb->Base.NumSamples ||
+ strb->surface->format != format ||
+ strb->surface->texture != resource ||
+ strb->surface->width != rtt_width ||
+ strb->surface->height != rtt_height ||
+ strb->surface->u.tex.level != level ||
+ strb->surface->u.tex.first_layer != first_layer ||
+ strb->surface->u.tex.last_layer != last_layer) {
+ /* create a new pipe_surface */
+ struct pipe_surface surf_tmpl;
+ memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+ surf_tmpl.format = format;
+ surf_tmpl.u.tex.level = level;
+ surf_tmpl.u.tex.first_layer = first_layer;
+ surf_tmpl.u.tex.last_layer = last_layer;
+
+ pipe_surface_release(pipe, &strb->surface);
+
+ strb->surface = pipe->create_surface(pipe, resource, &surf_tmpl);
+ }
+}