diff mbox series

[FFmpeg-devel] vulkan: enable VK_KHR_cooperative_matrix

Message ID NbeCLQn--3-9@lynne.ee
State New
Headers show
Series [FFmpeg-devel] vulkan: enable VK_KHR_cooperative_matrix | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Lynne Aug. 12, 2023, 2:45 p.m. UTC
It's of interest to API users, and of interest to us,
as a DCT/DST can be implemented via matrix multiplies.

Bumps up the required header version to 1.3.255, released
2 months ago, so it's had time to propagate.

Patch attached.

Comments

Kacper Michajłow Aug. 12, 2023, 10:15 p.m. UTC | #1
On Sat, 12 Aug 2023 at 16:45, Lynne <dev@lynne.ee> wrote:
>
> It's of interest to API users, and of interest to us,
> as a DCT/DST can be implemented via matrix multiplies.
>
> Bumps up the required header version to 1.3.255, released
> 2 months ago, so it's had time to propagate.

I would disagree, considering latest Vulkan SDK release is 1.3.250.1.
Please wait untill new version is released.

> Patch attached.
>
> _______________________________________________
> 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".
Lynne Aug. 26, 2023, 9:19 p.m. UTC | #2
Aug 13, 2023, 00:15 by kasper93@gmail.com:

> On Sat, 12 Aug 2023 at 16:45, Lynne <dev@lynne.ee> wrote:
>
>>
>> It's of interest to API users, and of interest to us,
>> as a DCT/DST can be implemented via matrix multiplies.
>>
>> Bumps up the required header version to 1.3.255, released
>> 2 months ago, so it's had time to propagate.
>>
>
> I would disagree, considering latest Vulkan SDK release is 1.3.250.1.
> Please wait untill new version is released.
>

New SDK version 1.3.261.0 was released 5 days ago by LunarG,
so I think everyone's had time to update their headers.
Thanks.
Kacper Michajłow Aug. 26, 2023, 10:44 p.m. UTC | #3
On Sat, 26 Aug 2023 at 23:19, Lynne <dev@lynne.ee> wrote:
>
> Aug 13, 2023, 00:15 by kasper93@gmail.com:
>
> > On Sat, 12 Aug 2023 at 16:45, Lynne <dev@lynne.ee> wrote:
> >
> >>
> >> It's of interest to API users, and of interest to us,
> >> as a DCT/DST can be implemented via matrix multiplies.
> >>
> >> Bumps up the required header version to 1.3.255, released
> >> 2 months ago, so it's had time to propagate.
> >>
> >
> > I would disagree, considering latest Vulkan SDK release is 1.3.250.1.
> > Please wait untill new version is released.
> >
>
> New SDK version 1.3.261.0 was released 5 days ago by LunarG,
> so I think everyone's had time to update their headers.
> Thanks.

Fine with me.

-Kacper
diff mbox series

Patch

From b3c9c3545d6ec97e3cad2b889ebfe932c13bcf67 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Sat, 12 Aug 2023 10:46:45 +0000
Subject: [PATCH] vulkan: enable VK_KHR_cooperative_matrix

It's of interest to API users, and of interest to us,
as a DCT/DST can be implemented via matrix multiplies.
---
 configure                    |  4 ++--
 libavutil/hwcontext_vulkan.c | 14 ++++++++++++--
 libavutil/vulkan.c           | 25 ++++++++++++++++++++++++-
 libavutil/vulkan.h           |  4 ++++
 libavutil/vulkan_functions.h |  2 ++
 libavutil/vulkan_loader.h    |  1 +
 6 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 932998b8d6..4015811cbd 100755
--- a/configure
+++ b/configure
@@ -7144,8 +7144,8 @@  enabled crystalhd && check_lib crystalhd "stdint.h libcrystalhd/libcrystalhd_if.
          "in maintaining it."
 
 if enabled vulkan; then
-    check_pkg_config_header_only vulkan "vulkan >= 1.3.238" "vulkan/vulkan.h" "defined VK_VERSION_1_3" ||
-        check_cpp_condition vulkan "vulkan/vulkan.h" "defined(VK_VERSION_1_4) || (defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 238)"
+    check_pkg_config_header_only vulkan "vulkan >= 1.3.255" "vulkan/vulkan.h" "defined VK_VERSION_1_3" ||
+        check_cpp_condition vulkan "vulkan/vulkan.h" "defined(VK_VERSION_1_4) || (defined(VK_VERSION_1_3) && VK_HEADER_VERSION >= 255)"
 fi
 
 if enabled x86; then
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 75314f1407..26f63e8f86 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -99,6 +99,7 @@  typedef struct VulkanDevicePriv {
     VkPhysicalDeviceVulkan13Features device_features_1_3;
     VkPhysicalDeviceDescriptorBufferFeaturesEXT desc_buf_features;
     VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_features;
+    VkPhysicalDeviceCooperativeMatrixFeaturesKHR coop_matrix_features;
 
     /* Queues */
     pthread_mutex_t **qf_mutex;
@@ -405,6 +406,7 @@  static const VulkanOptExtension optional_device_exts[] = {
     { VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME,                FF_VK_EXT_DESCRIPTOR_BUFFER,     },
     { VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME,              FF_VK_EXT_DEVICE_DRM             },
     { VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME,              FF_VK_EXT_ATOMIC_FLOAT           },
+    { VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME,               FF_VK_EXT_COOP_MATRIX            },
 
     /* Imports/exports */
     { VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,               FF_VK_EXT_EXTERNAL_FD_MEMORY     },
@@ -1202,9 +1204,13 @@  static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
     VkPhysicalDeviceTimelineSemaphoreFeatures timeline_features = {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES,
     };
+    VkPhysicalDeviceCooperativeMatrixFeaturesKHR coop_matrix_features = {
+        .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR,
+        .pNext = &timeline_features,
+    };
     VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_features = {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT,
-        .pNext = &timeline_features,
+        .pNext = &coop_matrix_features,
     };
     VkPhysicalDeviceDescriptorBufferFeaturesEXT desc_buf_features = {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT,
@@ -1242,7 +1248,9 @@  static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
     p->desc_buf_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_FEATURES_EXT;
     p->desc_buf_features.pNext = &p->atomic_float_features;
     p->atomic_float_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_FLOAT_FEATURES_EXT;
-    p->atomic_float_features.pNext = NULL;
+    p->atomic_float_features.pNext = &p->coop_matrix_features;
+    p->coop_matrix_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR;
+    p->coop_matrix_features.pNext = NULL;
 
     ctx->free = vulkan_device_free;
 
@@ -1304,6 +1312,8 @@  static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
     p->atomic_float_features.shaderBufferFloat32Atomics = atomic_float_features.shaderBufferFloat32Atomics;
     p->atomic_float_features.shaderBufferFloat32AtomicAdd = atomic_float_features.shaderBufferFloat32AtomicAdd;
 
+    p->coop_matrix_features.cooperativeMatrix = coop_matrix_features.cooperativeMatrix;
+
     dev_info.pNext = &hwctx->device_features;
 
     /* Setup queue family */
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 48f5f4b5dc..684b92de57 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -90,9 +90,13 @@  int ff_vk_load_props(FFVulkanContext *s)
     s->hprops = (VkPhysicalDeviceExternalMemoryHostPropertiesEXT) {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT,
     };
+    s->coop_matrix_props = (VkPhysicalDeviceCooperativeMatrixPropertiesKHR) {
+        .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_PROPERTIES_KHR,
+        .pNext = &s->hprops,
+    };
     s->subgroup_props = (VkPhysicalDeviceSubgroupSizeControlProperties) {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES,
-        .pNext = &s->hprops,
+        .pNext = &s->coop_matrix_props,
     };
     s->desc_buf_props = (VkPhysicalDeviceDescriptorBufferPropertiesEXT) {
         .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT,
@@ -161,6 +165,25 @@  int ff_vk_load_props(FFVulkanContext *s)
 
     vk->GetPhysicalDeviceQueueFamilyProperties2(s->hwctx->phys_dev, &s->tot_nb_qfs, s->qf_props);
 
+    if (vk->GetPhysicalDeviceCooperativeMatrixPropertiesKHR) {
+        vk->GetPhysicalDeviceCooperativeMatrixPropertiesKHR(s->hwctx->phys_dev,
+                                                            &s->coop_mat_props_nb, NULL);
+
+        if (s->coop_mat_props_nb) {
+            s->coop_mat_props = av_malloc_array(s->coop_mat_props_nb,
+                                                sizeof(VkCooperativeMatrixPropertiesKHR));
+            for (int i = 0; i < s->coop_mat_props_nb; i++) {
+                s->coop_mat_props[i] = (VkCooperativeMatrixPropertiesKHR) {
+                    .sType = VK_STRUCTURE_TYPE_COOPERATIVE_MATRIX_PROPERTIES_KHR,
+                };
+            }
+
+            vk->GetPhysicalDeviceCooperativeMatrixPropertiesKHR(s->hwctx->phys_dev,
+                                                                &s->coop_mat_props_nb,
+                                                                s->coop_mat_props);
+        }
+    }
+
     return 0;
 }
 
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 20b81105dd..25c5ad4b74 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -236,11 +236,15 @@  typedef struct FFVulkanContext {
     VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
     VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props;
     VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props;
+    VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props;
     VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
     VkQueueFamilyVideoPropertiesKHR *video_props;
     VkQueueFamilyProperties2 *qf_props;
     int tot_nb_qfs;
 
+    VkCooperativeMatrixPropertiesKHR *coop_mat_props;
+    uint32_t coop_mat_props_nb;
+
     VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats;
     VkPhysicalDeviceVulkan12Features feats_12;
     VkPhysicalDeviceFeatures2 feats;
diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 58a625dd65..65021b04b1 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -45,6 +45,7 @@  typedef enum FFVulkanExtensions {
     FF_VK_EXT_VIDEO_DECODE_H265      = 1ULL << 13, /* VK_EXT_video_decode_h265 */
     FF_VK_EXT_VIDEO_DECODE_AV1       = 1ULL << 14, /* VK_MESA_video_decode_av1 */
     FF_VK_EXT_ATOMIC_FLOAT           = 1ULL << 15, /* VK_EXT_shader_atomic_float */
+    FF_VK_EXT_COOP_MATRIX            = 1ULL << 16, /* VK_KHR_cooperative_matrix */
 
     FF_VK_EXT_NO_FLAG                = 1ULL << 31,
 } FFVulkanExtensions;
@@ -80,6 +81,7 @@  typedef enum FFVulkanExtensions {
     MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceImageFormatProperties2) \
     MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceQueueFamilyProperties)  \
     MACRO(1, 0, FF_VK_EXT_NO_FLAG,              GetPhysicalDeviceQueueFamilyProperties2) \
+    MACRO(1, 0, FF_VK_EXT_COOP_MATRIX,          GetPhysicalDeviceCooperativeMatrixPropertiesKHR) \
                                                                                          \
     /* Command pool */                                                                   \
     MACRO(1, 1, FF_VK_EXT_NO_FLAG,              CreateCommandPool)                       \
diff --git a/libavutil/vulkan_loader.h b/libavutil/vulkan_loader.h
index c45c674eaf..f88722f28f 100644
--- a/libavutil/vulkan_loader.h
+++ b/libavutil/vulkan_loader.h
@@ -46,6 +46,7 @@  static inline uint64_t ff_vk_extensions_to_mask(const char * const *extensions,
         { VK_EXT_DEBUG_UTILS_EXTENSION_NAME,               FF_VK_EXT_DEBUG_UTILS            },
         { VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME,       FF_VK_EXT_DEVICE_DRM             },
         { VK_EXT_SHADER_ATOMIC_FLOAT_EXTENSION_NAME,       FF_VK_EXT_ATOMIC_FLOAT           },
+        { VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME,        FF_VK_EXT_COOP_MATRIX            },
 #ifdef _WIN32
         { VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME,     FF_VK_EXT_EXTERNAL_WIN32_MEMORY  },
         { VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME,  FF_VK_EXT_EXTERNAL_WIN32_SEM     },
-- 
2.40.1