Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Createimage failed on android using Vulkan #1041

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Plugin~/WebRTCPlugin/GraphicsDevice/Vulkan/VulkanUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ namespace webrtc
if (exportHandle)
{
externalInfo.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;
externalInfo.handleTypes =
static_cast<VkExternalMemoryHandleTypeFlags>(EXTERNAL_MEMORY_HANDLE_SUPPORTED_TYPE);
externalInfo.handleTypes = EXTERNAL_MEMORY_HANDLE_SUPPORTED_TYPE;
imageInfo.pNext = &externalInfo;
}
imageInfo.imageType = VK_IMAGE_TYPE_2D;
Expand All @@ -86,6 +85,7 @@ namespace webrtc
VkResult result = vkCreateImage(instance.device, &imageInfo, allocator, &unityVulkanImage->image);
if (result != VK_SUCCESS)
{
RTC_LOG(LS_ERROR) << "Failed vkCreateImage result: " << result;
return result;
}

Expand All @@ -99,17 +99,27 @@ namespace webrtc
instance.physicalDevice, memRequirements.memoryTypeBits, properties, &allocInfo.memoryTypeIndex);
RTC_CHECK(success);

VkExportMemoryAllocateInfoKHR exportInfo = {};
VkExportMemoryAllocateInfo exportInfo = {};
VkMemoryDedicatedAllocateInfo dedicatedAllocateInfo = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux build is failed.

/home/bokken/build/output/Unity-Technologies/com.unity.webrtc/Plugin~/WebRTCPlugin/GraphicsDevice/Vulkan/VulkanUtility.cpp:103:39: error: unused variable 'dedicatedAllocateInfo' [-Werror,-Wunused-variable]
        VkMemoryDedicatedAllocateInfo dedicatedAllocateInfo = {};
                                      ^
1 error generated.

if (exportHandle)
{
exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR;
#if UNITY_ANDROID
// When AllocateMemory is executed, Android requires the VkImage to be used as additional information.
dedicatedAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
dedicatedAllocateInfo.pNext = nullptr;
dedicatedAllocateInfo.buffer = VK_NULL_HANDLE;
dedicatedAllocateInfo.image = unityVulkanImage->image;
exportInfo.pNext = &dedicatedAllocateInfo;
#endif
exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
exportInfo.handleTypes = EXTERNAL_MEMORY_HANDLE_SUPPORTED_TYPE;
allocInfo.pNext = &exportInfo;
}

result = vkAllocateMemory(instance.device, &allocInfo, allocator, &unityVulkanImage->memory.memory);
if (result != VK_SUCCESS)
{
RTC_LOG(LS_ERROR) << "Failed vkAllocateMemory result: " << result;
return result;
}

Expand All @@ -118,11 +128,12 @@ namespace webrtc
vkBindImageMemory(instance.device, unityVulkanImage->image, unityVulkanImage->memory.memory, memoryOffset);
if (result != VK_SUCCESS)
{
RTC_LOG(LS_ERROR) << "Failed vkBindImageMemory result: " << result;
return result;
}

unityVulkanImage->memory.offset = memoryOffset;
unityVulkanImage->memory.size = memRequirements.size;
unityVulkanImage->memory.size = allocInfo.allocationSize;
unityVulkanImage->memory.flags = properties;
unityVulkanImage->memory.memoryTypeIndex = allocInfo.memoryTypeIndex;
unityVulkanImage->layout = imageInfo.initialLayout;
Expand Down Expand Up @@ -163,7 +174,7 @@ namespace webrtc
VkImageView imageView = nullptr;
if (vkCreateImageView(instance.device, &viewInfo, allocator, &imageView) != VK_SUCCESS)
{
RTC_LOG(LS_INFO) << "Failed vkCreateImageView";
RTC_LOG(LS_ERROR) << "Failed vkCreateImageView";
return nullptr;
}

Expand Down