Mesa (main): radv: Add asserts to vk_format_depth/stencil_only

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 17 21:47:45 UTC 2021


Module: Mesa
Branch: main
Commit: 7878d516c67a8b64607bc38e1f42fe584fcf021e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7878d516c67a8b64607bc38e1f42fe584fcf021e

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Fri Jul 30 12:40:09 2021 -0500

radv: Add asserts to vk_format_depth/stencil_only

It doesn't make sense to ask for the depth-only or stencil-only format
if there is no depth or stencil.  One bit of radv_image.c did seem to
take advantage of the default case in vk_format_depth_only so throw an
`if (vk_format_has_depth(format))` around it.

Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12023>

---

 src/amd/vulkan/radv_image.c | 4 +++-
 src/amd/vulkan/vk_format.h  | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index 59eca338bcc..45ed9b7ed22 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -1389,6 +1389,8 @@ radv_image_reset_layout(struct radv_image *image)
 
    for (unsigned i = 0; i < image->plane_count; ++i) {
       VkFormat format = vk_format_get_plane_format(image->vk_format, i);
+      if (vk_format_has_depth(format))
+         format = vk_format_depth_only(format);
 
       uint64_t flags = image->planes[i].surface.flags;
       uint64_t modifier = image->planes[i].surface.modifier;
@@ -1398,7 +1400,7 @@ radv_image_reset_layout(struct radv_image *image)
       image->planes[i].surface.modifier = modifier;
       image->planes[i].surface.blk_w = vk_format_get_blockwidth(format);
       image->planes[i].surface.blk_h = vk_format_get_blockheight(format);
-      image->planes[i].surface.bpe = vk_format_get_blocksize(vk_format_depth_only(format));
+      image->planes[i].surface.bpe = vk_format_get_blocksize(format);
 
       /* align byte per element on dword */
       if (image->planes[i].surface.bpe == 3) {
diff --git a/src/amd/vulkan/vk_format.h b/src/amd/vulkan/vk_format.h
index d58180c0196..8f9d4cf5c90 100644
--- a/src/amd/vulkan/vk_format.h
+++ b/src/amd/vulkan/vk_format.h
@@ -124,6 +124,7 @@ vk_format_is_subsampled(VkFormat format)
 static inline VkFormat
 vk_format_depth_only(VkFormat format)
 {
+   assert(vk_format_has_depth(format));
    switch (format) {
    case VK_FORMAT_D16_UNORM_S8_UINT:
       return VK_FORMAT_D16_UNORM;
@@ -209,6 +210,7 @@ vk_format_no_srgb(VkFormat format)
 static inline VkFormat
 vk_format_stencil_only(VkFormat format)
 {
+   assert(vk_format_has_stencil(format));
    return VK_FORMAT_S8_UINT;
 }
 



More information about the mesa-commit mailing list