@@ -702,6 +702,7 @@ impl super::Device {
702702 . get_physical_device_memory_properties ( self . shared . physical_device )
703703 } ;
704704
705+ // https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPhysicalDeviceMemoryProperties.html
705706 for ( i, mem_ty) in mem_properties. memory_types_as_slice ( ) . iter ( ) . enumerate ( ) {
706707 if type_bits & ( 1 << i) != 0 && mem_ty. property_flags & flags == flags {
707708 return Some ( i) ;
@@ -715,16 +716,7 @@ impl super::Device {
715716 & self ,
716717 desc : & crate :: TextureDescriptor ,
717718 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 > {
728720 let copy_size = desc. copy_extent ( ) ;
729721
730722 let mut raw_flags = vk:: ImageCreateFlags :: empty ( ) ;
@@ -784,7 +776,13 @@ impl super::Device {
784776 }
785777 let req = unsafe { self . shared . raw . get_image_memory_requirements ( raw) } ;
786778
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+ } )
788786 }
789787
790788 /// # Safety
@@ -795,29 +793,38 @@ impl super::Device {
795793 #[ cfg( windows) ]
796794 pub unsafe fn texture_from_d3d11_shared_handle (
797795 & self ,
798- d3d11_shared_handle : * mut std :: ffi :: c_void ,
796+ d3d11_shared_handle : windows :: Win32 :: Foundation :: HANDLE ,
799797 desc : & crate :: TextureDescriptor ,
800798 ) -> Result < super :: Texture , crate :: DeviceError > {
801799 if !self . shared . private_caps . external_memory_win32 {
800+ log:: error!( "VK_KHR_external_memory extension is required" ) ;
802801 return Err ( crate :: DeviceError :: ResourceCreationFailed ) ;
803802 }
804803
805804 let mut external_memory_image_info = vk:: ExternalMemoryImageCreateInfo :: default ( )
806805 . handle_types ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE ) ;
807806
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) ) ?;
810814
811815 let mut import_memory_info = vk:: ImportMemoryWin32HandleInfoKHR :: default ( )
812816 . handle_type ( vk:: ExternalMemoryHandleTypeFlags :: D3D11_TEXTURE )
813- . handle ( d3d11_shared_handle as _ ) ;
817+ . handle ( d3d11_shared_handle. 0 as _ ) ;
814818
815819 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+ )
817824 . ok_or ( crate :: DeviceError :: ResourceCreationFailed ) ?;
818825
819826 let memory_allocate_info = vk:: MemoryAllocateInfo :: default ( )
820- . allocation_size ( req . size )
827+ . allocation_size ( requirements . size )
821828 . memory_type_index ( mem_type_index as _ )
822829 . push_next ( & mut import_memory_info) ;
823830 let memory = unsafe { self . shared . raw . allocate_memory ( & memory_allocate_info, None ) }
@@ -841,7 +848,7 @@ impl super::Device {
841848 format : desc. format ,
842849 raw_flags,
843850 copy_size,
844- view_formats : wgt_view_formats ,
851+ view_formats,
845852 } )
846853 }
847854
@@ -1173,17 +1180,22 @@ impl crate::Device for super::Device {
11731180 & self ,
11741181 desc : & crate :: TextureDescriptor ,
11751182 ) -> 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 ) ?;
11781190
11791191 let block = unsafe {
11801192 self . mem_allocator . lock ( ) . alloc (
11811193 & * self . shared ,
11821194 gpu_alloc:: Request {
1183- size : req . size ,
1184- align_mask : req . alignment - 1 ,
1195+ size : requirements . size ,
1196+ align_mask : requirements . alignment - 1 ,
11851197 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 ,
11871199 } ,
11881200 ) ?
11891201 } ;
@@ -1212,7 +1224,7 @@ impl crate::Device for super::Device {
12121224 format : desc. format ,
12131225 raw_flags,
12141226 copy_size,
1215- view_formats : wgt_view_formats ,
1227+ view_formats,
12161228 } )
12171229 }
12181230 unsafe fn destroy_texture ( & self , texture : super :: Texture ) {
@@ -2672,3 +2684,11 @@ impl From<gpu_descriptor::AllocationError> for crate::DeviceError {
26722684fn handle_unexpected ( err : vk:: Result ) -> ! {
26732685 panic ! ( "Unexpected Vulkan error: `{err}`" )
26742686}
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