From a33538cb9feca104d0c0b886994c655ef311971b Mon Sep 17 00:00:00 2001 From: Valentine Burley Date: Tue, 10 Sep 2024 20:13:16 +0200 Subject: [PATCH] nvk: Remap 10 and 12 bit formats to 16 bit formats Preserves the previous behavior while handling the new formats. Reviewed-by: Faith Ekstrand Signed-off-by: Valentine Burley Part-of: --- src/nouveau/vulkan/nvk_buffer_view.c | 4 ++-- src/nouveau/vulkan/nvk_cmd_clear.c | 3 ++- src/nouveau/vulkan/nvk_cmd_draw.c | 8 ++++---- src/nouveau/vulkan/nvk_descriptor_set.c | 3 ++- src/nouveau/vulkan/nvk_format.h | 16 ++++++++++++++++ src/nouveau/vulkan/nvk_image.c | 12 ++++++------ src/nouveau/vulkan/nvk_image_view.c | 2 +- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/nouveau/vulkan/nvk_buffer_view.c b/src/nouveau/vulkan/nvk_buffer_view.c index 484a4ec2581..3f8d03dd2e6 100644 --- a/src/nouveau/vulkan/nvk_buffer_view.c +++ b/src/nouveau/vulkan/nvk_buffer_view.c @@ -24,7 +24,7 @@ nvk_get_buffer_format_features(struct nvk_physical_device *pdev, if (nvk_get_va_format(pdev, vk_format)) features |= VK_FORMAT_FEATURE_2_VERTEX_BUFFER_BIT; - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = nvk_format_to_pipe_format(vk_format); if (nil_format_supports_buffer(&pdev->info, p_format)) { features |= VK_FORMAT_FEATURE_2_UNIFORM_TEXEL_BUFFER_BIT; @@ -60,7 +60,7 @@ nvk_CreateBufferView(VkDevice _device, return vk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY); const uint64_t addr = nvk_buffer_address(buffer, view->vk.offset); - enum pipe_format format = vk_format_to_pipe_format(view->vk.format); + enum pipe_format format = nvk_format_to_pipe_format(view->vk.format); if (nvk_use_edb_buffer_views(pdev)) { view->edb_desc = diff --git a/src/nouveau/vulkan/nvk_cmd_clear.c b/src/nouveau/vulkan/nvk_cmd_clear.c index 110c8bdd194..22af057ac35 100644 --- a/src/nouveau/vulkan/nvk_cmd_clear.c +++ b/src/nouveau/vulkan/nvk_cmd_clear.c @@ -6,6 +6,7 @@ #include "nvk_device.h" #include "nvk_entrypoints.h" +#include "nvk_format.h" #include "nvk_image.h" #include "nvk_image_view.h" #include "nvk_mme.h" @@ -329,7 +330,7 @@ nvk_CmdClearColorImage(VkCommandBuffer commandBuffer, 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 = nvk_format_to_pipe_format(vk_format); assert(p_format != PIPE_FORMAT_NONE); if (!nil_format_supports_color_targets(&pdev->info, p_format)) { diff --git a/src/nouveau/vulkan/nvk_cmd_draw.c b/src/nouveau/vulkan/nvk_cmd_draw.c index e6913b53d43..0e93609583f 100644 --- a/src/nouveau/vulkan/nvk_cmd_draw.c +++ b/src/nouveau/vulkan/nvk_cmd_draw.c @@ -989,7 +989,7 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, if (level->tiling.gob_type != NIL_GOB_TYPE_LINEAR) { const enum pipe_format p_format = - vk_format_to_pipe_format(iview->vk.format); + nvk_format_to_pipe_format(iview->vk.format); /* We use the stride for depth/stencil targets because the Z/S * hardware has no concept of a tile width. Instead, we just set @@ -1026,7 +1026,7 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, uint32_t pitch = level->row_stride_B; const enum pipe_format p_format = - vk_format_to_pipe_format(iview->vk.format); + nvk_format_to_pipe_format(iview->vk.format); /* When memory layout is set to LAYOUT_PITCH, the WIDTH field * takes row pitch */ @@ -1104,7 +1104,7 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, P_NV9097_SET_ZT_A(p, addr >> 32); P_NV9097_SET_ZT_B(p, addr); const enum pipe_format p_format = - vk_format_to_pipe_format(iview->vk.format); + nvk_format_to_pipe_format(iview->vk.format); const uint8_t zs_format = nil_format_to_depth_stencil(p_format); P_NV9097_SET_ZT_FORMAT(p, zs_format); assert(level->tiling.gob_type != NIL_GOB_TYPE_LINEAR); @@ -1192,7 +1192,7 @@ nvk_CmdBeginRendering(VkCommandBuffer commandBuffer, }); const enum pipe_format p_format = - vk_format_to_pipe_format(iview->vk.format); + nvk_format_to_pipe_format(iview->vk.format); const uint32_t row_stride_el = level->row_stride_B / util_format_get_blocksize(p_format); P_NVC597_SET_SHADING_RATE_INDEX_SURFACE_ALLOCATED_SIZE(p, 0, diff --git a/src/nouveau/vulkan/nvk_descriptor_set.c b/src/nouveau/vulkan/nvk_descriptor_set.c index 3a650eb29d1..f06f28f7274 100644 --- a/src/nouveau/vulkan/nvk_descriptor_set.c +++ b/src/nouveau/vulkan/nvk_descriptor_set.c @@ -9,6 +9,7 @@ #include "nvk_descriptor_set_layout.h" #include "nvk_device.h" #include "nvk_entrypoints.h" +#include "nvk_format.h" #include "nvk_image_view.h" #include "nvk_physical_device.h" #include "nvk_sampler.h" @@ -256,7 +257,7 @@ get_edb_buffer_view_desc(struct nvk_device *dev, { struct nvk_edb_buffer_view_descriptor desc = { }; if (info != NULL && info->address != 0) { - enum pipe_format format = vk_format_to_pipe_format(info->format); + enum pipe_format format = nvk_format_to_pipe_format(info->format); desc = nvk_edb_bview_cache_get_descriptor(dev, &dev->edb_bview_cache, info->address, info->range, format); diff --git a/src/nouveau/vulkan/nvk_format.h b/src/nouveau/vulkan/nvk_format.h index fbe586c2039..fe666b1042e 100644 --- a/src/nouveau/vulkan/nvk_format.h +++ b/src/nouveau/vulkan/nvk_format.h @@ -6,6 +6,7 @@ #define NVK_FORMAT_H 1 #include "nvk_private.h" +#include "vk_format.h" #include "util/format/u_formats.h" #include "nv_device_info.h" @@ -25,4 +26,19 @@ nvk_format_supports_atomics(const struct nv_device_info *dev, const struct nvk_va_format * nvk_get_va_format(const struct nvk_physical_device *pdev, VkFormat format); +static inline enum pipe_format +nvk_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); + } +} + #endif diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 4c6429f6369..8531623c169 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -34,7 +34,7 @@ nvk_get_image_plane_format_features(struct nvk_physical_device *pdev, !fourcc_mod_is_vendor(drm_format_mod, NVIDIA)) return 0; - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = nvk_format_to_pipe_format(vk_format); if (p_format == PIPE_FORMAT_NONE) return 0; @@ -195,7 +195,7 @@ nvk_get_drm_format_modifier_properties_list(struct nvk_physical_device *pdev, uint64_t mods[NIL_MAX_DRM_FORMAT_MODS]; size_t mod_count = NIL_MAX_DRM_FORMAT_MODS; - enum pipe_format p_format = vk_format_to_pipe_format(vk_format); + enum pipe_format p_format = nvk_format_to_pipe_format(vk_format); nil_drm_format_mods_for_format(&pdev->info, nil_format(p_format), &mod_count, &mods); if (mod_count == 0) { @@ -695,7 +695,7 @@ nvk_GetPhysicalDeviceSparseImageFormatProperties2( VkImageAspectFlags aspects = vk_format_aspects(pFormatInfo->format); const enum pipe_format pipe_format = - vk_format_to_pipe_format(pFormatInfo->format); + nvk_format_to_pipe_format(pFormatInfo->format); const enum nil_image_dim dim = vk_image_type_to_nil_dim(pFormatInfo->type); const enum nil_sample_layout sample_layout = nil_choose_sample_layout(pFormatInfo->samples); @@ -775,7 +775,7 @@ nvk_image_init(struct nvk_device *dev, IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT); enum pipe_format p_format = - vk_format_to_pipe_format(pCreateInfo->format); + nvk_format_to_pipe_format(pCreateInfo->format); image->vk.drm_format_mod = nil_select_best_drm_format_mod(&pdev->info, nil_format(p_format), mod_list_info->drmFormatModifierCount, @@ -789,7 +789,7 @@ nvk_image_init(struct nvk_device *dev, struct nil_image_init_info tiled_shadow_nil_info = { .dim = vk_image_type_to_nil_dim(pCreateInfo->imageType), - .format = nil_format(vk_format_to_pipe_format(image->vk.format)), + .format = nil_format(nvk_format_to_pipe_format(image->vk.format)), .modifier = DRM_FORMAT_MOD_INVALID, .extent_px = { .width = pCreateInfo->extent.width, @@ -818,7 +818,7 @@ nvk_image_init(struct nvk_device *dev, ycbcr_info->planes[plane].denominator_scales[1] : 1; struct nil_image_init_info nil_info = { .dim = vk_image_type_to_nil_dim(pCreateInfo->imageType), - .format = nil_format(vk_format_to_pipe_format(format)), + .format = nil_format(nvk_format_to_pipe_format(format)), .modifier = image->vk.drm_format_mod, .extent_px = { .width = pCreateInfo->extent.width / width_scale, diff --git a/src/nouveau/vulkan/nvk_image_view.c b/src/nouveau/vulkan/nvk_image_view.c index 05816006a5d..b4f65031d3c 100644 --- a/src/nouveau/vulkan/nvk_image_view.c +++ b/src/nouveau/vulkan/nvk_image_view.c @@ -152,7 +152,7 @@ nvk_image_view_init(struct nvk_device *dev, assert(ycbcr_info || view_plane == 0); 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 = nvk_format_to_pipe_format(plane_format); if (view->vk.aspects == VK_IMAGE_ASPECT_STENCIL_BIT) p_format = get_stencil_format(p_format);