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 #ifndef FREEDRENO_BATCH_H_
28 #define FREEDRENO_BATCH_H_
30 #include "util/u_inlines.h"
31 #include "util/u_queue.h"
32 #include "util/list.h"
34 #include "freedreno_util.h"
38 enum fd_resource_status
;
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.
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)
49 enum fd_render_stage
{
52 FD_STAGE_CLEAR
= 0x04,
53 /* used for driver internal draws (ie. util_blitter_blit()): */
58 #define MAX_HW_SAMPLE_PROVIDERS 5
59 struct fd_hw_sample_provider
;
62 /* A batch tracks everything about a cmdstream batch/submit, including the
63 * ringbuffers used for binning, draw, and gmem cmds, list of associated
67 struct pipe_reference reference
;
69 unsigned idx
; /* index into cache->batches[] */
72 bool needs_out_fence_fd
;
73 struct pipe_fence_handle
*fence
;
75 struct fd_context
*ctx
;
77 struct util_queue_fence flush_fence
;
79 /* do we need to mem2gmem before rendering. We don't, if for example,
80 * there was a glClear() that invalidated the entire previous buffer
81 * contents. Keep track of which buffer(s) are cleared, or needs
82 * restore. Masks of PIPE_CLEAR_*
84 * The 'cleared' bits will be set for buffers which are *entirely*
85 * cleared, and 'partial_cleared' bits will be set if you must
86 * check cleared_scissor.
89 /* align bitmask values w/ PIPE_CLEAR_*.. since that is convenient.. */
90 FD_BUFFER_COLOR
= PIPE_CLEAR_COLOR
,
91 FD_BUFFER_DEPTH
= PIPE_CLEAR_DEPTH
,
92 FD_BUFFER_STENCIL
= PIPE_CLEAR_STENCIL
,
93 FD_BUFFER_ALL
= FD_BUFFER_COLOR
| FD_BUFFER_DEPTH
| FD_BUFFER_STENCIL
,
94 } cleared
, restore
, resolve
;
96 /* is this a non-draw batch (ie compute/blit which has no pfb state)? */
101 bool back_blit
: 1; /* only blit so far is resource shadowing back-blit */
103 /* Keep track if WAIT_FOR_IDLE is needed for registers we need
108 /* To decide whether to render to system memory, keep track of the
109 * number of draws, and whether any of them require multisample,
110 * depth_test (or depth write), stencil_test, blending, and
111 * color_logic_Op (since those functions are disabled when by-
115 FD_GMEM_CLEARS_DEPTH_STENCIL
= 0x01,
116 FD_GMEM_DEPTH_ENABLED
= 0x02,
117 FD_GMEM_STENCIL_ENABLED
= 0x04,
119 FD_GMEM_BLEND_ENABLED
= 0x10,
120 FD_GMEM_LOGICOP_ENABLED
= 0x20,
122 unsigned num_draws
; /* number of draws in current batch */
124 /* Track the maximal bounds of the scissor of all the draws within a
125 * batch. Used at the tile rendering step (fd_gmem_render_tiles(),
126 * mem2gmem/gmem2mem) to avoid needlessly moving data in/out of gmem.
128 struct pipe_scissor_state max_scissor
;
130 /* Keep track of DRAW initiators that need to be patched up depending
131 * on whether we using binning or not:
133 struct util_dynarray draw_patches
;
135 /* Keep track of blitter GMEM offsets that need to be patched up once we
136 * know the gmem layout:
138 struct util_dynarray gmem_patches
;
140 /* Keep track of writes to RB_RENDER_CONTROL which need to be patched
141 * once we know whether or not to use GMEM, and GMEM tile pitch.
143 * (only for a3xx.. but having gen specific subclasses of fd_batch
144 * seemed overkill for now)
146 struct util_dynarray rbrc_patches
;
148 struct pipe_framebuffer_state framebuffer
;
150 /** draw pass cmdstream: */
151 struct fd_ringbuffer
*draw
;
152 /** binning pass cmdstream: */
153 struct fd_ringbuffer
*binning
;
154 /** tiling/gmem (IB0) cmdstream: */
155 struct fd_ringbuffer
*gmem
;
157 // TODO maybe more generically split out clear and clear_binning rings?
158 struct fd_ringbuffer
*lrz_clear
;
161 * hw query related state:
164 /* next sample offset.. incremented for each sample in the batch/
165 * submit, reset to zero on next submit.
167 uint32_t next_sample_offset
;
169 /* cached samples (in case multiple queries need to reference
170 * the same sample snapshot)
172 struct fd_hw_sample
*sample_cache
[MAX_HW_SAMPLE_PROVIDERS
];
174 /* which sample providers were active in the current batch: */
175 uint32_t active_providers
;
177 /* tracking for current stage, to know when to start/stop
178 * any active queries:
180 enum fd_render_stage stage
;
182 /* list of samples in current batch: */
183 struct util_dynarray samples
;
185 /* current query result bo and tile stride: */
186 struct pipe_resource
*query_buf
;
187 uint32_t query_tile_stride
;
191 /* Set of resources used by currently-unsubmitted batch (read or
192 * write).. does not hold a reference to the resource.
194 struct set
*resources
;
196 /** key in batch-cache (if not null): */
200 /** set of dependent batches.. holds refs to dependent batches: */
201 uint32_t dependents_mask
;
204 struct fd_batch
* fd_batch_create(struct fd_context
*ctx
, bool nondraw
);
206 void fd_batch_reset(struct fd_batch
*batch
);
207 void fd_batch_sync(struct fd_batch
*batch
);
208 void fd_batch_flush(struct fd_batch
*batch
, bool sync
, bool force
);
209 void fd_batch_add_dep(struct fd_batch
*batch
, struct fd_batch
*dep
);
210 void fd_batch_resource_used(struct fd_batch
*batch
, struct fd_resource
*rsc
, bool write
);
211 void fd_batch_check_size(struct fd_batch
*batch
);
213 /* not called directly: */
214 void __fd_batch_describe(char* buf
, const struct fd_batch
*batch
);
215 void __fd_batch_destroy(struct fd_batch
*batch
);
218 * NOTE the rule is, you need to hold the screen->lock when destroying
219 * a batch.. so either use fd_batch_reference() (which grabs the lock
220 * for you) if you don't hold the lock, or fd_batch_reference_locked()
221 * if you do hold the lock.
223 * WARNING the _locked() version can briefly drop the lock. Without
224 * recursive mutexes, I'm not sure there is much else we can do (since
225 * __fd_batch_destroy() needs to unref resources)
228 /* fwd-decl prototypes to untangle header dependency :-/ */
229 static inline void fd_context_assert_locked(struct fd_context
*ctx
);
230 static inline void fd_context_lock(struct fd_context
*ctx
);
231 static inline void fd_context_unlock(struct fd_context
*ctx
);
234 fd_batch_reference_locked(struct fd_batch
**ptr
, struct fd_batch
*batch
)
236 struct fd_batch
*old_batch
= *ptr
;
238 /* only need lock if a reference is dropped: */
240 fd_context_assert_locked(old_batch
->ctx
);
242 if (pipe_reference_described(&(*ptr
)->reference
, &batch
->reference
,
243 (debug_reference_descriptor
)__fd_batch_describe
))
244 __fd_batch_destroy(old_batch
);
250 fd_batch_reference(struct fd_batch
**ptr
, struct fd_batch
*batch
)
252 struct fd_batch
*old_batch
= *ptr
;
253 struct fd_context
*ctx
= old_batch
? old_batch
->ctx
: NULL
;
256 fd_context_lock(ctx
);
258 fd_batch_reference_locked(ptr
, batch
);
261 fd_context_unlock(ctx
);
264 #include "freedreno_context.h"
267 fd_reset_wfi(struct fd_batch
*batch
)
269 batch
->needs_wfi
= true;
272 void fd_wfi(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
);
274 /* emit a CP_EVENT_WRITE:
277 fd_event_write(struct fd_batch
*batch
, struct fd_ringbuffer
*ring
,
278 enum vgt_event_type evt
)
280 OUT_PKT3(ring
, CP_EVENT_WRITE
, 1);
285 #endif /* FREEDRENO_BATCH_H_ */