+ for (i = 0; i < num; i++) {
+ struct pipe_sampler_view *view = views[i];
+
+ if (view) {
+ struct pipe_resource *tex = view->texture;
+ struct softpipe_resource *sp_tex = softpipe_resource(tex);
+ unsigned width0 = tex->width0;
+ unsigned num_layers = tex->depth0;
+ unsigned first_level = 0;
+ unsigned last_level = 0;
+
+ /* We're referencing the texture's internal data, so save a
+ * reference to it.
+ */
+ pipe_resource_reference(&mapped_tex[i], tex);
+
+ if (!sp_tex->dt) {
+ /* regular texture - setup array of mipmap level offsets */
+ ASSERTED struct pipe_resource *res = view->texture;
+ int j;
+
+ if (view->target != PIPE_BUFFER) {
+ first_level = view->u.tex.first_level;
+ last_level = view->u.tex.last_level;
+ assert(first_level <= last_level);
+ assert(last_level <= res->last_level);
+ addr = sp_tex->data;
+
+ for (j = first_level; j <= last_level; j++) {
+ mip_offsets[j] = sp_tex->level_offset[j];
+ row_stride[j] = sp_tex->stride[j];
+ img_stride[j] = sp_tex->img_stride[j];
+ }
+ if (tex->target == PIPE_TEXTURE_1D_ARRAY ||
+ tex->target == PIPE_TEXTURE_2D_ARRAY ||
+ tex->target == PIPE_TEXTURE_CUBE ||
+ tex->target == PIPE_TEXTURE_CUBE_ARRAY) {
+ num_layers = view->u.tex.last_layer - view->u.tex.first_layer + 1;
+ for (j = first_level; j <= last_level; j++) {
+ mip_offsets[j] += view->u.tex.first_layer *
+ sp_tex->img_stride[j];
+ }
+ if (view->target == PIPE_TEXTURE_CUBE ||
+ view->target == PIPE_TEXTURE_CUBE_ARRAY) {
+ assert(num_layers % 6 == 0);
+ }
+ assert(view->u.tex.first_layer <= view->u.tex.last_layer);
+ assert(view->u.tex.last_layer < res->array_size);
+ }
+ }
+ else {
+ unsigned view_blocksize = util_format_get_blocksize(view->format);
+ addr = sp_tex->data;
+ /* probably don't really need to fill that out */
+ mip_offsets[0] = 0;
+ row_stride[0] = 0;
+ img_stride[0] = 0;
+
+ /* everything specified in number of elements here. */
+ width0 = view->u.buf.size / view_blocksize;
+ addr = (uint8_t *)addr + view->u.buf.offset;
+ assert(view->u.buf.offset + view->u.buf.size <= res->width0);
+ }
+ }
+ else {
+ /* display target texture/surface */
+ /*
+ * XXX: Where should this be unmapped?
+ */
+ struct softpipe_screen *screen = softpipe_screen(tex->screen);
+ struct sw_winsys *winsys = screen->winsys;
+ addr = winsys->displaytarget_map(winsys, sp_tex->dt,
+ PIPE_TRANSFER_READ);
+ row_stride[0] = sp_tex->stride[0];
+ img_stride[0] = sp_tex->img_stride[0];
+ mip_offsets[0] = 0;
+ assert(addr);
+ }
+ draw_set_mapped_texture(sp->draw,
+ shader_type,
+ i,
+ width0, tex->height0, num_layers,
+ first_level, last_level,
+ addr,
+ row_stride, img_stride, mip_offsets);