Vulkan: vkGetImageMemoryRequirements2 crashes on PowerVR 8300

Hi! Android 9, Huawei Y6 2019. During calling vkGetImageMemoryRequirements2 I got crash.

Vulkan extensions
VK_KHR_dedicated_allocation, VK_KHR_get_memory_requirements2 were added for VkDevice.

Test code:

void CreateImageTest(VkDevice vkDevice)
{
	VkImageCreateInfo vkImageCreateInfo = {};
	vkImageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
	vkImageCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
	vkImageCreateInfo.mipLevels = 1;
	vkImageCreateInfo.arrayLayers = 1;
	vkImageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
	vkImageCreateInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
	vkImageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
	vkImageCreateInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
	vkImageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
	vkImageCreateInfo.extent = {1424, 861, 1};

	VkImage vkImage = VK_NULL_HANDLE;
	VkResult  res = vkCreateImage(vkDevice, &vkImageCreateInfo, nullptr, &vkImage);


	const VkImageMemoryRequirementsInfo2 imageRequirementsInfo = {
			VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
			NULL,
			vkImage
	};
	VkMemoryDedicatedRequirements dedicatedRequirements;
	InitVkStructNextPtr(dedicatedRequirements, VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, nullptr);
	VkMemoryRequirements2 memoryRequirements2;
	InitVkStructNextPtr(memoryRequirements2, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, &dedicatedRequirements);
	vkGetImageMemoryRequirements2(vkDevice, &imageRequirementsInfo, &memoryRequirements2);
}

Minimal test case with debug apk:

Hi andreyogld3d,

I built your apk and managed to reproduce the issue on a PVR device. Taking a look at the logcat below, seems the crash is due to the function pointer vkGetImageMemoryRequirements2 being NULL:

--------- beginning of crash
10-28 17:33:08.094  4666  4666 E AndroidRuntime: FATAL EXCEPTION: main
10-28 17:33:08.094  4666  4666 E AndroidRuntime: Process: vkpipeline.android.d, PID: 4666
10-28 17:33:08.094  4666  4666 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{vkpipeline.android.d/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to find native library vkGetImageMemoryRequirements2 using classloader: dalvik.system.PathClassLoader[DexPathList[[],nativeLibraryDirectories=[/data/app/vkpipeline.android.d-bM_nuWDrUSmdiwVQrcwHPw==/lib/arm64, /data/app/vkpipeline.android.d-bM_nuWDrUSmdiwVQrcwHPw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]]
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:107)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:214)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7356)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Unable to find native library vkGetImageMemoryRequirements2 using classloader: dalvik.system.PathClassLoader[DexPathList[[],nativeLibraryDirectories=[/data/app/vkpipeline.android.d-bM_nuWDrUSmdiwVQrcwHPw==/lib/arm64, /data/app/vkpipeline.android.d-bM_nuWDrUSmdiwVQrcwHPw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]]
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.NativeActivity.onCreate(NativeActivity.java:164)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7802)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.Activity.performCreate(Activity.java:7791)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
10-28 17:33:08.094  4666  4666 E AndroidRuntime: 	... 11 more

I quickly modified the VulkanBumpmap demo from our SDK to add the code needed to reproduce the issue, adding the changes below to VulkanBumpmap.cpp:

// New code start
#define InitVkStruct(vkStruct, sType) InitVulkanStruct(&vkStruct, sType)
#define InitVkStructNextPtr(vkStruct, sType, pNext) InitVulkanStruct(&vkStruct, sType, pNext)

inline void InitVulkanStruct(void* vkStruct, VkStructureType sType, void* pNext = nullptr)
{
	struct VkStruct
	{
		VkStructureType sType;
		void* pNext;
	};
	const VkStruct vkSt = { sType, pNext };
	assert(vkStruct && "NULL Pointer");
	memcpy(vkStruct, &vkSt, sizeof(vkSt));
}

pvrvk::ImageView texBase;
pvrvk::ImageView texNormalMap;
// New code end

/// <summary>Loads the textures required for this training course.</summary>
/// <returns>Return true if no error occurred.</returns>
void VulkanBumpmap::createImageSamplerDescriptor(pvrvk::CommandBuffer& imageUploadCmd)
{
	pvrvk::Device& device = _deviceResources->device;

	// Remove "texBase" and "texNormalMap" and put them in the global scope
	
	// create the bilinear sampler
	pvrvk::SamplerCreateInfo samplerInfo;
	samplerInfo.magFilter = pvrvk::Filter::e_LINEAR;
	samplerInfo.minFilter = pvrvk::Filter::e_LINEAR;
...


...
pvr::utils::endQueueDebugLabel(_deviceResources->queue);

// New code start
Log(LogLevel::Information, "PRE-vkGetImageMemoryRequirements2 call");

const VkImageMemoryRequirementsInfo2 imageRequirementsInfo = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, NULL, texBase->getImage()->getVkHandle() };
VkMemoryDedicatedRequirements dedicatedRequirements;
InitVkStructNextPtr(dedicatedRequirements, VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR, nullptr);
VkMemoryRequirements2 memoryRequirements2;
InitVkStructNextPtr(memoryRequirements2, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, &dedicatedRequirements);
_deviceResources->device->getVkBindings().vkGetImageMemoryRequirements2(_deviceResources->device->getVkHandle(), &imageRequirementsInfo, &memoryRequirements2);

Log(LogLevel::Information, "POST-vkGetImageMemoryRequirements2 call");
// New code end


//  Initialize UIRenderer
...

I tried the modified demo and it worked fine. I could verify the code vkGetImageMemoryRequirements2 code was executed and the two debug messages were outputted to the logcat.

If possible, please add the changes I proposed to the VulkanBumpmap (let me know if you want me to prepare a fork with those changes). If the issue is still there, I think the problem might be driver-related, and for that I would ask you please to provide the drivers version from your PVR device, which you can get in the Aida64 apk, if you go to the field DisplayGPU Version.

If the application runs fine, then I would say the issue is related with the vulkan wrapper being used, which is not getting the function pointers correctly.

Best regards and many thanks,
Alejandro

Hi @AlejandroC, Thank you for your answer.

No, vkGetImageMemoryRequirements2 - this is native library inside Apk.

I fixed problem in new APK
Now, you can see log cat message:

2021-10-29 00:53:32.986 20010-20067/vkpipeline.android.d A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 20067 (eline.android.d), pid 20010 (eline.android.d)

Also I have checked vkGetImageMemoryRequirements2 before calling:

VulkanTest.cpp line 326:

#ifdef VK_NO_PROTOTYPES
	assert(vkGetImageMemoryRequirements2 && "NULL Pointer");
#endif

I use official official vulkan_wrapper.cpp
Code for vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2

Thank you for mentioning PowerVR SDK:
But! PowerVR SDK code for vkGetImageMemoryRequirements2

Now I see difference. Look at VulkanTest.cpp line 329, 330

I tried to get pointers like PowerVR SDK Framework does:

vkGetImageMemoryRequirements2 = reinterpret_cast<PFN_vkGetImageMemoryRequirements2>(vkGetDeviceProcAddr(vkDevice, "vkGetImageMemoryRequirements2KHR"));

because Vulkan 1.0 supports VK_KHR_get_memory_requirements2 with KHR suffix

and

vkGetImageMemoryRequirements2 = reinterpret_cast<PFN_vkGetImageMemoryRequirements2>(vkGetDeviceProcAddr(vkDevice, "vkGetImageMemoryRequirements2"));

Yes, please create fork, I’m going to try to run a modified VulkanBumpmap’s example

Driver version 1.228.2720

Hi andreyogld3d,

Thank you for your reply. Please find in this link a fork with the test code I mentioned in my previous message. Please build the VulkanBumpmap demo with the changes I added and run it on your PVR device. If it works, it’s most likely to be an implementation issue.

On the other hand, if it fails, it might be drivers-related. I would ask you in that case to please to send us the DDK version of your device, which is provided by apks like AIDA64 (we need the change list and the DDK version, information I’m afraid it is not given by the link you provided).

Best regards,
Alejandro

Hi @AlejandroC, sorry I can’t build project. A lot of problem

  1. Invalid revision: 3.18.1-g262b901-dirty

Could you provide a debug and release apk’s file with detailed logging info ? I can run on device and provide a result.

Hi andreyogld3d,

Thanks for your message. We will review the errors you’re experiencing when trying to build the SDK.

I built a debug and a release apk of the Vulkan Bumpmap demo from the repo fork I prepared last week, which has logging info before and after the call to vkGetImageMemoryRequirements2. Please raise a ticket through our internal support system here so I can provide you the apks (they are too big to be attached as a file).

Best regards and many thanks,
Alejandro

Hi @AlejandroC

Ticket 1220

@AlejandroC

I have fixed crash:

if (vkDeviceInfo.IsSupportExtension(VkPhysicalDeviceInfo::eSupportGetMemoryRequirements2)) {
		if (!vkGetBufferMemoryRequirements2 || !minorVersion) {
			vkGetBufferMemoryRequirements2 = reinterpret_cast<PFN_vkGetBufferMemoryRequirements2>(GetDeviceProcAddr("vkGetBufferMemoryRequirements2KHR"));
		}
		if (!vkGetImageMemoryRequirements2 || !minorVersion) {
			vkGetImageMemoryRequirements2 = reinterpret_cast<PFN_vkGetImageMemoryRequirements2>(GetDeviceProcAddr("vkGetImageMemoryRequirements2KHR"));
		}
	}

for Vulkan 1.0 we need get pointer vkGetImageMemoryRequirements2KHR and vkGetBufferMemoryRequirements2KHR

But! PowerVR SDK code uses vkGetImageMemoryRequirements2

Hi andreyogld3d,

Glad to know you fixed the crash :slight_smile:

Please let us know if you need help with any other issue.

Best regards,
Alejandro

I have only one question why it work for SDK?
because PowerVR SDK code uses vkGetImageMemoryRequirements2 any way I need apk for testing on my Device.

Hi andreyogld3d,

Thanks for pointing that out.

The postfixes in Vulkan APIs mean the API is part of a Vulkan extension (KHR, EXT, NV, AMD). In the case of KHR postfix, it is a Khronos extension. In Vulkan 1.1 many extensions were promoted to the core, losing their postfix. Since we use Vulkan 1.1 in our SDK, we don’t need to add the KHR to retrieve the function pointer to vkGetImageMemoryRequirements2, but in your case using Vulkan 1.0, you need use vkGetImageMemoryRequirements2KHR. I hope this helps clarify your question.

I replied your message in our internal support system with instructions to get the debug and release apks requested.

Let us know if you have any other questions.

Best regards,
Alejandro

1 Like

Hi @AlejandroC

During running apk I have crash. PowerVR8300_PowerVR_SDKCrash.log.zip (5.8 KB)

AIDA 64 info

also, I replied in opened ticked

Hi andreyogld3d,

Thanks a lot for taking the time to test the apk and for the provided information.

After reviewing the crash log, I can see the call stack shows a crash at:

pvrvk::impl::DebugUtilsMessenger_::DebugUtilsMessenger_

Which is executed quite at the beginning of the application. There’s no trace of the log message before calling vkGetImageMemoryRequirements2, PRE-vkGetImageMemoryRequirements2 call, so this crash seems to be related to a different reason. In any case we will setup a system with the DDK version provided (or as close as possible) and debug to try reproduce the issue.

Best regards and many thanks,
Alejandro

1 Like

© Imagination Technologies Limited. All rights reserved.
Privacy PolicyTerms & ConditionsTrademarksCookies