• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2022 Collabora Ltd.
3  * SPDX-License-Identifier: MIT
4  */
5 #ifndef NIL_IMAGE_H
6 #define NIL_IMAGE_H
7 
8 #include <assert.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 
12 #include "util/macros.h"
13 #include "util/format/u_format.h"
14 
15 struct nv_device_info;
16 
17 enum ENUM_PACKED nil_image_dim {
18    NIL_IMAGE_DIM_1D = 1,
19    NIL_IMAGE_DIM_2D = 2,
20    NIL_IMAGE_DIM_3D = 3,
21 };
22 
23 enum ENUM_PACKED nil_sample_layout {
24    NIL_SAMPLE_LAYOUT_1X1,
25    NIL_SAMPLE_LAYOUT_2X1,
26    NIL_SAMPLE_LAYOUT_2X2,
27    NIL_SAMPLE_LAYOUT_4X2,
28    NIL_SAMPLE_LAYOUT_4X4,
29    NIL_SAMPLE_LAYOUT_INVALID,
30 };
31 
32 enum nil_sample_layout nil_choose_sample_layout(uint32_t samples);
33 
34 enum nil_image_usage_flags {
35    NIL_IMAGE_USAGE_RENDER_TARGET_BIT   = BITFIELD_BIT(0),
36    NIL_IMAGE_USAGE_DEPTH_BIT           = BITFIELD_BIT(1),
37    NIL_IMAGE_USAGE_STENCIL_BIT         = BITFIELD_BIT(2),
38    NIL_IMAGE_USAGE_TEXTURE_BIT         = BITFIELD_BIT(3),
39    NIL_IMAGE_USAGE_STORAGE_BIT         = BITFIELD_BIT(4),
40    NIL_IMAGE_USAGE_CUBE_BIT            = BITFIELD_BIT(5),
41    NIL_IMAGE_USAGE_2D_VIEW_BIT         = BITFIELD_BIT(6),
42    NIL_IMAGE_USAGE_LINEAR_BIT          = BITFIELD_BIT(7),
43 };
44 
45 enum ENUM_PACKED nil_view_type {
46    NIL_VIEW_TYPE_1D,
47    NIL_VIEW_TYPE_2D,
48    NIL_VIEW_TYPE_3D,
49    NIL_VIEW_TYPE_CUBE,
50    NIL_VIEW_TYPE_1D_ARRAY,
51    NIL_VIEW_TYPE_2D_ARRAY,
52    NIL_VIEW_TYPE_CUBE_ARRAY,
53 };
54 
55 struct nil_extent4d {
56    union { uint32_t w, width; };
57    union { uint32_t h, height; };
58    union { uint32_t d, depth; };
59    union { uint32_t a, array_len; };
60 };
61 
62 static inline struct nil_extent4d
nil_extent4d(uint32_t w,uint32_t h,uint32_t d,uint32_t a)63 nil_extent4d(uint32_t w, uint32_t h, uint32_t d, uint32_t a)
64 {
65    struct nil_extent4d e;
66    e.w = w;
67    e.h = h;
68    e.d = d;
69    e.a = a;
70    return e;
71 }
72 
73 struct nil_extent4d
74 nil_extent4d_px_to_el(struct nil_extent4d extent_px,
75                       enum pipe_format format,
76                       enum nil_sample_layout sample_layout);
77 
78 struct nil_offset4d {
79    uint32_t x;
80    uint32_t y;
81    uint32_t z;
82    uint32_t a;
83 };
84 
85 static inline struct nil_offset4d
nil_offset4d(uint32_t x,uint32_t y,uint32_t z,uint32_t a)86 nil_offset4d(uint32_t x, uint32_t y, uint32_t z, uint32_t a)
87 {
88    struct nil_offset4d o;
89    o.x = x;
90    o.y = y;
91    o.z = z;
92    o.a = a;
93    return o;
94 }
95 
96 struct nil_offset4d
97 nil_offset4d_px_to_el(struct nil_offset4d offset_px,
98                       enum pipe_format format,
99                       enum nil_sample_layout sample_layout);
100 
101 #define NIL_GOB_WIDTH_B 64
102 #define NIL_GOB_HEIGHT(gob_height_8) ((gob_height_8) ? 8 : 4)
103 #define NIL_GOB_DEPTH 1
104 #define NIL_MAX_LEVELS 16
105 
106 struct nil_tiling {
107    bool is_tiled:1;
108    bool gob_height_8:1; /**< GOB height is 4 or 8 */
109    uint8_t y_log2:3; /**< log2 of the Y tile dimension in GOBs */
110    uint8_t z_log2:3; /**< log2 of the Z tile dimension in GOBs */
111 };
112 
113 struct nil_image_init_info {
114    enum nil_image_dim dim;
115    enum pipe_format format;
116 
117    struct nil_extent4d extent_px;
118    uint32_t levels;
119    uint32_t samples;
120 
121    enum nil_image_usage_flags usage;
122 };
123 
124 /** Represents the data layout of a single slice (level+lod) of an image */
125 struct nil_image_level {
126    /** Offset into the image of this level in bytes */
127    uint64_t offset_B;
128 
129    /** Tiling for this level */
130    struct nil_tiling tiling;
131 
132    /** Stride between rows in bytes */
133    uint32_t row_stride_B;
134 };
135 
136 struct nil_image {
137    enum nil_image_dim dim;
138    enum pipe_format format;
139 
140    struct nil_extent4d extent_px;
141    enum nil_sample_layout sample_layout;
142    uint8_t num_levels;
143 
144    struct nil_image_level levels[NIL_MAX_LEVELS];
145 
146    uint32_t array_stride_B;
147 
148    uint32_t align_B;
149    uint64_t size_B;
150 
151    uint16_t tile_mode;
152    uint8_t pte_kind;
153 };
154 
155 struct nil_view {
156    enum nil_view_type type;
157 
158    /**
159     * The format to use in the view
160     *
161     * This may differ from the format of the actual isl_surf but must have
162     * the same block size.
163     */
164    enum pipe_format format;
165 
166    uint32_t base_level;
167    uint32_t num_levels;
168 
169    /**
170     * Base array layer
171     *
172     * For cube maps, both base_array_layer and array_len should be
173     * specified in terms of 2-D layers and must be a multiple of 6.
174     */
175    uint32_t base_array_layer;
176 
177    /**
178     * Array Length
179     *
180     * Indicates the number of array elements starting at  Base Array Layer.
181     */
182    uint32_t array_len;
183 
184    enum pipe_swizzle swizzle[4];
185 
186    /* VK_EXT_image_view_min_lod */
187    float min_lod_clamp;
188 };
189 
190 bool nil_image_init(struct nv_device_info *dev,
191                     struct nil_image *image,
192                     const struct nil_image_init_info *restrict info);
193 
194 static inline uint64_t
nil_image_level_layer_offset_B(const struct nil_image * image,uint32_t level,uint32_t layer)195 nil_image_level_layer_offset_B(const struct nil_image *image,
196                                uint32_t level, uint32_t layer)
197 {
198    assert(level < image->num_levels);
199    assert(layer < image->extent_px.array_len);
200    return image->levels[level].offset_B + (layer * image->array_stride_B);
201 }
202 
203 struct nil_extent4d nil_image_level_extent_px(const struct nil_image *image,
204                                               uint32_t level);
205 struct nil_extent4d nil_image_level_extent_sa(const struct nil_image *image,
206                                               uint32_t level);
207 uint64_t nil_image_level_size_B(const struct nil_image *image,
208                                 uint32_t level);
209 uint64_t nil_image_level_depth_stride_B(const struct nil_image *image,
210                                         uint32_t level);
211 
212 void nil_image_for_level(const struct nil_image *image_in,
213                          uint32_t level,
214                          struct nil_image *level_image_out,
215                          uint64_t *offset_B_out);
216 
217 void nil_image_level_as_uncompressed(const struct nil_image *image_3d,
218                                      uint32_t level,
219                                      struct nil_image *uc_image_out,
220                                      uint64_t *offset_B_out);
221 
222 void nil_image_3d_level_as_2d_array(const struct nil_image *image_3d,
223                                     uint32_t level,
224                                     struct nil_image *image_2d_out,
225                                     uint64_t *offset_B_out);
226 
227 void nil_image_fill_tic(struct nv_device_info *dev,
228                         const struct nil_image *image,
229                         const struct nil_view *view,
230                         uint64_t base_address,
231                         void *desc_out);
232 
233 void nil_buffer_fill_tic(struct nv_device_info *dev,
234                          uint64_t base_address,
235                          enum pipe_format format,
236                          uint32_t num_elements,
237                          void *desc_out);
238 
239 #endif /* NIL_IMAGE_H */
240