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