freedreno: drop mem2gmem/gmem2mem query stages
[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 #include "util/u_queue.h"
32 #include "util/list.h"
33
34 #include "freedreno_util.h"
35
36 struct fd_context;
37 struct fd_resource;
38 enum fd_resource_status;
39
40 /* Bitmask of stages in rendering that a particular query query is
41 * active. Queries will be automatically started/stopped (generating
42 * additional fd_hw_sample_period's) on entrance/exit from stages that
43 * are applicable to the query.
44 *
45 * NOTE: set the stage to NULL at end of IB to ensure no query is still
46 * active. Things aren't going to work out the way you want if a query
47 * is active across IB's (or between tile IB and draw IB)
48 */
49 enum fd_render_stage {
50 FD_STAGE_NULL = 0x01,
51 FD_STAGE_DRAW = 0x02,
52 FD_STAGE_CLEAR = 0x04,
53 /* used for driver internal draws (ie. util_blitter_blit()): */
54 FD_STAGE_BLIT = 0x08,
55 FD_STAGE_ALL = 0xff,
56 };
57
58 #define MAX_HW_SAMPLE_PROVIDERS 4
59 struct fd_hw_sample_provider;
60 struct fd_hw_sample;
61
62 /* A batch tracks everything about a cmdstream batch/submit, including the
63 * ringbuffers used for binning, draw, and gmem cmds, list of associated
64 * fd_resource-s, etc.
65 */
66 struct fd_batch {
67 struct pipe_reference reference;
68 unsigned seqno;
69 unsigned idx;
70
71 struct fd_context *ctx;
72
73 struct util_queue_fence flush_fence;
74
75 /* do we need to mem2gmem before rendering. We don't, if for example,
76 * there was a glClear() that invalidated the entire previous buffer
77 * contents. Keep track of which buffer(s) are cleared, or needs
78 * restore. Masks of PIPE_CLEAR_*
79 *
80 * The 'cleared' bits will be set for buffers which are *entirely*
81 * cleared, and 'partial_cleared' bits will be set if you must
82 * check cleared_scissor.
83 */
84 enum {
85 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
86 FD_BUFFER_COLOR = PIPE_CLEAR_COLOR,
87 FD_BUFFER_DEPTH = PIPE_CLEAR_DEPTH,
88 FD_BUFFER_STENCIL = PIPE_CLEAR_STENCIL,
89 FD_BUFFER_ALL = FD_BUFFER_COLOR | FD_BUFFER_DEPTH | FD_BUFFER_STENCIL,
90 } cleared, partial_cleared, restore, resolve;
91
92 bool needs_flush : 1;
93 bool blit : 1;
94 bool back_blit : 1; /* only blit so far is resource shadowing back-blit */
95
96 /* To decide whether to render to system memory, keep track of the
97 * number of draws, and whether any of them require multisample,
98 * depth_test (or depth write), stencil_test, blending, and
99 * color_logic_Op (since those functions are disabled when by-
100 * passing GMEM.
101 */
102 enum {
103 FD_GMEM_CLEARS_DEPTH_STENCIL = 0x01,
104 FD_GMEM_DEPTH_ENABLED = 0x02,
105 FD_GMEM_STENCIL_ENABLED = 0x04,
106
107 FD_GMEM_MSAA_ENABLED = 0x08,
108 FD_GMEM_BLEND_ENABLED = 0x10,
109 FD_GMEM_LOGICOP_ENABLED = 0x20,
110 } gmem_reason;
111 unsigned num_draws; /* number of draws in current batch */
112
113 /* Track the maximal bounds of the scissor of all the draws within a
114 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
115 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
116 */
117 struct pipe_scissor_state max_scissor;
118
119 /* Track the cleared scissor for color/depth/stencil, so we know
120 * which, if any, tiles need to be restored (mem2gmem). Only valid
121 * if the corresponding bit in ctx->cleared is set.
122 */
123 struct {
124 struct pipe_scissor_state color, depth, stencil;
125 } cleared_scissor;
126
127 /* Keep track of DRAW initiators that need to be patched up depending
128 * on whether we using binning or not:
129 */
130 struct util_dynarray draw_patches;
131
132 /* Keep track of writes to RB_RENDER_CONTROL which need to be patched
133 * once we know whether or not to use GMEM, and GMEM tile pitch.
134 *
135 * (only for a3xx.. but having gen specific subclasses of fd_batch
136 * seemed overkill for now)
137 */
138 struct util_dynarray rbrc_patches;
139
140 struct pipe_framebuffer_state framebuffer;
141
142 /** draw pass cmdstream: */
143 struct fd_ringbuffer *draw;
144 /** binning pass cmdstream: */
145 struct fd_ringbuffer *binning;
146 /** tiling/gmem (IB0) cmdstream: */
147 struct fd_ringbuffer *gmem;
148
149 /**
150 * hw query related state:
151 */
152 /*@{*/
153 /* next sample offset.. incremented for each sample in the batch/
154 * submit, reset to zero on next submit.
155 */
156 uint32_t next_sample_offset;
157
158 /* cached samples (in case multiple queries need to reference
159 * the same sample snapshot)
160 */
161 struct fd_hw_sample *sample_cache[MAX_HW_SAMPLE_PROVIDERS];
162
163 /* which sample providers were active in the current batch: */
164 uint32_t active_providers;
165
166 /* tracking for current stage, to know when to start/stop
167 * any active queries:
168 */
169 enum fd_render_stage stage;
170
171 /* list of samples in current batch: */
172 struct util_dynarray samples;
173
174 /* current query result bo and tile stride: */
175 struct pipe_resource *query_buf;
176 uint32_t query_tile_stride;
177 /*@}*/
178
179
180 /* Set of resources used by currently-unsubmitted batch (read or
181 * write).. does not hold a reference to the resource.
182 */
183 struct set *resources;
184
185 /** key in batch-cache (if not null): */
186 const void *key;
187 uint32_t hash;
188
189 /** set of dependent batches.. holds refs to dependent batches: */
190 uint32_t dependents_mask;
191 };
192
193 struct fd_batch * fd_batch_create(struct fd_context *ctx);
194
195 void fd_batch_reset(struct fd_batch *batch);
196 void fd_batch_sync(struct fd_batch *batch);
197 void fd_batch_flush(struct fd_batch *batch, bool sync);
198 void fd_batch_resource_used(struct fd_batch *batch, struct fd_resource *rsc, bool write);
199 void fd_batch_check_size(struct fd_batch *batch);
200
201 /* not called directly: */
202 void __fd_batch_describe(char* buf, const struct fd_batch *batch);
203 void __fd_batch_destroy(struct fd_batch *batch);
204
205 static inline void
206 fd_batch_reference(struct fd_batch **ptr, struct fd_batch *batch)
207 {
208 struct fd_batch *old_batch = *ptr;
209 if (pipe_reference_described(&(*ptr)->reference, &batch->reference,
210 (debug_reference_descriptor)__fd_batch_describe))
211 __fd_batch_destroy(old_batch);
212 *ptr = batch;
213 }
214
215 #endif /* FREEDRENO_BATCH_H_ */