1 /*
2 * Copyright 2018 Collabora Ltd.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef ZINK_BATCH_H
25 #define ZINK_BATCH_H
26
27 #include <vulkan/vulkan_core.h>
28 #include "zink_types.h"
29
30 #include "util/list.h"
31 #include "util/set.h"
32 #include "util/u_dynarray.h"
33
34 #include "zink_fence.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40
41 void
42 zink_reset_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
43
44 void
45 zink_clear_batch_state(struct zink_context *ctx, struct zink_batch_state *bs);
46
47 void
48 zink_batch_reset_all(struct zink_context *ctx);
49
50 void
51 zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs);
52
53 void
54 zink_batch_state_clear_resources(struct zink_screen *screen, struct zink_batch_state *bs);
55
56 void
57 zink_reset_batch(struct zink_context *ctx);
58 void
59 zink_start_batch(struct zink_context *ctx);
60
61 void
62 zink_end_batch(struct zink_context *ctx);
63
64 void
65 zink_batch_reference_resource_rw(struct zink_context *ctx,
66 struct zink_resource *res,
67 bool write);
68 void
69 zink_batch_reference_resource(struct zink_context *ctx, struct zink_resource *res);
70
71 bool
72 zink_batch_reference_resource_move(struct zink_context *ctx, struct zink_resource *res);
73
74 void
75 zink_batch_reference_program(struct zink_context *ctx,
76 struct zink_program *pg);
77
78 void
79 zink_batch_bind_db(struct zink_context *ctx);
80 void
81 debug_describe_zink_batch_state(char *buf, const struct zink_batch_state *ptr);
82
83 static ALWAYS_INLINE bool
zink_batch_usage_is_unflushed(const struct zink_batch_usage * u)84 zink_batch_usage_is_unflushed(const struct zink_batch_usage *u)
85 {
86 return u && u->unflushed;
87 }
88
89 static ALWAYS_INLINE void
zink_batch_usage_unset(struct zink_batch_usage ** u,struct zink_batch_state * bs)90 zink_batch_usage_unset(struct zink_batch_usage **u, struct zink_batch_state *bs)
91 {
92 (void)p_atomic_cmpxchg((uintptr_t *)u, (uintptr_t)&bs->usage, (uintptr_t)NULL);
93 }
94
95 static ALWAYS_INLINE void
zink_batch_usage_set(struct zink_batch_usage ** u,struct zink_batch_state * bs)96 zink_batch_usage_set(struct zink_batch_usage **u, struct zink_batch_state *bs)
97 {
98 *u = &bs->usage;
99 }
100
101 static ALWAYS_INLINE bool
zink_batch_usage_matches(const struct zink_batch_usage * u,const struct zink_batch_state * bs)102 zink_batch_usage_matches(const struct zink_batch_usage *u, const struct zink_batch_state *bs)
103 {
104 return u == &bs->usage;
105 }
106
107 static ALWAYS_INLINE bool
zink_batch_usage_exists(const struct zink_batch_usage * u)108 zink_batch_usage_exists(const struct zink_batch_usage *u)
109 {
110 return u && (u->usage || u->unflushed);
111 }
112
113 bool
114 zink_screen_usage_check_completion(struct zink_screen *screen, const struct zink_batch_usage *u);
115 bool
116 zink_screen_usage_check_completion_fast(struct zink_screen *screen, const struct zink_batch_usage *u);
117
118 bool
119 zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);
120
121 void
122 zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u);
123
124 void
125 zink_batch_usage_try_wait(struct zink_context *ctx, struct zink_batch_usage *u);
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif
132