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