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