Use VK_KHR_video_maintenance1

This commit is contained in:
Patrick Nicolas
2025-08-08 14:06:01 +02:00
parent 5097ecef3b
commit 19ad856e59
7 changed files with 266 additions and 74 deletions
@@ -0,0 +1,64 @@
From 4905a1bd2a32d0cef4ade575021b17cf453632f0 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 5 Aug 2025 15:51:48 +0200
Subject: [PATCH 1/3] a/vk: Track VK_KHR_video_maintenance1
---
scripts/generate_vk_helpers.py | 1 +
src/xrt/auxiliary/vk/vk_bundle_init.c | 8 ++++++++
src/xrt/auxiliary/vk/vk_helpers.h | 1 +
3 files changed, 10 insertions(+)
diff --git a/scripts/generate_vk_helpers.py b/scripts/generate_vk_helpers.py
index 330b1b05e..80902193a 100755
--- a/scripts/generate_vk_helpers.py
+++ b/scripts/generate_vk_helpers.py
@@ -307,6 +307,7 @@ DEVICE_EXTENSIONS_TO_CHECK = [
"VK_KHR_present_wait",
"VK_KHR_synchronization2",
"VK_KHR_timeline_semaphore",
+ "VK_KHR_video_maintenance1",
"VK_EXT_calibrated_timestamps",
"VK_EXT_display_control",
"VK_EXT_external_memory_dma_buf",
diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c
index f28f7591f..b435d73dd 100644
--- a/src/xrt/auxiliary/vk/vk_bundle_init.c
+++ b/src/xrt/auxiliary/vk/vk_bundle_init.c
@@ -754,6 +754,7 @@ fill_in_has_device_extensions(struct vk_bundle *vk, struct u_string_list *ext_li
vk->has_KHR_present_wait = false;
vk->has_KHR_synchronization2 = false;
vk->has_KHR_timeline_semaphore = false;
+ vk->has_KHR_video_maintenance1 = false;
vk->has_EXT_calibrated_timestamps = false;
vk->has_EXT_display_control = false;
vk->has_EXT_external_memory_dma_buf = false;
@@ -868,6 +869,13 @@ fill_in_has_device_extensions(struct vk_bundle *vk, struct u_string_list *ext_li
}
#endif // defined(VK_KHR_timeline_semaphore)
+#if defined(VK_KHR_video_maintenance1)
+ if (strcmp(ext, VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME) == 0) {
+ vk->has_KHR_video_maintenance1 = true;
+ continue;
+ }
+#endif // defined(VK_KHR_video_maintenance1)
+
#if defined(VK_EXT_calibrated_timestamps)
if (strcmp(ext, VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME) == 0) {
vk->has_EXT_calibrated_timestamps = true;
diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h
index 896b597d4..3b5cbb9c8 100644
--- a/src/xrt/auxiliary/vk/vk_helpers.h
+++ b/src/xrt/auxiliary/vk/vk_helpers.h
@@ -142,6 +142,7 @@ struct vk_bundle
bool has_KHR_present_wait;
bool has_KHR_synchronization2;
bool has_KHR_timeline_semaphore;
+ bool has_KHR_video_maintenance1;
bool has_EXT_calibrated_timestamps;
bool has_EXT_display_control;
bool has_EXT_external_memory_dma_buf;
--
2.50.1
@@ -0,0 +1,134 @@
From 26d9345724a868304b9d3ca5b58fecef02493df3 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 5 Aug 2025 16:00:59 +0200
Subject: [PATCH 2/3] a/vk: Expose video_maintenance_1 device feature
---
src/xrt/auxiliary/vk/vk_bundle_init.c | 40 +++++++++++++++++++++++++--
src/xrt/auxiliary/vk/vk_helpers.h | 4 +++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c
index b435d73dd..501cd6f3c 100644
--- a/src/xrt/auxiliary/vk/vk_bundle_init.c
+++ b/src/xrt/auxiliary/vk/vk_bundle_init.c
@@ -1098,6 +1098,13 @@ filter_device_features(struct vk_bundle *vk,
};
#endif
+#ifdef VK_KHR_video_maintenance1
+ VkPhysicalDeviceVideoMaintenance1FeaturesKHR video_maintenance_1_info = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR,
+ .pNext = NULL,
+ };
+#endif
+
#ifdef VK_ANDROID_external_format_resolve
VkPhysicalDeviceExternalFormatResolveFeaturesANDROID ext_fmt_resolve_info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FORMAT_RESOLVE_FEATURES_ANDROID,
@@ -1148,6 +1155,13 @@ filter_device_features(struct vk_bundle *vk,
}
#endif
+#ifdef VK_KHR_video_maintenance1
+ if (vk->has_KHR_video_maintenance1) {
+ vk_append_to_pnext_chain((VkBaseInStructure *)&physical_device_features,
+ (VkBaseInStructure *)&video_maintenance_1_info);
+ }
+#endif
+
#ifdef VK_ANDROID_external_format_resolve
if (vk->has_ANDROID_external_format_resolve) {
vk_append_to_pnext_chain((VkBaseInStructure *)&physical_device_features,
@@ -1187,6 +1201,10 @@ filter_device_features(struct vk_bundle *vk,
CHECK(synchronization_2, synchronization_2_info.synchronization2);
#endif
+#ifdef VK_KHR_video_maintenance1
+ CHECK(video_maintenance_1, video_maintenance_1_info.videoMaintenance1);
+#endif
+
#ifdef VK_ANDROID_external_format_resolve
CHECK(ext_fmt_resolve, ext_fmt_resolve_info.externalFormatResolve);
#endif
@@ -1207,14 +1225,16 @@ filter_device_features(struct vk_bundle *vk,
"\n\tshader_storage_image_write_without_format: %i"
"\n\tstorage_buffer_8bit_access: %i"
"\n\tsynchronization_2: %i"
- "\n\ttimeline_semaphore: %i", //
+ "\n\ttimeline_semaphore: %i"
+ "\n\tvideo_maintenance_1: %i", //
device_features->ext_fmt_resolve, //
device_features->null_descriptor, //
device_features->shader_image_gather_extended, //
device_features->shader_storage_image_write_without_format, //
device_features->storage_buffer_8bit_access, //
device_features->synchronization_2, //
- device_features->timeline_semaphore); //
+ device_features->timeline_semaphore, //
+ device_features->video_maintenance_1); //
}
@@ -1262,6 +1282,7 @@ vk_create_device(struct vk_bundle *vk,
vk->features.timeline_semaphore = device_features.timeline_semaphore;
vk->features.synchronization_2 = device_features.synchronization_2;
vk->features.present_wait = device_features.present_wait;
+ vk->features.video_maintenance_1 = device_features.video_maintenance_1;
/*
@@ -1384,6 +1405,14 @@ vk_create_device(struct vk_bundle *vk,
};
#endif
+#ifdef VK_KHR_video_maintenance1
+ VkPhysicalDeviceVideoMaintenance1FeaturesKHR video_maintenance_1_info = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR,
+ .pNext = NULL,
+ .videoMaintenance1 = device_features.video_maintenance_1,
+ };
+#endif
+
#ifdef VK_ANDROID_external_format_resolve
VkPhysicalDeviceExternalFormatResolveFeaturesANDROID ext_fmt_resolve_info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FORMAT_RESOLVE_FEATURES_ANDROID,
@@ -1444,6 +1473,13 @@ vk_create_device(struct vk_bundle *vk,
}
#endif
+#ifdef VK_KHR_video_maintenance1
+ if (vk->has_KHR_video_maintenance1) {
+ vk_append_to_pnext_chain((VkBaseInStructure *)&device_create_info,
+ (VkBaseInStructure *)&video_maintenance_1_info);
+ }
+#endif
+
#ifdef VK_ANDROID_external_format_resolve
if (vk->has_ANDROID_external_format_resolve) {
vk_append_to_pnext_chain((VkBaseInStructure *)&device_create_info,
diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h
index 3b5cbb9c8..748c06dac 100644
--- a/src/xrt/auxiliary/vk/vk_helpers.h
+++ b/src/xrt/auxiliary/vk/vk_helpers.h
@@ -179,6 +179,9 @@ struct vk_bundle
//! Was KHR_present_wait requested, available, and enabled?
bool present_wait;
+
+ //! Was KHR_video_maintenance1 requested, available, and enabled?
+ bool video_maintenance_1;
} features;
//! Is the GPU a tegra device.
@@ -1030,6 +1033,7 @@ struct vk_device_features
bool ext_fmt_resolve;
bool storage_buffer_8bit_access;
bool present_wait;
+ bool video_maintenance_1;
};
/*!
--
2.50.1
@@ -0,0 +1,26 @@
From b8e23426ec5ac97efdceaf2a319b9d5921e7b412 Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Tue, 5 Aug 2025 16:01:59 +0200
Subject: [PATCH 3/3] c/util: Request video_maintenance_1 feature
This will only be enabled if the VK_KHR_maintenance1 extension was
requested.
---
src/xrt/compositor/util/comp_vulkan.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/xrt/compositor/util/comp_vulkan.c b/src/xrt/compositor/util/comp_vulkan.c
index 5618f4f78..9c719275c 100644
--- a/src/xrt/compositor/util/comp_vulkan.c
+++ b/src/xrt/compositor/util/comp_vulkan.c
@@ -282,6 +282,7 @@ create_device(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_args)
.timeline_semaphore = vk_args->timeline_semaphore,
.synchronization_2 = true,
.present_wait = true,
+ .video_maintenance_1 = true,
};
ret = vk_init_mutex(vk);
--
2.50.1
+38 -41
View File
@@ -23,12 +23,14 @@
#include "encoder/video_encoder.h"
#include "util/u_logging.h"
#include "utils/scoped_lock.h"
#include "wivrn_config.h"
#include "wivrn_foveation.h"
#include "main/comp_compositor.h"
#include "math/m_space.h"
#include "xrt_cast.h"
#include <algorithm>
#include <vector>
#include <vulkan/vulkan.hpp>
#include <vulkan/vulkan_core.h>
@@ -58,6 +60,9 @@ std::vector<const char *> wivrn_comp_target::wanted_device_extensions = {
#ifdef VK_KHR_video_encode_queue
VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_maintenance1
VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_encode_h264
VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME,
#endif
@@ -188,54 +193,46 @@ static VkResult create_images(struct wivrn_comp_target * cn, vk::ImageUsageFlags
cn->images = U_TYPED_ARRAY_CALLOC(struct comp_target_image, cn->image_count);
#if WIVRN_USE_VULKAN_ENCODE
auto [video_profiles, encoder_flags] = video_encoder::get_create_image_info(cn->settings);
vk::VideoProfileListInfoKHR video_profile_list{
.profileCount = uint32_t(video_profiles.size()),
.pProfiles = video_profiles.data(),
vk::StructureChain image_info{
vk::ImageCreateInfo{
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {
.width = cn->width,
.height = cn->height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 2, // colour then alpha
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = flags | vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive,
},
vk::ImageFormatListCreateInfo{
.viewFormatCount = formats.size(),
.pViewFormats = formats.data(),
},
};
#if WIVRN_USE_VULKAN_ENCODE
if (
vk->features.video_maintenance_1 and
std::ranges::any_of(
cn->settings,
[](const auto & item) { return item.encoder_name == encoder_vulkan //
and item.offset_x == 0 and item.offset_y == 0; }))
{
image_info.get().flags |= vk::ImageCreateFlagBits::eVideoProfileIndependentKHR;
image_info.get().usage |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
}
#endif
cn->psc.images.resize(cn->image_count);
for (uint32_t i = 0; i < cn->image_count; i++)
{
vk::ImageFormatListCreateInfo formats_info{
.viewFormatCount = formats.size(),
.pViewFormats = formats.data(),
};
#if WIVRN_USE_VULKAN_ENCODE
if (video_profile_list.profileCount)
formats_info.pNext = &video_profile_list;
#endif
auto & image = cn->psc.images[i].image;
image = image_allocation(
device, {
.pNext = &formats_info,
.flags = vk::ImageCreateFlagBits::eExtendedUsage | vk::ImageCreateFlagBits::eMutableFormat,
.imageType = vk::ImageType::e2D,
.format = format,
.extent = {
.width = cn->width,
.height = cn->height,
.depth = 1,
},
.mipLevels = 1,
.arrayLayers = 2, // colour then alpha
.samples = vk::SampleCountFlagBits::e1,
.tiling = vk::ImageTiling::eOptimal,
.usage = flags
#if WIVRN_USE_VULKAN_ENCODE
| encoder_flags
#endif
| vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eTransferSrc,
.sharingMode = vk::SharingMode::eExclusive,
},
{
.usage = VMA_MEMORY_USAGE_AUTO,
});
image = image_allocation(device, image_info.get(), {.usage = VMA_MEMORY_USAGE_AUTO});
cn->images[i].handle = image;
cn->wivrn_bundle->name(vk::Image(image), "comp target image");
}
-26
View File
@@ -180,32 +180,6 @@ std::unique_ptr<video_encoder> video_encoder::create(
return res;
}
#if WIVRN_USE_VULKAN_ENCODE
std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> video_encoder::get_create_image_info(const std::vector<encoder_settings> & settings)
{
std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> result;
for (const auto & item: settings)
{
if (item.encoder_name == encoder_vulkan)
{
result.second |= vk::ImageUsageFlagBits::eVideoEncodeSrcKHR;
switch (item.codec)
{
case h264:
result.first.push_back(video_encoder_vulkan_h264::video_profile_info.get());
break;
case h265:
// result.first.push_back(video_encoder_vulkan_h265::video_profile_info.get());
break;
case av1:
throw std::runtime_error("av1 not supported for vulkan video encode");
}
}
}
return result;
}
#endif
static const uint64_t idr_throttle = 100;
video_encoder::video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, double bitrate_multiplier, bool async_send) :
-5
View File
@@ -20,7 +20,6 @@
#pragma once
#include "driver/clock_offset.h"
#include "wivrn_config.h"
#include "wivrn_packets.h"
#include <atomic>
@@ -114,10 +113,6 @@ public:
int input_height,
float fps);
#if WIVRN_USE_VULKAN_ENCODE
static std::pair<std::vector<vk::VideoProfileInfoKHR>, vk::ImageUsageFlags> get_create_image_info(const std::vector<encoder_settings> &);
#endif
video_encoder(uint8_t stream_idx, to_headset::video_stream_description::channels_t channels, double bitrate_multiplier, bool async_send);
virtual ~video_encoder();
+4 -2
View File
@@ -15,6 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "vk/vk_helpers.h"
#include "video_encoder_vulkan.h"
#include "encoder/encoder_settings.h"
@@ -266,7 +268,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
.layerCount = 1},
};
if (rect.offset != vk::Offset2D{0, 0})
if (rect.offset != vk::Offset2D{0, 0} or not vk.vk.features.video_maintenance_1)
{
image_view_template.subresourceRange.baseArrayLayer = 0;
for (size_t i = 0; i < num_slots; ++i)
@@ -478,7 +480,7 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
video_cmd_buf.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
// If we encode from top left corner, encode from the source image directly
bool encode_direct = rect.offset == vk::Offset2D{0, 0};
bool encode_direct = not slot_item.tmp_image;
vk::ImageView image_view;