{"record":{"id":"7c9ac75e5b86066e","repo":"stride3d/stride","slug":"vulkan-no-memory-type-satisfies-the-iosurface-memorytypebits","errorCode":null,"errorMessage":"Vulkan: no memory type satisfies the IOSurface memoryTypeBits mask.","messagePattern":"Vulkan: no memory type satisfies the IOSurface memoryTypeBits mask\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Vulkan/Texture.Apple.Vulkan.cs","lineNumber":154,"sourceCode":"            texture.NativeImage = image;\n            texture.NativeMemory = memory;\n            texture.NativeImageView = imageView;\n            texture.NativeFormat = VkFormat.B8G8R8A8Srgb;\n            texture.ioSurfaceRef = ioSurface;\n            texture.isImportedImage = true;\n            texture.InitializeFrom(description);\n            return texture;\n        }\n\n        private static unsafe uint FindMemoryTypeIndex(GraphicsDevice device, uint memoryTypeBits)\n        {\n            device.NativeInstanceApi.vkGetPhysicalDeviceMemoryProperties(device.NativePhysicalDevice, out var memoryProperties);\n            for (uint i = 0; i < memoryProperties.memoryTypeCount; i++)\n            {\n                if ((memoryTypeBits & (1u << (int)i)) != 0)\n                    return i;\n            }\n            throw new InvalidOperationException(\"Vulkan: no memory type satisfies the IOSurface memoryTypeBits mask.\");\n        }\n\n        [DllImport(\"/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation\")]\n        private static extern IntPtr CFRetain(IntPtr cf);\n\n        [DllImport(\"/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation\")]\n        private static extern void CFRelease(IntPtr cf);\n    }\n}\n#endif\n","sourceCodeStart":136,"sourceCodeEnd":165,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Vulkan/Texture.Apple.Vulkan.cs#L136-L165","documentation":"During IOSurface import, Stride queries IOSurface memory requirements via vkGetMetalIOSurfaceCreateInfoEXT/vkBindMetalIOSurface flow and picks a Vulkan memory type from the returned memoryTypeBits mask. FindMemoryTypeIndex throws InvalidOperationException when no physical-device memory type intersects that mask, meaning the driver cannot back this IOSurface import with any available memory.","triggerScenarios":"Calling NewFromIOSurface where vkGetIOSurfaceProperties/Metal-objects property query yields a memoryTypeBits mask of 0 or disjoint from all device memory types; importing an IOSurface with pixel format/usage not supported by the GPU; MoltenVK reporting incomplete memory requirements for the surface.","commonSituations":"Importing IOSurfaces with exotic pixel formats or non-GPU-compatible usages; old MoltenVK builds with incomplete VK_EXT_metal_objects implementations; surfaces created by another subsystem (camera, video decode) without GPU-readable storage modes; mismatched storage mode (CPU-only) IOSurfaces.","solutions":["Recreate the IOSurface with GPU-capable storage/usage (kIOSurfaceStorageModeShared or GPU-friendly pixel format such as BGRA8/RGBA8).","Verify the IOSurface pixel format is one the Vulkan/MoltenVK implementation can import (e.g. MTLPixelFormat-compatible formats like BGRA8Unorm).","Update MoltenVK to a newer release with complete metal_objects support, then rebuild the device with VK_EXT_metal_objects enabled.","Fall back to reading the IOSurface pixels on CPU and uploading through Texture.Load/regular staging upload instead of direct import."],"exampleFix":"// before: CPU-only IOSurface\nvar ioSurface = IOSurface.Create(width, height, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, kIOSurfaceStorageModePrivate);\n\n// after: GPU-shareable format/storage\nvar ioSurface = IOSurface.Create(width, height, kCVPixelFormatType_32BGRA, kIOSurfaceStorageModeShared);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    texture = Texture.NewFromIOSurface(device, ioSurface, width, height);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"memoryTypeBits\"))\n{\n    log.Error(\"IOSurface has no compatible Vulkan memory type; falling back to CPU upload.\");\n    texture = UploadSurfaceData(device, ioSurface, width, height);\n}","preventionTips":["Create IOSurfaces with GPU-shareable storage modes and standard pixel formats (BGRA8/RGBA8).","Avoid importing surfaces produced by camera/video pipelines with CPU-only storage modes.","Keep MoltenVK up to date; incomplete metal_objects support yields zero masks.","Implement a CPU read + upload fallback so zero-copy import failure is non-fatal."],"tags":["vulkan","macos","memory-allocation","iosurface"],"backgroundTag":"no-suitable-vulkan-memory-type","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}