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