From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id BDFB74080F
	for <ffmpegdev@gitmailbox.com>; Fri, 18 Apr 2025 13:37:30 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F155687DA1;
	Fri, 18 Apr 2025 16:37:24 +0300 (EEST)
Received: from vidala.pars.ee (vidala.pars.ee [116.203.72.101])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D6B3687D4E
 for <ffmpeg-devel@ffmpeg.org>; Fri, 18 Apr 2025 16:37:17 +0300 (EEST)
DKIM-Signature: v=1; a=rsa-sha256; s=202405r; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1744983437; bh=izccGK54pRS20JXUWI2pPT+
 3pSFLibTE56gt8sKqMAM=; b=f3cKc5yvEUYADkCK4+vULf6+ktZBP3PP+QwLwwZ1sEeHpAVzFQ
 rAfQcfgnzSPiNC2TuWvujAogpeIRl/0hur0OJUO/B8JCKLd3XprBzrLoWeOmZ0Ca87LRU/1fII0
 1ZuOquIdLNvQ1ydd44aDy80BaYg6RHsm8IobULi81QnCw8YFd6pBh+KkFnDvDSkmuNrZENyhlfb
 wPRPEChOxi3dOqUW3kJav0RusFvEQVVvUwP68fLDChp1ku1PamTirvThaxOesWp/uLc/jwv+8BF
 +zkl8S8/qUy3F9j20KvLv47G/zwb9+5r5Gk3ODy55MbogE0T9FEHlYJMLgwZC72eDnQ==;
DKIM-Signature: v=1; a=ed25519-sha256; s=202405e; d=lynne.ee; c=relaxed/relaxed;
 h=Message-ID:Date:Subject:To:From; t=1744983437; bh=izccGK54pRS20JXUWI2pPT+
 3pSFLibTE56gt8sKqMAM=; b=eEeDA63gyOtqsPoKweKas++3qpDnILKv7EVMyEqnffQFQ9bP5e
 KwbcvqXUNLsCBOfJpWKN8gNmExKEYIJuJxBw==;
From: Lynne <dev@lynne.ee>
To: ffmpeg-devel@ffmpeg.org
Date: Fri, 18 Apr 2025 15:37:10 +0200
Message-ID: <20250418133716.429620-1-dev@lynne.ee>
X-Mailer: git-send-email 2.49.0.395.g12beb8f557c
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH] vulkan: use
 ReadWithoutFormat/WriteWithoutFormat
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Lynne <dev@lynne.ee>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250418133716.429620-1-dev@lynne.ee/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

This implements support for reading and writing storage images with
no format.
The issue is that we define our images as arrays, and arrays can
only have a single type, which means that f.ex. NV12 needs two
different images, R8 and RG8.

Not using any formats fixes this.
---
 libavutil/vulkan.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 8f444b2dfe..4bf3f76d78 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1804,10 +1804,13 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum FFVkShaderRepFormat rep_fmt)
     return VK_FORMAT_UNDEFINED;
 }
 
-static void bgr_workaround(AVVulkanFramesContext *vkfc,
+static void bgr_workaround(FFVulkanContext *s,
+                           AVVulkanFramesContext *vkfc,
                            VkImageViewCreateInfo *ci)
 {
-    if (!(vkfc->usage & VK_IMAGE_USAGE_STORAGE_BIT))
+    if (!(vkfc->usage & VK_IMAGE_USAGE_STORAGE_BIT) ||
+        s->feats.features.shaderStorageImageReadWithoutFormat ||
+        s->feats.features.shaderStorageImageWriteWithoutFormat)
         return;
     switch (ci->format) {
 #define REMAP(src, dst)   \
@@ -1858,7 +1861,7 @@ int ff_vk_create_imageview(FFVulkanContext *s,
             .layerCount = 1,
         },
     };
-    bgr_workaround(vkfc, &view_create_info);
+    bgr_workaround(s, vkfc, &view_create_info);
     if (view_create_info.format == VK_FORMAT_UNDEFINED) {
         av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
                                 "of format %i and mode %i\n",
@@ -1920,7 +1923,7 @@ int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
                 .layerCount = 1,
             },
         };
-        bgr_workaround(vkfc, &view_create_info);
+        bgr_workaround(s, vkfc, &view_create_info);
         if (view_create_info.format == VK_FORMAT_UNDEFINED) {
             av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
                                     "of format %i and mode %i\n",
@@ -2060,6 +2063,9 @@ int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name,
     GLSLC(0, #extension GL_EXT_scalar_block_layout : require                  );
     GLSLC(0, #extension GL_EXT_shader_explicit_arithmetic_types : require     );
     GLSLC(0, #extension GL_EXT_control_flow_attributes : require              );
+    if (s->feats.features.shaderStorageImageReadWithoutFormat ||
+        s->feats.features.shaderStorageImageWriteWithoutFormat)
+        GLSLC(0, #extension GL_EXT_shader_image_load_formatted : require      );
     if (s->extensions & FF_VK_EXT_EXPECT_ASSUME) {
         GLSLC(0, #extension GL_EXT_expect_assume : require                    );
     } else {
@@ -2458,7 +2464,13 @@ print:
         GLSLA("layout (set = %i, binding = %i", FFMAX(shd->nb_descriptor_sets - 1, 0), i);
 
         if (desc[i].mem_layout)
-            GLSLA(", %s", desc[i].mem_layout);
+            if ((desc[i].type != VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
+                (!strcmp(desc[i].mem_quali, "readonly") &&
+                 !s->feats.features.shaderStorageImageReadWithoutFormat) ||
+                (!strcmp(desc[i].mem_quali, "writeonly") &&
+                 !s->feats.features.shaderStorageImageWriteWithoutFormat))
+                GLSLA(", %s", desc[i].mem_layout);
+
         GLSLA(")");
 
         if (prop->is_uniform)
-- 
2.49.0.395.g12beb8f557c
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".