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