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