• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CACHE_H_
28 #define FREEDRENO_BATCH_CACHE_H_
29 
30 #include "pipe/p_state.h"
31 
32 #include "freedreno_util.h"
33 
34 struct fd_resource;
35 struct fd_batch;
36 struct fd_context;
37 struct fd_screen;
38 
39 struct hash_table;
40 
41 struct fd_batch_cache {
42    struct hash_table *ht;
43    unsigned cnt;
44 
45    /* set of active batches.. there is an upper limit on the number of
46     * in-flight batches, for two reasons:
47     * 1) to avoid big spikes in number of batches in edge cases, such as
48     *    game startup (ie, lots of texture uploads, but no usages yet of
49     *    the textures), etc.
50     * 2) so we can use a simple bitmask in fd_resource to track which
51     *    batches have reference to the resource
52     */
53    struct fd_batch *batches[32];
54    uint32_t batch_mask;
55 };
56 
57 /* note: if batches get unref'd in the body of the loop, they are removed
58  * from the various masks.. but since we copy the mask at the beginning of
59  * the loop into _m, we need the &= at the end of the loop to make sure
60  * we don't have stale bits in _m
61  */
62 #define foreach_batch(batch, cache, mask)                                      \
63    for (uint32_t _m = (mask);                                                  \
64         _m && ((batch) = (cache)->batches[u_bit_scan(&_m)]); _m &= (mask))
65 
66 void fd_bc_init(struct fd_batch_cache *cache);
67 void fd_bc_fini(struct fd_batch_cache *cache);
68 
69 void fd_bc_flush(struct fd_context *ctx, bool deferred) assert_dt;
70 void fd_bc_flush_writer(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
71 void fd_bc_flush_readers(struct fd_context *ctx, struct fd_resource *rsc) assert_dt;
72 void fd_bc_dump(struct fd_context *ctx, const char *fmt, ...)
73    _util_printf_format(2, 3);
74 
75 void fd_bc_invalidate_batch(struct fd_batch *batch, bool destroy);
76 void fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy);
77 struct fd_batch *fd_bc_alloc_batch(struct fd_context *ctx,
78                                    bool nondraw) assert_dt;
79 
80 struct fd_batch *
81 fd_batch_from_fb(struct fd_context *ctx,
82                  const struct pipe_framebuffer_state *pfb) assert_dt;
83 
84 #endif /* FREEDRENO_BATCH_CACHE_H_ */
85