@@ -709,6 +709,7 @@ impl super::Device {
709709 . get_physical_device_memory_properties ( self . shared . physical_device )
710710 } ;
711711
712+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceMemoryProperties.html
712713 for ( i, mem_ty) in mem_properties. memory_types_as_slice ( ) . iter ( ) . enumerate ( ) {
713714 if type_bits & ( 1 << i) != 0 && mem_ty. property_flags & flags == flags {
714715 return Some ( i) ;
@@ -722,16 +723,7 @@ impl super::Device {
722723 & self ,
723724 desc : & crate :: TextureDescriptor ,
724725 external_memory_image_create_info : Option < & mut vk:: ExternalMemoryImageCreateInfo > ,
725- ) -> Result <
726- (
727- vk:: Image ,
728- vk:: MemoryRequirements ,
729- crate :: CopyExtent ,
730- Vec < wgt:: TextureFormat > ,
731- vk:: ImageCreateFlags ,
732- ) ,
733- crate :: DeviceError ,
734- > {
726+ ) -> Result < ImageWithoutMemory , crate :: DeviceError > {
735727 let copy_size = desc. copy_extent ( ) ;
736728
737729 let mut raw_flags = vk:: ImageCreateFlags :: empty ( ) ;
@@ -791,7 +783,13 @@ impl super::Device {
791783 }
792784 let req = unsafe { self . shared . raw . get_image_memory_requirements ( raw) } ;
793785
794- Ok ( ( raw, req, copy_size, wgt_view_formats, raw_flags) )
786+ Ok ( ImageWithoutMemory {
787+ raw,
788+ requirements : req,
789+ copy_size,
790+ view_formats : wgt_view_formats,
791+ raw_flags,
792+ } )
795793 }
796794
797795 /// # Safety
@@ -802,29 +800,38 @@ impl super::Device {
802800 #[ cfg( windows) ]
803801 pub unsafe fn texture_from_d3d11_shared_handle (
804802 & self ,
805- d3d11_shared_handle : * mut std :: ffi :: c_void ,
803+ d3d11_shared_handle : windows :: Win32 :: Foundation :: HANDLE ,
806804 desc : & crate :: TextureDescriptor ,
807805 ) -> Result < super :: Texture , crate :: DeviceError > {
808806 if !self . shared . private_caps . external_memory_win32 {
807+ log:: error!( "VK_KHR_external_memory extension is required" ) ;
809808 return Err ( crate :: DeviceError :: ResourceCreationFailed ) ;
810809 }
811810
812811 let mut external_memory_image_info = vk:: ExternalMemoryImageCreateInfo :: default ( )
813812 . handle_types ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE ) ;
814813
815- let ( raw, req, copy_size, wgt_view_formats, raw_flags) =
816- self . create_image_without_memory ( desc, Some ( & mut external_memory_image_info) ) ?;
814+ let ImageWithoutMemory {
815+ raw,
816+ requirements,
817+ copy_size,
818+ view_formats,
819+ raw_flags,
820+ } = self . create_image_without_memory ( desc, Some ( & mut external_memory_image_info) ) ?;
817821
818822 let mut import_memory_info = vk:: ImportMemoryWin32HandleInfoKHR :: default ( )
819823 . handle_type ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE )
820- . handle ( d3d11_shared_handle as _ ) ;
824+ . handle ( d3d11_shared_handle. 0 as _ ) ;
821825
822826 let mem_type_index = self
823- . find_memory_type_index ( req. memory_type_bits , vk:: MemoryPropertyFlags :: DEVICE_LOCAL )
827+ . find_memory_type_index (
828+ requirements. memory_type_bits ,
829+ vk:: MemoryPropertyFlags :: DEVICE_LOCAL ,
830+ )
824831 . ok_or ( crate :: DeviceError :: ResourceCreationFailed ) ?;
825832
826833 let memory_allocate_info = vk:: MemoryAllocateInfo :: default ( )
827- . allocation_size ( req . size )
834+ . allocation_size ( requirements . size )
828835 . memory_type_index ( mem_type_index as _ )
829836 . push_next ( & mut import_memory_info) ;
830837 let memory = unsafe { self . shared . raw . allocate_memory ( & memory_allocate_info, None ) }
@@ -848,7 +855,7 @@ impl super::Device {
848855 format : desc. format ,
849856 raw_flags,
850857 copy_size,
851- view_formats : wgt_view_formats ,
858+ view_formats,
852859 } )
853860 }
854861
@@ -1185,17 +1192,22 @@ impl crate::Device for super::Device {
11851192 & self ,
11861193 desc : & crate :: TextureDescriptor ,
11871194 ) -> Result < super :: Texture , crate :: DeviceError > {
1188- let ( raw, req, copy_size, wgt_view_formats, raw_flags) =
1189- self . create_image_without_memory ( desc, None ) ?;
1195+ let ImageWithoutMemory {
1196+ raw,
1197+ requirements,
1198+ copy_size,
1199+ view_formats,
1200+ raw_flags,
1201+ } = self . create_image_without_memory ( desc, None ) ?;
11901202
11911203 let block = unsafe {
11921204 self . mem_allocator . lock ( ) . alloc (
11931205 & * self . shared ,
11941206 gpu_alloc:: Request {
1195- size : req . size ,
1196- align_mask : req . alignment - 1 ,
1207+ size : requirements . size ,
1208+ align_mask : requirements . alignment - 1 ,
11971209 usage : gpu_alloc:: UsageFlags :: FAST_DEVICE_ACCESS ,
1198- memory_types : req . memory_type_bits & self . valid_ash_memory_types ,
1210+ memory_types : requirements . memory_type_bits & self . valid_ash_memory_types ,
11991211 } ,
12001212 ) ?
12011213 } ;
@@ -1224,7 +1236,7 @@ impl crate::Device for super::Device {
12241236 format : desc. format ,
12251237 raw_flags,
12261238 copy_size,
1227- view_formats : wgt_view_formats ,
1239+ view_formats,
12281240 } )
12291241 }
12301242 unsafe fn destroy_texture ( & self , texture : super :: Texture ) {
@@ -2688,3 +2700,11 @@ impl From<gpu_descriptor::AllocationError> for crate::DeviceError {
26882700fn handle_unexpected ( err : vk:: Result ) -> ! {
26892701 panic ! ( "Unexpected Vulkan error: `{err}`" )
26902702}
2703+
2704+ struct ImageWithoutMemory {
2705+ raw : vk:: Image ,
2706+ requirements : vk:: MemoryRequirements ,
2707+ copy_size : crate :: CopyExtent ,
2708+ view_formats : Vec < wgt:: TextureFormat > ,
2709+ raw_flags : vk:: ImageCreateFlags ,
2710+ }
0 commit comments