Debian Codegraph @

src/kosmickrisp/vulkan/kk_image.h

raw symbols SCIP
1 /*
2 * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
3 * Copyright 2025 LunarG, Inc.
4 * Copyright 2025 Google LLC
5 * SPDX-License-Identifier: MIT
6 */
7
8 #ifndef KK_IMAGE_H
9 #define KK_IMAGE_H 1
10
11 #include "kk_private.h"
12
13 #include "kk_device_memory.h"
14 #include "kk_image_layout.h"
15
16 #include "kosmickrisp/bridge/mtl_types.h"
17
18 #include "vk_image.h"
19
20 struct kk_device_memory;
21 struct kk_physical_device;
22 struct kk_queue;
23
24 VkFormatFeatureFlags2
25 kk_get_image_format_features(struct kk_physical_device *pdevice,
26 VkFormat format, VkImageTiling tiling,
27 uint64_t drm_format_mod);
28
29 uint32_t kk_image_max_dimension(VkImageType image_type);
30
31 struct kk_image_plane {
32 struct kk_image_layout layout;
33 // TODO_KOSMICKRISP Only have one handle since we will only create 2D arrays
34 // anyway
35 /* Metal handle with original handle type */
36 mtl_texture *mtl_handle;
37 /* Metal handle with 2D array type for 3D images */
38 mtl_texture *mtl_handle_array;
39 uint64_t addr;
40 };
41
42 struct kk_image {
43 struct vk_image vk;
44
45 /** True if the planes are bound separately
46 * * This is set based on VK_IMAGE_CREATE_DISJOINT_BIT
47 */
48 bool disjoint;
49
50 uint8_t plane_count;
51 struct kk_image_plane planes[3];
52
53 /* In order to support D32_SFLOAT_S8_UINT, a temp area is
54 * needed. The stencil plane can't be a copied using the DMA
55 * engine in a single pass since it would need 8 components support.
56 * Instead we allocate a 16-bit temp, that gets copied into, then
57 * copied again down to the 8-bit result.
58 */
59 struct kk_image_plane stencil_copy_temp;
60 };
61
62 static inline mtl_resource *
63 kk_image_to_mtl_resource(const struct kk_image *image, int plane)
64 {
65 if (image != NULL) {
66 assert(plane < ARRAY_SIZE(image->planes));
67 return (mtl_resource *)image->planes[plane].mtl_handle;
68 }
69 return NULL;
70 }
71
72 VK_DEFINE_NONDISP_HANDLE_CASTS(kk_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
73
74 static inline uint64_t
75 kk_image_plane_base_address(const struct kk_image_plane *plane)
76 {
77 return plane->addr;
78 }
79
80 static inline uint64_t
81 kk_image_base_address(const struct kk_image *image, uint8_t plane)
82 {
83 return kk_image_plane_base_address(&image->planes[plane]);
84 }
85
86 static inline uint8_t
87 kk_image_aspects_to_plane(ASSERTED const struct kk_image *image,
88 VkImageAspectFlags aspectMask)
89 {
90 /* Memory planes are only allowed for memory operations */
91 assert(!(aspectMask & (VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT |
92 VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT |
93 VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT |
94 VK_IMAGE_ASPECT_MEMORY_PLANE_3_BIT_EXT)));
95
96 /* Verify that the aspects are actually in the image */
97 assert(!(aspectMask & ~image->vk.aspects));
98
99 /* Must only be one aspect unless it's depth/stencil */
100 assert(aspectMask ==
101 (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) ||
102 util_bitcount(aspectMask) == 1);
103
104 switch (aspectMask) {
105 case VK_IMAGE_ASPECT_PLANE_1_BIT:
106 return 1;
107 case VK_IMAGE_ASPECT_PLANE_2_BIT:
108 return 2;
109 default:
110 return 0;
111 }
112 }
113
114 static inline uint8_t
115 kk_image_memory_aspects_to_plane(ASSERTED const struct kk_image *image,
116 VkImageAspectFlags aspectMask)
117 {
118 if (aspectMask & (VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT |
119 VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT |
120 VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT |
121 VK_IMAGE_ASPECT_MEMORY_PLANE_3_BIT_EXT)) {
122 /* We don't support DRM format modifiers on anything but single-plane
123 * color at the moment.
124 */
125 assert(aspectMask == VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT);
126 return 0;
127 } else {
128 return kk_image_aspects_to_plane(image, aspectMask);
129 }
130 }
131
132 #endif