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
);
71 __fd_batch_destroy(struct fd_batch
*batch
)
73 fd_ringbuffer_del(batch
->draw
);
74 fd_ringbuffer_del(batch
->binning
);
75 fd_ringbuffer_del(batch
->gmem
);
81 __fd_batch_describe(char* buf
, const struct fd_batch
*batch
)
83 util_sprintf(buf
, "fd_batch<%u>", batch
->seqno
);
87 fd_batch_flush(struct fd_batch
*batch
)
89 struct fd_resource
*rsc
, *rsc_tmp
;
91 fd_gmem_render_tiles(batch
->ctx
);
93 /* go through all the used resources and clear their reading flag */
94 LIST_FOR_EACH_ENTRY_SAFE(rsc
, rsc_tmp
, &batch
->used_resources
, list
) {
95 debug_assert(rsc
->pending_batch
== batch
);
96 debug_assert(rsc
->status
!= 0);
98 fd_batch_reference(&rsc
->pending_batch
, NULL
);
99 list_delinit(&rsc
->list
);
102 assert(LIST_IS_EMPTY(&batch
->used_resources
));
106 fd_batch_resource_used(struct fd_batch
*batch
, struct fd_resource
*rsc
,
107 enum fd_resource_status status
)
109 rsc
->status
|= status
;
112 rsc
->stencil
->status
|= status
;
114 /* TODO resources can actually be shared across contexts,
115 * so I'm not sure a single list-head will do the trick?
117 debug_assert((rsc
->pending_batch
== batch
) || !rsc
->pending_batch
);
118 list_delinit(&rsc
->list
);
119 list_addtail(&rsc
->list
, &batch
->used_resources
);
120 fd_batch_reference(&rsc
->pending_batch
, batch
);
124 fd_batch_check_size(struct fd_batch
*batch
)
126 if (fd_device_version(batch
->ctx
->screen
->dev
) >= FD_VERSION_UNLIMITED_CMDS
)
129 struct fd_ringbuffer
*ring
= batch
->draw
;
130 if (((ring
->cur
- ring
->start
) > (ring
->size
/4 - 0x1000)) ||
131 (fd_mesa_debug
& FD_DBG_FLUSH
))
132 fd_context_render(&batch
->ctx
->base
);