gallium: make all checks for PIPE_TEXTURE_2D check for PIPE_TEXTURE_RECT too
[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 /*
589 * It would have blocked, but state tracker requested no to.
590 */
591 assert(do_not_block);
592 return NULL;
593 }
594 }
595
596 lpr = CALLOC_STRUCT(llvmpipe_transfer);
597 if (lpr) {
598 struct pipe_transfer *pt = &lpr->base;
599 pipe_resource_reference(&pt->resource, resource);
600 pt->box = *box;
601 pt->sr = sr;
602 pt->stride = lprex->row_stride[sr.level];
603 pt->slice_stride = lprex->img_stride[sr.level];
604 pt->usage = usage;
605
606 return pt;
607 }
608 return NULL;
609 }
610
611
612 static void
613 llvmpipe_transfer_destroy(struct pipe_context *pipe,
614 struct pipe_transfer *transfer)
615 {
616 /* Effectively do the texture_update work here - if texture images
617 * needed post-processing to put them into hardware layout, this is
618 * where it would happen. For llvmpipe, nothing to do.
619 */
620 assert (transfer->resource);
621 pipe_resource_reference(&transfer->resource, NULL);
622 FREE(transfer);
623 }
624
625
626 static void *
627 llvmpipe_transfer_map( struct pipe_context *pipe,
628 struct pipe_transfer *transfer )
629 {
630 struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
631 ubyte *map;
632 struct llvmpipe_resource *lpr;
633 enum pipe_format format;
634 enum lp_texture_usage tex_usage;
635 const char *mode;
636
637 assert(transfer->sr.face < 6);
638 assert(transfer->sr.level < LP_MAX_TEXTURE_LEVELS);
639
640 /*
641 printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n",
642 transfer->x, transfer->y, transfer->width, transfer->height,
643 transfer->texture->width0,
644 transfer->texture->height0,
645 transfer->usage);
646 */
647
648 if (transfer->usage == PIPE_TRANSFER_READ) {
649 tex_usage = LP_TEX_USAGE_READ;
650 mode = "read";
651 }
652 else {
653 tex_usage = LP_TEX_USAGE_READ_WRITE;
654 mode = "read/write";
655 }
656
657 if (0) {
658 struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource);
659 printf("transfer map tex %u mode %s\n", lpr->id, mode);
660 }
661
662
663 assert(transfer->resource);
664 lpr = llvmpipe_resource(transfer->resource);
665 format = lpr->base.format;
666
667 map = llvmpipe_resource_map(transfer->resource,
668 transfer->sr.face,
669 transfer->sr.level,
670 transfer->box.z,
671 tex_usage, LP_TEX_LAYOUT_LINEAR);
672
673
674 /* May want to do different things here depending on read/write nature
675 * of the map:
676 */
677 if (transfer->usage & PIPE_TRANSFER_WRITE) {
678 /* Do something to notify sharing contexts of a texture change.
679 */
680 screen->timestamp++;
681 }
682
683 map +=
684 transfer->box.y / util_format_get_blockheight(format) * transfer->stride +
685 transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
686
687 return map;
688 }
689
690
691 static void
692 llvmpipe_transfer_unmap(struct pipe_context *pipe,
693 struct pipe_transfer *transfer)
694 {
695 assert(transfer->resource);
696
697 llvmpipe_resource_unmap(transfer->resource,
698 transfer->sr.face,
699 transfer->sr.level,
700 transfer->box.z);
701 }
702
703 static unsigned int
704 llvmpipe_is_resource_referenced( struct pipe_context *pipe,
705 struct pipe_resource *presource,
706 unsigned face, unsigned level)
707 {
708 struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
709
710 if (presource->target == PIPE_BUFFER)
711 return PIPE_UNREFERENCED;
712
713 return lp_setup_is_resource_referenced(llvmpipe->setup, presource);
714 }
715
716
717
718 /**
719 * Create buffer which wraps user-space data.
720 */
721 static struct pipe_resource *
722 llvmpipe_user_buffer_create(struct pipe_screen *screen,
723 void *ptr,
724 unsigned bytes,
725 unsigned bind_flags)
726 {
727 struct llvmpipe_resource *buffer;
728
729 buffer = CALLOC_STRUCT(llvmpipe_resource);
730 if(!buffer)
731 return NULL;
732
733 pipe_reference_init(&buffer->base.reference, 1);
734 buffer->base.screen = screen;
735 buffer->base.format = PIPE_FORMAT_R8_UNORM; /* ?? */
736 buffer->base.bind = bind_flags;
737 buffer->base.usage = PIPE_USAGE_IMMUTABLE;
738 buffer->base.flags = 0;
739 buffer->base.width0 = bytes;
740 buffer->base.height0 = 1;
741 buffer->base.depth0 = 1;
742 buffer->userBuffer = TRUE;
743 buffer->data = ptr;
744
745 return &buffer->base;
746 }
747
748
749 /**
750 * Compute size (in bytes) need to store a texture image / mipmap level,
751 * for just one cube face or one 3D texture slice
752 */
753 static unsigned
754 tex_image_face_size(const struct llvmpipe_resource *lpr, unsigned level,
755 enum lp_texture_layout layout)
756 {
757 const unsigned width = u_minify(lpr->base.width0, level);
758 const unsigned height = u_minify(lpr->base.height0, level);
759
760 assert(layout == LP_TEX_LAYOUT_TILED ||
761 layout == LP_TEX_LAYOUT_LINEAR);
762
763 if (layout == LP_TEX_LAYOUT_TILED) {
764 /* for tiled layout, force a 32bpp format */
765 const enum pipe_format format = PIPE_FORMAT_B8G8R8A8_UNORM;
766 const unsigned block_size = util_format_get_blocksize(format);
767 const unsigned nblocksy =
768 util_format_get_nblocksy(format, align(height, TILE_SIZE));
769 const unsigned nblocksx =
770 util_format_get_nblocksx(format, align(width, TILE_SIZE));
771 const unsigned buffer_size = block_size * nblocksy * nblocksx;
772 return buffer_size;
773 }
774 else {
775 /* we already computed this */
776 return lpr->img_stride[level];
777 }
778 }
779
780
781 /**
782 * Compute size (in bytes) need to store a texture image / mipmap level,
783 * including all cube faces or 3D image slices
784 */
785 static unsigned
786 tex_image_size(const struct llvmpipe_resource *lpr, unsigned level,
787 enum lp_texture_layout layout)
788 {
789 const unsigned buf_size = tex_image_face_size(lpr, level, layout);
790 return buf_size * lpr->num_slices_faces[level];
791 }
792
793
794 /**
795 * This function encapsulates some complicated logic for determining
796 * how to convert a tile of image data from linear layout to tiled
797 * layout, or vice versa.
798 * \param cur_layout the current tile layout
799 * \param target_layout the desired tile layout
800 * \param usage how the tile will be accessed (R/W vs. read-only, etc)
801 * \param new_layout_return returns the new layout mode
802 * \param convert_return returns TRUE if image conversion is needed
803 */
804 static void
805 layout_logic(enum lp_texture_layout cur_layout,
806 enum lp_texture_layout target_layout,
807 enum lp_texture_usage usage,
808 enum lp_texture_layout *new_layout_return,
809 boolean *convert)
810 {
811 enum lp_texture_layout other_layout, new_layout;
812
813 *convert = FALSE;
814
815 new_layout = 99; /* debug check */
816
817 if (target_layout == LP_TEX_LAYOUT_LINEAR) {
818 other_layout = LP_TEX_LAYOUT_TILED;
819 }
820 else {
821 assert(target_layout == LP_TEX_LAYOUT_TILED);
822 other_layout = LP_TEX_LAYOUT_LINEAR;
823 }
824
825 new_layout = target_layout; /* may get changed below */
826
827 if (cur_layout == LP_TEX_LAYOUT_BOTH) {
828 if (usage == LP_TEX_USAGE_READ) {
829 new_layout = LP_TEX_LAYOUT_BOTH;
830 }
831 }
832 else if (cur_layout == other_layout) {
833 if (usage != LP_TEX_USAGE_WRITE_ALL) {
834 /* need to convert tiled data to linear or vice versa */
835 *convert = TRUE;
836
837 if (usage == LP_TEX_USAGE_READ)
838 new_layout = LP_TEX_LAYOUT_BOTH;
839 }
840 }
841 else {
842 assert(cur_layout == LP_TEX_LAYOUT_NONE ||
843 cur_layout == target_layout);
844 }
845
846 assert(new_layout == LP_TEX_LAYOUT_BOTH ||
847 new_layout == target_layout);
848
849 *new_layout_return = new_layout;
850 }
851
852
853 /**
854 * Return pointer to a 2D texture image/face/slice.
855 * No tiled/linear conversion is done.
856 */
857 ubyte *
858 llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
859 unsigned face_slice, unsigned level,
860 enum lp_texture_layout layout)
861 {
862 struct llvmpipe_texture_image *img;
863 unsigned offset;
864
865 if (layout == LP_TEX_LAYOUT_LINEAR) {
866 img = &lpr->linear[level];
867 }
868 else {
869 assert (layout == LP_TEX_LAYOUT_TILED);
870 img = &lpr->tiled[level];
871 }
872
873 if (face_slice > 0)
874 offset = face_slice * tex_image_face_size(lpr, level, layout);
875 else
876 offset = 0;
877
878 return (ubyte *) img->data + offset;
879 }
880
881
882 static INLINE enum lp_texture_layout
883 llvmpipe_get_texture_tile_layout(const struct llvmpipe_resource *lpr,
884 unsigned face_slice, unsigned level,
885 unsigned x, unsigned y)
886 {
887 uint i;
888 assert(resource_is_texture(&lpr->base));
889 assert(x < lpr->tiles_per_row[level]);
890 i = face_slice * lpr->tiles_per_image[level]
891 + y * lpr->tiles_per_row[level] + x;
892 return lpr->layout[level][i];
893 }
894
895
896 static INLINE void
897 llvmpipe_set_texture_tile_layout(struct llvmpipe_resource *lpr,
898 unsigned face_slice, unsigned level,
899 unsigned x, unsigned y,
900 enum lp_texture_layout layout)
901 {
902 uint i;
903 assert(resource_is_texture(&lpr->base));
904 assert(x < lpr->tiles_per_row[level]);
905 i = face_slice * lpr->tiles_per_image[level]
906 + y * lpr->tiles_per_row[level] + x;
907 lpr->layout[level][i] = layout;
908 }
909
910
911 /**
912 * Set the layout mode for all tiles in a particular image.
913 */
914 static INLINE void
915 llvmpipe_set_texture_image_layout(struct llvmpipe_resource *lpr,
916 unsigned face_slice, unsigned level,
917 unsigned width_t, unsigned height_t,
918 enum lp_texture_layout layout)
919 {
920 const unsigned start = face_slice * lpr->tiles_per_image[level];
921 unsigned i;
922
923 for (i = 0; i < width_t * height_t; i++) {
924 lpr->layout[level][start + i] = layout;
925 }
926 }
927
928
929 /**
930 * Allocate storage for a linear or tile texture image (all cube
931 * faces and all 3D slices.
932 */
933 static void
934 alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
935 enum lp_texture_layout layout)
936 {
937 uint alignment = MAX2(16, util_cpu_caps.cacheline);
938
939 if (lpr->dt)
940 assert(level == 0);
941
942 if (layout == LP_TEX_LAYOUT_TILED) {
943 /* tiled data is stored in regular memory */
944 uint buffer_size = tex_image_size(lpr, level, layout);
945 lpr->tiled[level].data = align_malloc(buffer_size, alignment);
946 }
947 else {
948 assert(layout == LP_TEX_LAYOUT_LINEAR);
949 if (lpr->dt) {
950 /* we get the linear memory from the winsys */
951 struct llvmpipe_screen *screen = llvmpipe_screen(lpr->base.screen);
952 struct sw_winsys *winsys = screen->winsys;
953
954 lpr->linear[0].data =
955 winsys->displaytarget_map(winsys, lpr->dt,
956 PIPE_TRANSFER_READ_WRITE);
957 }
958 else {
959 /* not a display target - allocate regular memory */
960 uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
961 lpr->linear[level].data = align_malloc(buffer_size, alignment);
962 }
963 }
964 }
965
966
967
968 /**
969 * Return pointer to texture image data (either linear or tiled layout)
970 * for a particular cube face or 3D texture slice.
971 *
972 * \param face_slice the cube face or 3D slice of interest
973 * \param usage one of LP_TEX_USAGE_READ/WRITE_ALL/READ_WRITE
974 * \param layout either LP_TEX_LAYOUT_LINEAR or _TILED or _NONE
975 */
976 void *
977 llvmpipe_get_texture_image(struct llvmpipe_resource *lpr,
978 unsigned face_slice, unsigned level,
979 enum lp_texture_usage usage,
980 enum lp_texture_layout layout)
981 {
982 /*
983 * 'target' refers to the image which we're retrieving (either in
984 * tiled or linear layout).
985 * 'other' refers to the same image but in the other layout. (it may
986 * or may not exist.
987 */
988 struct llvmpipe_texture_image *target_img;
989 struct llvmpipe_texture_image *other_img;
990 void *target_data;
991 void *other_data;
992 const unsigned width = u_minify(lpr->base.width0, level);
993 const unsigned height = u_minify(lpr->base.height0, level);
994 const unsigned width_t = align(width, TILE_SIZE) / TILE_SIZE;
995 const unsigned height_t = align(height, TILE_SIZE) / TILE_SIZE;
996 enum lp_texture_layout other_layout;
997 boolean only_allocate;
998
999 assert(layout == LP_TEX_LAYOUT_NONE ||
1000 layout == LP_TEX_LAYOUT_TILED ||
1001 layout == LP_TEX_LAYOUT_LINEAR);
1002
1003 assert(usage == LP_TEX_USAGE_READ ||
1004 usage == LP_TEX_USAGE_READ_WRITE ||
1005 usage == LP_TEX_USAGE_WRITE_ALL);
1006
1007 /* check for the special case of layout == LP_TEX_LAYOUT_NONE */
1008 if (layout == LP_TEX_LAYOUT_NONE) {
1009 only_allocate = TRUE;
1010 layout = LP_TEX_LAYOUT_TILED;
1011 }
1012 else {
1013 only_allocate = FALSE;
1014 }
1015
1016 if (lpr->dt) {
1017 assert(lpr->linear[level].data);
1018 }
1019
1020 /* which is target? which is other? */
1021 if (layout == LP_TEX_LAYOUT_LINEAR) {
1022 target_img = &lpr->linear[level];
1023 other_img = &lpr->tiled[level];
1024 other_layout = LP_TEX_LAYOUT_TILED;
1025 }
1026 else {
1027 target_img = &lpr->tiled[level];
1028 other_img = &lpr->linear[level];
1029 other_layout = LP_TEX_LAYOUT_LINEAR;
1030 }
1031
1032 target_data = target_img->data;
1033 other_data = other_img->data;
1034
1035 if (!target_data) {
1036 /* allocate memory for the target image now */
1037 alloc_image_data(lpr, level, layout);
1038 target_data = target_img->data;
1039 }
1040
1041 if (face_slice > 0) {
1042 unsigned target_offset, other_offset;
1043
1044 target_offset = face_slice * tex_image_face_size(lpr, level, layout);
1045 other_offset = face_slice * tex_image_face_size(lpr, level, other_layout);
1046 if (target_data) {
1047 target_data = (uint8_t *) target_data + target_offset;
1048 }
1049 if (other_data) {
1050 other_data = (uint8_t *) other_data + other_offset;
1051 }
1052 }
1053
1054 if (only_allocate) {
1055 /* Just allocating tiled memory. Don't initialize it from the
1056 * linear data if it exists.
1057 */
1058 return target_data;
1059 }
1060
1061 if (other_data) {
1062 /* may need to convert other data to the requested layout */
1063 enum lp_texture_layout new_layout;
1064 unsigned x, y;
1065
1066 /* loop over all image tiles, doing layout conversion where needed */
1067 for (y = 0; y < height_t; y++) {
1068 for (x = 0; x < width_t; x++) {
1069 enum lp_texture_layout cur_layout =
1070 llvmpipe_get_texture_tile_layout(lpr, face_slice, level, x, y);
1071 boolean convert;
1072
1073 layout_logic(cur_layout, layout, usage, &new_layout, &convert);
1074
1075 if (convert && other_data && target_data) {
1076 if (layout == LP_TEX_LAYOUT_TILED) {
1077 lp_linear_to_tiled(other_data, target_data,
1078 x * TILE_SIZE, y * TILE_SIZE,
1079 TILE_SIZE, TILE_SIZE,
1080 lpr->base.format,
1081 lpr->row_stride[level],
1082 lpr->tiles_per_row[level]);
1083 }
1084 else {
1085 assert(layout == LP_TEX_LAYOUT_LINEAR);
1086 lp_tiled_to_linear(other_data, target_data,
1087 x * TILE_SIZE, y * TILE_SIZE,
1088 TILE_SIZE, TILE_SIZE,
1089 lpr->base.format,
1090 lpr->row_stride[level],
1091 lpr->tiles_per_row[level]);
1092 }
1093 }
1094
1095 if (new_layout != cur_layout)
1096 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, x, y,
1097 new_layout);
1098 }
1099 }
1100 }
1101 else {
1102 /* no other data */
1103 llvmpipe_set_texture_image_layout(lpr, face_slice, level,
1104 width_t, height_t, layout);
1105 }
1106
1107 return target_data;
1108 }
1109
1110
1111 /**
1112 * Return pointer to start of a texture image (1D, 2D, 3D, CUBE).
1113 * All cube faces and 3D slices will be converted to the requested
1114 * layout if needed.
1115 * This is typically used when we're about to sample from a texture.
1116 */
1117 void *
1118 llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
1119 unsigned level,
1120 enum lp_texture_usage usage,
1121 enum lp_texture_layout layout)
1122 {
1123 const int slices = lpr->num_slices_faces[level];
1124 int slice;
1125 void *map = NULL;
1126
1127 assert(slices > 0);
1128
1129 for (slice = slices - 1; slice >= 0; slice--) {
1130 map = llvmpipe_get_texture_image(lpr, slice, level, usage, layout);
1131 }
1132
1133 return map;
1134 }
1135
1136
1137 /**
1138 * Get pointer to a linear image (not the tile!) where the tile at (x,y)
1139 * is known to be in linear layout.
1140 * Conversion from tiled to linear will be done if necessary.
1141 * \return pointer to start of image/face (not the tile)
1142 */
1143 ubyte *
1144 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
1145 unsigned face_slice, unsigned level,
1146 enum lp_texture_usage usage,
1147 unsigned x, unsigned y)
1148 {
1149 struct llvmpipe_texture_image *linear_img = &lpr->linear[level];
1150 enum lp_texture_layout cur_layout, new_layout;
1151 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1152 boolean convert;
1153 uint8_t *tiled_image, *linear_image;
1154
1155 assert(resource_is_texture(&lpr->base));
1156 assert(x % TILE_SIZE == 0);
1157 assert(y % TILE_SIZE == 0);
1158
1159 if (!linear_img->data) {
1160 /* allocate memory for the linear image now */
1161 alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR);
1162 }
1163
1164 /* compute address of the slice/face of the image that contains the tile */
1165 tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1166 LP_TEX_LAYOUT_TILED);
1167 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1168 LP_TEX_LAYOUT_LINEAR);
1169
1170 /* get current tile layout and determine if data conversion is needed */
1171 cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
1172
1173 layout_logic(cur_layout, LP_TEX_LAYOUT_LINEAR, usage,
1174 &new_layout, &convert);
1175
1176 if (convert && tiled_image && linear_image) {
1177 lp_tiled_to_linear(tiled_image, linear_image,
1178 x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
1179 lpr->row_stride[level],
1180 lpr->tiles_per_row[level]);
1181 }
1182
1183 if (new_layout != cur_layout)
1184 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);
1185
1186 return linear_image;
1187 }
1188
1189
1190 /**
1191 * Get pointer to tiled data for rendering.
1192 * \return pointer to the tiled data at the given tile position
1193 */
1194 ubyte *
1195 llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr,
1196 unsigned face_slice, unsigned level,
1197 enum lp_texture_usage usage,
1198 unsigned x, unsigned y)
1199 {
1200 struct llvmpipe_texture_image *tiled_img = &lpr->tiled[level];
1201 enum lp_texture_layout cur_layout, new_layout;
1202 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1203 boolean convert;
1204 uint8_t *tiled_image, *linear_image;
1205 unsigned tile_offset;
1206
1207 assert(x % TILE_SIZE == 0);
1208 assert(y % TILE_SIZE == 0);
1209
1210 if (!tiled_img->data) {
1211 /* allocate memory for the tiled image now */
1212 alloc_image_data(lpr, level, LP_TEX_LAYOUT_TILED);
1213 }
1214
1215 /* compute address of the slice/face of the image that contains the tile */
1216 tiled_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1217 LP_TEX_LAYOUT_TILED);
1218 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1219 LP_TEX_LAYOUT_LINEAR);
1220
1221 /* get current tile layout and see if we need to convert the data */
1222 cur_layout = llvmpipe_get_texture_tile_layout(lpr, face_slice, level, tx, ty);
1223
1224 layout_logic(cur_layout, LP_TEX_LAYOUT_TILED, usage, &new_layout, &convert);
1225 if (convert && linear_image && tiled_image) {
1226 lp_linear_to_tiled(linear_image, tiled_image,
1227 x, y, TILE_SIZE, TILE_SIZE, lpr->base.format,
1228 lpr->row_stride[level],
1229 lpr->tiles_per_row[level]);
1230 }
1231
1232 if (!tiled_image)
1233 return NULL;
1234
1235 if (new_layout != cur_layout)
1236 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty, new_layout);
1237
1238 /* compute, return address of the 64x64 tile */
1239 tile_offset = (ty * lpr->tiles_per_row[level] + tx)
1240 * TILE_SIZE * TILE_SIZE * 4;
1241
1242 return (ubyte *) tiled_image + tile_offset;
1243 }
1244
1245
1246 /**
1247 * Get pointer to tiled data for rendering.
1248 * \return pointer to the tiled data at the given tile position
1249 */
1250 void
1251 llvmpipe_unswizzle_cbuf_tile(struct llvmpipe_resource *lpr,
1252 unsigned face_slice, unsigned level,
1253 unsigned x, unsigned y,
1254 uint8_t *tile)
1255 {
1256 struct llvmpipe_texture_image *linear_img = &lpr->linear[level];
1257 const unsigned tx = x / TILE_SIZE, ty = y / TILE_SIZE;
1258 uint8_t *linear_image;
1259
1260 assert(x % TILE_SIZE == 0);
1261 assert(y % TILE_SIZE == 0);
1262
1263 if (!linear_img->data) {
1264 /* allocate memory for the linear image now */
1265 alloc_image_data(lpr, level, LP_TEX_LAYOUT_LINEAR);
1266 }
1267
1268 /* compute address of the slice/face of the image that contains the tile */
1269 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1270 LP_TEX_LAYOUT_LINEAR);
1271
1272 {
1273 uint ii = x, jj = y;
1274 uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE;
1275 uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4;
1276
1277 /* Note that lp_tiled_to_linear expects the tile parameter to
1278 * point at the first tile in a whole-image sized array. In
1279 * this code, we have only a single tile and have to do some
1280 * pointer arithmetic to figure out where the "image" would have
1281 * started.
1282 */
1283 lp_tiled_to_linear(tile - byte_offset, linear_image,
1284 x, y, TILE_SIZE, TILE_SIZE,
1285 lpr->base.format,
1286 lpr->row_stride[level],
1287 1); /* tiles per row */
1288 }
1289
1290 llvmpipe_set_texture_tile_layout(lpr, face_slice, level, tx, ty,
1291 LP_TEX_LAYOUT_LINEAR);
1292 }
1293
1294
1295 /**
1296 * Get pointer to tiled data for rendering.
1297 * \return pointer to the tiled data at the given tile position
1298 */
1299 void
1300 llvmpipe_swizzle_cbuf_tile(struct llvmpipe_resource *lpr,
1301 unsigned face_slice, unsigned level,
1302 unsigned x, unsigned y,
1303 uint8_t *tile)
1304 {
1305 uint8_t *linear_image;
1306
1307 assert(x % TILE_SIZE == 0);
1308 assert(y % TILE_SIZE == 0);
1309
1310 /* compute address of the slice/face of the image that contains the tile */
1311 linear_image = llvmpipe_get_texture_image_address(lpr, face_slice, level,
1312 LP_TEX_LAYOUT_LINEAR);
1313
1314 if (linear_image) {
1315 uint ii = x, jj = y;
1316 uint tile_offset = jj / TILE_SIZE + ii / TILE_SIZE;
1317 uint byte_offset = tile_offset * TILE_SIZE * TILE_SIZE * 4;
1318
1319 /* Note that lp_linear_to_tiled expects the tile parameter to
1320 * point at the first tile in a whole-image sized array. In
1321 * this code, we have only a single tile and have to do some
1322 * pointer arithmetic to figure out where the "image" would have
1323 * started.
1324 */
1325 lp_linear_to_tiled(linear_image, tile - byte_offset,
1326 x, y, TILE_SIZE, TILE_SIZE,
1327 lpr->base.format,
1328 lpr->row_stride[level],
1329 1); /* tiles per row */
1330 }
1331 }
1332
1333
1334 /**
1335 * Return size of resource in bytes
1336 */
1337 unsigned
1338 llvmpipe_resource_size(const struct pipe_resource *resource)
1339 {
1340 const struct llvmpipe_resource *lpr = llvmpipe_resource_const(resource);
1341 unsigned lvl, size = 0;
1342
1343 for (lvl = 0; lvl <= lpr->base.last_level; lvl++) {
1344 if (lpr->linear[lvl].data)
1345 size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_LINEAR);
1346
1347 if (lpr->tiled[lvl].data)
1348 size += tex_image_size(lpr, lvl, LP_TEX_LAYOUT_TILED);
1349 }
1350
1351 return size;
1352 }
1353
1354
1355 #ifdef DEBUG
1356 void
1357 llvmpipe_print_resources(void)
1358 {
1359 struct llvmpipe_resource *lpr;
1360 unsigned n = 0, total = 0;
1361
1362 debug_printf("LLVMPIPE: current resources:\n");
1363 foreach(lpr, &resource_list) {
1364 unsigned size = llvmpipe_resource_size(&lpr->base);
1365 debug_printf("resource %u at %p, size %ux%ux%u: %u bytes, refcount %u\n",
1366 lpr->id, (void *) lpr,
1367 lpr->base.width0, lpr->base.height0, lpr->base.depth0,
1368 size, lpr->base.reference.count);
1369 total += size;
1370 n++;
1371 }
1372 debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total);
1373 }
1374 #endif
1375
1376
1377 void
1378 llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen)
1379 {
1380 #ifdef DEBUG
1381 /* init linked list for tracking resources */
1382 {
1383 static boolean first_call = TRUE;
1384 if (first_call) {
1385 memset(&resource_list, 0, sizeof(resource_list));
1386 make_empty_list(&resource_list);
1387 first_call = FALSE;
1388 }
1389 }
1390 #endif
1391
1392 screen->resource_create = llvmpipe_resource_create;
1393 screen->resource_destroy = llvmpipe_resource_destroy;
1394 screen->resource_from_handle = llvmpipe_resource_from_handle;
1395 screen->resource_get_handle = llvmpipe_resource_get_handle;
1396 screen->user_buffer_create = llvmpipe_user_buffer_create;
1397
1398 screen->get_tex_surface = llvmpipe_get_tex_surface;
1399 screen->tex_surface_destroy = llvmpipe_tex_surface_destroy;
1400 }
1401
1402
1403 void
1404 llvmpipe_init_context_resource_funcs(struct pipe_context *pipe)
1405 {
1406 pipe->get_transfer = llvmpipe_get_transfer;
1407 pipe->transfer_destroy = llvmpipe_transfer_destroy;
1408 pipe->transfer_map = llvmpipe_transfer_map;
1409 pipe->transfer_unmap = llvmpipe_transfer_unmap;
1410 pipe->is_resource_referenced = llvmpipe_is_resource_referenced;
1411
1412 pipe->transfer_flush_region = u_default_transfer_flush_region;
1413 pipe->transfer_inline_write = u_default_transfer_inline_write;
1414 }