Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / drivers / llvmpipe / lp_texture.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Michel Dänzer <michel@tungstengraphics.com>
31 */
32
33 #include <stdio.h>
34
35 #include "pipe/p_context.h"
36 #include "pipe/p_defines.h"
37
38 #include "util/u_inlines.h"
39 #include "util/u_cpu_detect.h"
40 #include "util/u_format.h"
41 #include "util/u_math.h"
42 #include "util/u_memory.h"
43 #include "util/u_simple_list.h"
44 #include "util/u_transfer.h"
45
46 #include "lp_context.h"
47 #include "lp_flush.h"
48 #include "lp_screen.h"
49 #include "lp_tile_image.h"
50 #include "lp_texture.h"
51 #include "lp_setup.h"
52
53 #include "state_tracker/sw_winsys.h"
54
55
56 #ifdef DEBUG
57 static struct llvmpipe_resource resource_list;
58 #endif
59 static unsigned id_counter = 0;
60
61
62 static INLINE boolean
63 resource_is_texture(const struct pipe_resource *resource)
64 {
65 switch (resource->target) {
66 case PIPE_BUFFER:
67 return FALSE;
68 case PIPE_TEXTURE_1D:
69 case PIPE_TEXTURE_2D:
70 case PIPE_TEXTURE_RECT:
71 case PIPE_TEXTURE_3D:
72 case PIPE_TEXTURE_CUBE:
73 return TRUE;
74 default:
75 assert(0);
76 return FALSE;
77 }
78 }
79
80
81
82 /**
83 * Allocate storage for llvmpipe_texture::layout array.
84 * The number of elements is width_in_tiles * height_in_tiles.
85 */
86 static enum lp_texture_layout *
87 alloc_layout_array(unsigned num_slices, unsigned width, unsigned height)
88 {
89 const unsigned tx = align(width, TILE_SIZE) / TILE_SIZE;
90 const unsigned ty = align(height, TILE_SIZE) / TILE_SIZE;
91
92 assert(num_slices * tx * ty > 0);
93 assert(LP_TEX_LAYOUT_NONE == 0); /* calloc'ing LP_TEX_LAYOUT_NONE here */
94
95 return (enum lp_texture_layout *)
96 CALLOC(num_slices * tx * ty, sizeof(enum lp_texture_layout));
97 }
98
99
100
101 /**
102 * Conventional allocation path for non-display textures:
103 * Just compute row strides here. Storage is allocated on demand later.
104 */
105 static boolean
106 llvmpipe_texture_layout(struct llvmpipe_screen *screen,
107 struct llvmpipe_resource *lpr)
108 {
109 struct pipe_resource *pt = &lpr->base;
110 unsigned level;
111 unsigned width = pt->width0;
112 unsigned height = pt->height0;
113 unsigned depth = pt->depth0;
114
115 assert(LP_MAX_TEXTURE_2D_LEVELS <= LP_MAX_TEXTURE_LEVELS);
116 assert(LP_MAX_TEXTURE_3D_LEVELS <= LP_MAX_TEXTURE_LEVELS);
117
118 for (level = 0; level <= pt->last_level; level++) {
119
120 /* Row stride and image stride (for linear layout) */
121 {
122 unsigned alignment, nblocksx, nblocksy, block_size;
123
124 /* For non-compressed formats we need to align the texture size
125 * to the tile size to facilitate render-to-texture.
126 */
127 if (util_format_is_compressed(pt->format))
128 alignment = 1;
129 else
130 alignment = TILE_SIZE;
131
132 nblocksx = util_format_get_nblocksx(pt->format,
133 align(width, alignment));
134 nblocksy = util_format_get_nblocksy(pt->format,
135 align(height, alignment));
136 block_size = util_format_get_blocksize(pt->format);
137
138 lpr->row_stride[level] = align(nblocksx * block_size, 16);
139
140 lpr->img_stride[level] = lpr->row_stride[level] * nblocksy;
141 }
142
143 /* Size of the image in tiles (for tiled layout) */
144 {
145 const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE;
146 const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE;
147 lpr->tiles_per_row[level] = width_t;
148 lpr->tiles_per_image[level] = width_t * height_t;
149 }
150
151 /* Number of 3D image slices or cube faces */
152 {
153 unsigned num_slices;
154
155 if (lpr->base.target == PIPE_TEXTURE_CUBE)
156 num_slices = 6;
157 else if (lpr->base.target == PIPE_TEXTURE_3D)
158 num_slices = depth;
159 else
160 num_slices = 1;
161
162 lpr->num_slices_faces[level] = num_slices;
163
164 lpr->layout[level] = alloc_layout_array(num_slices, width, height);
165 }
166
167 /* Compute size of next mipmap level */
168 width = u_minify(width, 1);
169 height = u_minify(height, 1);
170 depth = u_minify(depth, 1);
171 }
172
173 return TRUE;
174 }
175
176
177
178 static boolean
179 llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen,
180 struct llvmpipe_resource *lpr)
181 {
182 struct sw_winsys *winsys = screen->winsys;
183
184 /* Round up the surface size to a multiple of the tile size to
185 * avoid tile clipping.
186 */
187 const unsigned width = align(lpr->base.width0, TILE_SIZE);
188 const unsigned height = align(lpr->base.height0, TILE_SIZE);
189 const unsigned width_t = width / TILE_SIZE;
190 const unsigned height_t = height / TILE_SIZE;
191
192 lpr->tiles_per_row[0] = width_t;
193 lpr->tiles_per_image[0] = width_t * height_t;
194 lpr->num_slices_faces[0] = 1;
195 lpr->img_stride[0] = 0;
196
197 lpr->layout[0] = alloc_layout_array(1, width, height);
198 //lpr->layout[0][0] = LP_TEX_LAYOUT_LINEAR;
199
200 lpr->dt = winsys->displaytarget_create(winsys,
201 lpr->base.bind,
202 lpr->base.format,
203 width, height,
204 16,
205 &lpr->row_stride[0] );
206
207 return lpr->dt != NULL;
208 }
209
210
211 static struct pipe_resource *
212 llvmpipe_resource_create(struct pipe_screen *_screen,
213 const struct pipe_resource *templat)
214 {
215 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
216 struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource);
217 if (!lpr)
218 return NULL;
219
220 lpr->base = *templat;
221 pipe_reference_init(&lpr->base.reference, 1);
222 lpr->base.screen = &screen->base;
223
224 /* assert(lpr->base.bind); */
225
226 if (resource_is_texture(&lpr->base)) {
227 if (lpr->base.bind & PIPE_BIND_DISPLAY_TARGET) {
228 /* displayable surface */
229 if (!llvmpipe_displaytarget_layout(screen, lpr))
230 goto fail;
231 assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE);
232 }
233 else {
234 /* texture map */
235 if (!llvmpipe_texture_layout(screen, lpr))
236 goto fail;
237 assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE);
238 }
239 assert(lpr->layout[0]);
240 }
241 else {
242 /* other data (vertex buffer, const buffer, etc) */
243 const enum pipe_format format = templat->format;
244 const uint w = templat->width0 / util_format_get_blockheight(format);
245 const uint h = templat->height0 / util_format_get_blockwidth(format);
246 const uint d = templat->depth0;
247 const uint bpp = util_format_get_blocksize(format);
248 const uint bytes = w * h * d * bpp;
249 lpr->data = align_malloc(bytes, 16);
250 if (!lpr->data)
251 goto fail;
252 }
253
254 lpr->id = id_counter++;
255
256 #ifdef DEBUG
257 insert_at_tail(&resource_list, lpr);
258 #endif
259
260 return &lpr->base;
261
262 fail:
263 FREE(lpr);
264 return NULL;
265 }
266
267
268 static void
269 llvmpipe_resource_destroy(struct pipe_screen *pscreen,
270 struct pipe_resource *pt)
271 {
272 struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
273 struct llvmpipe_resource *lpr = llvmpipe_resource(pt);
274
275 if (lpr->dt) {
276 /* display target */
277 struct sw_winsys *winsys = screen->winsys;
278 winsys->displaytarget_destroy(winsys, lpr->dt);
279
280 if (lpr->tiled[0].data) {
281 align_free(lpr->tiled[0].data);
282 lpr->tiled[0].data = NULL;
283 }
284
285 FREE(lpr->layout[0]);
286 }
287 else if (resource_is_texture(pt)) {
288 /* regular texture */
289 uint level;
290
291 /* free linear image data */
292 for (level = 0; level < Elements(lpr->linear); level++) {
293 if (lpr->linear[level].data) {
294 align_free(lpr->linear[level].data);
295 lpr->linear[level].data = NULL;
296 }
297 }
298
299 /* free tiled image data */
300 for (level = 0; level < Elements(lpr->tiled); level++) {
301 if (lpr->tiled[level].data) {
302 align_free(lpr->tiled[level].data);
303 lpr->tiled[level].data = NULL;
304 }
305 }
306
307 /* free layout flag arrays */
308 for (level = 0; level < Elements(lpr->tiled); level++) {
309 FREE(lpr->layout[level]);
310 lpr->layout[level] = NULL;
311 }
312 }
313 else if (!lpr->userBuffer) {
314 assert(lpr->data);
315 align_free(lpr->data);
316 }
317
318 #ifdef DEBUG
319 if (lpr->next)
320 remove_from_list(lpr);
321 #endif
322
323 FREE(lpr);
324 }
325
326
327 /**
328 * Map a resource for read/write.
329 */
330 void *
331 llvmpipe_resource_map(struct pipe_resource *resource,
332 unsigned face,
333 unsigned level,
334 unsigned zslice,
335 enum lp_texture_usage tex_usage,
336 enum lp_texture_layout layout)
337 {
338 struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
339 uint8_t *map;
340
341 assert(face < 6);
342 assert(level < LP_MAX_TEXTURE_LEVELS);
343
344 assert(tex_usage == LP_TEX_USAGE_READ ||
345 tex_usage == LP_TEX_USAGE_READ_WRITE ||
346 tex_usage == LP_TEX_USAGE_WRITE_ALL);
347
348 assert(layout == LP_TEX_LAYOUT_NONE ||
349 layout == LP_TEX_LAYOUT_TILED ||
350 layout == LP_TEX_LAYOUT_LINEAR);
351
352 if (lpr->dt) {
353 /* display target */
354 struct llvmpipe_screen *screen = llvmpipe_screen(resource->screen);
355 struct sw_winsys *winsys = screen->winsys;
356 unsigned dt_usage;
357 uint8_t *map2;
358
359 if (tex_usage == LP_TEX_USAGE_READ) {
360 dt_usage = PIPE_TRANSFER_READ;
361 }
362 else {
363 dt_usage = PIPE_TRANSFER_READ_WRITE;
364 }
365
366 assert(face == 0);
367 assert(level == 0);
368 assert(zslice == 0);
369
370 /* FIXME: keep map count? */
371 map = winsys->displaytarget_map(winsys, lpr->dt, dt_usage);
372
373 /* install this linear image in texture data structure */
374 lpr->linear[level].data = map;
375
376 /* make sure tiled data gets converted to linear data */
377 map2 = llvmpipe_get_texture_image(lpr, 0, 0, tex_usage, layout);
378 if (layout == LP_TEX_LAYOUT_LINEAR)
379 assert(map == map2);
380
381 return map2;
382 }
383 else if (resource_is_texture(resource)) {
384 /* regular texture */
385 if (resource->target != PIPE_TEXTURE_CUBE) {
386 assert(face == 0);
387 }
388 if (resource->target != PIPE_TEXTURE_3D) {
389 assert(zslice == 0);
390 }
391
392 map = llvmpipe_get_texture_image(lpr, face + zslice, level,
393 tex_usage, layout);
394 return map;
395 }
396 else {
397 return lpr->data;
398 }
399 }
400
401
402 /**
403 * Unmap a resource.
404 */
405 void
406 llvmpipe_resource_unmap(struct pipe_resource *resource,
407 unsigned face,
408 unsigned level,
409 unsigned zslice)
410 {
411 struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
412
413 if (lpr->dt) {
414 /* display target */
415 struct llvmpipe_screen *lp_screen = llvmpipe_screen(resource->screen);
416 struct sw_winsys *winsys = lp_screen->winsys;
417
418 assert(face == 0);
419 assert(level == 0);
420 assert(zslice == 0);
421
422 /* make sure linear image is up to date */
423 (void) llvmpipe_get_texture_image(lpr, face + zslice, level,
424 LP_TEX_USAGE_READ,
425 LP_TEX_LAYOUT_LINEAR);
426
427 winsys->displaytarget_unmap(winsys, lpr->dt);
428 }
429 }
430
431
432 void *
433 llvmpipe_resource_data(struct pipe_resource *resource)
434 {
435 struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
436
437 assert(!resource_is_texture(resource));
438
439 return lpr->data;
440 }
441
442
443 static struct pipe_resource *
444 llvmpipe_resource_from_handle(struct pipe_screen *screen,
445 const struct pipe_resource *template,
446 struct winsys_handle *whandle)
447 {
448 struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
449 struct llvmpipe_resource *lpr = CALLOC_STRUCT(llvmpipe_resource);
450 unsigned width, height, width_t, height_t;
451
452 /* XXX Seems like from_handled depth textures doesn't work that well */
453
454 if (!lpr)
455 return NULL;
456
457 lpr->base = *template;
458 pipe_reference_init(&lpr->base.reference, 1);
459 lpr->base.screen = screen;
460
461 width = align(lpr->base.width0, TILE_SIZE);
462 height = align(lpr->base.height0, TILE_SIZE);
463 width_t = width / TILE_SIZE;
464 height_t = height / TILE_SIZE;
465
466 /*
467 * Looks like unaligned displaytargets work just fine,
468 * at least sampler/render ones.
469 */
470 #if 0
471 assert(lpr->base.width0 == width);
472 assert(lpr->base.height0 == height);
473 #endif
474
475 lpr->tiles_per_row[0] = width_t;
476 lpr->tiles_per_image[0] = width_t * height_t;
477 lpr->num_slices_faces[0] = 1;
478 lpr->img_stride[0] = 0;
479
480 lpr->dt = winsys->displaytarget_from_handle(winsys,
481 template,
482 whandle,
483 &lpr->row_stride[0]);
484 if (!lpr->dt)
485 goto fail;
486
487 lpr->layout[0] = alloc_layout_array(1, lpr->base.width0, lpr->base.height0);
488
489 assert(lpr->layout[0]);
490 assert(lpr->layout[0][0] == LP_TEX_LAYOUT_NONE);
491
492 lpr->id = id_counter++;
493
494 #ifdef DEBUG
495 insert_at_tail(&resource_list, lpr);
496 #endif
497
498 return &lpr->base;
499
500 fail:
501 FREE(lpr);
502 return NULL;
503 }
504
505
506 static boolean
507 llvmpipe_resource_get_handle(struct pipe_screen *screen,
508 struct pipe_resource *pt,
509 struct winsys_handle *whandle)
510 {
511 struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys;
512 struct llvmpipe_resource *lpr = llvmpipe_resource(pt);
513
514 assert(lpr->dt);
515 if (!lpr->dt)
516 return FALSE;
517
518 return winsys->displaytarget_get_handle(winsys, lpr->dt, whandle);
519 }
520
521
522 static struct pipe_surface *
523 llvmpipe_get_tex_surface(struct pipe_screen *screen,
524 struct pipe_resource *pt,
525 unsigned face, unsigned level, unsigned zslice,
526 unsigned usage)
527 {
528 struct pipe_surface *ps;
529
530 assert(level <= pt->last_level);
531
532 ps = CALLOC_STRUCT(pipe_surface);
533 if (ps) {
534 pipe_reference_init(&ps->reference, 1);
535 pipe_resource_reference(&ps->texture, pt);
536 ps->format = pt->format;
537 ps->width = u_minify(pt->width0, level);
538 ps->height = u_minify(pt->height0, level);
539 ps->usage = usage;
540
541 ps->face = face;
542 ps->level = level;
543 ps->zslice = zslice;
544 }
545 return ps;
546 }
547
548
549 static void
550 llvmpipe_tex_surface_destroy(struct pipe_surface *surf)
551 {
552 /* Effectively do the texture_update work here - if texture images
553 * needed post-processing to put them into hardware layout, this is
554 * where it would happen. For llvmpipe, nothing to do.
555 */
556 assert(surf->texture);
557 pipe_resource_reference(&surf->texture, NULL);
558 FREE(surf);
559 }
560
561
562 static struct pipe_transfer *
563 llvmpipe_get_transfer(struct pipe_context *pipe,
564 struct pipe_resource *resource,
565 struct pipe_subresource sr,
566 unsigned usage,
567 const struct pipe_box *box)
568 {
569 struct llvmpipe_resource *lprex = llvmpipe_resource(resource);
570 struct llvmpipe_transfer *lpr;
571
572 assert(resource);
573 assert(sr.level <= resource->last_level);
574
575 /*
576 * Transfers, like other pipe operations, must happen in order, so flush the
577 * context if necessary.
578 */
579 if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
580 boolean read_only = !(usage & PIPE_TRANSFER_WRITE);
581 boolean do_not_block = !!(usage & PIPE_TRANSFER_DONTBLOCK);
582 if (!llvmpipe_flush_resource(pipe, resource,
583 sr.face, sr.level,
584 0, /* flush_flags */
585 read_only,
586 TRUE, /* cpu_access */
587 do_not_block,
588 "transfer dest")) {
589 /*
590 * It would have blocked, but state tracker requested no to.
591 */
592 assert(do_not_block);
593 return NULL;
594 }
595 }
596
597 lpr = CALLOC_STRUCT(llvmpipe_transfer);
598 if (lpr) {
599 struct pipe_transfer *pt = &lpr->base;
600 pipe_resource_reference(&pt->resource, resource);
601 pt->box = *box;
602 pt->sr = sr;
603 pt->stride = lprex->row_stride[sr.level];
604 pt->slice_stride = lprex->img_stride[sr.level];
605 pt->usage = usage;
606
607 return pt;
608 }
609 return NULL;
610 }
611
612
613 static void
614 llvmpipe_transfer_destroy(struct pipe_context *pipe,
615 struct pipe_transfer *transfer)
616 {
617 /* Effectively do the texture_update work here - if texture images
618 * needed post-processing to put them into hardware layout, this is
619 * where it would happen. For llvmpipe, nothing to do.
620 */
621 assert (transfer->resource);
622 pipe_resource_reference(&transfer->resource, NULL);
623 FREE(transfer);
624 }
625
626
627 static void *
628 llvmpipe_transfer_map( struct pipe_context *pipe,
629 struct pipe_transfer *transfer )
630 {
631 struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
632 ubyte *map;
633 struct llvmpipe_resource *lpr;
634 enum pipe_format format;
635 enum lp_texture_usage tex_usage;
636 const char *mode;
637
638 assert(transfer->sr.face < 6);
639 assert(transfer->sr.level < LP_MAX_TEXTURE_LEVELS);
640
641 /*
642 printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n",
643 transfer->x, transfer->y, transfer->width, transfer->height,
644 transfer->texture->width0,
645 transfer->texture->height0,
646 transfer->usage);
647 */
648
649 if (transfer->usage == PIPE_TRANSFER_READ) {
650 tex_usage = LP_TEX_USAGE_READ;
651 mode = "read";
652 }
653 else {
654 tex_usage = LP_TEX_USAGE_READ_WRITE;
655 mode = "read/write";
656 }
657
658 if (0) {
659 struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource);
660 printf("transfer map tex %u mode %s\n", lpr->id, mode);
661 }
662
663
664 assert(transfer->resource);
665 lpr = llvmpipe_resource(transfer->resource);
666 format = lpr->base.format;
667
668 map = llvmpipe_resource_map(transfer->resource,
669 transfer->sr.face,
670 transfer->sr.level,
671 transfer->box.z,
672 tex_usage, LP_TEX_LAYOUT_LINEAR);
673
674
675 /* May want to do different things here depending on read/write nature
676 * of the map:
677 */
678 if (transfer->usage & PIPE_TRANSFER_WRITE) {
679 /* Do something to notify sharing contexts of a texture change.
680 */
681 screen->timestamp++;
682 }
683
684 map +=
685 transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
686 transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
687
688 return map;
689 }
690
691
692 static void
693 llvmpipe_transfer_unmap(struct pipe_context *pipe,
694 struct pipe_transfer *transfer)
695 {
696 assert(transfer->resource);
697
698 llvmpipe_resource_unmap(transfer->resource,
699 transfer->sr.face,
700 transfer->sr.level,
701 transfer->box.z);
702 }
703
704 static unsigned int
705 llvmpipe_is_resource_referenced( struct pipe_context *pipe,
706 struct pipe_resource *presource,
707 unsigned face, unsigned level)
708 {
709 struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
710
711 if (presource->target == PIPE_BUFFER)
712 return PIPE_UNREFERENCED;
713
714 return lp_setup_is_resource_referenced(llvmpipe->setup, presource);
715 }
716
717
718
719 /**
720 * Create buffer which wraps user-space data.
721 */
722 static struct pipe_resource *
723 llvmpipe_user_buffer_create(struct pipe_screen *screen,
724 void *ptr,
725 unsigned bytes,
726 unsigned bind_flags)
727 {
728 struct llvmpipe_resource *buffer;
729
730 buffer = CALLOC_STRUCT(llvmpipe_resource);
731 if(!buffer)
732 return NULL;
733
734 pipe_reference_init(&buffer->base.reference, 1);
735 buffer->base.screen = screen;
736 buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
737 buffer->base.bind = bind_flags;
738 buffer->base.usage = PIPE_USAGE_IMMUTABLE;
739 buffer->base.flags = 0;
740 buffer->base.width0 = bytes;
741 buffer->base.height0 = 1;
742 buffer->base.depth0 = 1;
743 buffer->userBuffer = TRUE;
744 buffer->data = ptr;
745
746 return &buffer->base;
747 }
748
749
750 /**
751 * Compute size (in bytes) need to store a texture image / mipmap level,
752 * for just one cube face or one 3D texture slice
753 */
754 static unsigned
755 tex_image_face_size(const struct llvmpipe_resource *lpr, unsigned level,
756 enum lp_texture_layout layout)
757 {
758 const unsigned width = u_minify(lpr->base.width0, level);
759 const unsigned height = u_minify(lpr->base.height0, level);
760
761 assert(layout == LP_TEX_LAYOUT_TILED ||
762 layout == LP_TEX_LAYOUT_LINEAR);
763
764 if (layout == LP_TEX_LAYOUT_TILED) {
765 /* for tiled layout, force a 32bpp format */
766 const enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM;
767 const unsigned block_size = util_format_get_blocksize(format);
768 const unsigned nblocksy =
769 util_format_get_nblocksy(format, align(height, TILE_SIZE));
770 const unsigned nblocksx =
771 util_format_get_nblocksx(format, align(width, TILE_SIZE));
772 const unsigned buffer_size = block_size * nblocksy * nblocksx;
773 return buffer_size;
774 }
775 else {
776 /* we already computed this */
777 return lpr->img_stride[level];
778 }
779 }
780
781
782 /**
783 * Compute size (in bytes) need to store a texture image / mipmap level,
784 * including all cube faces or 3D image slices
785 */
786 static unsigned
787 tex_image_size(const struct llvmpipe_resource *lpr, unsigned level,
788 enum lp_texture_layout layout)
789 {
790 const unsigned buf_size = tex_image_face_size(lpr, level, layout);
791 return buf_size * lpr->num_slices_faces[level];
792 }
793
794
795 /**
796 * This function encapsulates some complicated logic for determining
797 * how to convert a tile of image data from linear layout to tiled
798 * layout, or vice versa.
799 * \param cur_layout the current tile layout
800 * \param target_layout the desired tile layout
801 * \param usage how the tile will be accessed (R/W vs. read-only, etc)
802 * \param new_layout_return returns the new layout mode
803 * \param convert_return returns TRUE if image conversion is needed
804 */
805 static void
806 layout_logic(enum lp_texture_layout cur_layout,
807 enum lp_texture_layout target_layout,
808 enum lp_texture_usage usage,
809 enum lp_texture_layout *new_layout_return,
810 boolean *convert)
811 {
812 enum lp_texture_layout other_layout, new_layout;
813
814 *convert = FALSE;
815
816 new_layout = 99; /* debug check */
817
818 if (target_layout == LP_TEX_LAYOUT_LINEAR) {
819 other_layout = LP_TEX_LAYOUT_TILED;
820 }
821 else {
822 assert(target_layout == LP_TEX_LAYOUT_TILED);
823 other_layout = LP_TEX_LAYOUT_LINEAR;
824 }
825
826 new_layout = target_layout; /* may get changed below */
827
828 if (cur_layout == LP_TEX_LAYOUT_BOTH) {
829 if (usage == LP_TEX_USAGE_READ) {
830 new_layout = LP_TEX_LAYOUT_BOTH;
831 }
832 }
833 else if (cur_layout == other_layout) {
834 if (usage != LP_TEX_USAGE_WRITE_ALL) {
835 /* need to convert tiled data to linear or vice versa */
836 *convert = TRUE;
837
838 if (usage == LP_TEX_USAGE_READ)
839 new_layout = LP_TEX_LAYOUT_BOTH;
840 }
841 }
842 else {
843 assert(cur_layout == LP_TEX_LAYOUT_NONE ||
844 cur_layout == target_layout);
845 }
846
847 assert(new_layout == LP_TEX_LAYOUT_BOTH ||
848 new_layout == target_layout);
849
850 *new_layout_return = new_layout;
851 }
852
853
854 /**
855 * Return pointer to a 2D texture image/face/slice.
856 * No tiled/linear conversion is done.
857 */
858 ubyte *
859 llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
860 unsigned face_slice, unsigned level,
861 enum lp_texture_layout layout)
862 {
863 struct llvmpipe_texture_image *img;
864 unsigned offset;
865
866 if (layout == LP_TEX_LAYOUT_LINEAR) {
867 img = &lpr->linear[level];
868 }
869 else {
870 assert (layout == LP_TEX_LAYOUT_TILED);
871 img = &lpr->tiled[level];
872 }
873
874 if (face_slice > 0)
875 offset = face_slice * tex_image_face_size(lpr, level, layout);
876 else
877 offset = 0;
878
879 return (ubyte *) img->data + offset;
880 }
881
882
883 static INLINE enum lp_texture_layout
884 llvmpipe_get_texture_tile_layout(const struct llvmpipe_resource *lpr,
885 unsigned face_slice, unsigned level,
886 unsigned x, unsigned y)
887 {
888 uint i;
889 assert(resource_is_texture(&lpr->base));
890 assert(x < lpr->tiles_per_row[level]);
891 i = face_slice * lpr->tiles_per_image[level]
892 + y * lpr->tiles_per_row[level] + x;
893 return lpr->layout[level][i];
894 }
895
896
897 static INLINE void
898 llvmpipe_set_texture_tile_layout(struct llvmpipe_resource *lpr,
899 unsigned face_slice, unsigned level,
900 unsigned x, unsigned y,
901 enum lp_texture_layout layout)
902 {
903 uint i;
904 assert(resource_is_texture(&lpr->base));
905 assert(x < lpr->tiles_per_row[level]);
906 i = face_slice * lpr->tiles_per_image[level]
907 + y * lpr->tiles_per_row[level] + x;
908 lpr->layout[level][i] = layout;
909 }
910
911
912 /**
913 * Set the layout mode for all tiles in a particular image.
914 */
915 static INLINE void
916 llvmpipe_set_texture_image_layout(struct llvmpipe_resource *lpr,
917 unsigned face_slice, unsigned level,
918 unsigned width_t, unsigned height_t,
919 enum lp_texture_layout layout)
920 {
921 const unsigned start = face_slice * lpr->tiles_per_image[level];
922 unsigned i;
923
924 for (i = 0; i < width_t * height_t; i++) {
925 lpr->layout[level][start + i] = layout;
926 }
927 }
928
929
930 /**
931 * Allocate storage for a linear or tile texture image (all cube
932 * faces and all 3D slices.
933 */
934 static void
935 alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
936 enum lp_texture_layout layout)
937 {
938 uint alignment = MAX2(16, util_cpu_caps.cacheline);
939
940 if (lpr->dt)
941 assert(level == 0);
942
943 if (layout == LP_TEX_LAYOUT_TILED) {
944 /* tiled data is stored in regular memory */
945 uint buffer_size = tex_image_size(lpr, level, layout);
946 lpr->tiled[level].data = align_malloc(buffer_size, alignment);
947 }
948 else {
949 assert(layout == LP_TEX_LAYOUT_LINEAR);
950 if (lpr->dt) {
951 /* we get the linear memory from the winsys */
952 struct llvmpipe_screen *screen = llvmpipe_screen(lpr->base.screen);
953 struct sw_winsys *winsys = screen->winsys;
954
955 lpr->linear[0].data =
956 winsys->displaytarget_map(winsys, lpr->dt,
957 PIPE_TRANSFER_READ_WRITE);
958 }
959 else {
960 /* not a display target - allocate regular memory */
961 uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
962 lpr->linear[level].data = align_malloc(buffer_size, alignment);
963 }
964 }
965 }
966
967
968
969 /**
970 * Return pointer to texture image data (either linear or tiled layout)
971 * for a particular cube face or 3D texture slice.
972 *
973 * \param face_slice the cube face or 3D slice of interest
974 * \param usage one of LP_TEX_USAGE_READ/WRITE_ALL/READ_WRITE
975 * \param layout either LP_TEX_LAYOUT_LINEAR or _TILED or _NONE
976 */
977 void *
978 llvmpipe_get_texture_image(struct llvmpipe_resource *lpr,
979 unsigned face_slice, unsigned level,
980 enum lp_texture_usage usage,
981 enum lp_texture_layout layout)
982 {
983 /*
984 * 'target' refers to the image which we're retrieving (either in
985 * tiled or linear layout).
986 * 'other' refers to the same image but in the other layout. (it may
987 * or may not exist.
988 */
989 struct llvmpipe_texture_image *target_img;
990 struct llvmpipe_texture_image *other_img;
991 void *target_data;
992 void *other_data;
993 const unsigned width = u_minify(lpr->base.width0, level);
994 const unsigned height = u_minify(lpr->base.height0, level);
995 const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE;
996 const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE;
997 enum lp_texture_layout other_layout;
998 boolean only_allocate;
999
1000 assert(layout == LP_TEX_LAYOUT_NONE ||
1001 layout == LP_TEX_LAYOUT_TILED ||
1002 layout == LP_TEX_LAYOUT_LINEAR);
1003
1004 assert(usage == LP_TEX_USAGE_READ ||
1005 usage == LP_TEX_USAGE_READ_WRITE ||
1006 usage == LP_TEX_USAGE_WRITE_ALL);
1007
1008 /* check for the special case of layout == LP_TEX_LAYOUT_NONE */
1009 if (layout == LP_TEX_LAYOUT_NONE) {
1010 only_allocate = TRUE;
1011 layout = LP_TEX_LAYOUT_TILED;
1012 }
1013 else {
1014 only_allocate = FALSE;
1015 }
1016
1017 if (lpr->dt) {
1018 assert(lpr->linear[level].data);
1019 }
1020
1021 /* which is target? which is other? */
1022 if (layout == LP_TEX_LAYOUT_LINEAR) {
1023 target_img = &lpr->linear[level];
1024 other_img = &lpr->tiled[level];
1025 other_layout = LP_TEX_LAYOUT_TILED;
1026 }
1027 else {
1028 target_img = &lpr->tiled[level];
1029 other_img = &lpr->linear[level];
1030 other_layout = LP_TEX_LAYOUT_LINEAR;
1031 }
1032
1033 target_data = target_img->data;
1034 other_data = other_img->data;
1035
1036 if (!target_data) {
1037 /* allocate memory for the target image now */
1038 alloc_image_data(lpr, level, layout);
1039 target_data = target_img->data;
1040 }
1041
1042 if (face_slice > 0) {
1043 unsigned target_offset, other_offset;
1044
1045 target_offset = face_slice * tex_image_face_size(lpr, level, layout);
1046 other_offset = face_slice * tex_image_face_size(lpr, level, other_layout);
1047 if (target_data) {
1048 target_data = (uint8_t *) target_data + target_offset;
1049 }
1050 if (other_data) {
1051 other_data = (uint8_t *) other_data + other_offset;
1052 }
1053 }
1054
1055 if (only_allocate) {
1056 /* Just allocating tiled memory. Don't initialize it from the
1057 * linear data if it exists.
1058 */
1059 return target_data;
1060 }
1061
1062 if (other_data) {
1063 /* may need to convert other data to the requested layout */
1064 enum lp_texture_layout new_layout;
1065 unsigned x, y;
1066
1067 /* loop over all image tiles, doing layout conversion where needed */
1068 for (y = 0; y < height_t; y++) {
1069 for (x = 0; x < width_t; x++) {
1070 enum lp_texture_layout cur_layout =
1071 llvmpipe_get_texture_tile_layout(lpr, face_slice, level, x, y);
1072 boolean convert;
1073
1074 layout_logic(cur_layout, layout, usage, &new_layout, &convert);
1075
1076 if (convert && other_data && target_data) {
1077 if (layout == LP_TEX_LAYOUT_TILED) {
1078 lp_linear_to_tiled(other_data, target_data,
1079 x * TILE_SIZE, y * TILE_SIZE,
1080 TILE_SIZE, TILE_SIZE,
1081 lpr->base.format,
1082 lpr->row_stride[level],
1083 lpr->tiles_per_row[level]);
1084 }
1085 else {
1086 assert(layout == LP_TEX_LAYOUT_LINEAR);
1087 lp_tiled_to_linear(other_data, target_data,
1088 x * TILE_SIZE, y * TILE_SIZE,
1089 TILE_SIZE, TILE_SIZE,
1090 lpr->base.format,
1091 lpr->row_stride[level],
1092 lpr->tiles_per_row[level]);
1093 }
1094 }
1095
1096 if (new_layout != cur_layout)
1097 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, x, y,
1098 new_layout);
1099 }
1100 }
1101 }
1102 else {
1103 /* no other data */
1104 llvmpipe_set_texture_image_layout(lpr, face_slice, level,
1105 width_t, height_t, layout);
1106 }
1107
1108 return target_data;
1109 }
1110
1111
1112 /**
1113 * Return pointer to start of a texture image (1D, 2D, 3D, CUBE).
1114 * All cube faces and 3D slices will be converted to the requested
1115 * layout if needed.
1116 * This is typically used when we're about to sample from a texture.
1117 */
1118 void *
1119 llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
1120 unsigned level,
1121 enum lp_texture_usage usage,
1122 enum lp_texture_layout layout)
1123 {
1124 const int slices = lpr->num_slices_faces[level];
1125 int slice;
1126 void *map = NULL;
1127
1128 assert(slices > 0);
1129
1130 for (slice = slices - 1; slice >= 0; slice--) {
1131 map = llvmpipe_get_texture_image(lpr, slice, level, usage, layout);
1132 }
1133
1134 return map;
1135 }
1136
1137
1138 /**
1139 * Get pointer to a linear image (not the tile!) where the tile at (x,y)
1140 * is known to be in linear layout.
1141 * Conversion from tiled to linear will be done if necessary.
1142 * \return pointer to start of image/face (not the tile)
1143 */
1144 ubyte *
1145 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
1146 unsigned face_slice, unsigned level,
1147 enum lp_texture_usage usage,
1148 unsigned x, unsigned y)
1149 {
1150 struct llvmpipe_texture_image *linear_img = &lpr->linear[level];
1151 enum lp_texture_layout cur_layout, new_layout;
1152 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1153 boolean convert;
1154 uint8_t *tiled_image, *linear_image;
1155
1156 assert(resource_is_texture(&lpr->base));
1157 assert(x % TILE_SIZE == 0);
1158 assert(y % TILE_SIZE == 0);
1159
1160 if (!linear_img->data) {
1161 /* allocate memory for the linear image now */
1162 alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR);
1163 }
1164
1165 /* compute address of the slice/face of the image that contains the tile */
1166 tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1167 LP_TEX_LAYOUT_TILED);
1168 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1169 LP_TEX_LAYOUT_LINEAR);
1170
1171 /* get current tile layout and determine if data conversion is needed */
1172 cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
1173
1174 layout_logic(cur_layout, LP_TEX_LAYOUT_LINEAR, usage,
1175 &new_layout, &convert);
1176
1177 if (convert && tiled_image && linear_image) {
1178 lp_tiled_to_linear(tiled_image, linear_image,
1179 x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
1180 lpr->row_stride[level],
1181 lpr->tiles_per_row[level]);
1182 }
1183
1184 if (new_layout != cur_layout)
1185 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);
1186
1187 return linear_image;
1188 }
1189
1190
1191 /**
1192 * Get pointer to tiled data for rendering.
1193 * \return pointer to the tiled data at the given tile position
1194 */
1195 ubyte *
1196 llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr,
1197 unsigned face_slice, unsigned level,
1198 enum lp_texture_usage usage,
1199 unsigned x, unsigned y)
1200 {
1201 struct llvmpipe_texture_image *tiled_img = &lpr->tiled[level];
1202 enum lp_texture_layout cur_layout, new_layout;
1203 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1204 boolean convert;
1205 uint8_t *tiled_image, *linear_image;
1206 unsigned tile_offset;
1207
1208 assert(x % TILE_SIZE == 0);
1209 assert(y % TILE_SIZE == 0);
1210
1211 if (!tiled_img->data) {
1212 /* allocate memory for the tiled image now */
1213 alloc_image_data(lpr, level, LP_TEX_LAYOUT_TILED);
1214 }
1215
1216 /* compute address of the slice/face of the image that contains the tile */
1217 tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1218 LP_TEX_LAYOUT_TILED);
1219 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1220 LP_TEX_LAYOUT_LINEAR);
1221
1222 /* get current tile layout and see if we need to convert the data */
1223 cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
1224
1225 layout_logic(cur_layout, LP_TEX_LAYOUT_TILED, usage, &new_layout, &convert);
1226 if (convert && linear_image && tiled_image) {
1227 lp_linear_to_tiled(linear_image, tiled_image,
1228 x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
1229 lpr->row_stride[level],
1230 lpr->tiles_per_row[level]);
1231 }
1232
1233 if (!tiled_image)
1234 return NULL;
1235
1236 if (new_layout != cur_layout)
1237 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);
1238
1239 /* compute, return address of the 64x64 tile */
1240 tile_offset = (ty * lpr->tiles_per_row[level] + tx)
1241 * TILE_SIZE * TILE_SIZE * 4;
1242
1243 return (ubyte *) tiled_image + tile_offset;
1244 }
1245
1246
1247 /**
1248 * Get pointer to tiled data for rendering.
1249 * \return pointer to the tiled data at the given tile position
1250 */
1251 void
1252 llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource *lpr,
1253 unsigned face_slice, unsigned level,
1254 unsigned x, unsigned y,
1255 uint8_t *tile)
1256 {
1257 struct llvmpipe_texture_image *linear_img = &lpr->linear[level];
1258 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1259 uint8_t *linear_image;
1260
1261 assert(x % TILE_SIZE == 0);
1262 assert(y % TILE_SIZE == 0);
1263
1264 if (!linear_img->data) {
1265 /* allocate memory for the linear image now */
1266 alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR);
1267 }
1268
1269 /* compute address of the slice/face of the image that contains the tile */
1270 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1271 LP_TEX_LAYOUT_LINEAR);
1272
1273 {
1274 uint ii = x, jj = y;
1275 uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE;
1276 uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4;
1277
1278 /* Note that lp_tiled_to_linear expects the tile parameter to
1279 * point at the first tile in a whole-image sized array. In
1280 * this code, we have only a single tile and have to do some
1281 * pointer arithmetic to figure out where the "image" would have
1282 * started.
1283 */
1284 lp_tiled_to_linear(tile - byte_offset, linear_image,
1285 x, y, TILE_SIZE, TILE_SIZE,
1286 lpr->base.format,
1287 lpr->row_stride[level],
1288 1); /* tiles per row */
1289 }
1290
1291 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty,
1292 LP_TEX_LAYOUT_LINEAR);
1293 }
1294
1295
1296 /**
1297 * Get pointer to tiled data for rendering.
1298 * \return pointer to the tiled data at the given tile position
1299 */
1300 void
1301 llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource *lpr,
1302 unsigned face_slice, unsigned level,
1303 unsigned x, unsigned y,
1304 uint8_t *tile)
1305 {
1306 uint8_t *linear_image;
1307
1308 assert(x % TILE_SIZE == 0);
1309 assert(y % TILE_SIZE == 0);
1310
1311 /* compute address of the slice/face of the image that contains the tile */
1312 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1313 LP_TEX_LAYOUT_LINEAR);
1314
1315 if (linear_image) {
1316 uint ii = x, jj = y;
1317 uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE;
1318 uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4;
1319
1320 /* Note that lp_linear_to_tiled expects the tile parameter to
1321 * point at the first tile in a whole-image sized array. In
1322 * this code, we have only a single tile and have to do some
1323 * pointer arithmetic to figure out where the "image" would have
1324 * started.
1325 */
1326 lp_linear_to_tiled(linear_image, tile - byte_offset,
1327 x, y, TILE_SIZE, TILE_SIZE,
1328 lpr->base.format,
1329 lpr->row_stride[level],
1330 1); /* tiles per row */
1331 }
1332 }
1333
1334
1335 /**
1336 * Return size of resource in bytes
1337 */
1338 unsigned
1339 llvmpipe_resource_size(const struct pipe_resource *resource)
1340 {
1341 const struct llvmpipe_resource *lpr = llvmpipe_resource_const(resource);
1342 unsigned lvl, size = 0;
1343
1344 for (lvl = 0; lvl <= lpr->base.last_level; lvl++) {
1345 if (lpr->linear[lvl].data)
1346 size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_LINEAR);
1347
1348 if (lpr->tiled[lvl].data)
1349 size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_TILED);
1350 }
1351
1352 return size;
1353 }
1354
1355
1356 #ifdef DEBUG
1357 void
1358 llvmpipe_print_resources(void)
1359 {
1360 struct llvmpipe_resource *lpr;
1361 unsigned n = 0, total = 0;
1362
1363 debug_printf("LLVMPIPE: current resources:\n");
1364 foreach(lpr, &resource_list) {
1365 unsigned size = llvmpipe_resource_size(&lpr->base);
1366 debug_printf("resource %u at %p, size %ux%ux%u: %u bytes, refcount %u\n",
1367 lpr->id, (void *) lpr,
1368 lpr->base.width0, lpr->base.height0, lpr->base.depth0,
1369 size, lpr->base.reference.count);
1370 total += size;
1371 n++;
1372 }
1373 debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total);
1374 }
1375 #endif
1376
1377
1378 void
1379 llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
1380 {
1381 #ifdef DEBUG
1382 /* init linked list for tracking resources */
1383 {
1384 static boolean first_call = TRUE;
1385 if (first_call) {
1386 memset(&resource_list, 0, sizeof(resource_list));
1387 make_empty_list(&resource_list);
1388 first_call = FALSE;
1389 }
1390 }
1391 #endif
1392
1393 screen->resource_create = llvmpipe_resource_create;
1394 screen->resource_destroy = llvmpipe_resource_destroy;
1395 screen->resource_from_handle = llvmpipe_resource_from_handle;
1396 screen->resource_get_handle = llvmpipe_resource_get_handle;
1397 screen->user_buffer_create = llvmpipe_user_buffer_create;
1398
1399 screen->get_tex_surface = llvmpipe_get_tex_surface;
1400 screen->tex_surface_destroy = llvmpipe_tex_surface_destroy;
1401 }
1402
1403
1404 void
1405 llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
1406 {
1407 pipe->get_transfer = llvmpipe_get_transfer;
1408 pipe->transfer_destroy = llvmpipe_transfer_destroy;
1409 pipe->transfer_map = llvmpipe_transfer_map;
1410 pipe->transfer_unmap = llvmpipe_transfer_unmap;
1411 pipe->is_resource_referenced = llvmpipe_is_resource_referenced;
1412
1413 pipe->transfer_flush_region = u_default_transfer_flush_region;
1414 pipe->transfer_inline_write = u_default_transfer_inline_write;
1415 }