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/list.h"
28 #include "util/u_string.h"
30 #include "freedreno_batch.h"
31 #include "freedreno_context.h"
32 #include "freedreno_resource.h"
35 fd_batch_create(struct fd_context
*ctx
)
37 struct fd_batch
*batch
= CALLOC_STRUCT(fd_batch
);
38 static unsigned seqno
= 0;
44 pipe_reference_init(&batch
->reference
, 1);
45 batch
->seqno
= ++seqno
;
48 /* if kernel is too old to support unlimited # of cmd buffers, we
49 * have no option but to allocate large worst-case sizes so that
50 * we don't need to grow the ringbuffer. Performance is likely to
51 * suffer, but there is no good alternative.
53 if (fd_device_version(ctx
->screen
->dev
) < FD_VERSION_UNLIMITED_CMDS
) {
57 batch
->draw
= fd_ringbuffer_new(ctx
->screen
->pipe
, size
);
58 batch
->binning
= fd_ringbuffer_new(ctx
->screen
->pipe
, size
);
59 batch
->gmem
= fd_ringbuffer_new(ctx
->screen
->pipe
, size
);
61 fd_ringbuffer_set_parent(batch
->gmem
, NULL
);
62 fd_ringbuffer_set_parent(batch
->draw
, batch
->gmem
);
63 fd_ringbuffer_set_parent(batch
->binning
, batch
->gmem
);
65 list_inithead(&batch
->used_resources
);
67 /* reset maximal bounds: */
68 batch
->max_scissor
.minx
= batch
->max_scissor
.miny
= ~0;
69 batch
->max_scissor
.maxx
= batch
->max_scissor
.maxy
= 0;
71 util_dynarray_init(&batch
->draw_patches
);
73 if (is_a3xx(ctx
->screen
))
74 util_dynarray_init(&batch
->rbrc_patches
);
80 __fd_batch_destroy(struct fd_batch
*batch
)
82 util_copy_framebuffer_state(&batch
->framebuffer
, NULL
);
83 fd_ringbuffer_del(batch
->draw
);
84 fd_ringbuffer_del(batch
->binning
);
85 fd_ringbuffer_del(batch
->gmem
);
87 util_dynarray_fini(&batch
->draw_patches
);
89 if (is_a3xx(batch
->ctx
->screen
))
90 util_dynarray_fini(&batch
->rbrc_patches
);
96 __fd_batch_describe(char* buf
, const struct fd_batch
*batch
)
98 util_sprintf(buf
, "fd_batch<%u>", batch
->seqno
);
102 fd_batch_flush(struct fd_batch
*batch
)
104 struct fd_resource
*rsc
, *rsc_tmp
;
106 DBG("%p: needs_flush=%d", batch
, batch
->needs_flush
);
108 if (!batch
->needs_flush
)
111 fd_gmem_render_tiles(batch
);
113 /* go through all the used resources and clear their reading flag */
114 LIST_FOR_EACH_ENTRY_SAFE(rsc
, rsc_tmp
, &batch
->used_resources
, list
) {
115 debug_assert(rsc
->pending_batch
== batch
);
116 debug_assert(rsc
->status
!= 0);
118 fd_batch_reference(&rsc
->pending_batch
, NULL
);
119 list_delinit(&rsc
->list
);
122 assert(LIST_IS_EMPTY(&batch
->used_resources
));
126 fd_batch_resource_used(struct fd_batch
*batch
, struct fd_resource
*rsc
,
127 enum fd_resource_status status
)
129 rsc
->status
|= status
;
132 rsc
->stencil
->status
|= status
;
134 /* TODO resources can actually be shared across contexts,
135 * so I'm not sure a single list-head will do the trick?
137 debug_assert((rsc
->pending_batch
== batch
) || !rsc
->pending_batch
);
138 list_delinit(&rsc
->list
);
139 list_addtail(&rsc
->list
, &batch
->used_resources
);
140 fd_batch_reference(&rsc
->pending_batch
, batch
);
144 fd_batch_check_size(struct fd_batch
*batch
)
146 if (fd_device_version(batch
->ctx
->screen
->dev
) >= FD_VERSION_UNLIMITED_CMDS
)
149 struct fd_ringbuffer
*ring
= batch
->draw
;
150 if (((ring
->cur
- ring
->start
) > (ring
->size
/4 - 0x1000)) ||
151 (fd_mesa_debug
& FD_DBG_FLUSH
))
152 fd_context_render(&batch
->ctx
->base
);