diff --git a/src/asahi/vulkan/hk_buffer_view.c b/src/asahi/vulkan/hk_buffer_view.c index 27657141222..33ac27f781d 100644 --- a/src/asahi/vulkan/hk_buffer_view.c +++ b/src/asahi/vulkan/hk_buffer_view.c @@ -17,6 +17,7 @@ #include "hk_buffer.h" #include "hk_device.h" #include "hk_entrypoints.h" +#include "hk_image.h" #include "hk_physical_device.h" #include "vk_format.h" @@ -26,7 +27,7 @@ hk_get_buffer_format_features(struct hk_physical_device *pdev, VkFormat vk_format) { VkFormatFeatureFlags2 features = 0; - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = hk_format_to_pipe_format(vk_format); if (p_format == PIPE_FORMAT_NONE) return 0; @@ -69,7 +70,7 @@ hk_CreateBufferView(VkDevice _device, const VkBufferViewCreateInfo *pCreateInfo, if (!view) return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - enum pipe_format format = vk_format_to_pipe_format(view->vk.format); + enum pipe_format format = hk_format_to_pipe_format(view->vk.format); const struct util_format_description *desc = util_format_description(format); uint8_t format_swizzle[4] = { diff --git a/src/asahi/vulkan/hk_cmd_clear.c b/src/asahi/vulkan/hk_cmd_clear.c index 59116fc8859..044a2447fa6 100644 --- a/src/asahi/vulkan/hk_cmd_clear.c +++ b/src/asahi/vulkan/hk_cmd_clear.c @@ -165,7 +165,7 @@ hk_CmdClearColorImage(VkCommandBuffer commandBuffer, VkImage _image, if (vk_format == VK_FORMAT_R64_UINT || vk_format == VK_FORMAT_R64_SINT) vk_format = VK_FORMAT_R32G32_UINT; - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = hk_format_to_pipe_format(vk_format); assert(p_format != PIPE_FORMAT_NONE); if (!ail_pixel_format[p_format].renderable) { diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index 7bcf742cb15..170b93dd0db 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -658,7 +658,7 @@ hk_CmdBeginRendering(VkCommandBuffer commandBuffer, /* Choose a tilebuffer layout given the framebuffer key */ enum pipe_format formats[HK_MAX_RTS] = {0}; for (unsigned i = 0; i < render->color_att_count; ++i) { - formats[i] = vk_format_to_pipe_format(render->color_att[i].vk_format); + formats[i] = hk_format_to_pipe_format(render->color_att[i].vk_format); } /* For now, we force layered=true since it makes compatibility problems way @@ -725,7 +725,7 @@ hk_CmdBeginRendering(VkCommandBuffer commandBuffer, unsigned first_layer = view->vk.base_array_layer; const struct util_format_description *desc = - util_format_description(vk_format_to_pipe_format(view->vk.format)); + util_format_description(hk_format_to_pipe_format(view->vk.format)); assert(desc->format == PIPE_FORMAT_Z32_FLOAT || desc->format == PIPE_FORMAT_Z16_UNORM || @@ -2757,7 +2757,7 @@ hk_flush_dynamic_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, util_bitcount64(sw_vs->info.vs.attribs_read & BITFIELD_MASK(a)); key.prolog.attribs[slot] = (struct agx_velem_key){ - .format = vk_format_to_pipe_format(attr.format), + .format = hk_format_to_pipe_format(attr.format), .stride = dyn->vi_binding_strides[attr.binding], .divisor = binding.divisor, .instanced = binding.input_rate == VK_VERTEX_INPUT_RATE_INSTANCE, @@ -2779,7 +2779,7 @@ hk_flush_dynamic_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, struct hk_addr_range vb = gfx->vb[attr.binding]; desc->root.draw.attrib_clamps[slot] = agx_calculate_vbo_clamp( - vb.addr, sink, vk_format_to_pipe_format(attr.format), vb.range, + vb.addr, sink, hk_format_to_pipe_format(attr.format), vb.range, dyn->vi_binding_strides[attr.binding], attr.offset, &desc->root.draw.attrib_base[slot]); } else { @@ -2887,7 +2887,7 @@ hk_flush_dynamic_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, struct hk_rendering_state *render = &cmd->state.gfx.render; for (uint32_t i = 0; i < render->color_att_count; i++) { key.epilog.rt_formats[i] = - vk_format_to_pipe_format(render->color_att[i].vk_format); + hk_format_to_pipe_format(render->color_att[i].vk_format); const struct vk_color_blend_attachment_state *cb = &dyn->cb.attachments[i]; diff --git a/src/asahi/vulkan/hk_cmd_meta.c b/src/asahi/vulkan/hk_cmd_meta.c index 4c9ce572650..af6f3b95cb2 100644 --- a/src/asahi/vulkan/hk_cmd_meta.c +++ b/src/asahi/vulkan/hk_cmd_meta.c @@ -206,7 +206,7 @@ aspect_format(VkFormat fmt, VkImageAspectFlags aspect) bool depth = (aspect & VK_IMAGE_ASPECT_DEPTH_BIT); bool stencil = (aspect & VK_IMAGE_ASPECT_STENCIL_BIT); - enum pipe_format p_format = vk_format_to_pipe_format(fmt); + enum pipe_format p_format = hk_format_to_pipe_format(fmt); if (util_format_is_depth_or_stencil(p_format)) { assert(depth ^ stencil); @@ -308,7 +308,7 @@ static VkFormat canonical_format(VkFormat fmt) { return vk_format_from_pipe_format( - canonical_format_pipe(vk_format_to_pipe_format(fmt), false)); + canonical_format_pipe(hk_format_to_pipe_format(fmt), false)); } enum copy_type { @@ -759,7 +759,7 @@ hk_meta_copy_image_to_buffer2(struct vk_command_buffer *cmd, } bool per_layer = - util_format_is_compressed(vk_format_to_pipe_format(image->format)); + util_format_is_compressed(hk_format_to_pipe_format(image->format)); for (unsigned i = 0; i < pCopyBufferInfo->regionCount; ++i) { const VkBufferImageCopy2 *region = &pCopyBufferInfo->pRegions[i]; @@ -776,9 +776,9 @@ hk_meta_copy_image_to_buffer2(struct vk_command_buffer *cmd, VkFormat canonical = canonical_format(aspect_fmt); uint32_t blocksize_B = - util_format_get_blocksize(vk_format_to_pipe_format(canonical)); + util_format_get_blocksize(hk_format_to_pipe_format(canonical)); - enum pipe_format p_format = vk_format_to_pipe_format(image->format); + enum pipe_format p_format = hk_format_to_pipe_format(image->format); unsigned row_extent = util_format_get_nblocksx( p_format, MAX2(region->bufferRowLength, @@ -800,8 +800,8 @@ hk_meta_copy_image_to_buffer2(struct vk_command_buffer *cmd, .type = IMG2BUF, .block_size = blocksize_B, .nr_samples = image->samples, - .src_format = vk_format_to_pipe_format(canonical), - .dst_format = vk_format_to_pipe_format(canonical), + .src_format = hk_format_to_pipe_format(canonical), + .dst_format = hk_format_to_pipe_format(canonical), }; VkPipelineLayout pipeline_layout; @@ -874,7 +874,7 @@ hk_meta_copy_image_to_buffer2(struct vk_command_buffer *cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); enum pipe_format p_src_fmt = - vk_format_to_pipe_format(src_image->format); + hk_format_to_pipe_format(src_image->format); struct vk_meta_push_data push = { .buffer = hk_buffer_address(buffer, region->bufferOffset), @@ -962,7 +962,7 @@ hk_meta_copy_buffer_to_image2(struct vk_command_buffer *cmd, } bool per_layer = - util_format_is_compressed(vk_format_to_pipe_format(image->format)); + util_format_is_compressed(hk_format_to_pipe_format(image->format)); for (unsigned r = 0; r < info->regionCount; ++r) { const VkBufferImageCopy2 *region = &info->pRegions[r]; @@ -976,7 +976,7 @@ hk_meta_copy_buffer_to_image2(struct vk_command_buffer *cmd, VkImageAspectFlags aspect = region->imageSubresource.aspectMask; VkFormat aspect_fmt = aspect_format(image->format, aspect); VkFormat canonical = canonical_format(aspect_fmt); - enum pipe_format p_format = vk_format_to_pipe_format(aspect_fmt); + enum pipe_format p_format = hk_format_to_pipe_format(aspect_fmt); uint32_t blocksize_B = util_format_get_blocksize(p_format); bool is_3d = region->imageExtent.depth > 1; @@ -985,9 +985,9 @@ hk_meta_copy_buffer_to_image2(struct vk_command_buffer *cmd, .type = BUF2IMG, .block_size = blocksize_B, .nr_samples = image->samples, - .src_format = vk_format_to_pipe_format(canonical), + .src_format = hk_format_to_pipe_format(canonical), .dst_format = canonical_format_pipe( - vk_format_to_pipe_format(aspect_format(image->format, aspect)), + hk_format_to_pipe_format(aspect_format(image->format, aspect)), false), /* TODO: MSAA path */ @@ -1111,8 +1111,8 @@ hk_meta_copy_image2(struct vk_command_buffer *cmd, struct vk_meta_device *meta, } bool per_layer = - util_format_is_compressed(vk_format_to_pipe_format(src_image->format)) || - util_format_is_compressed(vk_format_to_pipe_format(dst_image->format)); + util_format_is_compressed(hk_format_to_pipe_format(src_image->format)) || + util_format_is_compressed(hk_format_to_pipe_format(dst_image->format)); for (unsigned r = 0; r < info->regionCount; ++r) { const VkImageCopy2 *region = &info->pRegions[r]; @@ -1131,7 +1131,7 @@ hk_meta_copy_image2(struct vk_command_buffer *cmd, struct vk_meta_device *meta, VkFormat aspect_fmt = aspect_format(src_image->format, 1 << aspect); VkFormat canonical = canonical_format(aspect_fmt); uint32_t blocksize_B = - util_format_get_blocksize(vk_format_to_pipe_format(canonical)); + util_format_get_blocksize(hk_format_to_pipe_format(canonical)); VkImageAspectFlagBits dst_aspect_mask = vk_format_get_ycbcr_info(dst_image->format) || @@ -1144,9 +1144,9 @@ hk_meta_copy_image2(struct vk_command_buffer *cmd, struct vk_meta_device *meta, .type = IMG2IMG, .block_size = blocksize_B, .nr_samples = dst_image->samples, - .src_format = vk_format_to_pipe_format(canonical), + .src_format = hk_format_to_pipe_format(canonical), .dst_format = - canonical_format_pipe(vk_format_to_pipe_format(aspect_format( + canonical_format_pipe(hk_format_to_pipe_format(aspect_format( dst_image->format, dst_aspect_mask)), false), @@ -1276,10 +1276,10 @@ hk_meta_copy_image2(struct vk_command_buffer *cmd, struct vk_meta_device *meta, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); enum pipe_format p_src_fmt = - vk_format_to_pipe_format(src_image->format); + hk_format_to_pipe_format(src_image->format); enum pipe_format p_dst_fmt = - vk_format_to_pipe_format(dst_image->format); - enum pipe_format p_format = vk_format_to_pipe_format(aspect_fmt); + hk_format_to_pipe_format(dst_image->format); + enum pipe_format p_format = hk_format_to_pipe_format(aspect_fmt); struct vk_meta_push_data push = { .src_offset_el[0] = diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index ac73001d7fa..4beb9b72ff3 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -44,7 +44,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, break; } - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = hk_format_to_pipe_format(vk_format); if (p_format == PIPE_FORMAT_NONE) return 0; @@ -264,7 +264,7 @@ hk_can_compress(struct agx_device *dev, VkFormat format, unsigned plane, return false; } - enum pipe_format p_format = vk_format_to_pipe_format(format); + enum pipe_format p_format = hk_format_to_pipe_format(format); /* Check for format compatibility if mutability is enabled. */ if (flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) { @@ -279,7 +279,7 @@ hk_can_compress(struct agx_device *dev, VkFormat format, unsigned plane, continue; enum pipe_format view_format = - vk_format_to_pipe_format(format_list->pViewFormats[i]); + hk_format_to_pipe_format(format_list->pViewFormats[i]); if (!ail_formats_compatible(p_format, view_format)) { perf_debug_dev(dev, "No compression: incompatible image view"); @@ -807,7 +807,7 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, image->planes[plane].layout = (struct ail_layout){ .tiling = tiling, .mipmapped_z = pCreateInfo->imageType == VK_IMAGE_TYPE_3D, - .format = vk_format_to_pipe_format(format), + .format = hk_format_to_pipe_format(format), .width_px = pCreateInfo->extent.width / width_scale, .height_px = pCreateInfo->extent.height / height_scale, diff --git a/src/asahi/vulkan/hk_image.h b/src/asahi/vulkan/hk_image.h index a15129032aa..0666b364979 100644 --- a/src/asahi/vulkan/hk_image.h +++ b/src/asahi/vulkan/hk_image.h @@ -12,6 +12,7 @@ #include "hk_private.h" +#include "vk_format.h" #include "vk_image.h" /* Because small images can end up with an array_stride_B that is less than @@ -87,6 +88,21 @@ hk_image_base_address(const struct hk_image *image, uint8_t plane) return hk_image_plane_base_address(&image->planes[plane]); } +static inline enum pipe_format +hk_format_to_pipe_format(enum VkFormat vkformat) +{ + switch (vkformat) { + case VK_FORMAT_R10X6_UNORM_PACK16: + case VK_FORMAT_R12X4_UNORM_PACK16: + return PIPE_FORMAT_R16_UNORM; + case VK_FORMAT_R10X6G10X6_UNORM_2PACK16: + case VK_FORMAT_R12X4G12X4_UNORM_2PACK16: + return PIPE_FORMAT_R16G16_UNORM; + default: + return vk_format_to_pipe_format(vkformat); + } +} + static inline uint8_t hk_image_aspects_to_plane(const struct hk_image *image, VkImageAspectFlags aspectMask) diff --git a/src/asahi/vulkan/hk_image_view.c b/src/asahi/vulkan/hk_image_view.c index 531a0813ffa..cd09dfc13d6 100644 --- a/src/asahi/vulkan/hk_image_view.c +++ b/src/asahi/vulkan/hk_image_view.c @@ -142,9 +142,9 @@ struct hk_3d { static struct hk_3d view_denominator(struct hk_image_view *view) { - enum pipe_format view_format = vk_format_to_pipe_format(view->vk.format); + enum pipe_format view_format = hk_format_to_pipe_format(view->vk.format); enum pipe_format img_format = - vk_format_to_pipe_format(view->vk.image->format); + hk_format_to_pipe_format(view->vk.image->format); if (util_format_is_compressed(view_format)) { /* @@ -185,7 +185,7 @@ format_for_plane(struct hk_image_view *view, unsigned view_plane) VkFormat plane_format = ycbcr_info ? ycbcr_info->planes[view_plane].format : view->vk.format; - enum pipe_format p_format = vk_format_to_pipe_format(plane_format); + enum pipe_format p_format = hk_format_to_pipe_format(plane_format); if (view->vk.aspects == VK_IMAGE_ASPECT_STENCIL_BIT) p_format = get_stencil_format(p_format);