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