xref: /aosp_15_r20/external/mesa3d/src/vulkan/runtime/vk_meta_private.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 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  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 #ifndef VK_META_PRIVATE_H
24 #define VK_META_PRIVATE_H
25 
26 #include "vk_image.h"
27 #include "vk_meta.h"
28 
29 #include "glsl_types.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 extern const VkPipelineVertexInputStateCreateInfo vk_meta_draw_rects_vi_state;
36 extern const VkPipelineInputAssemblyStateCreateInfo vk_meta_draw_rects_ia_state;
37 extern const VkPipelineViewportStateCreateInfo vk_meta_draw_rects_vs_state;
38 
39 struct nir_shader *
40 vk_meta_draw_rects_vs_nir(struct vk_meta_device *device, bool use_gs);
41 
42 struct nir_shader *
43 vk_meta_draw_rects_gs_nir(struct vk_meta_device *device);
44 
45 static inline void
vk_meta_rendering_info_copy(struct vk_meta_rendering_info * dst,const struct vk_meta_rendering_info * src)46 vk_meta_rendering_info_copy(struct vk_meta_rendering_info *dst,
47                             const struct vk_meta_rendering_info *src)
48 {
49    dst->view_mask = src->view_mask;
50    dst->samples = src->samples;
51    dst->color_attachment_count = src->color_attachment_count;
52    for (uint32_t a = 0; a < src->color_attachment_count; a++) {
53       dst->color_attachment_formats[a] = src->color_attachment_formats[a];
54       dst->color_attachment_write_masks[a] =
55          src->color_attachment_write_masks[a];
56    }
57    dst->depth_attachment_format = src->depth_attachment_format;
58    dst->stencil_attachment_format = src->stencil_attachment_format;
59 }
60 
61 static inline VkImageViewType
vk_image_sampled_view_type(const struct vk_image * image)62 vk_image_sampled_view_type(const struct vk_image *image)
63 {
64    switch (image->image_type) {
65    case VK_IMAGE_TYPE_1D: return VK_IMAGE_VIEW_TYPE_1D_ARRAY;
66    case VK_IMAGE_TYPE_2D: return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
67    case VK_IMAGE_TYPE_3D: return VK_IMAGE_VIEW_TYPE_3D;
68    default: unreachable("Invalid image type");
69    }
70 }
71 
72 static inline VkImageViewType
vk_image_render_view_type(const struct vk_image * image,uint32_t layer_count)73 vk_image_render_view_type(const struct vk_image *image, uint32_t layer_count)
74 {
75    switch (image->image_type) {
76    case VK_IMAGE_TYPE_1D:
77       return layer_count == 1 ? VK_IMAGE_VIEW_TYPE_1D :
78                                 VK_IMAGE_VIEW_TYPE_1D_ARRAY;
79    case VK_IMAGE_TYPE_2D:
80    case VK_IMAGE_TYPE_3D:
81       return layer_count == 1 ? VK_IMAGE_VIEW_TYPE_2D :
82                                 VK_IMAGE_VIEW_TYPE_2D_ARRAY;
83    default:
84       unreachable("Invalid image type");
85    }
86 }
87 
88 static inline VkImageViewType
vk_image_storage_view_type(const struct vk_image * image)89 vk_image_storage_view_type(const struct vk_image *image)
90 {
91    switch (image->image_type) {
92    case VK_IMAGE_TYPE_1D:
93       return image->array_layers == 1 ? VK_IMAGE_VIEW_TYPE_1D
94                                       : VK_IMAGE_VIEW_TYPE_1D_ARRAY;
95    case VK_IMAGE_TYPE_2D:
96       return image->array_layers == 1 ? VK_IMAGE_VIEW_TYPE_2D
97                                       : VK_IMAGE_VIEW_TYPE_2D_ARRAY;
98    case VK_IMAGE_TYPE_3D:
99       return VK_IMAGE_VIEW_TYPE_3D;
100    default:
101       unreachable("Invalid image type");
102    }
103 }
104 
105 static inline enum glsl_sampler_dim
vk_image_view_type_to_sampler_dim(VkImageViewType view_type)106 vk_image_view_type_to_sampler_dim(VkImageViewType view_type)
107 {
108    switch (view_type) {
109    case VK_IMAGE_VIEW_TYPE_1D:
110    case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
111       return GLSL_SAMPLER_DIM_1D;
112 
113    case VK_IMAGE_VIEW_TYPE_2D:
114    case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
115       return GLSL_SAMPLER_DIM_2D;
116 
117    case VK_IMAGE_VIEW_TYPE_CUBE:
118    case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
119       return GLSL_SAMPLER_DIM_CUBE;
120 
121    case VK_IMAGE_VIEW_TYPE_3D:
122       return GLSL_SAMPLER_DIM_3D;
123 
124    default:
125       unreachable();
126    }
127 }
128 
129 static inline bool
vk_image_view_type_is_array(VkImageViewType view_type)130 vk_image_view_type_is_array(VkImageViewType view_type)
131 {
132    switch (view_type) {
133    case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
134    case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
135    case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
136       return true;
137 
138    case VK_IMAGE_VIEW_TYPE_1D:
139    case VK_IMAGE_VIEW_TYPE_2D:
140    case VK_IMAGE_VIEW_TYPE_3D:
141    case VK_IMAGE_VIEW_TYPE_CUBE:
142       return false;
143 
144    default:
145       unreachable();
146    }
147 }
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* VK_META_PRIVATE_H */
154