kk: Create image layout from vk_image

`vk_image_init` sanitizes create info parameters for us, which we should
use instead.

For example, `maintenance5` blit-with-remaining-layers tests pass the layer
count in `depth` and later pull it out inside the test to set the `arrayLayers`.
They do not reset `depth` to 1, but `vk_image_create` sanitizes it for us.

While we're here, also pull out the extra stencil plane created from original
NVK code, as we don't use it.

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41663>
This commit is contained in:
squidbus 2026-05-16 15:49:25 -07:00 committed by Marge Bot
parent 7882321d4f
commit 65acc110d4
4 changed files with 20 additions and 50 deletions

View file

@ -545,16 +545,11 @@ kk_image_init(struct kk_device *dev, struct kk_image *image,
ycbcr_info ? ycbcr_info->planes[plane].denominator_scales[0] : 1;
const uint8_t height_scale =
ycbcr_info ? ycbcr_info->planes[plane].denominator_scales[1] : 1;
kk_image_layout_init(dev, pCreateInfo, vk_format_to_pipe_format(format),
kk_image_layout_init(dev, &image->vk, vk_format_to_pipe_format(format),
width_scale, height_scale,
&image->planes[plane].layout);
}
if (image->vk.format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
kk_image_layout_init(dev, pCreateInfo, PIPE_FORMAT_R32_UINT, 1, 1,
&image->stencil_copy_temp.layout);
}
return VK_SUCCESS;
}
@ -587,11 +582,6 @@ kk_image_finish(struct kk_device *dev, struct kk_image *image,
pAllocator);
}
if (image->stencil_copy_temp.layout.size_B > 0) {
kk_image_plane_finish(dev, &image->stencil_copy_temp,
image->vk.create_flags, pAllocator);
}
vk_image_finish(&image->vk);
}
@ -687,11 +677,6 @@ kk_get_image_memory_requirements(struct kk_device *dev, struct kk_image *image,
}
}
if (image->stencil_copy_temp.layout.size_B > 0) {
kk_image_plane_add_req(dev, image, &image->stencil_copy_temp, &size_B,
&align_B);
}
pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types;
pMemoryRequirements->memoryRequirements.alignment = align_B;
pMemoryRequirements->memoryRequirements.size = size_B;
@ -918,13 +903,6 @@ kk_bind_image_memory(struct kk_device *dev, const VkBindImageMemoryInfo *info)
}
}
if (image->stencil_copy_temp.layout.size_B > 0) {
result = kk_image_plane_bind(dev, image, &image->stencil_copy_temp, mem,
&offset_B);
if (result != VK_SUCCESS)
return result;
}
return VK_SUCCESS;
}

View file

@ -49,14 +49,6 @@ struct kk_image {
uint8_t plane_count;
struct kk_image_plane planes[3];
/* In order to support D32_SFLOAT_S8_UINT, a temp area is
* needed. The stencil plane can't be a copied using the DMA
* engine in a single pass since it would need 8 components support.
* Instead we allocate a 16-bit temp, that gets copied into, then
* copied again down to the 8-bit result.
*/
struct kk_image_plane stencil_copy_temp;
};
static inline mtl_resource *

View file

@ -15,17 +15,17 @@
#include "util/format/u_format.h"
static enum mtl_texture_type
vk_image_create_info_to_mtl_texture_type(
const struct VkImageCreateInfo *create_info)
vk_image_to_mtl_texture_type(
const struct vk_image *image)
{
uint32_t array_layers = create_info->arrayLayers;
uint32_t samples = create_info->samples;
switch (create_info->imageType) {
uint32_t array_layers = image->array_layers;
uint32_t samples = image->samples;
switch (image->image_type) {
case VK_IMAGE_TYPE_1D:
case VK_IMAGE_TYPE_2D:
/* We require input attachments to be arrays */
if (array_layers > 1 ||
(create_info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
(image->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT))
return samples > 1u ? MTL_TEXTURE_TYPE_2D_ARRAY_MULTISAMPLE
: MTL_TEXTURE_TYPE_2D_ARRAY;
return samples > 1u ? MTL_TEXTURE_TYPE_2D_MULTISAMPLE
@ -78,27 +78,27 @@ vk_image_usage_flags_to_mtl_texture_usage(VkImageUsageFlags usage_flags,
void
kk_image_layout_init(const struct kk_device *dev,
const struct VkImageCreateInfo *create_info,
const struct vk_image *image,
enum pipe_format format, const uint8_t width_scale,
const uint8_t height_scale, struct kk_image_layout *layout)
{
const struct kk_va_format *supported_format = kk_get_va_format(format);
layout->type = vk_image_create_info_to_mtl_texture_type(create_info);
layout->width_px = create_info->extent.width / width_scale;
layout->height_px = create_info->extent.height / height_scale;
layout->depth_px = create_info->extent.depth;
layout->layers = create_info->arrayLayers;
layout->levels = create_info->mipLevels;
layout->optimized_layout = create_info->tiling == VK_IMAGE_TILING_OPTIMAL;
layout->type = vk_image_to_mtl_texture_type(image);
layout->width_px = image->extent.width / width_scale;
layout->height_px = image->extent.height / height_scale;
layout->depth_px = image->extent.depth;
layout->layers = image->array_layers;
layout->levels = image->mip_levels;
layout->optimized_layout = image->tiling == VK_IMAGE_TILING_OPTIMAL;
layout->usage = vk_image_usage_flags_to_mtl_texture_usage(
create_info->usage, create_info->flags, supported_format->atomic);
image->usage, image->create_flags, supported_format->atomic);
layout->format.pipe = format;
layout->format.mtl = supported_format->mtl_pixel_format;
layout->swizzle.red = supported_format->unswizzle.red;
layout->swizzle.green = supported_format->unswizzle.green;
layout->swizzle.blue = supported_format->unswizzle.blue;
layout->swizzle.alpha = supported_format->unswizzle.alpha;
layout->sample_count_sa = create_info->samples;
layout->sample_count_sa = image->samples;
mtl_heap_texture_size_and_align_with_descriptor(dev->mtl_handle, layout);
/*
@ -111,7 +111,7 @@ kk_image_layout_init(const struct kk_device *dev,
}
// TODO_KOSMICKRISP Fill remaining offsets and strides whenever possible
if (create_info->tiling == VK_IMAGE_TILING_LINEAR) {
if (image->tiling == VK_IMAGE_TILING_LINEAR) {
const struct util_format_description *format_desc =
util_format_description(layout->format.pipe);
size_t bytes_per_texel = format_desc->block.bits / 8;

View file

@ -12,7 +12,7 @@
#include "util/format/u_formats.h"
#include "vulkan/vulkan.h"
#include "vk_image.h"
#define KK_MAX_MIP_LEVELS 16
@ -132,7 +132,7 @@ struct kk_view_layout {
};
void kk_image_layout_init(const struct kk_device *dev,
const struct VkImageCreateInfo *create_info,
const struct vk_image *image,
enum pipe_format format, const uint8_t width_scale,
const uint8_t height_scale,
struct kk_image_layout *layout);