@@ -699,6 +699,7 @@ impl super::Device {
699
699
. get_physical_device_memory_properties ( self . shared . physical_device )
700
700
} ;
701
701
702
+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceMemoryProperties.html
702
703
for ( i, mem_ty) in mem_properties. memory_types_as_slice ( ) . iter ( ) . enumerate ( ) {
703
704
if type_bits & ( 1 << i) != 0 && mem_ty. property_flags & flags == flags {
704
705
return Some ( i) ;
@@ -712,16 +713,7 @@ impl super::Device {
712
713
& self ,
713
714
desc : & crate :: TextureDescriptor ,
714
715
external_memory_image_create_info : Option < & mut vk:: ExternalMemoryImageCreateInfo > ,
715
- ) -> Result <
716
- (
717
- vk:: Image ,
718
- vk:: MemoryRequirements ,
719
- crate :: CopyExtent ,
720
- Vec < wgt:: TextureFormat > ,
721
- vk:: ImageCreateFlags ,
722
- ) ,
723
- crate :: DeviceError ,
724
- > {
716
+ ) -> Result < ImageWithoutMemory , crate :: DeviceError > {
725
717
let copy_size = desc. copy_extent ( ) ;
726
718
727
719
let mut raw_flags = vk:: ImageCreateFlags :: empty ( ) ;
@@ -781,7 +773,13 @@ impl super::Device {
781
773
}
782
774
let req = unsafe { self . shared . raw . get_image_memory_requirements ( raw) } ;
783
775
784
- Ok ( ( raw, req, copy_size, wgt_view_formats, raw_flags) )
776
+ Ok ( ImageWithoutMemory {
777
+ raw,
778
+ requirements : req,
779
+ copy_size,
780
+ view_formats : wgt_view_formats,
781
+ raw_flags,
782
+ } )
785
783
}
786
784
787
785
/// # Safety
@@ -792,29 +790,38 @@ impl super::Device {
792
790
#[ cfg( windows) ]
793
791
pub unsafe fn texture_from_d3d11_shared_handle (
794
792
& self ,
795
- d3d11_shared_handle : * mut std :: ffi :: c_void ,
793
+ d3d11_shared_handle : windows :: Win32 :: Foundation :: HANDLE ,
796
794
desc : & crate :: TextureDescriptor ,
797
795
) -> Result < super :: Texture , crate :: DeviceError > {
798
796
if !self . shared . private_caps . external_memory_win32 {
797
+ log:: error!( "VK_KHR_external_memory extension is required" ) ;
799
798
return Err ( crate :: DeviceError :: ResourceCreationFailed ) ;
800
799
}
801
800
802
801
let mut external_memory_image_info = vk:: ExternalMemoryImageCreateInfo :: default ( )
803
802
. handle_types ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE ) ;
804
803
805
- let ( raw, req, copy_size, wgt_view_formats, raw_flags) =
806
- self . create_image_without_memory ( desc, Some ( & mut external_memory_image_info) ) ?;
804
+ let ImageWithoutMemory {
805
+ raw,
806
+ requirements,
807
+ copy_size,
808
+ view_formats,
809
+ raw_flags,
810
+ } = self . create_image_without_memory ( desc, Some ( & mut external_memory_image_info) ) ?;
807
811
808
812
let mut import_memory_info = vk:: ImportMemoryWin32HandleInfoKHR :: default ( )
809
813
. handle_type ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE )
810
- . handle ( d3d11_shared_handle as _ ) ;
814
+ . handle ( d3d11_shared_handle. 0 as _ ) ;
811
815
812
816
let mem_type_index = self
813
- . find_memory_type_index ( req. memory_type_bits , vk:: MemoryPropertyFlags :: DEVICE_LOCAL )
817
+ . find_memory_type_index (
818
+ requirements. memory_type_bits ,
819
+ vk:: MemoryPropertyFlags :: DEVICE_LOCAL ,
820
+ )
814
821
. ok_or ( crate :: DeviceError :: ResourceCreationFailed ) ?;
815
822
816
823
let memory_allocate_info = vk:: MemoryAllocateInfo :: default ( )
817
- . allocation_size ( req . size )
824
+ . allocation_size ( requirements . size )
818
825
. memory_type_index ( mem_type_index as _ )
819
826
. push_next ( & mut import_memory_info) ;
820
827
let memory = unsafe { self . shared . raw . allocate_memory ( & memory_allocate_info, None ) }
@@ -838,7 +845,7 @@ impl super::Device {
838
845
format : desc. format ,
839
846
raw_flags,
840
847
copy_size,
841
- view_formats : wgt_view_formats ,
848
+ view_formats,
842
849
} )
843
850
}
844
851
@@ -1170,17 +1177,22 @@ impl crate::Device for super::Device {
1170
1177
& self ,
1171
1178
desc : & crate :: TextureDescriptor ,
1172
1179
) -> Result < super :: Texture , crate :: DeviceError > {
1173
- let ( raw, req, copy_size, wgt_view_formats, raw_flags) =
1174
- self . create_image_without_memory ( desc, None ) ?;
1180
+ let ImageWithoutMemory {
1181
+ raw,
1182
+ requirements,
1183
+ copy_size,
1184
+ view_formats,
1185
+ raw_flags,
1186
+ } = self . create_image_without_memory ( desc, None ) ?;
1175
1187
1176
1188
let block = unsafe {
1177
1189
self . mem_allocator . lock ( ) . alloc (
1178
1190
& * self . shared ,
1179
1191
gpu_alloc:: Request {
1180
- size : req . size ,
1181
- align_mask : req . alignment - 1 ,
1192
+ size : requirements . size ,
1193
+ align_mask : requirements . alignment - 1 ,
1182
1194
usage : gpu_alloc:: UsageFlags :: FAST_DEVICE_ACCESS ,
1183
- memory_types : req . memory_type_bits & self . valid_ash_memory_types ,
1195
+ memory_types : requirements . memory_type_bits & self . valid_ash_memory_types ,
1184
1196
} ,
1185
1197
) ?
1186
1198
} ;
@@ -1209,7 +1221,7 @@ impl crate::Device for super::Device {
1209
1221
format : desc. format ,
1210
1222
raw_flags,
1211
1223
copy_size,
1212
- view_formats : wgt_view_formats ,
1224
+ view_formats,
1213
1225
} )
1214
1226
}
1215
1227
unsafe fn destroy_texture ( & self , texture : super :: Texture ) {
@@ -2669,3 +2681,11 @@ impl From<gpu_descriptor::AllocationError> for crate::DeviceError {
2669
2681
fn handle_unexpected ( err : vk:: Result ) -> ! {
2670
2682
panic ! ( "Unexpected Vulkan error: `{err}`" )
2671
2683
}
2684
+
2685
+ struct ImageWithoutMemory {
2686
+ raw : vk:: Image ,
2687
+ requirements : vk:: MemoryRequirements ,
2688
+ copy_size : crate :: CopyExtent ,
2689
+ view_formats : Vec < wgt:: TextureFormat > ,
2690
+ raw_flags : vk:: ImageCreateFlags ,
2691
+ }
0 commit comments