tu: Use common vk_image struct

This eliminates some boilerplate, and will be necessary to use the
common render pass implementation for debugging purposes.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17378>
This commit is contained in:
Connor Abbott 2022-07-18 12:30:59 +02:00 committed by Marge Bot
parent cb0f414b2a
commit 89263fde20
5 changed files with 1179 additions and 1234 deletions

View File

@ -151,9 +151,9 @@ hash_renderpass_instance(const struct tu_render_pass *pass,
for (unsigned i = 0; i < pass->attachment_count; i++) {
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->view.width);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->view.height);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->vk_format);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->layer_count);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->level_count);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->vk.format);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->vk.array_layers);
APPEND_TO_HASH(&hash_state, cmd->state.attachments[i]->image->vk.mip_levels);
}
APPEND_TO_HASH(&hash_state, pass->subpass_count);

File diff suppressed because it is too large Load Diff

View File

@ -184,7 +184,7 @@ tu_image_view_init(struct tu_image_view *iview,
const struct fdl_layout *layouts[3];
layouts[0] = &image->layout[tu6_plane_index(image->vk_format, aspect_mask)];
layouts[0] = &image->layout[tu6_plane_index(image->vk.format, aspect_mask)];
enum pipe_format format;
if (aspect_mask != VK_IMAGE_ASPECT_COLOR_BIT)
@ -192,7 +192,7 @@ tu_image_view_init(struct tu_image_view *iview,
else
format = tu_vk_format_to_pipe_format(vk_format);
if (image->vk_format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM &&
if (image->vk.format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM &&
aspect_mask == VK_IMAGE_ASPECT_PLANE_0_BIT) {
if (vk_format == VK_FORMAT_R8_UNORM) {
/* The 0'th plane of this format has a different UBWC compression. */
@ -216,8 +216,8 @@ tu_image_view_init(struct tu_image_view *iview,
args.iova = image->iova;
args.base_array_layer = range->baseArrayLayer;
args.base_miplevel = range->baseMipLevel;
args.layer_count = tu_get_layerCount(image, range);
args.level_count = tu_get_levelCount(image, range);
args.layer_count = vk_image_subresource_layer_count(&image->vk, range);
args.level_count = vk_image_subresource_level_count(&image->vk, range);
args.min_lod_clamp = min_lod ? min_lod->minLod : 0.f;
args.format = tu_format_for_aspect(format, aspect_mask);
vk_component_mapping_to_pipe_swizzle(pCreateInfo->components, args.swiz);
@ -258,7 +258,7 @@ tu_image_view_init(struct tu_image_view *iview,
fdl6_view_init(&iview->view, layouts, &args, has_z24uint_s8uint);
if (image->vk_format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
if (image->vk.format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
struct fdl_layout *layout = &image->layout[0];
iview->depth_base_addr = image->iova +
fdl_surface_offset(layout, range->baseMipLevel, range->baseArrayLayer);
@ -359,13 +359,8 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
const VkImageCreateInfo *pCreateInfo, uint64_t modifier,
const VkSubresourceLayout *plane_layouts)
{
const VkExternalMemoryImageCreateInfo *external_info =
vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_MEMORY_IMAGE_CREATE_INFO);
image->shareable = external_info != NULL;
image->vk_format = pCreateInfo->format;
image->level_count = pCreateInfo->mipLevels;
image->layer_count = pCreateInfo->arrayLayers;
vk_image_init(&device->vk, &image->vk, pCreateInfo);
image->vk.drm_format_mod = modifier;
enum a6xx_tile_mode tile_mode = TILE6_3;
bool ubwc_enabled = true;
@ -377,7 +372,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
}
/* Force linear tiling for formats with "fake" optimalTilingFeatures */
if (!tiling_possible(image->vk_format)) {
if (!tiling_possible(image->vk.format)) {
tile_mode = TILE6_LINEAR;
ubwc_enabled = false;
}
@ -389,7 +384,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
}
enum pipe_format format =
tu_vk_format_to_pipe_format(image->vk_format);
tu_vk_format_to_pipe_format(image->vk.format);
/* Whether a view of the image with an R8G8 format could be made. */
bool has_r8g8 = tu_is_r8g8(format);
@ -406,7 +401,7 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
* - figure out which UBWC compressions are compatible to keep it enabled
*/
if ((pCreateInfo->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
!vk_format_is_depth_or_stencil(image->vk_format)) {
!vk_format_is_depth_or_stencil(image->vk.format)) {
const VkImageFormatListCreateInfo *fmt_list =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_FORMAT_LIST_CREATE_INFO);
bool may_be_swapped = true;
@ -451,11 +446,8 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
ubwc_enabled = false;
}
const VkImageStencilUsageCreateInfo *stencil_usage_info =
vk_find_struct_const(pCreateInfo->pNext, IMAGE_STENCIL_USAGE_CREATE_INFO);
if (!ubwc_possible(image->vk_format, pCreateInfo->imageType, pCreateInfo->usage,
stencil_usage_info ? stencil_usage_info->stencilUsage : pCreateInfo->usage,
if (!ubwc_possible(image->vk.format, pCreateInfo->imageType,
pCreateInfo->usage, image->vk.stencil_usage,
device->physical_device->info, pCreateInfo->samples,
device->use_z24uint_s8uint))
ubwc_enabled = false;
@ -475,14 +467,14 @@ tu_image_init(struct tu_device *device, struct tu_image *image,
tile_mode = TILE6_LINEAR;
}
for (uint32_t i = 0; i < tu6_plane_count(image->vk_format); i++) {
for (uint32_t i = 0; i < tu6_plane_count(image->vk.format); i++) {
struct fdl_layout *layout = &image->layout[i];
enum pipe_format format = tu6_plane_format(image->vk_format, i);
enum pipe_format format = tu6_plane_format(image->vk.format, i);
uint32_t width0 = pCreateInfo->extent.width;
uint32_t height0 = pCreateInfo->extent.height;
if (i > 0) {
switch (image->vk_format) {
switch (image->vk.format) {
case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM:
case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM:
/* half width/height on chroma planes */
@ -714,7 +706,8 @@ tu_get_image_memory_requirements(struct tu_image *image,
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
VkMemoryDedicatedRequirements *req =
(VkMemoryDedicatedRequirements *) ext;
req->requiresDedicatedAllocation = image->shareable;
req->requiresDedicatedAllocation =
image->vk.external_handle_types != 0;
req->prefersDedicatedAllocation = req->requiresDedicatedAllocation;
break;
}
@ -779,7 +772,7 @@ tu_GetImageSubresourceLayout(VkDevice _device,
TU_FROM_HANDLE(tu_image, image, _image);
struct fdl_layout *layout =
&image->layout[tu6_plane_index(image->vk_format, pSubresource->aspectMask)];
&image->layout[tu6_plane_index(image->vk.format, pSubresource->aspectMask)];
const struct fdl_slice *slice = layout->slices + pSubresource->mipLevel;
pLayout->offset =
@ -793,31 +786,10 @@ tu_GetImageSubresourceLayout(VkDevice _device,
/* UBWC starts at offset 0 */
pLayout->offset = 0;
/* UBWC scanout won't match what the kernel wants if we have levels/layers */
assert(image->level_count == 1 && image->layer_count == 1);
assert(image->vk.mip_levels == 1 && image->vk.array_layers == 1);
}
}
VKAPI_ATTR VkResult VKAPI_CALL
tu_GetImageDrmFormatModifierPropertiesEXT(
VkDevice device,
VkImage _image,
VkImageDrmFormatModifierPropertiesEXT* pProperties)
{
TU_FROM_HANDLE(tu_image, image, _image);
/* TODO invent a modifier for tiled but not UBWC buffers */
if (!image->layout[0].tile_mode)
pProperties->drmFormatModifier = DRM_FORMAT_MOD_LINEAR;
else if (image->layout[0].ubwc_layer_size)
pProperties->drmFormatModifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
else
pProperties->drmFormatModifier = DRM_FORMAT_MOD_INVALID;
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL
tu_CreateImageView(VkDevice _device,
const VkImageViewCreateInfo *pCreateInfo,

View File

@ -544,7 +544,7 @@ tu_lrz_clear_depth_image(struct tu_cmd_buffer *cmd,
tu6_write_lrz_reg(cmd, &cmd->cs, A6XX_GRAS_LRZ_DEPTH_VIEW(
.base_layer = range->baseArrayLayer,
.layer_count = tu_get_layerCount(image, range),
.layer_count = vk_image_subresource_layer_count(&image->vk, range),
.base_mip_level = range->baseMipLevel,
));

View File

@ -2069,14 +2069,7 @@ tu6_base_format(enum pipe_format format)
struct tu_image
{
struct vk_object_base base;
/* The original VkFormat provided by the client. This may not match any
* of the actual surface formats.
*/
VkFormat vk_format;
uint32_t level_count;
uint32_t layer_count;
struct vk_image vk;
struct fdl_layout layout[3];
uint32_t total_size;
@ -2095,28 +2088,8 @@ struct tu_image
uint32_t lrz_offset;
uint32_t lrz_fc_offset;
uint32_t lrz_fc_size;
bool shareable;
};
static inline uint32_t
tu_get_layerCount(const struct tu_image *image,
const VkImageSubresourceRange *range)
{
return range->layerCount == VK_REMAINING_ARRAY_LAYERS
? image->layer_count - range->baseArrayLayer
: range->layerCount;
}
static inline uint32_t
tu_get_levelCount(const struct tu_image *image,
const VkImageSubresourceRange *range)
{
return range->levelCount == VK_REMAINING_MIP_LEVELS
? image->level_count - range->baseMipLevel
: range->levelCount;
}
uint32_t tu6_plane_count(VkFormat format);
enum pipe_format tu6_plane_format(VkFormat format, uint32_t plane);
@ -2376,7 +2349,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(tu_device_memory, base, VkDeviceMemory,
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_framebuffer, base, VkFramebuffer,
VK_OBJECT_TYPE_FRAMEBUFFER)
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, base, VkImage, VK_OBJECT_TYPE_IMAGE)
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, base, VkImageView,
VK_OBJECT_TYPE_IMAGE_VIEW);
VK_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache, base, VkPipelineCache,