| 1 |
/* |
| 2 |
* Copyright © 2021 Collabora Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef PANVK_IMAGE_H |
| 7 |
#define PANVK_IMAGE_H |
| 8 |
|
| 9 |
#include "util/format/u_format.h" |
| 10 |
|
| 11 |
#include "vk_format.h" |
| 12 |
#include "vk_image.h" |
| 13 |
|
| 14 |
#include "pan_image.h" |
| 15 |
|
| 16 |
#define PANVK_MAX_PLANES 3 |
| 17 |
|
| 18 |
struct panvk_device_memory; |
| 19 |
struct panvk_physical_device; |
| 20 |
|
| 21 |
/* Right now, planar YUV images are treated as N different images, hence the 1:1 |
| 22 |
* association between pan_image and pan_image_plane, but this can be optimized |
| 23 |
* once planar YUV support is hooked up. */ |
| 24 |
struct panvk_image_plane { |
| 25 |
struct pan_image image; |
| 26 |
struct pan_image_plane plane; |
| 27 |
|
| 28 |
struct panvk_device_memory *mem; |
| 29 |
|
| 30 |
/* Plane offset inside the memory object. */ |
| 31 |
uint64_t mem_offset; |
| 32 |
}; |
| 33 |
|
| 34 |
struct panvk_image { |
| 35 |
struct vk_image vk; |
| 36 |
|
| 37 |
struct { |
| 38 |
VkDeviceAddress device_address; |
| 39 |
} sparse; |
| 40 |
|
| 41 |
uint8_t plane_count; |
| 42 |
struct panvk_image_plane planes[PANVK_MAX_PLANES]; |
| 43 |
|
| 44 |
/* One image each for 2x 4x 8x 16x. We don't support more than 16x. */ |
| 45 |
VkImage ms_imgs[4]; |
| 46 |
}; |
| 47 |
|
| 48 |
VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_image, vk.base, VkImage, |
| 49 |
VK_OBJECT_TYPE_IMAGE) |
| 50 |
|
| 51 |
/* Check whether it is possible that images in a given configuration may use |
| 52 |
* AFBC tiling. This function does not have access to all of the relevant |
| 53 |
* image configuration, and returns true if any images with the specified |
| 54 |
* configuration subset may use AFBC. */ |
| 55 |
bool panvk_image_can_use_afbc( |
| 56 |
struct panvk_physical_device *phys_dev, VkFormat fmt, |
| 57 |
VkImageUsageFlags usage, VkImageType type, VkImageTiling tiling, |
| 58 |
VkImageCreateFlags flags); |
| 59 |
|
| 60 |
static inline unsigned |
| 61 |
panvk_plane_index(const struct panvk_image *image, |
| 62 |
VkImageAspectFlags aspect_mask) |
| 63 |
{ |
| 64 |
switch (aspect_mask) { |
| 65 |
default: |
| 66 |
return 0; |
| 67 |
case VK_IMAGE_ASPECT_PLANE_1_BIT: |
| 68 |
return 1; |
| 69 |
case VK_IMAGE_ASPECT_PLANE_2_BIT: |
| 70 |
return 2; |
| 71 |
case VK_IMAGE_ASPECT_STENCIL_BIT: |
| 72 |
assert(image->plane_count > 0); |
| 73 |
return image->plane_count - 1; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
static inline bool |
| 78 |
panvk_image_is_interleaved_depth_stencil(const struct panvk_image *image){ |
| 79 |
return image->plane_count == 1 && |
| 80 |
vk_format_aspects(image->vk.format) == |
| 81 |
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 82 |
} |
| 83 |
|
| 84 |
static inline bool |
| 85 |
panvk_image_is_planar_depth_stencil(const struct panvk_image *image){ |
| 86 |
return image->plane_count > 1 && |
| 87 |
vk_format_aspects(image->vk.format) == |
| 88 |
(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT); |
| 89 |
} |
| 90 |
|
| 91 |
static inline enum pipe_format |
| 92 |
panvk_image_depth_only_pfmt(const struct panvk_image *image) |
| 93 |
{ |
| 94 |
assert(vk_format_has_depth(image->vk.format)); |
| 95 |
|
| 96 |
return util_format_get_depth_only(image->planes[0].image.props.format); |
| 97 |
} |
| 98 |
|
| 99 |
static inline enum pipe_format |
| 100 |
panvk_image_stencil_only_pfmt(const struct panvk_image *image) |
| 101 |
{ |
| 102 |
assert(vk_format_has_stencil(image->vk.format)); |
| 103 |
|
| 104 |
return util_format_stencil_only( |
| 105 |
image->planes[image->plane_count - 1].image.props.format); |
| 106 |
} |
| 107 |
|
| 108 |
VkResult panvk_image_init(struct panvk_image *image, |
| 109 |
const VkImageCreateInfo *pCreateInfo); |
| 110 |
|
| 111 |
struct panvk_sparse_block_desc { |
| 112 |
struct VkExtent3D extent; |
| 113 |
uint64_t size_B; |
| 114 |
|
| 115 |
/* Whether this is a standard (as defined by Vulkan) sparse block size, for |
| 116 |
* the given arguments */ |
| 117 |
bool standard; |
| 118 |
}; |
| 119 |
|
| 120 |
struct panvk_sparse_block_desc panvk_get_sparse_block_desc(VkImageType type, VkFormat format); |
| 121 |
|
| 122 |
static inline bool |
| 123 |
panvk_sparse_block_is_valid(struct panvk_sparse_block_desc desc) { return desc.size_B > 0; } |
| 124 |
|
| 125 |
VkSparseImageFormatProperties panvk_get_sparse_image_fmt_props(VkImageType type, VkFormat format); |
| 126 |
|
| 127 |
#endif |