freedreno: introduce fd_batch
[mesa.git] / src / gallium / drivers / freedreno / freedreno_batch.c
1 /*
2 * Copyright (C) 2016 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_string.h"
28
29 #include "freedreno_batch.h"
30 #include "freedreno_context.h"
31
32 struct fd_batch *
33 fd_batch_create(struct fd_context *ctx)
34 {
35 struct fd_batch *batch = CALLOC_STRUCT(fd_batch);
36 static unsigned seqno = 0;
37
38 if (!batch)
39 return NULL;
40
41 pipe_reference_init(&batch->reference, 1);
42 batch->seqno = ++seqno;
43 batch->ctx = ctx;
44
45 /* TODO how to pick a good size? Or maybe we should introduce
46 * fd_ringlist? Also, make sure size is aligned with bo-cache
47 * bucket size, since otherwise that will round up size..
48 */
49 batch->draw = fd_ringbuffer_new(ctx->screen->pipe, 0x10000);
50 batch->binning = fd_ringbuffer_new(ctx->screen->pipe, 0x10000);
51 batch->gmem = fd_ringbuffer_new(ctx->screen->pipe, 0x10000);
52
53 fd_ringbuffer_set_parent(batch->gmem, NULL);
54 fd_ringbuffer_set_parent(batch->draw, batch->gmem);
55 fd_ringbuffer_set_parent(batch->binning, batch->gmem);
56
57 return batch;
58 }
59
60 void
61 __fd_batch_destroy(struct fd_batch *batch)
62 {
63 fd_ringbuffer_del(batch->draw);
64 fd_ringbuffer_del(batch->binning);
65 fd_ringbuffer_del(batch->gmem);
66
67 free(batch);
68 }
69
70 void
71 __fd_batch_describe(char* buf, const struct fd_batch *batch)
72 {
73 util_sprintf(buf, "fd_batch<%u>", batch->seqno);
74 }
75
76 void
77 fd_batch_flush(struct fd_batch *batch)
78 {
79 fd_gmem_render_tiles(batch->ctx);
80 }
81
82 void
83 fd_batch_check_size(struct fd_batch *batch)
84 {
85 /* TODO eventually support having a list of draw/binning rb's
86 * and if we are too close to the end, add another to the
87 * list. For now we just flush.
88 */
89 struct fd_ringbuffer *ring = batch->draw;
90 if (((ring->cur - ring->start) > (ring->size/4 - 0x1000)) ||
91 (fd_mesa_debug & FD_DBG_FLUSH))
92 fd_context_render(&batch->ctx->base);
93 }