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