freedreno: avoid mem2gmem for invalidated buffers
[mesa.git] / src / gallium / drivers / freedreno / freedreno_resource.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #include "util/u_format.h"
30 #include "util/u_format_rgtc.h"
31 #include "util/u_format_zs.h"
32 #include "util/u_inlines.h"
33 #include "util/u_transfer.h"
34 #include "util/u_string.h"
35 #include "util/u_surface.h"
36 #include "util/set.h"
37
38 #include "freedreno_resource.h"
39 #include "freedreno_batch_cache.h"
40 #include "freedreno_screen.h"
41 #include "freedreno_surface.h"
42 #include "freedreno_context.h"
43 #include "freedreno_query_hw.h"
44 #include "freedreno_util.h"
45
46 #include <errno.h>
47
48 /* XXX this should go away, needed for 'struct winsys_handle' */
49 #include "state_tracker/drm_driver.h"
50
51 /**
52 * Go through the entire state and see if the resource is bound
53 * anywhere. If it is, mark the relevant state as dirty. This is
54 * called on realloc_bo to ensure the neccessary state is re-
55 * emitted so the GPU looks at the new backing bo.
56 */
57 static void
58 rebind_resource(struct fd_context *ctx, struct pipe_resource *prsc)
59 {
60 /* VBOs */
61 for (unsigned i = 0; i < ctx->vtx.vertexbuf.count && !(ctx->dirty & FD_DIRTY_VTXBUF); i++) {
62 if (ctx->vtx.vertexbuf.vb[i].buffer.resource == prsc)
63 ctx->dirty |= FD_DIRTY_VTXBUF;
64 }
65
66 /* per-shader-stage resources: */
67 for (unsigned stage = 0; stage < PIPE_SHADER_TYPES; stage++) {
68 /* Constbufs.. note that constbuf[0] is normal uniforms emitted in
69 * cmdstream rather than by pointer..
70 */
71 const unsigned num_ubos = util_last_bit(ctx->constbuf[stage].enabled_mask);
72 for (unsigned i = 1; i < num_ubos; i++) {
73 if (ctx->dirty_shader[stage] & FD_DIRTY_SHADER_CONST)
74 break;
75 if (ctx->constbuf[stage].cb[i].buffer == prsc)
76 ctx->dirty_shader[stage] |= FD_DIRTY_SHADER_CONST;
77 }
78
79 /* Textures */
80 for (unsigned i = 0; i < ctx->tex[stage].num_textures; i++) {
81 if (ctx->dirty_shader[stage] & FD_DIRTY_SHADER_TEX)
82 break;
83 if (ctx->tex[stage].textures[i] && (ctx->tex[stage].textures[i]->texture == prsc))
84 ctx->dirty_shader[stage] |= FD_DIRTY_SHADER_TEX;
85 }
86
87 /* SSBOs */
88 const unsigned num_ssbos = util_last_bit(ctx->shaderbuf[stage].enabled_mask);
89 for (unsigned i = 0; i < num_ssbos; i++) {
90 if (ctx->dirty_shader[stage] & FD_DIRTY_SHADER_SSBO)
91 break;
92 if (ctx->shaderbuf[stage].sb[i].buffer == prsc)
93 ctx->dirty_shader[stage] |= FD_DIRTY_SHADER_SSBO;
94 }
95 }
96 }
97
98 static void
99 realloc_bo(struct fd_resource *rsc, uint32_t size)
100 {
101 struct fd_screen *screen = fd_screen(rsc->base.b.screen);
102 uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
103 DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
104
105 /* if we start using things other than write-combine,
106 * be sure to check for PIPE_RESOURCE_FLAG_MAP_COHERENT
107 */
108
109 if (rsc->bo)
110 fd_bo_del(rsc->bo);
111
112 rsc->bo = fd_bo_new(screen->dev, size, flags);
113 util_range_set_empty(&rsc->valid_buffer_range);
114 fd_bc_invalidate_resource(rsc, true);
115 }
116
117 static void
118 do_blit(struct fd_context *ctx, const struct pipe_blit_info *blit, bool fallback)
119 {
120 /* TODO size threshold too?? */
121 if ((blit->src.resource->target != PIPE_BUFFER) && !fallback) {
122 /* do blit on gpu: */
123 fd_blitter_pipe_begin(ctx, false, true, FD_STAGE_BLIT);
124 util_blitter_blit(ctx->blitter, blit);
125 fd_blitter_pipe_end(ctx);
126 } else {
127 /* do blit on cpu: */
128 util_resource_copy_region(&ctx->base,
129 blit->dst.resource, blit->dst.level, blit->dst.box.x,
130 blit->dst.box.y, blit->dst.box.z,
131 blit->src.resource, blit->src.level, &blit->src.box);
132 }
133 }
134
135 static bool
136 fd_try_shadow_resource(struct fd_context *ctx, struct fd_resource *rsc,
137 unsigned level, unsigned usage, const struct pipe_box *box)
138 {
139 struct pipe_context *pctx = &ctx->base;
140 struct pipe_resource *prsc = &rsc->base.b;
141 bool fallback = false;
142
143 if (prsc->next)
144 return false;
145
146 /* TODO: somehow munge dimensions and format to copy unsupported
147 * render target format to something that is supported?
148 */
149 if (!pctx->screen->is_format_supported(pctx->screen,
150 prsc->format, prsc->target, prsc->nr_samples,
151 PIPE_BIND_RENDER_TARGET))
152 fallback = true;
153
154 /* these cases should be handled elsewhere.. just for future
155 * reference in case this gets split into a more generic(ish)
156 * helper.
157 */
158 debug_assert(!(usage & PIPE_TRANSFER_READ));
159 debug_assert(!(usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE));
160
161 /* if we do a gpu blit to clone the whole resource, we'll just
162 * end up stalling on that.. so only allow if we can discard
163 * current range (and blit, possibly cpu or gpu, the rest)
164 */
165 if (!(usage & PIPE_TRANSFER_DISCARD_RANGE))
166 return false;
167
168 bool whole_level = util_texrange_covers_whole_level(prsc, level,
169 box->x, box->y, box->z, box->width, box->height, box->depth);
170
171 /* TODO need to be more clever about current level */
172 if ((prsc->target >= PIPE_TEXTURE_2D) && !whole_level)
173 return false;
174
175 struct pipe_resource *pshadow =
176 pctx->screen->resource_create(pctx->screen, prsc);
177
178 if (!pshadow)
179 return false;
180
181 assert(!ctx->in_shadow);
182 ctx->in_shadow = true;
183
184 /* get rid of any references that batch-cache might have to us (which
185 * should empty/destroy rsc->batches hashset)
186 */
187 fd_bc_invalidate_resource(rsc, false);
188
189 mtx_lock(&ctx->screen->lock);
190
191 /* Swap the backing bo's, so shadow becomes the old buffer,
192 * blit from shadow to new buffer. From here on out, we
193 * cannot fail.
194 *
195 * Note that we need to do it in this order, otherwise if
196 * we go down cpu blit path, the recursive transfer_map()
197 * sees the wrong status..
198 */
199 struct fd_resource *shadow = fd_resource(pshadow);
200
201 DBG("shadow: %p (%d) -> %p (%d)\n", rsc, rsc->base.b.reference.count,
202 shadow, shadow->base.b.reference.count);
203
204 /* TODO valid_buffer_range?? */
205 swap(rsc->bo, shadow->bo);
206 swap(rsc->write_batch, shadow->write_batch);
207
208 /* at this point, the newly created shadow buffer is not referenced
209 * by any batches, but the existing rsc (probably) is. We need to
210 * transfer those references over:
211 */
212 debug_assert(shadow->batch_mask == 0);
213 struct fd_batch *batch;
214 foreach_batch(batch, &ctx->screen->batch_cache, rsc->batch_mask) {
215 struct set_entry *entry = _mesa_set_search(batch->resources, rsc);
216 _mesa_set_remove(batch->resources, entry);
217 _mesa_set_add(batch->resources, shadow);
218 }
219 swap(rsc->batch_mask, shadow->batch_mask);
220
221 mtx_unlock(&ctx->screen->lock);
222
223 struct pipe_blit_info blit = {0};
224 blit.dst.resource = prsc;
225 blit.dst.format = prsc->format;
226 blit.src.resource = pshadow;
227 blit.src.format = pshadow->format;
228 blit.mask = util_format_get_mask(prsc->format);
229 blit.filter = PIPE_TEX_FILTER_NEAREST;
230
231 #define set_box(field, val) do { \
232 blit.dst.field = (val); \
233 blit.src.field = (val); \
234 } while (0)
235
236 /* blit the other levels in their entirety: */
237 for (unsigned l = 0; l <= prsc->last_level; l++) {
238 if (l == level)
239 continue;
240
241 /* just blit whole level: */
242 set_box(level, l);
243 set_box(box.width, u_minify(prsc->width0, l));
244 set_box(box.height, u_minify(prsc->height0, l));
245 set_box(box.depth, u_minify(prsc->depth0, l));
246
247 do_blit(ctx, &blit, fallback);
248 }
249
250 /* deal w/ current level specially, since we might need to split
251 * it up into a couple blits:
252 */
253 if (!whole_level) {
254 set_box(level, level);
255
256 switch (prsc->target) {
257 case PIPE_BUFFER:
258 case PIPE_TEXTURE_1D:
259 set_box(box.y, 0);
260 set_box(box.z, 0);
261 set_box(box.height, 1);
262 set_box(box.depth, 1);
263
264 if (box->x > 0) {
265 set_box(box.x, 0);
266 set_box(box.width, box->x);
267
268 do_blit(ctx, &blit, fallback);
269 }
270 if ((box->x + box->width) < u_minify(prsc->width0, level)) {
271 set_box(box.x, box->x + box->width);
272 set_box(box.width, u_minify(prsc->width0, level) - (box->x + box->width));
273
274 do_blit(ctx, &blit, fallback);
275 }
276 break;
277 case PIPE_TEXTURE_2D:
278 /* TODO */
279 default:
280 unreachable("TODO");
281 }
282 }
283
284 ctx->in_shadow = false;
285
286 pipe_resource_reference(&pshadow, NULL);
287
288 return true;
289 }
290
291 static unsigned
292 fd_resource_layer_offset(struct fd_resource *rsc,
293 struct fd_resource_slice *slice,
294 unsigned layer)
295 {
296 if (rsc->layer_first)
297 return layer * rsc->layer_size;
298 else
299 return layer * slice->size0;
300 }
301
302 static void
303 fd_resource_flush_z32s8(struct fd_transfer *trans, const struct pipe_box *box)
304 {
305 struct fd_resource *rsc = fd_resource(trans->base.resource);
306 struct fd_resource_slice *slice = fd_resource_slice(rsc, trans->base.level);
307 struct fd_resource_slice *sslice = fd_resource_slice(rsc->stencil, trans->base.level);
308 enum pipe_format format = trans->base.resource->format;
309
310 float *depth = fd_bo_map(rsc->bo) + slice->offset +
311 fd_resource_layer_offset(rsc, slice, trans->base.box.z) +
312 (trans->base.box.y + box->y) * slice->pitch * 4 + (trans->base.box.x + box->x) * 4;
313 uint8_t *stencil = fd_bo_map(rsc->stencil->bo) + sslice->offset +
314 fd_resource_layer_offset(rsc->stencil, sslice, trans->base.box.z) +
315 (trans->base.box.y + box->y) * sslice->pitch + trans->base.box.x + box->x;
316
317 if (format != PIPE_FORMAT_X32_S8X24_UINT)
318 util_format_z32_float_s8x24_uint_unpack_z_float(
319 depth, slice->pitch * 4,
320 trans->staging, trans->base.stride,
321 box->width, box->height);
322
323 util_format_z32_float_s8x24_uint_unpack_s_8uint(
324 stencil, sslice->pitch,
325 trans->staging, trans->base.stride,
326 box->width, box->height);
327 }
328
329 static void
330 fd_resource_flush_rgtc(struct fd_transfer *trans, const struct pipe_box *box)
331 {
332 struct fd_resource *rsc = fd_resource(trans->base.resource);
333 struct fd_resource_slice *slice = fd_resource_slice(rsc, trans->base.level);
334 enum pipe_format format = trans->base.resource->format;
335
336 uint8_t *data = fd_bo_map(rsc->bo) + slice->offset +
337 fd_resource_layer_offset(rsc, slice, trans->base.box.z) +
338 ((trans->base.box.y + box->y) * slice->pitch +
339 trans->base.box.x + box->x) * rsc->cpp;
340
341 uint8_t *source = trans->staging +
342 util_format_get_nblocksy(format, box->y) * trans->base.stride +
343 util_format_get_stride(format, box->x);
344
345 switch (format) {
346 case PIPE_FORMAT_RGTC1_UNORM:
347 case PIPE_FORMAT_RGTC1_SNORM:
348 case PIPE_FORMAT_LATC1_UNORM:
349 case PIPE_FORMAT_LATC1_SNORM:
350 util_format_rgtc1_unorm_unpack_rgba_8unorm(
351 data, slice->pitch * rsc->cpp,
352 source, trans->base.stride,
353 box->width, box->height);
354 break;
355 case PIPE_FORMAT_RGTC2_UNORM:
356 case PIPE_FORMAT_RGTC2_SNORM:
357 case PIPE_FORMAT_LATC2_UNORM:
358 case PIPE_FORMAT_LATC2_SNORM:
359 util_format_rgtc2_unorm_unpack_rgba_8unorm(
360 data, slice->pitch * rsc->cpp,
361 source, trans->base.stride,
362 box->width, box->height);
363 break;
364 default:
365 assert(!"Unexpected format\n");
366 break;
367 }
368 }
369
370 static void
371 fd_resource_flush(struct fd_transfer *trans, const struct pipe_box *box)
372 {
373 enum pipe_format format = trans->base.resource->format;
374
375 switch (format) {
376 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
377 case PIPE_FORMAT_X32_S8X24_UINT:
378 fd_resource_flush_z32s8(trans, box);
379 break;
380 case PIPE_FORMAT_RGTC1_UNORM:
381 case PIPE_FORMAT_RGTC1_SNORM:
382 case PIPE_FORMAT_RGTC2_UNORM:
383 case PIPE_FORMAT_RGTC2_SNORM:
384 case PIPE_FORMAT_LATC1_UNORM:
385 case PIPE_FORMAT_LATC1_SNORM:
386 case PIPE_FORMAT_LATC2_UNORM:
387 case PIPE_FORMAT_LATC2_SNORM:
388 fd_resource_flush_rgtc(trans, box);
389 break;
390 default:
391 assert(!"Unexpected staging transfer type");
392 break;
393 }
394 }
395
396 static void fd_resource_transfer_flush_region(struct pipe_context *pctx,
397 struct pipe_transfer *ptrans,
398 const struct pipe_box *box)
399 {
400 struct fd_resource *rsc = fd_resource(ptrans->resource);
401 struct fd_transfer *trans = fd_transfer(ptrans);
402
403 if (ptrans->resource->target == PIPE_BUFFER)
404 util_range_add(&rsc->valid_buffer_range,
405 ptrans->box.x + box->x,
406 ptrans->box.x + box->x + box->width);
407
408 if (trans->staging)
409 fd_resource_flush(trans, box);
410 }
411
412 static void
413 fd_resource_transfer_unmap(struct pipe_context *pctx,
414 struct pipe_transfer *ptrans)
415 {
416 struct fd_context *ctx = fd_context(pctx);
417 struct fd_resource *rsc = fd_resource(ptrans->resource);
418 struct fd_transfer *trans = fd_transfer(ptrans);
419
420 if (trans->staging && !(ptrans->usage & PIPE_TRANSFER_FLUSH_EXPLICIT)) {
421 struct pipe_box box;
422 u_box_2d(0, 0, ptrans->box.width, ptrans->box.height, &box);
423 fd_resource_flush(trans, &box);
424 }
425
426 if (!(ptrans->usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
427 fd_bo_cpu_fini(rsc->bo);
428 if (rsc->stencil)
429 fd_bo_cpu_fini(rsc->stencil->bo);
430 }
431
432 util_range_add(&rsc->valid_buffer_range,
433 ptrans->box.x,
434 ptrans->box.x + ptrans->box.width);
435
436 pipe_resource_reference(&ptrans->resource, NULL);
437 slab_free(&ctx->transfer_pool, ptrans);
438
439 free(trans->staging);
440 }
441
442 static void *
443 fd_resource_transfer_map(struct pipe_context *pctx,
444 struct pipe_resource *prsc,
445 unsigned level, unsigned usage,
446 const struct pipe_box *box,
447 struct pipe_transfer **pptrans)
448 {
449 struct fd_context *ctx = fd_context(pctx);
450 struct fd_resource *rsc = fd_resource(prsc);
451 struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
452 struct fd_transfer *trans;
453 struct pipe_transfer *ptrans;
454 enum pipe_format format = prsc->format;
455 uint32_t op = 0;
456 uint32_t offset;
457 char *buf;
458 int ret = 0;
459
460 DBG("prsc=%p, level=%u, usage=%x, box=%dx%d+%d,%d", prsc, level, usage,
461 box->width, box->height, box->x, box->y);
462
463 ptrans = slab_alloc(&ctx->transfer_pool);
464 if (!ptrans)
465 return NULL;
466
467 /* slab_alloc_st() doesn't zero: */
468 trans = fd_transfer(ptrans);
469 memset(trans, 0, sizeof(*trans));
470
471 pipe_resource_reference(&ptrans->resource, prsc);
472 ptrans->level = level;
473 ptrans->usage = usage;
474 ptrans->box = *box;
475 ptrans->stride = util_format_get_nblocksx(format, slice->pitch) * rsc->cpp;
476 ptrans->layer_stride = rsc->layer_first ? rsc->layer_size : slice->size0;
477
478 if (ctx->in_shadow && !(usage & PIPE_TRANSFER_READ))
479 usage |= PIPE_TRANSFER_UNSYNCHRONIZED;
480
481 if (usage & PIPE_TRANSFER_READ)
482 op |= DRM_FREEDRENO_PREP_READ;
483
484 if (usage & PIPE_TRANSFER_WRITE)
485 op |= DRM_FREEDRENO_PREP_WRITE;
486
487 if (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) {
488 realloc_bo(rsc, fd_bo_size(rsc->bo));
489 if (rsc->stencil)
490 realloc_bo(rsc->stencil, fd_bo_size(rsc->stencil->bo));
491 rebind_resource(ctx, prsc);
492 } else if ((usage & PIPE_TRANSFER_WRITE) &&
493 prsc->target == PIPE_BUFFER &&
494 !util_ranges_intersect(&rsc->valid_buffer_range,
495 box->x, box->x + box->width)) {
496 /* We are trying to write to a previously uninitialized range. No need
497 * to wait.
498 */
499 } else if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
500 struct fd_batch *write_batch = NULL;
501
502 /* hold a reference, so it doesn't disappear under us: */
503 fd_batch_reference(&write_batch, rsc->write_batch);
504
505 if ((usage & PIPE_TRANSFER_WRITE) && write_batch &&
506 write_batch->back_blit) {
507 /* if only thing pending is a back-blit, we can discard it: */
508 fd_batch_reset(write_batch);
509 }
510
511 /* If the GPU is writing to the resource, or if it is reading from the
512 * resource and we're trying to write to it, flush the renders.
513 */
514 bool needs_flush = pending(rsc, !!(usage & PIPE_TRANSFER_WRITE));
515 bool busy = needs_flush || (0 != fd_bo_cpu_prep(rsc->bo,
516 ctx->pipe, op | DRM_FREEDRENO_PREP_NOSYNC));
517
518 /* if we need to flush/stall, see if we can make a shadow buffer
519 * to avoid this:
520 *
521 * TODO we could go down this path !reorder && !busy_for_read
522 * ie. we only *don't* want to go down this path if the blit
523 * will trigger a flush!
524 */
525 if (ctx->screen->reorder && busy && !(usage & PIPE_TRANSFER_READ)) {
526 if (fd_try_shadow_resource(ctx, rsc, level, usage, box)) {
527 needs_flush = busy = false;
528 rebind_resource(ctx, prsc);
529 }
530 }
531
532 if (needs_flush) {
533 if (usage & PIPE_TRANSFER_WRITE) {
534 struct fd_batch *batch, *batches[32] = {0};
535 uint32_t batch_mask;
536
537 /* This is a bit awkward, probably a fd_batch_flush_locked()
538 * would make things simpler.. but we need to hold the lock
539 * to iterate the batches which reference this resource. So
540 * we must first grab references under a lock, then flush.
541 */
542 mtx_lock(&ctx->screen->lock);
543 batch_mask = rsc->batch_mask;
544 foreach_batch(batch, &ctx->screen->batch_cache, batch_mask)
545 fd_batch_reference(&batches[batch->idx], batch);
546 mtx_unlock(&ctx->screen->lock);
547
548 foreach_batch(batch, &ctx->screen->batch_cache, batch_mask)
549 fd_batch_flush(batch, false, false);
550
551 foreach_batch(batch, &ctx->screen->batch_cache, batch_mask) {
552 fd_batch_sync(batch);
553 fd_batch_reference(&batches[batch->idx], NULL);
554 }
555 assert(rsc->batch_mask == 0);
556 } else {
557 fd_batch_flush(write_batch, true, false);
558 }
559 assert(!rsc->write_batch);
560 }
561
562 fd_batch_reference(&write_batch, NULL);
563
564 /* The GPU keeps track of how the various bo's are being used, and
565 * will wait if necessary for the proper operation to have
566 * completed.
567 */
568 if (busy) {
569 ret = fd_bo_cpu_prep(rsc->bo, ctx->pipe, op);
570 if (ret)
571 goto fail;
572 }
573 }
574
575 buf = fd_bo_map(rsc->bo);
576 if (!buf)
577 goto fail;
578
579 offset = slice->offset +
580 box->y / util_format_get_blockheight(format) * ptrans->stride +
581 box->x / util_format_get_blockwidth(format) * rsc->cpp +
582 fd_resource_layer_offset(rsc, slice, box->z);
583
584 if (prsc->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT ||
585 prsc->format == PIPE_FORMAT_X32_S8X24_UINT) {
586 assert(trans->base.box.depth == 1);
587
588 trans->base.stride = trans->base.box.width * rsc->cpp * 2;
589 trans->staging = malloc(trans->base.stride * trans->base.box.height);
590 if (!trans->staging)
591 goto fail;
592
593 /* if we're not discarding the whole range (or resource), we must copy
594 * the real data in.
595 */
596 if (!(usage & (PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE |
597 PIPE_TRANSFER_DISCARD_RANGE))) {
598 struct fd_resource_slice *sslice =
599 fd_resource_slice(rsc->stencil, level);
600 void *sbuf = fd_bo_map(rsc->stencil->bo);
601 if (!sbuf)
602 goto fail;
603
604 float *depth = (float *)(buf + slice->offset +
605 fd_resource_layer_offset(rsc, slice, box->z) +
606 box->y * slice->pitch * 4 + box->x * 4);
607 uint8_t *stencil = sbuf + sslice->offset +
608 fd_resource_layer_offset(rsc->stencil, sslice, box->z) +
609 box->y * sslice->pitch + box->x;
610
611 if (format != PIPE_FORMAT_X32_S8X24_UINT)
612 util_format_z32_float_s8x24_uint_pack_z_float(
613 trans->staging, trans->base.stride,
614 depth, slice->pitch * 4,
615 box->width, box->height);
616
617 util_format_z32_float_s8x24_uint_pack_s_8uint(
618 trans->staging, trans->base.stride,
619 stencil, sslice->pitch,
620 box->width, box->height);
621 }
622
623 buf = trans->staging;
624 offset = 0;
625 } else if (rsc->internal_format != format &&
626 util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC) {
627 assert(trans->base.box.depth == 1);
628
629 trans->base.stride = util_format_get_stride(
630 format, trans->base.box.width);
631 trans->staging = malloc(
632 util_format_get_2d_size(format, trans->base.stride,
633 trans->base.box.height));
634 if (!trans->staging)
635 goto fail;
636
637 /* if we're not discarding the whole range (or resource), we must copy
638 * the real data in.
639 */
640 if (!(usage & (PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE |
641 PIPE_TRANSFER_DISCARD_RANGE))) {
642 uint8_t *rgba8 = (uint8_t *)buf + slice->offset +
643 fd_resource_layer_offset(rsc, slice, box->z) +
644 box->y * slice->pitch * rsc->cpp + box->x * rsc->cpp;
645
646 switch (format) {
647 case PIPE_FORMAT_RGTC1_UNORM:
648 case PIPE_FORMAT_RGTC1_SNORM:
649 case PIPE_FORMAT_LATC1_UNORM:
650 case PIPE_FORMAT_LATC1_SNORM:
651 util_format_rgtc1_unorm_pack_rgba_8unorm(
652 trans->staging, trans->base.stride,
653 rgba8, slice->pitch * rsc->cpp,
654 box->width, box->height);
655 break;
656 case PIPE_FORMAT_RGTC2_UNORM:
657 case PIPE_FORMAT_RGTC2_SNORM:
658 case PIPE_FORMAT_LATC2_UNORM:
659 case PIPE_FORMAT_LATC2_SNORM:
660 util_format_rgtc2_unorm_pack_rgba_8unorm(
661 trans->staging, trans->base.stride,
662 rgba8, slice->pitch * rsc->cpp,
663 box->width, box->height);
664 break;
665 default:
666 assert(!"Unexpected format");
667 break;
668 }
669 }
670
671 buf = trans->staging;
672 offset = 0;
673 }
674
675 if (usage & PIPE_TRANSFER_WRITE)
676 rsc->valid = true;
677
678 *pptrans = ptrans;
679
680 return buf + offset;
681
682 fail:
683 fd_resource_transfer_unmap(pctx, ptrans);
684 return NULL;
685 }
686
687 static void
688 fd_resource_destroy(struct pipe_screen *pscreen,
689 struct pipe_resource *prsc)
690 {
691 struct fd_resource *rsc = fd_resource(prsc);
692 fd_bc_invalidate_resource(rsc, true);
693 if (rsc->bo)
694 fd_bo_del(rsc->bo);
695 util_range_destroy(&rsc->valid_buffer_range);
696 FREE(rsc);
697 }
698
699 static boolean
700 fd_resource_get_handle(struct pipe_screen *pscreen,
701 struct pipe_resource *prsc,
702 struct winsys_handle *handle)
703 {
704 struct fd_resource *rsc = fd_resource(prsc);
705
706 return fd_screen_bo_get_handle(pscreen, rsc->bo,
707 rsc->slices[0].pitch * rsc->cpp, handle);
708 }
709
710
711 static const struct u_resource_vtbl fd_resource_vtbl = {
712 .resource_get_handle = fd_resource_get_handle,
713 .resource_destroy = fd_resource_destroy,
714 .transfer_map = fd_resource_transfer_map,
715 .transfer_flush_region = fd_resource_transfer_flush_region,
716 .transfer_unmap = fd_resource_transfer_unmap,
717 };
718
719 static uint32_t
720 setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format format)
721 {
722 struct pipe_resource *prsc = &rsc->base.b;
723 struct fd_screen *screen = fd_screen(prsc->screen);
724 enum util_format_layout layout = util_format_description(format)->layout;
725 uint32_t pitchalign = screen->gmem_alignw;
726 uint32_t level, size = 0;
727 uint32_t width = prsc->width0;
728 uint32_t height = prsc->height0;
729 uint32_t depth = prsc->depth0;
730 /* in layer_first layout, the level (slice) contains just one
731 * layer (since in fact the layer contains the slices)
732 */
733 uint32_t layers_in_level = rsc->layer_first ? 1 : prsc->array_size;
734
735 if (is_a5xx(screen) && (rsc->base.b.target >= PIPE_TEXTURE_2D))
736 height = align(height, screen->gmem_alignh);
737
738 for (level = 0; level <= prsc->last_level; level++) {
739 struct fd_resource_slice *slice = fd_resource_slice(rsc, level);
740 uint32_t blocks;
741
742 if (layout == UTIL_FORMAT_LAYOUT_ASTC)
743 slice->pitch = width =
744 util_align_npot(width, pitchalign * util_format_get_blockwidth(format));
745 else
746 slice->pitch = width = align(width, pitchalign);
747 slice->offset = size;
748 blocks = util_format_get_nblocks(format, width, height);
749 /* 1d array and 2d array textures must all have the same layer size
750 * for each miplevel on a3xx. 3d textures can have different layer
751 * sizes for high levels, but the hw auto-sizer is buggy (or at least
752 * different than what this code does), so as soon as the layer size
753 * range gets into range, we stop reducing it.
754 */
755 if (prsc->target == PIPE_TEXTURE_3D && (
756 level == 1 ||
757 (level > 1 && rsc->slices[level - 1].size0 > 0xf000)))
758 slice->size0 = align(blocks * rsc->cpp, alignment);
759 else if (level == 0 || rsc->layer_first || alignment == 1)
760 slice->size0 = align(blocks * rsc->cpp, alignment);
761 else
762 slice->size0 = rsc->slices[level - 1].size0;
763
764 size += slice->size0 * depth * layers_in_level;
765
766 width = u_minify(width, 1);
767 height = u_minify(height, 1);
768 depth = u_minify(depth, 1);
769 }
770
771 return size;
772 }
773
774 static uint32_t
775 slice_alignment(struct pipe_screen *pscreen, const struct pipe_resource *tmpl)
776 {
777 /* on a3xx, 2d array and 3d textures seem to want their
778 * layers aligned to page boundaries:
779 */
780 switch (tmpl->target) {
781 case PIPE_TEXTURE_3D:
782 case PIPE_TEXTURE_1D_ARRAY:
783 case PIPE_TEXTURE_2D_ARRAY:
784 return 4096;
785 default:
786 return 1;
787 }
788 }
789
790 /* special case to resize query buf after allocated.. */
791 void
792 fd_resource_resize(struct pipe_resource *prsc, uint32_t sz)
793 {
794 struct fd_resource *rsc = fd_resource(prsc);
795
796 debug_assert(prsc->width0 == 0);
797 debug_assert(prsc->target == PIPE_BUFFER);
798 debug_assert(prsc->bind == PIPE_BIND_QUERY_BUFFER);
799
800 prsc->width0 = sz;
801 realloc_bo(rsc, setup_slices(rsc, 1, prsc->format));
802 }
803
804 // TODO common helper?
805 static bool
806 has_depth(enum pipe_format format)
807 {
808 switch (format) {
809 case PIPE_FORMAT_Z16_UNORM:
810 case PIPE_FORMAT_Z32_UNORM:
811 case PIPE_FORMAT_Z32_FLOAT:
812 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
813 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
814 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
815 case PIPE_FORMAT_Z24X8_UNORM:
816 case PIPE_FORMAT_X8Z24_UNORM:
817 return true;
818 default:
819 return false;
820 }
821 }
822
823 /**
824 * Create a new texture object, using the given template info.
825 */
826 static struct pipe_resource *
827 fd_resource_create(struct pipe_screen *pscreen,
828 const struct pipe_resource *tmpl)
829 {
830 struct fd_screen *screen = fd_screen(pscreen);
831 struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
832 struct pipe_resource *prsc = &rsc->base.b;
833 enum pipe_format format = tmpl->format;
834 uint32_t size, alignment;
835
836 DBG("%p: target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
837 "nr_samples=%u, usage=%u, bind=%x, flags=%x", prsc,
838 tmpl->target, util_format_name(format),
839 tmpl->width0, tmpl->height0, tmpl->depth0,
840 tmpl->array_size, tmpl->last_level, tmpl->nr_samples,
841 tmpl->usage, tmpl->bind, tmpl->flags);
842
843 if (!rsc)
844 return NULL;
845
846 *prsc = *tmpl;
847
848 pipe_reference_init(&prsc->reference, 1);
849
850 prsc->screen = pscreen;
851
852 util_range_init(&rsc->valid_buffer_range);
853
854 rsc->base.vtbl = &fd_resource_vtbl;
855
856 if (format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT)
857 format = PIPE_FORMAT_Z32_FLOAT;
858 else if (screen->gpu_id < 400 &&
859 util_format_description(format)->layout == UTIL_FORMAT_LAYOUT_RGTC)
860 format = PIPE_FORMAT_R8G8B8A8_UNORM;
861 rsc->internal_format = format;
862 rsc->cpp = util_format_get_blocksize(format);
863
864 assert(rsc->cpp);
865
866 // XXX probably need some extra work if we hit rsc shadowing path w/ lrz..
867 if (is_a5xx(screen) && (fd_mesa_debug & FD_DBG_LRZ) && has_depth(format)) {
868 const uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
869 DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
870 unsigned lrz_pitch = align(DIV_ROUND_UP(tmpl->width0, 8), 32);
871 unsigned lrz_height = DIV_ROUND_UP(tmpl->height0, 8);
872 unsigned size = lrz_pitch * lrz_height * 2;
873
874 size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
875
876 rsc->lrz_height = lrz_height;
877 rsc->lrz_width = lrz_pitch;
878 rsc->lrz_pitch = lrz_pitch;
879 rsc->lrz = fd_bo_new(screen->dev, size, flags);
880 }
881
882 alignment = slice_alignment(pscreen, tmpl);
883 if (is_a4xx(screen) || is_a5xx(screen)) {
884 switch (tmpl->target) {
885 case PIPE_TEXTURE_3D:
886 rsc->layer_first = false;
887 break;
888 default:
889 rsc->layer_first = true;
890 alignment = 1;
891 break;
892 }
893 }
894
895 size = setup_slices(rsc, alignment, format);
896
897 /* special case for hw-query buffer, which we need to allocate before we
898 * know the size:
899 */
900 if (size == 0) {
901 /* note, semi-intention == instead of & */
902 debug_assert(prsc->bind == PIPE_BIND_QUERY_BUFFER);
903 return prsc;
904 }
905
906 if (rsc->layer_first) {
907 rsc->layer_size = align(size, 4096);
908 size = rsc->layer_size * prsc->array_size;
909 }
910
911 realloc_bo(rsc, size);
912 if (!rsc->bo)
913 goto fail;
914
915 /* There is no native Z32F_S8 sampling or rendering format, so this must
916 * be emulated via two separate textures. The depth texture still keeps
917 * its Z32F_S8 format though, and we also keep a reference to a separate
918 * S8 texture.
919 */
920 if (tmpl->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
921 struct pipe_resource stencil = *tmpl;
922 stencil.format = PIPE_FORMAT_S8_UINT;
923 rsc->stencil = fd_resource(fd_resource_create(pscreen, &stencil));
924 if (!rsc->stencil)
925 goto fail;
926 }
927
928 return prsc;
929 fail:
930 fd_resource_destroy(pscreen, prsc);
931 return NULL;
932 }
933
934 /**
935 * Create a texture from a winsys_handle. The handle is often created in
936 * another process by first creating a pipe texture and then calling
937 * resource_get_handle.
938 */
939 static struct pipe_resource *
940 fd_resource_from_handle(struct pipe_screen *pscreen,
941 const struct pipe_resource *tmpl,
942 struct winsys_handle *handle, unsigned usage)
943 {
944 struct fd_resource *rsc = CALLOC_STRUCT(fd_resource);
945 struct fd_resource_slice *slice = &rsc->slices[0];
946 struct pipe_resource *prsc = &rsc->base.b;
947 uint32_t pitchalign = fd_screen(pscreen)->gmem_alignw;
948
949 DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, "
950 "nr_samples=%u, usage=%u, bind=%x, flags=%x",
951 tmpl->target, util_format_name(tmpl->format),
952 tmpl->width0, tmpl->height0, tmpl->depth0,
953 tmpl->array_size, tmpl->last_level, tmpl->nr_samples,
954 tmpl->usage, tmpl->bind, tmpl->flags);
955
956 if (!rsc)
957 return NULL;
958
959 *prsc = *tmpl;
960
961 pipe_reference_init(&prsc->reference, 1);
962
963 prsc->screen = pscreen;
964
965 util_range_init(&rsc->valid_buffer_range);
966
967 rsc->bo = fd_screen_bo_from_handle(pscreen, handle);
968 if (!rsc->bo)
969 goto fail;
970
971 rsc->base.vtbl = &fd_resource_vtbl;
972 rsc->cpp = util_format_get_blocksize(tmpl->format);
973 slice->pitch = handle->stride / rsc->cpp;
974 slice->offset = handle->offset;
975 slice->size0 = handle->stride * prsc->height0;
976
977 if ((slice->pitch < align(prsc->width0, pitchalign)) ||
978 (slice->pitch & (pitchalign - 1)))
979 goto fail;
980
981 assert(rsc->cpp);
982
983 return prsc;
984
985 fail:
986 fd_resource_destroy(pscreen, prsc);
987 return NULL;
988 }
989
990 /**
991 * _copy_region using pipe (3d engine)
992 */
993 static bool
994 fd_blitter_pipe_copy_region(struct fd_context *ctx,
995 struct pipe_resource *dst,
996 unsigned dst_level,
997 unsigned dstx, unsigned dsty, unsigned dstz,
998 struct pipe_resource *src,
999 unsigned src_level,
1000 const struct pipe_box *src_box)
1001 {
1002 /* not until we allow rendertargets to be buffers */
1003 if (dst->target == PIPE_BUFFER || src->target == PIPE_BUFFER)
1004 return false;
1005
1006 if (!util_blitter_is_copy_supported(ctx->blitter, dst, src))
1007 return false;
1008
1009 /* TODO we could discard if dst box covers dst level fully.. */
1010 fd_blitter_pipe_begin(ctx, false, false, FD_STAGE_BLIT);
1011 util_blitter_copy_texture(ctx->blitter,
1012 dst, dst_level, dstx, dsty, dstz,
1013 src, src_level, src_box);
1014 fd_blitter_pipe_end(ctx);
1015
1016 return true;
1017 }
1018
1019 /**
1020 * Copy a block of pixels from one resource to another.
1021 * The resource must be of the same format.
1022 * Resources with nr_samples > 1 are not allowed.
1023 */
1024 static void
1025 fd_resource_copy_region(struct pipe_context *pctx,
1026 struct pipe_resource *dst,
1027 unsigned dst_level,
1028 unsigned dstx, unsigned dsty, unsigned dstz,
1029 struct pipe_resource *src,
1030 unsigned src_level,
1031 const struct pipe_box *src_box)
1032 {
1033 struct fd_context *ctx = fd_context(pctx);
1034
1035 /* TODO if we have 2d core, or other DMA engine that could be used
1036 * for simple copies and reasonably easily synchronized with the 3d
1037 * core, this is where we'd plug it in..
1038 */
1039
1040 /* try blit on 3d pipe: */
1041 if (fd_blitter_pipe_copy_region(ctx,
1042 dst, dst_level, dstx, dsty, dstz,
1043 src, src_level, src_box))
1044 return;
1045
1046 /* else fallback to pure sw: */
1047 util_resource_copy_region(pctx,
1048 dst, dst_level, dstx, dsty, dstz,
1049 src, src_level, src_box);
1050 }
1051
1052 bool
1053 fd_render_condition_check(struct pipe_context *pctx)
1054 {
1055 struct fd_context *ctx = fd_context(pctx);
1056
1057 if (!ctx->cond_query)
1058 return true;
1059
1060 union pipe_query_result res = { 0 };
1061 bool wait =
1062 ctx->cond_mode != PIPE_RENDER_COND_NO_WAIT &&
1063 ctx->cond_mode != PIPE_RENDER_COND_BY_REGION_NO_WAIT;
1064
1065 if (pctx->get_query_result(pctx, ctx->cond_query, wait, &res))
1066 return (bool)res.u64 != ctx->cond_cond;
1067
1068 return true;
1069 }
1070
1071 /**
1072 * Optimal hardware path for blitting pixels.
1073 * Scaling, format conversion, up- and downsampling (resolve) are allowed.
1074 */
1075 static void
1076 fd_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
1077 {
1078 struct fd_context *ctx = fd_context(pctx);
1079 struct pipe_blit_info info = *blit_info;
1080 bool discard = false;
1081
1082 if (info.src.resource->nr_samples > 1 &&
1083 info.dst.resource->nr_samples <= 1 &&
1084 !util_format_is_depth_or_stencil(info.src.resource->format) &&
1085 !util_format_is_pure_integer(info.src.resource->format)) {
1086 DBG("color resolve unimplemented");
1087 return;
1088 }
1089
1090 if (info.render_condition_enable && !fd_render_condition_check(pctx))
1091 return;
1092
1093 if (!info.scissor_enable && !info.alpha_blend) {
1094 discard = util_texrange_covers_whole_level(info.dst.resource,
1095 info.dst.level, info.dst.box.x, info.dst.box.y,
1096 info.dst.box.z, info.dst.box.width,
1097 info.dst.box.height, info.dst.box.depth);
1098 }
1099
1100 if (util_try_blit_via_copy_region(pctx, &info)) {
1101 return; /* done */
1102 }
1103
1104 if (info.mask & PIPE_MASK_S) {
1105 DBG("cannot blit stencil, skipping");
1106 info.mask &= ~PIPE_MASK_S;
1107 }
1108
1109 if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
1110 DBG("blit unsupported %s -> %s",
1111 util_format_short_name(info.src.resource->format),
1112 util_format_short_name(info.dst.resource->format));
1113 return;
1114 }
1115
1116 fd_blitter_pipe_begin(ctx, info.render_condition_enable, discard, FD_STAGE_BLIT);
1117 util_blitter_blit(ctx->blitter, &info);
1118 fd_blitter_pipe_end(ctx);
1119 }
1120
1121 void
1122 fd_blitter_pipe_begin(struct fd_context *ctx, bool render_cond, bool discard,
1123 enum fd_render_stage stage)
1124 {
1125 util_blitter_save_fragment_constant_buffer_slot(ctx->blitter,
1126 ctx->constbuf[PIPE_SHADER_FRAGMENT].cb);
1127 util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vtx.vertexbuf.vb);
1128 util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx.vtx);
1129 util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vp);
1130 util_blitter_save_so_targets(ctx->blitter, ctx->streamout.num_targets,
1131 ctx->streamout.targets);
1132 util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
1133 util_blitter_save_viewport(ctx->blitter, &ctx->viewport);
1134 util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
1135 util_blitter_save_fragment_shader(ctx->blitter, ctx->prog.fp);
1136 util_blitter_save_blend(ctx->blitter, ctx->blend);
1137 util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
1138 util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref);
1139 util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask);
1140 util_blitter_save_framebuffer(ctx->blitter,
1141 ctx->batch ? &ctx->batch->framebuffer : NULL);
1142 util_blitter_save_fragment_sampler_states(ctx->blitter,
1143 ctx->tex[PIPE_SHADER_FRAGMENT].num_samplers,
1144 (void **)ctx->tex[PIPE_SHADER_FRAGMENT].samplers);
1145 util_blitter_save_fragment_sampler_views(ctx->blitter,
1146 ctx->tex[PIPE_SHADER_FRAGMENT].num_textures,
1147 ctx->tex[PIPE_SHADER_FRAGMENT].textures);
1148 if (!render_cond)
1149 util_blitter_save_render_condition(ctx->blitter,
1150 ctx->cond_query, ctx->cond_cond, ctx->cond_mode);
1151
1152 if (ctx->batch)
1153 fd_batch_set_stage(ctx->batch, stage);
1154
1155 ctx->in_blit = discard;
1156 }
1157
1158 void
1159 fd_blitter_pipe_end(struct fd_context *ctx)
1160 {
1161 if (ctx->batch)
1162 fd_batch_set_stage(ctx->batch, FD_STAGE_NULL);
1163 ctx->in_blit = false;
1164 }
1165
1166 static void
1167 fd_flush_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
1168 {
1169 struct fd_resource *rsc = fd_resource(prsc);
1170
1171 if (rsc->write_batch)
1172 fd_batch_flush(rsc->write_batch, true, false);
1173
1174 assert(!rsc->write_batch);
1175 }
1176
1177 static void
1178 fd_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc)
1179 {
1180 struct fd_resource *rsc = fd_resource(prsc);
1181
1182 /*
1183 * TODO I guess we could track that the resource is invalidated and
1184 * use that as a hint to realloc rather than stall in _transfer_map(),
1185 * even in the non-DISCARD_WHOLE_RESOURCE case?
1186 */
1187
1188 if (rsc->write_batch) {
1189 struct fd_batch *batch = rsc->write_batch;
1190 struct pipe_framebuffer_state *pfb = &batch->framebuffer;
1191
1192 if (pfb->zsbuf && pfb->zsbuf->texture == prsc)
1193 batch->resolve &= ~(FD_BUFFER_DEPTH | FD_BUFFER_STENCIL);
1194
1195 for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
1196 if (pfb->cbufs[i] && pfb->cbufs[i]->texture == prsc) {
1197 batch->resolve &= ~(PIPE_CLEAR_COLOR0 << i);
1198 }
1199 }
1200 }
1201
1202 rsc->valid = false;
1203 }
1204
1205 void
1206 fd_resource_screen_init(struct pipe_screen *pscreen)
1207 {
1208 pscreen->resource_create = fd_resource_create;
1209 pscreen->resource_from_handle = fd_resource_from_handle;
1210 pscreen->resource_get_handle = u_resource_get_handle_vtbl;
1211 pscreen->resource_destroy = u_resource_destroy_vtbl;
1212 }
1213
1214 void
1215 fd_resource_context_init(struct pipe_context *pctx)
1216 {
1217 pctx->transfer_map = u_transfer_map_vtbl;
1218 pctx->transfer_flush_region = u_transfer_flush_region_vtbl;
1219 pctx->transfer_unmap = u_transfer_unmap_vtbl;
1220 pctx->buffer_subdata = u_default_buffer_subdata;
1221 pctx->texture_subdata = u_default_texture_subdata;
1222 pctx->create_surface = fd_create_surface;
1223 pctx->surface_destroy = fd_surface_destroy;
1224 pctx->resource_copy_region = fd_resource_copy_region;
1225 pctx->blit = fd_blit;
1226 pctx->flush_resource = fd_flush_resource;
1227 pctx->invalidate_resource = fd_invalidate_resource;
1228 }