2 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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:
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
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
24 * Rob Clark <robclark@freedesktop.org>
27 #include "pipe/p_state.h"
28 #include "util/hash_table.h"
29 #include "util/u_dump.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_inlines.h"
33 #include "util/format/u_format.h"
35 #include "freedreno_gmem.h"
36 #include "freedreno_context.h"
37 #include "freedreno_fence.h"
38 #include "freedreno_log.h"
39 #include "freedreno_resource.h"
40 #include "freedreno_query_hw.h"
41 #include "freedreno_util.h"
44 * GMEM is the small (ie. 256KiB for a200, 512KiB for a220, etc) tile buffer
45 * inside the GPU. All rendering happens to GMEM. Larger render targets
46 * are split into tiles that are small enough for the color (and depth and/or
47 * stencil, if enabled) buffers to fit within GMEM. Before rendering a tile,
48 * if there was not a clear invalidating the previous tile contents, we need
49 * to restore the previous tiles contents (system mem -> GMEM), and after all
50 * the draw calls, before moving to the next tile, we need to save the tile
51 * contents (GMEM -> system mem).
53 * The code in this file handles dealing with GMEM and tiling.
55 * The structure of the ringbuffer ends up being:
57 * +--<---<-- IB ---<---+---<---+---<---<---<--+
60 * ------------------------------------------------------
61 * | clear/draw cmds | Tile0 | Tile1 | .... | TileN |
62 * ------------------------------------------------------
65 * address submitted in issueibcmds
67 * Where the per-tile section handles scissor setup, mem2gmem restore (if
68 * needed), IB to draw cmds earlier in the ringbuffer, and then gmem2mem
77 * Caches GMEM state based on a given framebuffer state. The key is
78 * meant to be the minimal set of data that results in a unique gmem
79 * configuration, avoiding multiple keys arriving at the same gmem
80 * state. For example, the render target format is not part of the
81 * key, only the size per pixel. And the max_scissor bounds is not
82 * part of they key, only the minx/miny (after clamping to tile
83 * alignment) and width/height. This ensures that slightly different
84 * max_scissor which would result in the same gmem state, do not
85 * become different keys that map to the same state.
90 uint16_t width
, height
;
91 uint8_t gmem_page_align
; /* alignment in multiples of 0x1000 to reduce key size */
93 uint8_t cbuf_cpp
[MAX_RENDER_TARGETS
];
98 gmem_key_hash(const void *_key
)
100 const struct gmem_key
*key
= _key
;
101 return _mesa_hash_data(key
, sizeof(*key
));
105 gmem_key_equals(const void *_a
, const void *_b
)
107 const struct gmem_key
*a
= _a
;
108 const struct gmem_key
*b
= _b
;
109 return memcmp(a
, b
, sizeof(*a
)) == 0;
113 dump_gmem_key(const struct gmem_key
*key
)
115 printf("{ .minx=%u, .miny=%u, .width=%u, .height=%u",
116 key
->minx
, key
->miny
, key
->width
, key
->height
);
117 printf(", .gmem_page_align=%u, .nr_cbufs=%u",
118 key
->gmem_page_align
, key
->nr_cbufs
);
119 printf(", .cbuf_cpp = {");
120 for (unsigned i
= 0; i
< ARRAY_SIZE(key
->cbuf_cpp
); i
++)
121 printf("%u,", key
->cbuf_cpp
[i
]);
122 printf("}, .zsbuf_cpp = {");
123 for (unsigned i
= 0; i
< ARRAY_SIZE(key
->zsbuf_cpp
); i
++)
124 printf("%u,", key
->zsbuf_cpp
[i
]);
129 dump_gmem_state(const struct fd_gmem_stateobj
*gmem
)
132 printf("GMEM LAYOUT: bin=%ux%u, nbins=%ux%u\n",
133 gmem
->bin_w
, gmem
->bin_h
, gmem
->nbins_x
, gmem
->nbins_y
);
134 for (int i
= 0; i
< ARRAY_SIZE(gmem
->cbuf_base
); i
++) {
135 if (!gmem
->cbuf_cpp
[i
])
138 unsigned size
= gmem
->cbuf_cpp
[i
] * gmem
->bin_w
* gmem
->bin_h
;
139 printf(" cbuf[%d]: base=0x%06x, size=0x%x, cpp=%u\n", i
,
140 gmem
->cbuf_base
[i
], size
, gmem
->cbuf_cpp
[i
]);
142 total
= gmem
->cbuf_base
[i
] + size
;
145 for (int i
= 0; i
< ARRAY_SIZE(gmem
->zsbuf_base
); i
++) {
146 if (!gmem
->zsbuf_cpp
[i
])
149 unsigned size
= gmem
->zsbuf_cpp
[i
] * gmem
->bin_w
* gmem
->bin_h
;
150 printf(" zsbuf[%d]: base=0x%06x, size=0x%x, cpp=%u\n", i
,
151 gmem
->zsbuf_base
[i
], size
, gmem
->zsbuf_cpp
[i
]);
153 total
= gmem
->zsbuf_base
[i
] + size
;
156 printf("total: 0x%06x (of 0x%06x)\n", total
,
157 gmem
->screen
->gmemsize_bytes
);
160 static uint32_t bin_width(struct fd_screen
*screen
)
162 if (is_a4xx(screen
) || is_a5xx(screen
) || is_a6xx(screen
))
170 div_align(unsigned num
, unsigned denom
, unsigned al
)
172 return util_align_npot(DIV_ROUND_UP(num
, denom
), al
);
176 layout_gmem(struct gmem_key
*key
, uint32_t nbins_x
, uint32_t nbins_y
,
177 struct fd_gmem_stateobj
*gmem
)
179 struct fd_screen
*screen
= gmem
->screen
;
180 uint32_t gmem_align
= key
->gmem_page_align
* 0x1000;
181 uint32_t total
= 0, i
;
183 if ((nbins_x
== 0) || (nbins_y
== 0))
186 uint32_t bin_w
, bin_h
;
187 bin_w
= div_align(key
->width
, nbins_x
, screen
->tile_alignw
);
188 bin_h
= div_align(key
->height
, nbins_y
, screen
->tile_alignh
);
193 /* due to aligning bin_w/h, we could end up with one too
194 * many bins in either dimension, so recalculate:
196 gmem
->nbins_x
= DIV_ROUND_UP(key
->width
, bin_w
);
197 gmem
->nbins_y
= DIV_ROUND_UP(key
->height
, bin_h
);
199 for (i
= 0; i
< MAX_RENDER_TARGETS
; i
++) {
200 if (key
->cbuf_cpp
[i
]) {
201 gmem
->cbuf_base
[i
] = util_align_npot(total
, gmem_align
);
202 total
= gmem
->cbuf_base
[i
] + key
->cbuf_cpp
[i
] * bin_w
* bin_h
;
206 if (key
->zsbuf_cpp
[0]) {
207 gmem
->zsbuf_base
[0] = util_align_npot(total
, gmem_align
);
208 total
= gmem
->zsbuf_base
[0] + key
->zsbuf_cpp
[0] * bin_w
* bin_h
;
211 if (key
->zsbuf_cpp
[1]) {
212 gmem
->zsbuf_base
[1] = util_align_npot(total
, gmem_align
);
213 total
= gmem
->zsbuf_base
[1] + key
->zsbuf_cpp
[1] * bin_w
* bin_h
;
216 return total
<= screen
->gmemsize_bytes
;
219 static struct fd_gmem_stateobj
*
220 gmem_stateobj_init(struct fd_screen
*screen
, struct gmem_key
*key
)
222 struct fd_gmem_stateobj
*gmem
=
223 rzalloc(screen
->gmem_cache
.ht
, struct fd_gmem_stateobj
);
224 pipe_reference_init(&gmem
->reference
, 1);
225 gmem
->screen
= screen
;
227 list_inithead(&gmem
->node
);
229 const unsigned npipes
= screen
->num_vsc_pipes
;
230 uint32_t nbins_x
= 1, nbins_y
= 1;
231 uint32_t max_width
= bin_width(screen
);
232 uint32_t i
, j
, t
, xoff
, yoff
;
233 uint32_t tpp_x
, tpp_y
;
236 if (fd_mesa_debug
& FD_DBG_MSGS
) {
237 debug_printf("binning input: cbuf cpp:");
238 for (i
= 0; i
< key
->nr_cbufs
; i
++)
239 debug_printf(" %d", key
->cbuf_cpp
[i
]);
240 debug_printf(", zsbuf cpp: %d; %dx%d\n",
241 key
->zsbuf_cpp
[0], key
->width
, key
->height
);
244 /* first, find a bin width that satisfies the maximum width
247 while (div_align(key
->width
, nbins_x
, screen
->tile_alignw
) > max_width
) {
251 /* then find a bin width/height that satisfies the memory
254 while (!layout_gmem(key
, nbins_x
, nbins_y
, gmem
)) {
255 if (nbins_y
> nbins_x
) {
262 /* Lets see if we can tweak the layout a bit and come up with
265 if ((((nbins_x
- 1) * (nbins_y
+ 1)) < (nbins_x
* nbins_y
)) &&
266 layout_gmem(key
, nbins_x
- 1, nbins_y
+ 1, gmem
)) {
269 } else if ((((nbins_x
+ 1) * (nbins_y
- 1)) < (nbins_x
* nbins_y
)) &&
270 layout_gmem(key
, nbins_x
+ 1, nbins_y
- 1, gmem
)) {
275 layout_gmem(key
, nbins_x
, nbins_y
, gmem
);
277 DBG("using %d bins of size %dx%d", gmem
->nbins_x
* gmem
->nbins_y
,
278 gmem
->bin_w
, gmem
->bin_h
);
280 memcpy(gmem
->cbuf_cpp
, key
->cbuf_cpp
, sizeof(key
->cbuf_cpp
));
281 memcpy(gmem
->zsbuf_cpp
, key
->zsbuf_cpp
, sizeof(key
->zsbuf_cpp
));
282 gmem
->minx
= key
->minx
;
283 gmem
->miny
= key
->miny
;
284 gmem
->width
= key
->width
;
285 gmem
->height
= key
->height
;
288 dump_gmem_state(gmem
);
293 * Assign tiles and pipes:
295 * At some point it might be worth playing with different
296 * strategies and seeing if that makes much impact on
300 #define div_round_up(v, a) (((v) + (a) - 1) / (a))
301 /* figure out number of tiles per pipe: */
302 if (is_a20x(screen
)) {
303 /* for a20x we want to minimize the number of "pipes"
304 * binning data has 3 bits for x/y (8x8) but the edges are used to
305 * cull off-screen vertices with hw binning, so we have 6x6 pipes
311 while (div_round_up(nbins_y
, tpp_y
) > npipes
)
313 while ((div_round_up(nbins_y
, tpp_y
) *
314 div_round_up(nbins_x
, tpp_x
)) > npipes
)
321 /* configure pipes: */
323 for (i
= 0; i
< npipes
; i
++) {
324 struct fd_vsc_pipe
*pipe
= &gmem
->vsc_pipe
[i
];
326 if (xoff
>= nbins_x
) {
331 if (yoff
>= nbins_y
) {
337 pipe
->w
= MIN2(tpp_x
, nbins_x
- xoff
);
338 pipe
->h
= MIN2(tpp_y
, nbins_y
- yoff
);
343 /* number of pipes to use for a20x */
344 gmem
->num_vsc_pipes
= MAX2(1, i
);
346 for (; i
< npipes
; i
++) {
347 struct fd_vsc_pipe
*pipe
= &gmem
->vsc_pipe
[i
];
348 pipe
->x
= pipe
->y
= pipe
->w
= pipe
->h
= 0;
352 printf("%dx%d ... tpp=%dx%d\n", nbins_x
, nbins_y
, tpp_x
, tpp_y
);
353 for (i
= 0; i
< ARRAY_SIZE(gmem
->vsc_pipe
); i
++) {
354 struct fd_vsc_pipe
*pipe
= &gmem
->vsc_pipe
[i
];
355 printf("pipe[%d]: %ux%u @ %u,%u\n", i
,
356 pipe
->w
, pipe
->h
, pipe
->x
, pipe
->y
);
360 /* configure tiles: */
363 memset(tile_n
, 0, sizeof(tile_n
));
364 for (i
= 0; i
< nbins_y
; i
++) {
369 /* clip bin height: */
370 bh
= MIN2(gmem
->bin_h
, key
->miny
+ key
->height
- yoff
);
372 for (j
= 0; j
< nbins_x
; j
++) {
373 struct fd_tile
*tile
= &gmem
->tile
[t
];
376 assert(t
< ARRAY_SIZE(gmem
->tile
));
379 p
= ((i
/ tpp_y
) * div_round_up(nbins_x
, tpp_x
)) + (j
/ tpp_x
);
380 assert(p
< gmem
->num_vsc_pipes
);
382 /* clip bin width: */
383 bw
= MIN2(gmem
->bin_w
, key
->minx
+ key
->width
- xoff
);
384 tile
->n
= !is_a20x(screen
) ? tile_n
[p
]++ :
385 ((i
% tpp_y
+ 1) << 3 | (j
% tpp_x
+ 1));
393 printf("tile[%d]: p=%u, bin=%ux%u+%u+%u\n", t
,
394 p
, bw
, bh
, xoff
, yoff
);
407 for (i
= 0; i
< nbins_y
; i
++) {
408 for (j
= 0; j
< nbins_x
; j
++) {
409 struct fd_tile
*tile
= &gmem
->tile
[t
++];
410 printf("|p:%u n:%u|", tile
->p
, tile
->n
);
420 __fd_gmem_destroy(struct fd_gmem_stateobj
*gmem
)
422 struct fd_gmem_cache
*cache
= &gmem
->screen
->gmem_cache
;
424 fd_screen_assert_locked(gmem
->screen
);
426 _mesa_hash_table_remove_key(cache
->ht
, gmem
->key
);
427 list_del(&gmem
->node
);
429 ralloc_free(gmem
->key
);
433 static struct gmem_key
*
434 gmem_key_init(struct fd_batch
*batch
, bool assume_zs
, bool no_scis_opt
)
436 struct fd_screen
*screen
= batch
->ctx
->screen
;
437 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
438 bool has_zs
= pfb
->zsbuf
&& !!(batch
->gmem_reason
& (FD_GMEM_DEPTH_ENABLED
|
439 FD_GMEM_STENCIL_ENABLED
| FD_GMEM_CLEARS_DEPTH_STENCIL
));
440 struct gmem_key
*key
= rzalloc(screen
->gmem_cache
.ht
, struct gmem_key
);
442 if (has_zs
|| assume_zs
) {
443 struct fd_resource
*rsc
= fd_resource(pfb
->zsbuf
->texture
);
444 key
->zsbuf_cpp
[0] = rsc
->layout
.cpp
;
446 key
->zsbuf_cpp
[1] = rsc
->stencil
->layout
.cpp
;
448 /* we might have a zsbuf, but it isn't used */
449 batch
->restore
&= ~(FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
);
450 batch
->resolve
&= ~(FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
);
453 key
->nr_cbufs
= pfb
->nr_cbufs
;
454 for (unsigned i
= 0; i
< pfb
->nr_cbufs
; i
++) {
456 key
->cbuf_cpp
[i
] = util_format_get_blocksize(pfb
->cbufs
[i
]->format
);
458 key
->cbuf_cpp
[i
] = 4;
459 /* if MSAA, color buffers are super-sampled in GMEM: */
460 key
->cbuf_cpp
[i
] *= pfb
->samples
;
463 /* NOTE: on a6xx, the max-scissor-rect is handled in fd6_gmem, and
464 * we just rely on CP_COND_EXEC to skip bins with no geometry.
466 if ((fd_mesa_debug
& FD_DBG_NOSCIS
) || no_scis_opt
|| is_a6xx(screen
)) {
469 key
->width
= pfb
->width
;
470 key
->height
= pfb
->height
;
472 struct pipe_scissor_state
*scissor
= &batch
->max_scissor
;
474 /* round down to multiple of alignment: */
475 key
->minx
= scissor
->minx
& ~(screen
->gmem_alignw
- 1);
476 key
->miny
= scissor
->miny
& ~(screen
->gmem_alignh
- 1);
477 key
->width
= scissor
->maxx
- key
->minx
;
478 key
->height
= scissor
->maxy
- key
->miny
;
481 if (is_a20x(screen
) && batch
->cleared
) {
482 /* under normal circumstances the requirement would be 4K
483 * but the fast clear path requires an alignment of 32K
485 key
->gmem_page_align
= 8;
486 } else if (is_a6xx(screen
)) {
487 key
->gmem_page_align
= is_a650(screen
) ? 3 : 1;
489 // TODO re-check this across gens.. maybe it should only
490 // be a single page in some cases:
491 key
->gmem_page_align
= 4;
497 static struct fd_gmem_stateobj
*
498 lookup_gmem_state(struct fd_batch
*batch
, bool assume_zs
, bool no_scis_opt
)
500 struct fd_screen
*screen
= batch
->ctx
->screen
;
501 struct fd_gmem_cache
*cache
= &screen
->gmem_cache
;
502 struct fd_gmem_stateobj
*gmem
= NULL
;
503 struct gmem_key
*key
= gmem_key_init(batch
, assume_zs
, no_scis_opt
);
504 uint32_t hash
= gmem_key_hash(key
);
506 fd_screen_lock(screen
);
508 struct hash_entry
*entry
=
509 _mesa_hash_table_search_pre_hashed(cache
->ht
, hash
, key
);
515 /* limit the # of cached gmem states, discarding the least
516 * recently used state if needed:
518 if (cache
->ht
->entries
>= 20) {
519 struct fd_gmem_stateobj
*last
=
520 list_last_entry(&cache
->lru
, struct fd_gmem_stateobj
, node
);
521 fd_gmem_reference(&last
, NULL
);
524 entry
= _mesa_hash_table_insert_pre_hashed(cache
->ht
,
525 hash
, key
, gmem_stateobj_init(screen
, key
));
528 fd_gmem_reference(&gmem
, entry
->data
);
529 /* Move to the head of the LRU: */
530 list_delinit(&gmem
->node
);
531 list_add(&gmem
->node
, &cache
->lru
);
533 fd_screen_unlock(screen
);
543 render_tiles(struct fd_batch
*batch
, struct fd_gmem_stateobj
*gmem
)
545 struct fd_context
*ctx
= batch
->ctx
;
548 mtx_lock(&ctx
->gmem_lock
);
550 ctx
->emit_tile_init(batch
);
553 ctx
->stats
.batch_restore
++;
555 for (i
= 0; i
< (gmem
->nbins_x
* gmem
->nbins_y
); i
++) {
556 struct fd_tile
*tile
= &gmem
->tile
[i
];
558 fd_log(batch
, "bin_h=%d, yoff=%d, bin_w=%d, xoff=%d",
559 tile
->bin_h
, tile
->yoff
, tile
->bin_w
, tile
->xoff
);
561 ctx
->emit_tile_prep(batch
, tile
);
563 if (batch
->restore
) {
564 ctx
->emit_tile_mem2gmem(batch
, tile
);
567 ctx
->emit_tile_renderprep(batch
, tile
);
569 if (ctx
->query_prepare_tile
)
570 ctx
->query_prepare_tile(batch
, i
, batch
->gmem
);
572 /* emit IB to drawcmds: */
573 fd_log(batch
, "TILE[%d]: START DRAW IB", i
);
574 if (ctx
->emit_tile
) {
575 ctx
->emit_tile(batch
, tile
);
577 ctx
->screen
->emit_ib(batch
->gmem
, batch
->draw
);
579 fd_log(batch
, "TILE[%d]: END DRAW IB", i
);
582 /* emit gmem2mem to transfer tile back to system memory: */
583 ctx
->emit_tile_gmem2mem(batch
, tile
);
586 if (ctx
->emit_tile_fini
)
587 ctx
->emit_tile_fini(batch
);
589 mtx_unlock(&ctx
->gmem_lock
);
593 render_sysmem(struct fd_batch
*batch
)
595 struct fd_context
*ctx
= batch
->ctx
;
597 ctx
->emit_sysmem_prep(batch
);
599 if (ctx
->query_prepare_tile
)
600 ctx
->query_prepare_tile(batch
, 0, batch
->gmem
);
602 /* emit IB to drawcmds: */
603 fd_log(batch
, "SYSMEM: START DRAW IB");
604 ctx
->screen
->emit_ib(batch
->gmem
, batch
->draw
);
605 fd_log(batch
, "SYSMEM: END DRAW IB");
608 if (ctx
->emit_sysmem_fini
)
609 ctx
->emit_sysmem_fini(batch
);
613 flush_ring(struct fd_batch
*batch
)
616 int out_fence_fd
= -1;
618 if (unlikely(fd_mesa_debug
& FD_DBG_NOHW
))
621 fd_submit_flush(batch
->submit
, batch
->in_fence_fd
,
622 batch
->needs_out_fence_fd
? &out_fence_fd
: NULL
,
625 fd_fence_populate(batch
->fence
, timestamp
, out_fence_fd
);
630 fd_gmem_render_tiles(struct fd_batch
*batch
)
632 struct fd_context
*ctx
= batch
->ctx
;
633 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
636 if (ctx
->emit_sysmem_prep
&& !batch
->nondraw
) {
637 if (batch
->cleared
|| batch
->gmem_reason
||
638 ((batch
->num_draws
> 5) && !batch
->blit
) ||
639 (pfb
->samples
> 1)) {
640 fd_log(batch
, "GMEM: cleared=%x, gmem_reason=%x, num_draws=%u, samples=%u",
641 batch
->cleared
, batch
->gmem_reason
, batch
->num_draws
,
643 } else if (!(fd_mesa_debug
& FD_DBG_NOBYPASS
)) {
647 /* For ARB_framebuffer_no_attachments: */
648 if ((pfb
->nr_cbufs
== 0) && !pfb
->zsbuf
) {
653 if (fd_mesa_debug
& FD_DBG_NOGMEM
)
656 /* Layered rendering always needs bypass. */
657 for (unsigned i
= 0; i
< pfb
->nr_cbufs
; i
++) {
658 struct pipe_surface
*psurf
= pfb
->cbufs
[i
];
661 if (psurf
->u
.tex
.first_layer
< psurf
->u
.tex
.last_layer
)
665 /* Tessellation doesn't seem to support tiled rendering so fall back to
668 if (batch
->tessellation
) {
669 debug_assert(ctx
->emit_sysmem_prep
);
675 ctx
->stats
.batch_total
++;
677 if (unlikely(fd_mesa_debug
& FD_DBG_LOG
) && !batch
->nondraw
) {
678 fd_log_stream(batch
, stream
, util_dump_framebuffer_state(stream
, pfb
));
679 for (unsigned i
= 0; i
< pfb
->nr_cbufs
; i
++) {
680 fd_log_stream(batch
, stream
, util_dump_surface(stream
, pfb
->cbufs
[i
]));
682 fd_log_stream(batch
, stream
, util_dump_surface(stream
, pfb
->zsbuf
));
685 if (batch
->nondraw
) {
686 DBG("%p: rendering non-draw", batch
);
687 ctx
->stats
.batch_nondraw
++;
689 fd_log(batch
, "%p: rendering sysmem %ux%u (%s/%s), num_draws=%u",
690 batch
, pfb
->width
, pfb
->height
,
691 util_format_short_name(pipe_surface_format(pfb
->cbufs
[0])),
692 util_format_short_name(pipe_surface_format(pfb
->zsbuf
)),
694 if (ctx
->query_prepare
)
695 ctx
->query_prepare(batch
, 1);
696 render_sysmem(batch
);
697 ctx
->stats
.batch_sysmem
++;
699 struct fd_gmem_stateobj
*gmem
= lookup_gmem_state(batch
, false, false);
700 batch
->gmem_state
= gmem
;
701 fd_log(batch
, "%p: rendering %dx%d tiles %ux%u (%s/%s)",
702 batch
, pfb
->width
, pfb
->height
, gmem
->nbins_x
, gmem
->nbins_y
,
703 util_format_short_name(pipe_surface_format(pfb
->cbufs
[0])),
704 util_format_short_name(pipe_surface_format(pfb
->zsbuf
)));
705 if (ctx
->query_prepare
)
706 ctx
->query_prepare(batch
, gmem
->nbins_x
* gmem
->nbins_y
);
707 render_tiles(batch
, gmem
);
708 batch
->gmem_state
= NULL
;
710 fd_screen_lock(ctx
->screen
);
711 fd_gmem_reference(&gmem
, NULL
);
712 fd_screen_unlock(ctx
->screen
);
714 ctx
->stats
.batch_gmem
++;
720 /* Determine a worst-case estimate (ie. assuming we don't eliminate an
721 * unused depth/stencil) number of bins per vsc pipe.
724 fd_gmem_estimate_bins_per_pipe(struct fd_batch
*batch
)
726 struct pipe_framebuffer_state
*pfb
= &batch
->framebuffer
;
727 struct fd_screen
*screen
= batch
->ctx
->screen
;
728 struct fd_gmem_stateobj
*gmem
= lookup_gmem_state(batch
, !!pfb
->zsbuf
, true);
729 unsigned nbins
= gmem
->maxpw
* gmem
->maxph
;
731 fd_screen_lock(screen
);
732 fd_gmem_reference(&gmem
, NULL
);
733 fd_screen_unlock(screen
);
738 /* When deciding whether a tile needs mem2gmem, we need to take into
739 * account the scissor rect(s) that were cleared. To simplify we only
740 * consider the last scissor rect for each buffer, since the common
741 * case would be a single clear.
744 fd_gmem_needs_restore(struct fd_batch
*batch
, const struct fd_tile
*tile
,
747 if (!(batch
->restore
& buffers
))
754 fd_gmem_screen_init(struct pipe_screen
*pscreen
)
756 struct fd_gmem_cache
*cache
= &fd_screen(pscreen
)->gmem_cache
;
758 cache
->ht
= _mesa_hash_table_create(NULL
, gmem_key_hash
, gmem_key_equals
);
759 list_inithead(&cache
->lru
);
763 fd_gmem_screen_fini(struct pipe_screen
*pscreen
)
765 struct fd_gmem_cache
*cache
= &fd_screen(pscreen
)->gmem_cache
;
767 _mesa_hash_table_destroy(cache
->ht
, NULL
);