freedreno: move more batch related tracking to fd_batch
[mesa.git] / src / gallium / drivers / freedreno / freedreno_batch.h
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 #ifndef FREEDRENO_BATCH_H_
28 #define FREEDRENO_BATCH_H_
29
30 #include "util/u_inlines.h"
31
32 #include "freedreno_util.h"
33
34 struct fd_context;
35 struct fd_resource;
36 enum fd_resource_status;
37
38 /* A batch tracks everything about a cmdstream batch/submit, including the
39 * ringbuffers used for binning, draw, and gmem cmds, list of associated
40 * fd_resource-s, etc.
41 */
42 struct fd_batch {
43 struct pipe_reference reference;
44 unsigned seqno;
45
46 struct fd_context *ctx;
47
48 /* do we need to mem2gmem before rendering. We don't, if for example,
49 * there was a glClear() that invalidated the entire previous buffer
50 * contents. Keep track of which buffer(s) are cleared, or needs
51 * restore. Masks of PIPE_CLEAR_*
52 *
53 * The 'cleared' bits will be set for buffers which are *entirely*
54 * cleared, and 'partial_cleared' bits will be set if you must
55 * check cleared_scissor.
56 */
57 enum {
58 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
59 FD_BUFFER_COLOR = PIPE_CLEAR_COLOR,
60 FD_BUFFER_DEPTH = PIPE_CLEAR_DEPTH,
61 FD_BUFFER_STENCIL = PIPE_CLEAR_STENCIL,
62 FD_BUFFER_ALL = FD_BUFFER_COLOR | FD_BUFFER_DEPTH | FD_BUFFER_STENCIL,
63 } cleared, partial_cleared, restore, resolve;
64
65 bool needs_flush;
66
67 /* To decide whether to render to system memory, keep track of the
68 * number of draws, and whether any of them require multisample,
69 * depth_test (or depth write), stencil_test, blending, and
70 * color_logic_Op (since those functions are disabled when by-
71 * passing GMEM.
72 */
73 enum {
74 FD_GMEM_CLEARS_DEPTH_STENCIL = 0x01,
75 FD_GMEM_DEPTH_ENABLED = 0x02,
76 FD_GMEM_STENCIL_ENABLED = 0x04,
77
78 FD_GMEM_MSAA_ENABLED = 0x08,
79 FD_GMEM_BLEND_ENABLED = 0x10,
80 FD_GMEM_LOGICOP_ENABLED = 0x20,
81 } gmem_reason;
82 unsigned num_draws; /* number of draws in current batch */
83
84 /* Track the maximal bounds of the scissor of all the draws within a
85 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
86 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
87 */
88 struct pipe_scissor_state max_scissor;
89
90 /* Track the cleared scissor for color/depth/stencil, so we know
91 * which, if any, tiles need to be restored (mem2gmem). Only valid
92 * if the corresponding bit in ctx->cleared is set.
93 */
94 struct {
95 struct pipe_scissor_state color, depth, stencil;
96 } cleared_scissor;
97
98 /* Keep track of DRAW initiators that need to be patched up depending
99 * on whether we using binning or not:
100 */
101 struct util_dynarray draw_patches;
102
103 /* Keep track of writes to RB_RENDER_CONTROL which need to be patched
104 * once we know whether or not to use GMEM, and GMEM tile pitch.
105 *
106 * (only for a3xx.. but having gen specific subclasses of fd_batch
107 * seemed overkill for now)
108 */
109 struct util_dynarray rbrc_patches;
110
111 struct pipe_framebuffer_state framebuffer;
112
113 /** draw pass cmdstream: */
114 struct fd_ringbuffer *draw;
115 /** binning pass cmdstream: */
116 struct fd_ringbuffer *binning;
117 /** tiling/gmem (IB0) cmdstream: */
118 struct fd_ringbuffer *gmem;
119
120 /** list of resources used by currently-unsubmitted batch */
121 struct list_head used_resources;
122 };
123
124 struct fd_batch * fd_batch_create(struct fd_context *ctx);
125
126 void fd_batch_flush(struct fd_batch *batch);
127 void fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc,
128 enum fd_resource_status status);
129 void fd_batch_check_size(struct fd_batch *batch);
130
131 /* not called directly: */
132 void __fd_batch_describe(char* buf, const struct fd_batch *batch);
133 void __fd_batch_destroy(struct fd_batch *batch);
134
135 static inline void
136 fd_batch_reference(struct fd_batch **ptr, struct fd_batch *batch)
137 {
138 struct fd_batch *old_batch = *ptr;
139 if (pipe_reference_described(&(*ptr)->reference, &batch->reference,
140 (debug_reference_descriptor)__fd_batch_describe))
141 __fd_batch_destroy(old_batch);
142 *ptr = batch;
143 }
144
145 #endif /* FREEDRENO_BATCH_H_ */