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