| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* based in part on anv driver which is: |
| 5 |
* Copyright © 2015 Intel Corporation |
| 6 |
* |
| 7 |
* based in part on radv driver which is: |
| 8 |
* Copyright © 2016 Red Hat. |
| 9 |
* Copyright © 2016 Bas Nieuwenhuizen |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef PVR_IMAGE_H |
| 15 |
#define PVR_IMAGE_H |
| 16 |
|
| 17 |
#include <stdint.h> |
| 18 |
|
| 19 |
#include "vk_image.h" |
| 20 |
|
| 21 |
#include "pvr_common.h" |
| 22 |
#include "pvr_types.h" |
| 23 |
|
| 24 |
#define PVR_MAX_PLANE_COUNT 3 |
| 25 |
|
| 26 |
struct pvr_device; |
| 27 |
|
| 28 |
struct pvr_mip_level { |
| 29 |
/* Offset of the mip level in bytes */ |
| 30 |
uint32_t offset; |
| 31 |
|
| 32 |
/* Aligned mip level size in bytes */ |
| 33 |
uint32_t size; |
| 34 |
|
| 35 |
/* Aligned row length in bytes */ |
| 36 |
uint32_t pitch; |
| 37 |
|
| 38 |
/* Aligned height in bytes */ |
| 39 |
uint32_t height_pitch; |
| 40 |
}; |
| 41 |
|
| 42 |
struct pvr_image_plane { |
| 43 |
/* Derived and other state */ |
| 44 |
VkExtent3D physical_extent; |
| 45 |
|
| 46 |
VkDeviceSize layer_size; |
| 47 |
VkDeviceSize size; |
| 48 |
VkDeviceSize offset; |
| 49 |
|
| 50 |
struct pvr_mip_level mip_levels[14]; |
| 51 |
}; |
| 52 |
|
| 53 |
struct pvr_image { |
| 54 |
struct vk_image vk; |
| 55 |
|
| 56 |
/* vma this image is bound to */ |
| 57 |
struct pvr_winsys_vma *vma; |
| 58 |
|
| 59 |
/* Device address the image is mapped to in device virtual address space */ |
| 60 |
pvr_dev_addr_t dev_addr; |
| 61 |
|
| 62 |
enum pvr_memlayout memlayout; |
| 63 |
|
| 64 |
VkDeviceSize alignment; |
| 65 |
VkDeviceSize total_size; |
| 66 |
|
| 67 |
uint8_t plane_count; |
| 68 |
struct pvr_image_plane planes[PVR_MAX_PLANE_COUNT]; |
| 69 |
}; |
| 70 |
|
| 71 |
/* Gets the first plane and asserts we only have one plane. For use in areas |
| 72 |
* where we never want to deal with multiplanar images. |
| 73 |
*/ |
| 74 |
static inline struct pvr_image_plane *pvr_single_plane(struct pvr_image *image) |
| 75 |
{ |
| 76 |
assert(image->plane_count == 1); |
| 77 |
return &image->planes[0]; |
| 78 |
} |
| 79 |
|
| 80 |
static inline const struct pvr_image_plane * |
| 81 |
pvr_single_plane_const(const struct pvr_image *image) |
| 82 |
{ |
| 83 |
assert(image->plane_count == 1); |
| 84 |
return &image->planes[0]; |
| 85 |
} |
| 86 |
|
| 87 |
static inline struct pvr_image_plane * |
| 88 |
pvr_plane_from_aspect(struct pvr_image *image, VkImageAspectFlags aspect) |
| 89 |
{ |
| 90 |
switch (aspect) { |
| 91 |
case VK_IMAGE_ASPECT_COLOR_BIT: |
| 92 |
case VK_IMAGE_ASPECT_DEPTH_BIT: |
| 93 |
case VK_IMAGE_ASPECT_STENCIL_BIT: |
| 94 |
case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
| 95 |
return pvr_single_plane(image); |
| 96 |
case VK_IMAGE_ASPECT_PLANE_0_BIT: |
| 97 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT: |
| 98 |
return &image->planes[0]; |
| 99 |
case VK_IMAGE_ASPECT_PLANE_1_BIT: |
| 100 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT: |
| 101 |
return &image->planes[1]; |
| 102 |
case VK_IMAGE_ASPECT_PLANE_2_BIT: |
| 103 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT: |
| 104 |
return &image->planes[2]; |
| 105 |
default: |
| 106 |
UNREACHABLE("invalid image aspect"); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
static inline const struct pvr_image_plane * |
| 111 |
pvr_plane_from_aspect_const(const struct pvr_image *image, |
| 112 |
VkImageAspectFlags aspect) |
| 113 |
{ |
| 114 |
switch (aspect) { |
| 115 |
case VK_IMAGE_ASPECT_COLOR_BIT: |
| 116 |
case VK_IMAGE_ASPECT_DEPTH_BIT: |
| 117 |
case VK_IMAGE_ASPECT_STENCIL_BIT: |
| 118 |
case VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT: |
| 119 |
return pvr_single_plane_const(image); |
| 120 |
case VK_IMAGE_ASPECT_PLANE_0_BIT: |
| 121 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT: |
| 122 |
return &image->planes[0]; |
| 123 |
case VK_IMAGE_ASPECT_PLANE_1_BIT: |
| 124 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT: |
| 125 |
return &image->planes[1]; |
| 126 |
case VK_IMAGE_ASPECT_PLANE_2_BIT: |
| 127 |
case VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT: |
| 128 |
return &image->planes[2]; |
| 129 |
default: |
| 130 |
UNREACHABLE("invalid image aspect"); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
struct pvr_image_view { |
| 135 |
struct vk_image_view vk; |
| 136 |
|
| 137 |
/* Prepacked Texture Image dword 0 and 1. It will be copied to the |
| 138 |
* descriptor info during pvr_UpdateDescriptorSets(). |
| 139 |
* |
| 140 |
* We create separate texture states for sampling, storage and input |
| 141 |
* attachment cases. |
| 142 |
*/ |
| 143 |
struct pvr_image_descriptor image_state[PVR_TEXTURE_STATE_MAX_ENUM]; |
| 144 |
|
| 145 |
/* Prepacked Sampler Words with YCbCr plane addresses */ |
| 146 |
uint64_t sampler_words[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS]; |
| 147 |
}; |
| 148 |
|
| 149 |
VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE) |
| 150 |
|
| 151 |
VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_image_view, |
| 152 |
vk.base, |
| 153 |
VkImageView, |
| 154 |
VK_OBJECT_TYPE_IMAGE_VIEW) |
| 155 |
|
| 156 |
static inline const struct pvr_image * |
| 157 |
vk_to_pvr_image(const struct vk_image *image) |
| 158 |
{ |
| 159 |
return container_of(image, const struct pvr_image, vk); |
| 160 |
} |
| 161 |
|
| 162 |
static inline const struct pvr_image * |
| 163 |
pvr_image_view_get_image(const struct pvr_image_view *const iview) |
| 164 |
{ |
| 165 |
return vk_to_pvr_image(iview->vk.image); |
| 166 |
} |
| 167 |
|
| 168 |
void pvr_get_image_subresource_layout(const struct pvr_image *image, |
| 169 |
const VkImageSubresource *subresource, |
| 170 |
VkSubresourceLayout *layout); |
| 171 |
|
| 172 |
void pvr_image_init(struct pvr_device *device, |
| 173 |
const VkImageCreateInfo *pCreateInfo, |
| 174 |
struct pvr_image *image); |
| 175 |
void pvr_image_fini(struct pvr_device *device, struct pvr_image *image); |
| 176 |
|
| 177 |
#endif /* PVR_IMAGE_H */ |