How to export the vulkan image to android hardware buffer?

In detail, i want to write to android hardware buffer directly. But when i consulted the documentation specification of vulkan. In the following link, in chapter of 11.2.17, i found the specification said “Vulkan can import Android hardware buffers that have external formats, but since the image contents are in an undiscoverable and possibly proprietary representation, images with external formats must only be used as sampled images …”
so i change the point to create ta vulkan image that can be attached to frame buffer, then export that image to andorid hardware buffer. i create an export image like this.

void createExportImage()
    VkDevice device;
	VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo
	VkImageCreateInfo imageCreateInfo = {};
	imageCreateInfo.pNext = &externalMemoryImageCreateInfo;
	imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
	imageCreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
	imageCreateInfo.extent.width = uint32_t(lWidth);
	imageCreateInfo.extent.height = uint32_t(lHeight);
	imageCreateInfo.extent.depth = 1;
	imageCreateInfo.mipLevels = mipLevels;
	imageCreateInfo.arrayLayers = 1;
	imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
	imageCreateInfo.queueFamilyIndexCount = 0;
	imageCreateInfo.pQueueFamilyIndices = nullptr;
	imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
	imageCreateInfo.flags = 0;
	imageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED,
	imageCreateInfo.tiling = VK_IMAGE_TILING_LINEAR;

	vkCreateImage(device, &imageCreateInfo, NULL, &image);

	VkMemoryRequirements memReqs;
	vkGetImageMemoryRequirements(device, image, &memReqs);

	VkExportMemoryAllocateInfo exportAllocInfo{};

	VkMemoryAllocateInfo memAllocInfo = {};
	memAllocInfo.pNext = &exportAllocInfo;
	memAllocInfo.allocationSize = memReqs.size;
	memAllocInfo.memoryTypeIndex = 0;
	// Allocate the memory for buffer objects
	vkAllocateMemory(device, &memAllocInfo,nullptr, &memory);
	// Bind the image device memory 
	vkBindImageMemory(device, image, memory, 0);

then in android hardware buffer side, use the code like that:

bool SetVkDeviceMemory(AHardwareBuffer* buffer, VkDevice* pDevice, VkDeviceMemory* pVkDeviceMemory)
    VkMemoryGetAndroidHardwareBufferInfoANDROID memoryInfo
        .pNext = nullptr,
        .memory = *pVkDeviceMemory,
    vkGetMemoryAndroidHardwareBufferANDROID(*pDevice, &memoryInfo, &buffer);
    return true;

Now, that problem is that the export seems not work as expected.So what the entire process of export
vulkan image to android hardware buffer?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.