summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/freedreno/freedreno_batch_cache.h
blob: 59e9d44253e347d0baad164af3ef6cf1a4124bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Rob Clark <robclark@freedesktop.org>
 */

#ifndef FREEDRENO_BATCH_CACHE_H_
#define FREEDRENO_BATCH_CACHE_H_

#include "pipe/p_state.h"

struct fd_resource;
struct fd_batch;
struct fd_context;
struct fd_screen;

struct hash_table;

struct fd_batch_cache {
	struct hash_table *ht;
	unsigned cnt;

	/* set of active batches.. there is an upper limit on the number of
	 * in-flight batches, for two reasons:
	 * 1) to avoid big spikes in number of batches in edge cases, such as
	 *    game startup (ie, lots of texture uploads, but no usages yet of
	 *    the textures), etc.
	 * 2) so we can use a simple bitmask in fd_resource to track which
	 *    batches have reference to the resource
	 */
	struct fd_batch *batches[32];
	uint32_t batch_mask;
};

/* note: if batches get unref'd in the body of the loop, they are removed
 * from the various masks.. but since we copy the mask at the beginning of
 * the loop into _m, we need the &= at the end of the loop to make sure
 * we don't have stale bits in _m
 */
#define foreach_batch(batch, cache, mask) \
	for (uint32_t _m = (mask); _m && ((batch) = (cache)->batches[u_bit_scan(&_m)]); _m &= (mask))

void fd_bc_init(struct fd_batch_cache *cache);
void fd_bc_fini(struct fd_batch_cache *cache);

void fd_bc_flush(struct fd_batch_cache *cache, struct fd_context *ctx);
void fd_bc_flush_deferred(struct fd_batch_cache *cache, struct fd_context *ctx);
void fd_bc_dump(struct fd_screen *screen, const char *fmt, ...)  _util_printf_format(2, 3);

void fd_bc_invalidate_context(struct fd_context *ctx);
void fd_bc_invalidate_batch(struct fd_batch *batch, bool destroy);
void fd_bc_invalidate_resource(struct fd_resource *rsc, bool destroy);
struct fd_batch * fd_bc_alloc_batch(struct fd_batch_cache *cache, struct fd_context *ctx, bool nondraw);

struct fd_batch * fd_batch_from_fb(struct fd_batch_cache *cache,
		struct fd_context *ctx, const struct pipe_framebuffer_state *pfb);

#endif /* FREEDRENO_BATCH_CACHE_H_ */