2 * Copyright (C) 2016 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 "util/u_string.h"
29 #include "freedreno_batch.h"
30 #include "freedreno_context.h"
33 fd_batch_create(struct fd_context
*ctx
)
35 struct fd_batch
*batch
= CALLOC_STRUCT(fd_batch
);
36 static unsigned seqno
= 0;
41 pipe_reference_init(&batch
->reference
, 1);
42 batch
->seqno
= ++seqno
;
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..
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);
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
);
61 __fd_batch_destroy(struct fd_batch
*batch
)
63 fd_ringbuffer_del(batch
->draw
);
64 fd_ringbuffer_del(batch
->binning
);
65 fd_ringbuffer_del(batch
->gmem
);
71 __fd_batch_describe(char* buf
, const struct fd_batch
*batch
)
73 util_sprintf(buf
, "fd_batch<%u>", batch
->seqno
);
77 fd_batch_flush(struct fd_batch
*batch
)
79 fd_gmem_render_tiles(batch
->ctx
);
83 fd_batch_check_size(struct fd_batch
*batch
)
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.
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
);