From 2d56c8cdf3e8a0f91d2ce316f46fda67272d707d Mon Sep 17 00:00:00 2001 From: Tony Zlatinski Date: Sat, 20 Dec 2025 19:13:57 -0600 Subject: [PATCH] decode: Fix the parameters passed to InitVulkanDecoderDevice Fix the parameters passed to InitVulkanDecoderDevice() from the applications. This is a regression since 28d581b (28d581be9efb9257bb290365b1e21d0c27f32612) where there was a change that added a codec to the InitVulkanDecoderDevice() but did not update all of the clients. Also, fix codec extension handling in InitVulkanDecoderDevice When InitVulkanDecoderDevice is called with a specific codec flag (e.g., VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR), only that codec's extension should be required. Previously, the code used separate 'if' statements which meant all conditions were evaluated independently. This was incorrect because the videoCodecs parameter is typically a single codec flag, not a bitmask of multiple codecs. - Convert separate 'if' statements to 'else if' chain for mutually exclusive codec selection - Add 'else' branch for when videoCodecs is VK_VIDEO_CODEC_OPERATION_NONE_KHR or VIDEO_CODEC_OPERATIONS_ALL (0 or all bits set) - In the else case, add all codec extensions as OPTIONAL rather than required, allowing the device to support whatever codecs are available This fixes device initialization when the caller doesn't know the specific codec ahead of time (e.g., auto-detection scenarios). Signed-off-by: Tony Zlatinski --- .../libs/VkCodecUtils/VulkanDeviceContext.cpp | 20 +++++--- .../VkCodecUtils/VulkanVideoProcessor.cpp | 2 +- vk_video_decoder/demos/vk-video-dec/Main.cpp | 23 ++++----- vk_video_decoder/src/vulkan_video_decoder.cpp | 12 +++-- .../test/vulkan-video-dec/Main.cpp | 49 +++++++++++-------- 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/common/libs/VkCodecUtils/VulkanDeviceContext.cpp b/common/libs/VkCodecUtils/VulkanDeviceContext.cpp index 1901ebcb..2b29d798 100644 --- a/common/libs/VkCodecUtils/VulkanDeviceContext.cpp +++ b/common/libs/VkCodecUtils/VulkanDeviceContext.cpp @@ -1144,15 +1144,23 @@ VkResult VulkanDeviceContext::InitVulkanDecoderDevice(const char * pAppName, if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR) { AddReqDeviceExtension(VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME); - } - if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR) { + } else if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR) { AddReqDeviceExtension(VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME); - } - if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR) { + } else if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_AV1_BIT_KHR) { AddReqDeviceExtension(VK_KHR_VIDEO_DECODE_AV1_EXTENSION_NAME); - } - if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_VP9_BIT_KHR) { + } else if (videoCodecs == VK_VIDEO_CODEC_OPERATION_DECODE_VP9_BIT_KHR) { AddReqDeviceExtension(VK_KHR_VIDEO_DECODE_VP9_EXTENSION_NAME); + } else { + static const char* const optinalCodecsExtensions[] = { + VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME, + VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME, + VK_KHR_VIDEO_DECODE_AV1_EXTENSION_NAME, + VK_KHR_VIDEO_DECODE_VP9_EXTENSION_NAME, + nullptr + }; + // If the codec set is VK_VIDEO_CODEC_OPERATION_NONE_KHR or + // VIDEO_CODEC_OPERATIONS_ALL, then set all codecs as optional extensions. + AddOptDeviceExtensions(optinalCodecsExtensions); } VkResult result = InitVulkanDevice(pAppName, vkInstance, enbaleVerboseDump); diff --git a/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp b/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp index dc21ac58..da480f3e 100644 --- a/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp +++ b/common/libs/VkCodecUtils/VulkanVideoProcessor.cpp @@ -54,7 +54,7 @@ int32_t VulkanVideoProcessor::Initialize(const VulkanDeviceContext* vkDevCtx, const int32_t numBitstreamBuffersToPreallocate = std::max(programConfig.numBitstreamBuffersToPreallocate, 4); const bool enableHwLoadBalancing = programConfig.enableHwLoadBalancing; const bool enablePostProcessFilter = (programConfig.enablePostProcessFilter >= 0); - const bool enableDisplayPresent = (programConfig.noPresent == 0); + const bool enableDisplayPresent = (programConfig.noPresent == false); const VulkanFilterYuvCompute::FilterType postProcessFilterType = enablePostProcessFilter ? (VulkanFilterYuvCompute::FilterType)programConfig.enablePostProcessFilter : VulkanFilterYuvCompute::YCBCRCOPY; diff --git a/vk_video_decoder/demos/vk-video-dec/Main.cpp b/vk_video_decoder/demos/vk-video-dec/Main.cpp index 8ddc3e7b..0ced75d6 100644 --- a/vk_video_decoder/demos/vk-video-dec/Main.cpp +++ b/vk_video_decoder/demos/vk-video-dec/Main.cpp @@ -52,19 +52,20 @@ int main(int argc, const char **argv) return -1; } - VkVideoCodecOperationFlagsKHR videoCodecOperation = (decoderConfig.forceParserType != VK_VIDEO_CODEC_OPERATION_NONE_KHR) ? - decoderConfig.forceParserType : - videoStreamDemuxer->GetVideoCodec(); + const VkVideoCodecOperationFlagsKHR videoCodecOperation = + (decoderConfig.forceParserType != VK_VIDEO_CODEC_OPERATION_NONE_KHR) ? + decoderConfig.forceParserType : + ((videoStreamDemuxer != nullptr) ? videoStreamDemuxer->GetVideoCodec() : VK_VIDEO_CODEC_OPERATION_NONE_KHR); VulkanDeviceContext vkDevCtxt; result = vkDevCtxt.InitVulkanDecoderDevice(decoderConfig.appName.c_str(), - VK_NULL_HANDLE, - videoCodecOperation, - !decoderConfig.noPresent, - decoderConfig.directMode, - decoderConfig.validate, - decoderConfig.validateVerbose, - decoderConfig.verbose); + VK_NULL_HANDLE, + videoCodecOperation, + decoderConfig.noPresent, + decoderConfig.directMode, + decoderConfig.validate, + decoderConfig.validateVerbose, + decoderConfig.verbose); if (result != VK_SUCCESS) { printf("Could not initialize the Vulkan decoder device!\n"); @@ -87,7 +88,7 @@ int main(int argc, const char **argv) requestVideoComputeQueueMask = VK_QUEUE_COMPUTE_BIT; } - if (!decoderConfig.noPresent) { + if (decoderConfig.noPresent == false) { VkSharedBaseObj displayShell; const Shell::Configuration configuration(decoderConfig.appName.c_str(), diff --git a/vk_video_decoder/src/vulkan_video_decoder.cpp b/vk_video_decoder/src/vulkan_video_decoder.cpp index 76f8d692..0d05fa44 100644 --- a/vk_video_decoder/src/vulkan_video_decoder.cpp +++ b/vk_video_decoder/src/vulkan_video_decoder.cpp @@ -141,9 +141,15 @@ VkResult VulkanVideoDecoderImpl::Initialize(VkInstance vkInstance, return VK_NOT_READY; } + const VkVideoCodecOperationFlagsKHR videoCodecOperation = + (m_decoderConfig.forceParserType != VK_VIDEO_CODEC_OPERATION_NONE_KHR) ? + m_decoderConfig.forceParserType : + ((videoStreamDemuxer != nullptr) ? videoStreamDemuxer->GetVideoCodec() : VK_VIDEO_CODEC_OPERATION_NONE_KHR); + VkResult result = m_vkDevCtxt.InitVulkanDecoderDevice(m_decoderConfig.appName.c_str(), vkInstance, - !m_decoderConfig.noPresent, + videoCodecOperation, + m_decoderConfig.noPresent, m_decoderConfig.directMode, m_decoderConfig.validate, m_decoderConfig.validateVerbose, @@ -170,9 +176,7 @@ VkResult VulkanVideoDecoderImpl::Initialize(VkInstance vkInstance, requestVideoComputeQueueMask = VK_QUEUE_COMPUTE_BIT; } - VkVideoCodecOperationFlagsKHR videoCodecOperation = videoStreamDemuxer->GetVideoCodec(); - - const bool supportsShellPresent = ((!m_decoderConfig.noPresent == false) && (pWsiDisplay != nullptr)); + const bool supportsShellPresent = ((m_decoderConfig.noPresent == false) && (pWsiDisplay != nullptr)); const bool createGraphicsQueue = supportsShellPresent ? true : false; const bool createDisplayQueue = supportsShellPresent ? true : false; diff --git a/vk_video_decoder/test/vulkan-video-dec/Main.cpp b/vk_video_decoder/test/vulkan-video-dec/Main.cpp index 1aac07d9..8928551f 100644 --- a/vk_video_decoder/test/vulkan-video-dec/Main.cpp +++ b/vk_video_decoder/test/vulkan-video-dec/Main.cpp @@ -51,14 +51,34 @@ int main(int argc, const char** argv) return -1; } + VkSharedBaseObj videoStreamDemuxer; + VkResult result = VideoStreamDemuxer::Create(decoderConfig.videoFileName.c_str(), + decoderConfig.forceParserType, + decoderConfig.enableStreamDemuxing, + decoderConfig.initialWidth, + decoderConfig.initialHeight, + decoderConfig.initialBitdepth, + videoStreamDemuxer); + if (result != VK_SUCCESS) { + assert(!"Can't initialize the VideoStreamDemuxer!"); + return result; + } + + const VkVideoCodecOperationFlagsKHR videoCodecOperation = + (decoderConfig.forceParserType != VK_VIDEO_CODEC_OPERATION_NONE_KHR) ? + decoderConfig.forceParserType : + ((videoStreamDemuxer != nullptr) ? videoStreamDemuxer->GetVideoCodec() : VK_VIDEO_CODEC_OPERATION_NONE_KHR); + + VulkanDeviceContext vkDevCtxt; - VkResult result = vkDevCtxt.InitVulkanDecoderDevice(decoderConfig.appName.c_str(), - VK_NULL_HANDLE, - !decoderConfig.noPresent, - decoderConfig.directMode, - decoderConfig.validate, - decoderConfig.validateVerbose, - decoderConfig.verbose); + result = vkDevCtxt.InitVulkanDecoderDevice(decoderConfig.appName.c_str(), + VK_NULL_HANDLE, + videoCodecOperation, + decoderConfig.noPresent, + decoderConfig.directMode, + decoderConfig.validate, + decoderConfig.validateVerbose, + decoderConfig.verbose); if (result != VK_SUCCESS) { printf("Could not initialize the Vulkan decoder device!\n"); @@ -66,19 +86,6 @@ int main(int argc, const char** argv) } - VkSharedBaseObj videoStreamDemuxer; - result = VideoStreamDemuxer::Create(decoderConfig.videoFileName.c_str(), - decoderConfig.forceParserType, - decoderConfig.enableStreamDemuxing, - decoderConfig.initialWidth, - decoderConfig.initialHeight, - decoderConfig.initialBitdepth, - videoStreamDemuxer); - if (result != VK_SUCCESS) { - assert(!"Can't initialize the VideoStreamDemuxer!"); - return result; - } - const int32_t numDecodeQueues = ((decoderConfig.queueId != 0) || (decoderConfig.enableHwLoadBalancing != 0)) ? -1 : // all available HW decoders @@ -99,7 +106,7 @@ int main(int argc, const char** argv) decoderConfig.forceParserType : videoStreamDemuxer->GetVideoCodec(); - if (!decoderConfig.noPresent) { + if (decoderConfig.noPresent == false) { VkSharedBaseObj displayShell; const Shell::Configuration configuration(decoderConfig.appName.c_str(),