44//! from the Vulkan video extensions.
55
66use ash:: vk;
7+ use ash:: vk:: TaggedStructure ;
78use pixelforge:: { Codec , VideoContextBuilder } ;
89use tracing_subscriber:: { layer:: SubscriberExt , util:: SubscriberInitExt , Layer } ;
910
@@ -37,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3738 println ! ( "Codec Support:" ) ;
3839 println ! ( "--------------" ) ;
3940
40- let codecs = [ Codec :: H264 , Codec :: H265 ] ;
41+ let codecs = [ Codec :: H264 , Codec :: H265 , Codec :: AV1 ] ;
4142
4243 for codec in codecs {
4344 println ! ( "\n {:?}:" , codec) ;
@@ -95,7 +96,7 @@ fn query_detailed_capabilities(
9596 println ! ( " Checking {}: " , desc) ;
9697
9798 // Construct profile info
98- let ( mut profile_info, mut h264_profile, mut h265_profile) = match codec {
99+ let ( mut profile_info, mut h264_profile, mut h265_profile, mut av1_profile ) = match codec {
99100 Codec :: H264 => {
100101 let profile_idc = if subsampling == vk:: VideoChromaSubsamplingFlagsKHR :: TYPE_444 {
101102 ash:: vk:: native:: StdVideoH264ProfileIdc_STD_VIDEO_H264_PROFILE_IDC_HIGH_444_PREDICTIVE
@@ -110,7 +111,7 @@ fn query_detailed_capabilities(
110111 . chroma_subsampling ( subsampling)
111112 . luma_bit_depth ( bit_depth)
112113 . chroma_bit_depth ( bit_depth) ;
113- ( info, Some ( h264) , None )
114+ ( info, Some ( h264) , None , None )
114115 }
115116 Codec :: H265 => {
116117 let profile_idc = if subsampling == vk:: VideoChromaSubsamplingFlagsKHR :: TYPE_444 {
@@ -128,30 +129,46 @@ fn query_detailed_capabilities(
128129 . chroma_subsampling ( subsampling)
129130 . luma_bit_depth ( bit_depth)
130131 . chroma_bit_depth ( bit_depth) ;
131- ( info, None , Some ( h265) )
132+ ( info, None , Some ( h265) , None )
133+ }
134+ Codec :: AV1 => {
135+ let profile = if subsampling == vk:: VideoChromaSubsamplingFlagsKHR :: TYPE_444 {
136+ ash:: vk:: native:: StdVideoAV1Profile_STD_VIDEO_AV1_PROFILE_HIGH
137+ } else {
138+ ash:: vk:: native:: StdVideoAV1Profile_STD_VIDEO_AV1_PROFILE_MAIN
139+ } ;
140+
141+ let av1 = vk:: VideoEncodeAV1ProfileInfoKHR :: default ( ) . std_profile ( profile) ;
142+ let info = vk:: VideoProfileInfoKHR :: default ( )
143+ . video_codec_operation ( vk:: VideoCodecOperationFlagsKHR :: ENCODE_AV1 )
144+ . chroma_subsampling ( subsampling)
145+ . luma_bit_depth ( bit_depth)
146+ . chroma_bit_depth ( bit_depth) ;
147+ ( info, None , None , Some ( av1) )
132148 }
133- _ => return Ok ( ( ) ) ,
134149 } ;
135150
136151 if let Some ( h264) = & mut h264_profile {
137- profile_info. p_next = ( h264 as * mut vk :: VideoEncodeH264ProfileInfoKHR ) . cast ( ) ;
152+ profile_info = profile_info . push ( h264 ) ;
138153 }
139154 if let Some ( h265) = & mut h265_profile {
140- profile_info. p_next = ( h265 as * mut vk:: VideoEncodeH265ProfileInfoKHR ) . cast ( ) ;
155+ profile_info = profile_info. push ( h265) ;
156+ }
157+ if let Some ( av1) = & mut av1_profile {
158+ profile_info = profile_info. push ( av1) ;
141159 }
142160
143161 // 1. Query Video Capabilities
144- let mut caps = vk:: VideoCapabilitiesKHR :: default ( ) ;
145162 let mut encode_caps = vk:: VideoEncodeCapabilitiesKHR :: default ( ) ;
146- caps . p_next = ( & mut encode_caps as * mut vk:: VideoEncodeCapabilitiesKHR ) . cast ( ) ;
163+ let mut caps = vk:: VideoCapabilitiesKHR :: default ( ) . push ( & mut encode_caps ) ;
147164
148165 let mut h264_caps = vk:: VideoEncodeH264CapabilitiesKHR :: default ( ) ;
149166 let mut h265_caps = vk:: VideoEncodeH265CapabilitiesKHR :: default ( ) ;
150-
151- if codec == Codec :: H264 {
152- encode_caps . p_next = ( & mut h264_caps as * mut vk :: VideoEncodeH264CapabilitiesKHR ) . cast ( ) ;
153- } else if codec == Codec :: H265 {
154- encode_caps . p_next = ( & mut h265_caps as * mut vk :: VideoEncodeH265CapabilitiesKHR ) . cast ( ) ;
167+ let mut av1_caps = vk :: VideoEncodeAV1CapabilitiesKHR :: default ( ) ;
168+ match codec {
169+ Codec :: H264 => caps = caps . push ( & mut h264_caps) ,
170+ Codec :: H265 => caps = caps . push ( & mut h265_caps ) ,
171+ Codec :: AV1 => caps = caps . push ( & mut av1_caps ) ,
155172 }
156173
157174 let result = unsafe {
@@ -185,9 +202,9 @@ fn query_detailed_capabilities(
185202 vk:: VideoProfileListInfoKHR :: default ( ) . profiles ( std:: slice:: from_ref ( & profile_info) ) ;
186203
187204 // Check for Input Image support (VIDEO_ENCODE_SRC_KHR)
188- let mut format_info = vk:: PhysicalDeviceVideoFormatInfoKHR :: default ( )
189- . image_usage ( vk:: ImageUsageFlags :: VIDEO_ENCODE_SRC_KHR ) ;
190- format_info . p_next = ( & mut format_props_list as * mut vk :: VideoProfileListInfoKHR ) . cast ( ) ;
205+ let format_info = vk:: PhysicalDeviceVideoFormatInfoKHR :: default ( )
206+ . image_usage ( vk:: ImageUsageFlags :: VIDEO_ENCODE_SRC_KHR )
207+ . push ( & mut format_props_list) ;
191208
192209 let result = unsafe {
193210 ( video_queue_fn
@@ -220,9 +237,9 @@ fn query_detailed_capabilities(
220237 }
221238
222239 // Check for DPB Image support (VIDEO_ENCODE_DPB_KHR)
223- let mut format_info = vk:: PhysicalDeviceVideoFormatInfoKHR :: default ( )
224- . image_usage ( vk:: ImageUsageFlags :: VIDEO_ENCODE_DPB_KHR ) ;
225- format_info . p_next = ( & mut format_props_list as * mut vk :: VideoProfileListInfoKHR ) . cast ( ) ;
240+ let format_info = vk:: PhysicalDeviceVideoFormatInfoKHR :: default ( )
241+ . image_usage ( vk:: ImageUsageFlags :: VIDEO_ENCODE_DPB_KHR )
242+ . push ( & mut format_props_list) ;
226243
227244 let mut format_props_count = 0 ;
228245 let result = unsafe {
0 commit comments