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