1 /*
2 * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
3 * SPDX-License-Identifier: MIT
4 */
5 #ifndef NVK_IMAGE_H
6 #define NVK_IMAGE_H 1
7
8 #include "nvk_private.h"
9
10 #include "vk_image.h"
11
12 #include "nil_image.h"
13
14 struct nvk_device_memory;
15 struct nvk_physical_device;
16
17 static VkFormatFeatureFlags2
18 nvk_get_image_plane_format_features(struct nvk_physical_device *pdev,
19 VkFormat vk_format, VkImageTiling tiling);
20
21 VkFormatFeatureFlags2
22 nvk_get_image_format_features(struct nvk_physical_device *pdevice,
23 VkFormat format, VkImageTiling tiling);
24
25 uint32_t
26 nvk_image_max_dimension(const struct nv_device_info *info,
27 VkImageType image_type);
28
29 struct nvk_image_plane {
30 struct nil_image nil;
31 uint64_t addr;
32
33 /** Size of the reserved VMA range for sparse images, zero otherwise. */
34 uint64_t vma_size_B;
35 };
36
37 struct nvk_image {
38 struct vk_image vk;
39
40 /** True if the planes are bound separately
41 *
42 * This is set based on VK_IMAGE_CREATE_DISJOINT_BIT
43 */
44 bool disjoint;
45
46 uint8_t plane_count;
47 struct nvk_image_plane planes[3];
48
49 /* In order to support D32_SFLOAT_S8_UINT, a temp area is
50 * needed. The stencil plane can't be a copied using the DMA
51 * engine in a single pass since it would need 8 components support.
52 * Instead we allocate a 16-bit temp, that gets copied into, then
53 * copied again down to the 8-bit result.
54 */
55 struct nvk_image_plane stencil_copy_temp;
56 };
57
58 VK_DEFINE_NONDISP_HANDLE_CASTS(nvk_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
59
60 static inline uint64_t
nvk_image_plane_base_address(const struct nvk_image_plane * plane)61 nvk_image_plane_base_address(const struct nvk_image_plane *plane)
62 {
63 return plane->addr;
64 }
65
66 static inline uint64_t
nvk_image_base_address(const struct nvk_image * image,uint8_t plane)67 nvk_image_base_address(const struct nvk_image *image, uint8_t plane)
68 {
69 return nvk_image_plane_base_address(&image->planes[plane]);
70 }
71
72 static inline uint8_t
nvk_image_aspects_to_plane(ASSERTED const struct nvk_image * image,VkImageAspectFlags aspectMask)73 nvk_image_aspects_to_plane(ASSERTED const struct nvk_image *image,
74 VkImageAspectFlags aspectMask)
75 {
76 /* Verify that the aspects are actually in the image */
77 assert(!(aspectMask & ~image->vk.aspects));
78
79 /* Must only be one aspect unless it's depth/stencil */
80 assert(aspectMask == (VK_IMAGE_ASPECT_DEPTH_BIT |
81 VK_IMAGE_ASPECT_STENCIL_BIT) ||
82 util_bitcount(aspectMask) == 1);
83
84 switch(aspectMask) {
85 case VK_IMAGE_ASPECT_PLANE_1_BIT: return 1;
86 case VK_IMAGE_ASPECT_PLANE_2_BIT: return 2;
87 default: return 0;
88 }
89 }
90
91 #endif
92