Debian Codegraph @

src/kosmickrisp/vulkan/kk_image_layout.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_LAYOUT_H
9 #define KK_IMAGE_LAYOUT_H 1
10
11 #include "kosmickrisp/bridge/mtl_types.h"
12
13 #include "util/format/u_formats.h"
14
15 #include "vulkan/vulkan.h"
16
17 #define KK_MAX_MIP_LEVELS 16
18
19 struct kk_device;
20 struct VkImageCreateInfo;
21 enum pipe_swizzle;
22
23 struct kk_image_layout {
24 /** Width, height, and depth in pixels at level 0 */
25 uint32_t width_px, height_px, depth_px, layers;
26
27 enum mtl_texture_type type;
28
29 /** Number of samples per pixel. 1 if multisampling is disabled. */
30 uint8_t sample_count_sa;
31
32 /** Number of miplevels. 1 if no mipmapping is used. */
33 uint8_t levels;
34
35 uint8_t optimized_layout;
36
37 enum mtl_texture_usage usage;
38
39 /** Texture format */
40 struct {
41 enum pipe_format pipe;
42 uint32_t mtl;
43 } format;
44
45 /* Required to correctly set image swizzle for non-native formats */
46 /* Would love to use enum pipe_swizzle, but it's bigger than the required
47 * type for util_format_compose_swizzles... */
48 struct {
49 uint8_t red;
50 uint8_t green;
51 uint8_t blue;
52 uint8_t alpha;
53 } swizzle;
54
55 /**
56 * If tiling is LINEAR, the number of bytes between adjacent rows of
57 * elements. Otherwise, this field is zero.
58 */
59 uint32_t linear_stride_B;
60
61 /**
62 * Stride between layers of an array texture, including a cube map. Layer i
63 * begins at offset (i * layer_stride_B) from the beginning of the texture.
64 *
65 * If depth_px = 1, the value of this field is UNDEFINED.
66 */
67 uint64_t layer_stride_B;
68
69 /**
70 * Offsets of mip levels within a layer.
71 */
72 uint64_t level_offsets_B[KK_MAX_MIP_LEVELS];
73
74 /**
75 * If tiling is TWIDDLED, the stride in elements used for each mip level
76 * within a layer. Calculating level strides is the sole responsibility of
77 * ail_initialized_twiddled. This is necessary because compressed pixel
78 * formats may add extra stride padding.
79 */
80 uint32_t stride_el[KK_MAX_MIP_LEVELS];
81
82 /* Size of entire texture */
83 uint64_t size_B;
84
85 /* Alignment required */
86 uint64_t align_B;
87 };
88
89 struct kk_view_layout {
90 /** Type */
91 VkImageViewType view_type;
92
93 /** Number of samples per pixel. 1 if multisampling is disabled.
94 * Required to be able to correctly set the MTLTextureType.
95 */
96 uint8_t sample_count_sa;
97
98 /** Texture format */
99 struct {
100 enum pipe_format pipe;
101 uint32_t mtl;
102 } format;
103
104 /** Array base level. 0 if no array is used. */
105 uint16_t base_array_layer;
106
107 /** Array length. 1 if no array is used. */
108 uint16_t array_len;
109
110 /** Swizzle */
111 /* Would love to use enum pipe_swizzle, but it's bigger than the required
112 * type for util_format_compose_swizzles... */
113 struct {
114 union {
115 struct {
116 uint8_t red;
117 uint8_t green;
118 uint8_t blue;
119 uint8_t alpha;
120 };
121 uint8_t channels[4];
122 };
123 } swizzle;
124
125 /** Mipmap base level. 0 if no mipmapping is used. */
126 uint8_t base_level;
127
128 /** Number of miplevels. 1 if no mipmapping is used. */
129 uint8_t num_levels;
130
131 uint16_t min_lod_clamp;
132 };
133
134 void kk_image_layout_init(const struct kk_device *dev,
135 const struct VkImageCreateInfo *create_info,
136 enum pipe_format format, const uint8_t width_scale,
137 const uint8_t height_scale,
138 struct kk_image_layout *layout);
139
140 #endif /* KK_IMAGE_LAYOUT_H */