xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/zink/zink_surface.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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_SURFACE_H
25  #define ZINK_SURFACE_H
26 
27 #include "zink_types.h"
28 
29 void
30 zink_destroy_surface(struct zink_screen *screen, struct pipe_surface *psurface);
31 
32 static inline void
zink_surface_reference(struct zink_screen * screen,struct zink_surface ** dst,struct zink_surface * src)33 zink_surface_reference(struct zink_screen *screen, struct zink_surface **dst, struct zink_surface *src)
34 {
35    struct zink_surface *old_dst = *dst;
36 
37    if (pipe_reference_described(old_dst ? &old_dst->base.reference : NULL,
38                                 src ? &src->base.reference : NULL,
39                                 (debug_reference_descriptor)
40                                 debug_describe_surface))
41       zink_destroy_surface(screen, &old_dst->base);
42    *dst = src;
43 }
44 
45 void
46 zink_context_surface_init(struct pipe_context *context);
47 
48 VkImageViewCreateInfo
49 create_ivci(struct zink_screen *screen,
50             struct zink_resource *res,
51             const struct pipe_surface *templ,
52             enum pipe_texture_target target);
53 
54 struct zink_surface *
55 zink_get_surface(struct zink_context *ctx,
56             struct pipe_resource *pres,
57             const struct pipe_surface *templ,
58             VkImageViewCreateInfo *ivci);
59 
60 /* cube image types are clamped by gallium rules to 2D or 2D_ARRAY viewtypes if not using all layers */
61 static inline VkImageViewType
zink_surface_clamp_viewtype(VkImageViewType viewType,unsigned first_layer,unsigned last_layer,unsigned array_size)62 zink_surface_clamp_viewtype(VkImageViewType viewType, unsigned first_layer, unsigned last_layer, unsigned array_size)
63 {
64    unsigned layerCount = 1 + last_layer - first_layer;
65    if (viewType == VK_IMAGE_VIEW_TYPE_CUBE || viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
66       if (first_layer == last_layer)
67          return VK_IMAGE_VIEW_TYPE_2D;
68       if (layerCount % 6 != 0 && (first_layer || layerCount != array_size))
69          return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
70    }
71    return viewType;
72 }
73 
74 bool
75 zink_rebind_surface(struct zink_context *ctx, struct pipe_surface **psurface);
76 
77 static inline bool
zink_rebind_ctx_surface(struct zink_context * ctx,struct pipe_surface ** psurface)78 zink_rebind_ctx_surface(struct zink_context *ctx, struct pipe_surface **psurface)
79 {
80    struct zink_ctx_surface *csurf = (struct zink_ctx_surface*)*psurface;
81    return zink_rebind_surface(ctx, (struct pipe_surface**)&csurf->surf);
82 }
83 
84 struct pipe_surface *
85 zink_surface_create_null(struct zink_context *ctx, enum pipe_texture_target target, unsigned width, unsigned height, unsigned samples);
86 
87 void
88 zink_surface_swapchain_update(struct zink_context *ctx, struct zink_surface *surface);
89 #endif
90