@@ -4,8 +4,8 @@ use crate::error;
44use crate :: error:: { Error , Variant } ;
55use crate :: video:: h264:: H264StreamInspector ;
66use ash:: khr:: {
7- video_decode_queue:: DeviceFn as KhrVideoDecodeQueueDeviceFn ,
8- video_queue:: { DeviceFn as KhrVideoQueueDeviceFn , InstanceFn as KhrVideoQueueInstanceFn } ,
7+ video_decode_queue:: Device as KhrVideoDecodeQueueDevice ,
8+ video_queue:: { Device as KhrVideoQueueDevice , Instance as KhrVideoQueueInstance } ,
99} ;
1010use ash:: vk:: native:: { StdVideoH264ProfileIdc , StdVideoH264ProfileIdc_STD_VIDEO_H264_PROFILE_IDC_BASELINE } ;
1111use ash:: vk:: {
@@ -34,8 +34,8 @@ impl VideoDecodeCapabilities {
3434
3535pub ( crate ) struct VideoSessionShared {
3636 shared_device : Arc < DeviceShared > ,
37- native_queue_fns : KhrVideoQueueDeviceFn ,
38- native_decode_queue_fns : KhrVideoDecodeQueueDeviceFn ,
37+ native_queue_device : KhrVideoQueueDevice ,
38+ native_decode_queue_device : KhrVideoDecodeQueueDevice ,
3939 // native_video_instance_fns: KhrVideoQueueInstanceFn,
4040 native_session : VideoSessionKHR ,
4141 // allocations: Vec<Allocation>,
@@ -78,33 +78,11 @@ impl VideoSessionShared {
7878 . std_header_version ( & extensions_names) ;
7979
8080 let result = unsafe {
81- let queue_fns = KhrVideoQueueDeviceFn :: load (
82- |x| {
83- native_entry
84- . get_instance_proc_addr ( native_instance. handle ( ) , x. as_ptr ( ) . cast ( ) )
85- . expect ( "Must have function pointer" ) as * const _
86- } , // TODO: Is this guaranteed to exist?
87- ) ;
88-
89- let decode_queue_fns = KhrVideoDecodeQueueDeviceFn :: load (
90- |x| {
91- native_entry
92- . get_instance_proc_addr ( native_instance. handle ( ) , x. as_ptr ( ) . cast ( ) )
93- . expect ( "Must have function pointer" ) as * const _
94- } , // TODO: Is this guaranteed to exist?
95- ) ;
96-
97- let video_instance_fn = KhrVideoQueueInstanceFn :: load ( |x| {
98- native_entry
99- . get_instance_proc_addr ( native_instance. handle ( ) , x. as_ptr ( ) . cast ( ) )
100- . expect ( "Must have function pointer" ) as * const _
101- } ) ;
102-
103- let get_physical_device_video_format_properties_khr = video_instance_fn. get_physical_device_video_format_properties_khr ;
104- let get_physical_device_video_capabilities = video_instance_fn. get_physical_device_video_capabilities_khr ;
105- let create_video_session = queue_fns. create_video_session_khr ;
106- let bind_video_session_memory = queue_fns. bind_video_session_memory_khr ;
107- let memory_requirements = queue_fns. get_video_session_memory_requirements_khr ;
81+ let queue_device = KhrVideoQueueDevice :: new ( & native_instance, & native_device) ;
82+
83+ let decode_queue_device = KhrVideoDecodeQueueDevice :: new ( & native_instance, & native_device) ;
84+
85+ let video_instance = KhrVideoQueueInstance :: new ( & native_entry, & native_instance) ;
10886
10987 let mut video_decode_h264_profile =
11088 VideoDecodeH264ProfileInfoKHR :: default ( ) . std_profile_idc ( StdVideoH264ProfileIdc_STD_VIDEO_H264_PROFILE_IDC_BASELINE ) ;
@@ -125,8 +103,11 @@ impl VideoSessionShared {
125103 . extend ( & mut video_decode_capabilities)
126104 . extend ( & mut video_decode_h264_capabilities) ;
127105
128- ( get_physical_device_video_capabilities) ( shared_device. physical_device ( ) . native ( ) , & video_profile, & mut video_capabilities)
129- . result ( ) ?;
106+ video_instance. get_physical_device_video_capabilities (
107+ shared_device. physical_device ( ) . native ( ) ,
108+ & video_profile,
109+ & mut video_capabilities,
110+ ) ?;
130111
131112 let array = & [ video_profile] ;
132113
@@ -136,44 +117,27 @@ impl VideoSessionShared {
136117 . image_usage ( ImageUsageFlags :: VIDEO_DECODE_DPB_KHR )
137118 . extend ( & mut video_profile_list_info) ;
138119
139- let mut num_video_format_properties = 0 ;
140-
141- ( get_physical_device_video_format_properties_khr) (
142- shared_device. physical_device ( ) . native ( ) ,
143- & video_format_info,
144- & mut num_video_format_properties,
145- null_mut ( ) ,
146- )
147- . result ( ) ?;
120+ let num_video_format_properties = video_instance
121+ . get_physical_device_video_format_properties_len ( shared_device. physical_device ( ) . native ( ) , & video_format_info) ?;
148122
149123 let mut video_format_properties = vec ! [ VideoFormatPropertiesKHR :: default ( ) ; num_video_format_properties as usize ] ;
150124
151- ( get_physical_device_video_format_properties_khr ) (
125+ video_instance . get_physical_device_video_format_properties (
152126 shared_device. physical_device ( ) . native ( ) ,
153127 & video_format_info,
154- & mut num_video_format_properties,
155- video_format_properties. as_mut_ptr ( ) ,
156- )
157- . result ( ) ?;
128+ & mut video_format_properties,
129+ ) ?;
158130
159- let mut native_session = VideoSessionKHR :: default ( ) ;
160- let mut video_session_count = 0 ;
161131 let mut allocations = Vec :: new ( ) ;
162132 let mut bindings = Vec :: new ( ) ;
163133
164- create_video_session ( native_device . handle ( ) , & video_session_create_info, null ( ) , & mut native_session ) . result ( ) ?;
134+ let native_session = queue_device . create_video_session ( & video_session_create_info, None ) ?;
165135
166- memory_requirements ( native_device . handle ( ) , native_session , & mut video_session_count, null_mut ( ) ) . result ( ) ?;
136+ let video_session_count = queue_device . get_video_session_memory_requirements_len ( native_session ) ?;
167137
168138 let mut video_session_requirements = vec ! [ VideoSessionMemoryRequirementsKHR :: default ( ) ; video_session_count as usize ] ;
169139
170- memory_requirements (
171- native_device. handle ( ) ,
172- native_session,
173- & mut video_session_count,
174- video_session_requirements. as_mut_ptr ( ) ,
175- )
176- . result ( ) ?;
140+ queue_device. get_video_session_memory_requirements ( native_session, & mut video_session_requirements) ?;
177141
178142 let video_session_requirements = & video_session_requirements[ 0 ..video_session_count as usize ] ;
179143
@@ -192,12 +156,12 @@ impl VideoSessionShared {
192156 bindings. push ( bind) ;
193157 }
194158
195- bind_video_session_memory ( native_device . handle ( ) , native_session, bindings. len ( ) as u32 , bindings . as_ptr ( ) ) . result ( ) ?;
159+ queue_device . bind_video_session_memory ( native_session, & bindings) ?;
196160
197161 Ok ( Self {
198162 shared_device,
199- native_queue_fns : queue_fns ,
200- native_decode_queue_fns : decode_queue_fns ,
163+ native_queue_device : queue_device ,
164+ native_decode_queue_device : decode_queue_device ,
201165 // native_video_instance_fns: video_instance_fn,
202166 native_session,
203167 // allocations,
@@ -211,16 +175,16 @@ impl VideoSessionShared {
211175 self . native_session
212176 }
213177
214- pub ( crate ) fn queue_fns ( & self ) -> KhrVideoQueueDeviceFn {
215- self . native_queue_fns . clone ( )
178+ pub ( crate ) fn queue_device ( & self ) -> KhrVideoQueueDevice {
179+ self . native_queue_device . clone ( )
216180 }
217181
218- pub ( crate ) fn decode_fns ( & self ) -> KhrVideoDecodeQueueDeviceFn {
219- self . native_decode_queue_fns . clone ( )
182+ pub ( crate ) fn decode_queue_device ( & self ) -> KhrVideoDecodeQueueDevice {
183+ self . native_decode_queue_device . clone ( )
220184 }
221185
222- // pub(crate) fn video_instance_fns (&self) -> KhrVideoQueueInstanceFn {
223- // self.native_video_instance_fns .clone()
186+ // pub(crate) fn video_instance (&self) -> KhrVideoQueueInstance {
187+ // self.native_video_instance .clone()
224188 // }
225189
226190 pub ( crate ) fn device ( & self ) -> Arc < DeviceShared > {
@@ -234,11 +198,8 @@ impl VideoSessionShared {
234198
235199impl Drop for VideoSessionShared {
236200 fn drop ( & mut self ) {
237- let native_device = self . shared_device . native ( ) ;
238- let destroy_video_session_khr = self . native_queue_fns . destroy_video_session_khr ;
239-
240201 unsafe {
241- destroy_video_session_khr ( native_device . handle ( ) , self . native_session , null ( ) ) ;
202+ self . native_queue_device . destroy_video_session ( self . native_session , None ) ;
242203 }
243204 }
244205}
0 commit comments