xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/freedreno/freedreno_batch_cache.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2016 Rob Clark <[email protected]>
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Rob Clark <[email protected]>
7  */
8 
9 #ifndef FREEDRENO_BATCH_CACHE_H_
10 #define FREEDRENO_BATCH_CACHE_H_
11 
12 #include "pipe/p_state.h"
13 
14 #include "freedreno_util.h"
15 
16 BEGINC;
17 
18 struct fd_resource;
19 struct fd_batch;
20 struct fd_context;
21 struct fd_screen;
22 
23 struct hash_table;
24 
25 struct fd_batch_cache {
26    struct hash_table *ht;
27    seqno_t cnt;
28 
29    /* set of active batches.. there is an upper limit on the number of
30     * in-flight batches, for two reasons:
31     * 1) to avoid big spikes in number of batches in edge cases, such as
32     *    game startup (ie, lots of texture uploads, but no usages yet of
33     *    the textures), etc.
34     * 2) so we can use a simple bitmask in fd_resource to track which
35     *    batches have reference to the resource
36     */
37    struct fd_batch *batches[32];
38    uint32_t batch_mask;
39 };
40 
41 /* note: if batches get unref'd in the body of the loop, they are removed
42  * from the various masks.. but since we copy the mask at the beginning of
43  * the loop into _m, we need the &= at the end of the loop to make sure
44  * we don't have stale bits in _m
45  */
46 #define foreach_batch(batch, cache, mask)                                      \
47    for (uint32_t _m = (mask);                                                  \
48         _m && ((batch) = (cache)->batches[u_bit_scan(&_m)]); _m &= (mask))
49 
50 void fd_bc_init(struct fd_batch_cache *cache);
51 void fd_bc_fini(struct fd_batch_cache *cache);
52 
53 struct fd_batch *fd_bc_last_batch(struct fd_context *ctx) assert_dt;
54 void fd_bc_add_flush_deps(struct fd_context *ctx, struct fd_batch *last_batch) assert_dt;
55 void fd_bc_flush_writer(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
56 void fd_bc_flush_readers(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
57 void fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
58    _util_printf_format(2, 3);
59 
60 void fd_bc_invalidate_batch(struct fd_batch *batch, bool destroy);
61 void fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy);
62 struct fd_batch *fd_bc_alloc_batch(struct fd_context *ctx,
63                                    bool nondraw) assert_dt;
64 
65 struct fd_batch *
66 fd_batch_from_fb(struct fd_context *ctx,
67                  const struct pipe_framebuffer_state *pfb) assert_dt;
68 
69 ENDC;
70 
71 #endif /* FREEDRENO_BATCH_CACHE_H_ */
72