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_RESOURCE_H
25 #define ZINK_RESOURCE_H
26
27 #include "zink_types.h"
28
29 #define ZINK_MAP_TEMPORARY (PIPE_MAP_DRV_PRV << 0)
30 #define ZINK_BIND_DESCRIPTOR (1u << 27)
31 #define ZINK_BIND_MUTABLE (1u << 28)
32 #define ZINK_BIND_DMABUF (1u << 29)
33 #define ZINK_BIND_TRANSIENT (1u << 30) //transient fb attachment
34 #define ZINK_BIND_VIDEO (1u << 31)
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 bool
41 zink_screen_resource_init(struct pipe_screen *pscreen);
42
43 void
44 zink_context_resource_init(struct pipe_context *pctx);
45 void
46 zink_screen_buffer_unmap(struct pipe_screen *pscreen, struct pipe_transfer *ptrans);
47 void
48 zink_get_depth_stencil_resources(struct pipe_resource *res,
49 struct zink_resource **out_z,
50 struct zink_resource **out_s);
51 VkMappedMemoryRange
52 zink_resource_init_mem_range(struct zink_screen *screen, struct zink_resource_object *obj, VkDeviceSize offset, VkDeviceSize size);
53 void
54 zink_resource_setup_transfer_layouts(struct zink_context *ctx, struct zink_resource *src, struct zink_resource *dst);
55
56 void
57 zink_destroy_resource_object(struct zink_screen *screen, struct zink_resource_object *resource_object);
58
59 void
60 debug_describe_zink_resource_object(char *buf, const struct zink_resource_object *ptr);
61
62 static inline void
zink_resource_object_reference(struct zink_screen * screen,struct zink_resource_object ** dst,struct zink_resource_object * src)63 zink_resource_object_reference(struct zink_screen *screen,
64 struct zink_resource_object **dst,
65 struct zink_resource_object *src)
66 {
67 struct zink_resource_object *old_dst = dst ? *dst : NULL;
68
69 if (pipe_reference_described(old_dst ? &old_dst->reference : NULL, &src->reference,
70 (debug_reference_descriptor)debug_describe_zink_resource_object))
71 zink_destroy_resource_object(screen, old_dst);
72 if (dst) *dst = src;
73 }
74
75 bool
76 zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource *res);
77 bool
78 zink_resource_object_init_mutable(struct zink_context *ctx, struct zink_resource *res);
79
80 VkDeviceAddress
81 zink_resource_get_address(struct zink_screen *screen, struct zink_resource *res);
82
83 static ALWAYS_INLINE bool
zink_resource_has_binds(const struct zink_resource * res)84 zink_resource_has_binds(const struct zink_resource *res)
85 {
86 return res->all_binds > 0;
87 }
88
89 static ALWAYS_INLINE bool
zink_is_swapchain(const struct zink_resource * res)90 zink_is_swapchain(const struct zink_resource *res)
91 {
92 return res->swapchain;
93 }
94
95 bool
96 zink_resource_copy_box_intersects(struct zink_resource *res, unsigned level, const struct pipe_box *box);
97 void
98 zink_resource_copy_box_add(struct zink_context *ctx, struct zink_resource *res, unsigned level, const struct pipe_box *box);
99 void
100 zink_resource_copies_reset(struct zink_resource *res);
101
102 #include "zink_batch.h"
103 #include "zink_bo.h"
104 #include "zink_kopper.h"
105
106 static inline bool
zink_resource_usage_is_unflushed(const struct zink_resource * res)107 zink_resource_usage_is_unflushed(const struct zink_resource *res)
108 {
109 return zink_bo_has_unflushed_usage(res->obj->bo);
110 }
111
112 static inline bool
zink_resource_usage_is_unflushed_write(const struct zink_resource * res)113 zink_resource_usage_is_unflushed_write(const struct zink_resource *res)
114 {
115 return zink_batch_usage_is_unflushed(res->obj->bo->writes.u);
116 }
117
118
119 static inline bool
zink_resource_usage_matches(const struct zink_resource * res,const struct zink_batch_state * bs)120 zink_resource_usage_matches(const struct zink_resource *res, const struct zink_batch_state *bs)
121 {
122 return zink_bo_usage_matches(res->obj->bo, bs);
123 }
124
125 static inline bool
zink_resource_has_usage(const struct zink_resource * res)126 zink_resource_has_usage(const struct zink_resource *res)
127 {
128 return zink_bo_has_usage(res->obj->bo);
129 }
130
131 static inline bool
zink_resource_has_unflushed_usage(const struct zink_resource * res)132 zink_resource_has_unflushed_usage(const struct zink_resource *res)
133 {
134 return zink_bo_has_unflushed_usage(res->obj->bo);
135 }
136
137 static inline bool
zink_resource_usage_check_completion(struct zink_screen * screen,struct zink_resource * res,enum zink_resource_access access)138 zink_resource_usage_check_completion(struct zink_screen *screen, struct zink_resource *res, enum zink_resource_access access)
139 {
140 return zink_bo_usage_check_completion(screen, res->obj->bo, access);
141 }
142
143 static inline bool
zink_resource_usage_check_completion_fast(struct zink_screen * screen,struct zink_resource * res,enum zink_resource_access access)144 zink_resource_usage_check_completion_fast(struct zink_screen *screen, struct zink_resource *res, enum zink_resource_access access)
145 {
146 return zink_bo_usage_check_completion_fast(screen, res->obj->bo, access);
147 }
148
149 static inline void
zink_resource_usage_try_wait(struct zink_context * ctx,struct zink_resource * res,enum zink_resource_access access)150 zink_resource_usage_try_wait(struct zink_context *ctx, struct zink_resource *res, enum zink_resource_access access)
151 {
152 zink_bo_usage_try_wait(ctx, res->obj->bo, access);
153 }
154
155 static inline void
zink_resource_usage_wait(struct zink_context * ctx,struct zink_resource * res,enum zink_resource_access access)156 zink_resource_usage_wait(struct zink_context *ctx, struct zink_resource *res, enum zink_resource_access access)
157 {
158 zink_bo_usage_wait(ctx, res->obj->bo, access);
159 }
160
161 static inline void
zink_resource_usage_set(struct zink_resource * res,struct zink_batch_state * bs,bool write)162 zink_resource_usage_set(struct zink_resource *res, struct zink_batch_state *bs, bool write)
163 {
164 zink_bo_usage_set(res->obj->bo, bs, write);
165 res->obj->unsync_access = false;
166 }
167
168 static inline bool
zink_resource_object_usage_unset(struct zink_resource_object * obj,struct zink_batch_state * bs)169 zink_resource_object_usage_unset(struct zink_resource_object *obj, struct zink_batch_state *bs)
170 {
171 return zink_bo_usage_unset(obj->bo, bs);
172 }
173
174 static inline void
zink_batch_resource_usage_set(struct zink_batch_state * bs,struct zink_resource * res,bool write,bool is_buffer)175 zink_batch_resource_usage_set(struct zink_batch_state *bs, struct zink_resource *res, bool write, bool is_buffer)
176 {
177 if (!is_buffer) {
178 if (res->obj->dt) {
179 VkSemaphore acquire = zink_kopper_acquire_submit(zink_screen(bs->ctx->base.screen), res);
180 if (acquire)
181 util_dynarray_append(&bs->acquires, VkSemaphore, acquire);
182 }
183 if (write) {
184 if (!res->valid && res->fb_bind_count)
185 bs->ctx->rp_loadop_changed = true;
186 res->valid = true;
187 }
188 }
189 zink_resource_usage_set(res, bs, write);
190 }
191
192 void
193 zink_debug_mem_print_stats(struct zink_screen *screen);
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199 #endif
200