Comments (20)
I found the solution:
Apparently the internal table of vulkan function pointers are not initialized on Android. Setting:
#define VMA_STATIC_VULKAN_FUNCTIONS 1
didn't help, because the Android compiler doesn't like the syntax of the function that initializes the pointers. So instead, I have to fill the pointers manually when creating VmaAllocator, like this:
VmaAllocatorCreateInfo allocatorInfo = {};
allocatorInfo.physicalDevice = gpu;
allocatorInfo.device = device;
allocatorInfo.preferredLargeHeapBlockSize = blockSize;
VmaVulkanFunctions fn;
fn.vkAllocateMemory = (PFN_vkAllocateMemory)vkAllocateMemory;
fn.vkBindBufferMemory = (PFN_vkBindBufferMemory)vkBindBufferMemory;
fn.vkBindImageMemory = (PFN_vkBindImageMemory)vkBindImageMemory;
fn.vkCmdCopyBuffer = (PFN_vkCmdCopyBuffer)vkCmdCopyBuffer;
fn.vkCreateBuffer = (PFN_vkCreateBuffer)vkCreateBuffer;
fn.vkCreateImage = (PFN_vkCreateImage)vkCreateImage;
fn.vkDestroyBuffer = (PFN_vkDestroyBuffer)vkDestroyBuffer;
fn.vkDestroyImage = (PFN_vkDestroyImage)vkDestroyImage;
fn.vkFlushMappedMemoryRanges = (PFN_vkFlushMappedMemoryRanges)vkFlushMappedMemoryRanges;
fn.vkFreeMemory = (PFN_vkFreeMemory)vkFreeMemory;
fn.vkGetBufferMemoryRequirements = (PFN_vkGetBufferMemoryRequirements)vkGetBufferMemoryRequirements;
fn.vkGetImageMemoryRequirements = (PFN_vkGetImageMemoryRequirements)vkGetImageMemoryRequirements;
fn.vkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties)vkGetPhysicalDeviceMemoryProperties;
fn.vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties)vkGetPhysicalDeviceProperties;
fn.vkInvalidateMappedMemoryRanges = (PFN_vkInvalidateMappedMemoryRanges)vkInvalidateMappedMemoryRanges;
fn.vkMapMemory = (PFN_vkMapMemory)vkMapMemory;
fn.vkUnmapMemory = (PFN_vkUnmapMemory)vkUnmapMemory;
fn.vkGetBufferMemoryRequirements2KHR = 0; //(PFN_vkGetBufferMemoryRequirements2KHR)vkGetBufferMemoryRequirements2KHR;
fn.vkGetImageMemoryRequirements2KHR = 0; //(PFN_vkGetImageMemoryRequirements2KHR)vkGetImageMemoryRequirements2KHR;
allocatorInfo.pVulkanFunctions = &fn;
VmaAllocator allocator;
vmaCreateAllocator(&allocatorInfo, &allocator);
from vulkanmemoryallocator.
Thank you for reporting this issue. I've changed the syntax used in function VmaAllocator_T::ImportVulkanFunctions
like you suggested. Can you please check if the latest version from "master" branch works for you with just #define VMA_STATIC_VULKAN_FUNCTIONS 1
?
Besides, I would recommend to always first compile and run your program with asserts enabled. If VMA_ASSERT
was active in the way appropriate to your platform, your issue would be caught at the end of VmaAllocator_T::ImportVulkanFunctions
function and you wouldn't need to debug the crash that happened later.
from vulkanmemoryallocator.
Adam, master is still crashing on Android whether #define VMA_STATIC_VULKAN_FUNCTIONS is 0 or 1. Renelindsay's workaround still works. I'm guessing ImportVulkanFunctions() has an ordering problem, but I did not grind though the logic to figure it out.
from vulkanmemoryallocator.
@mgrivich I've made some fixes in the master branch. Can you please test on Android whether it solves your problem?
from vulkanmemoryallocator.
I'm closing this issue, but please let me know if there is anything more that can be fixed to make it working on your platform.
from vulkanmemoryallocator.
Sorry, I was working on a different project. Your current version still crashes. It can be corrected either by the original workaround, or this new fix:
Add
#ifdef __ANDROID__
#define VMA_STATIC_VULKAN_FUNCTIONS 1
#define VK_NO_PROTOTYPES 1
#include <vulkan/vulkan.h>
extern PFN_vkAllocateMemory vkAllocateMemory;
extern PFN_vkBindBufferMemory vkBindBufferMemory;
extern PFN_vkBindImageMemory vkBindImageMemory;
extern PFN_vkCmdCopyBuffer vkCmdCopyBuffer;
extern PFN_vkCreateBuffer vkCreateBuffer;
extern PFN_vkCreateImage vkCreateImage;
extern PFN_vkDestroyBuffer vkDestroyBuffer;
extern PFN_vkDestroyImage vkDestroyImage;
extern PFN_vkFlushMappedMemoryRanges vkFlushMappedMemoryRanges;
extern PFN_vkFreeMemory vkFreeMemory;
extern PFN_vkGetBufferMemoryRequirements vkGetBufferMemoryRequirements;
extern PFN_vkGetImageMemoryRequirements vkGetImageMemoryRequirements;
extern PFN_vkGetPhysicalDeviceMemoryProperties vkGetPhysicalDeviceMemoryProperties;
extern PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties;
extern PFN_vkInvalidateMappedMemoryRanges vkInvalidateMappedMemoryRanges;
extern PFN_vkMapMemory vkMapMemory;
extern PFN_vkUnmapMemory vkUnmapMemory;
extern PFN_vkGetBufferMemoryRequirements2KHR vkGetBufferMemoryRequirements2KHR;
extern PFN_vkGetImageMemoryRequirements2KHR vkGetImageMemoryRequirements2KHR;
extern PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
extern PFN_vkGetDeviceProcAddr vkGetDeviceProcAddr;
#endif
to the top of vk_mem_alloc.h (right after #define AMD_VULKAN_MEMORY_ALLOCATOR_H). It can't be in the extern C, and the VK_NO_PROTOTYPES 1
, #include <vulkan/vulkan.h>
, extern ...
ordering is required.
This code is extracted from vulkan_wrapper.h/.cpp at https://github.com/KhronosGroup/Vulkan-Tools/tree/master/common
from vulkanmemoryallocator.
Actually, I don't know why did I ever used statically linked functions instead of always fetching them with vkGetInstanceProcAddr
/vkGetDeviceProcAddr
. This should work on any platform, right?
Please check the latest code on master branch and see if it works for you.
from vulkanmemoryallocator.
I'm getting
vk_mem_alloc.h:12739:32: error: use of undeclared identifier 'VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR'; did you mean 'VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT_KHR'?
during compilation.
from vulkanmemoryallocator.
How about now? Does it work for you?
from vulkanmemoryallocator.
It is crashing with a SIGSEGV. Could I just make a simple Android Studio project for you to test with? You could either buy a cheap Android device or use the free emulators to test.
from vulkanmemoryallocator.
Unfortunately I don't have Android development environment. The library is developed mostly on- and for Windows. Please feel free to propose a pull request with fix.
from vulkanmemoryallocator.
Android Studio is free. https://developer.android.com/studio.
I gave you a fix above (the post with the externs), you didn't implement it.
from vulkanmemoryallocator.
OK, I made further changes. I also added extern
declarations as you proposed above. I think that defining VK_NO_PROTOTYPES
should be done by the user before including the library. VMA_STATIC_VULKAN_FUNCTIONS
is defined to 1 by default. Please let me know if it works for you now.
from vulkanmemoryallocator.
@adam-sawicki-a I checked the latest version. I think it's better add "#if VMA_DYNAMIC_VULKAN_FUNCTIONS == 1" for "VmaAllocator_T::ImportVulkanFunctions_Dynamic()" (both declaration and definition). Then we don't need to define vkGetInstanceProcAddr and vkGetDeviceProcAddr globally but just provide custom function pointers when create the allocator.
from vulkanmemoryallocator.
Good point, thanks! I made this change.
from vulkanmemoryallocator.
So, what do you think about the current code? Is it working in your environment?
from vulkanmemoryallocator.
I'm closing this ticket due to inactivity for a long time. Please let me know if the issue still needs fixing.
from vulkanmemoryallocator.
I tried it, It works fine on android. But v2.3.0 does not contain this patch.
Can you release a new version? BTW, I've added it to the xmake-repo to make it easier for users to use it. But currently I can only use latest commit and datae as version number because 2.3.0 is too old.
https://github.com/xmake-io/xmake-repo/blob/master/packages/v/vulkan-memory-allocator/xmake.lua
from vulkanmemoryallocator.
I know that there hasn't been an official release for long time and so using latest code from the "master" branch is recommended at the moment. We are working on a major release. It is tracked as #162.
Thank you for your feedback.
from vulkanmemoryallocator.
ok, thanks!
from vulkanmemoryallocator.
Related Issues (20)
- Example for External Memory support HOT 4
- Make a new version HOT 1
- vmaCreatePool failing at startup on some Nvidia gpu + driver combos HOT 5
- 3.0.1 doesn't build on armeabi-v7a HOT 1
- Validation error (VkMemoryRequirements::alignment) in v2.3.0 HOT 2
- Support using parts of VMA without vulkan [virtual allocation & defragmentation] HOT 1
- VMA crashing at startup on Android 14 devices HOT 9
- 3.0.2 release for gcc-13 fix? HOT 1
- PRIu64 format sometimes being used with a type other than uint64_t
- vmaDestroyBuffer() destroy everything but VkDeviceMemory HOT 4
- Need help at identifying potential copy-paste bug HOT 2
- missing VMA_LEN_IF_NOT_NULL in vmaCopyMemoryToAllocation/vmaCopyAllocationToMemory HOT 1
- Buggy mapping hysteresis optimization HOT 2
- Asserts on Android 9 wth vkGetPhysicalDeviceMemoryProperties2KHR HOT 1
- no support for `VkBufferUsageFlags2CreateInfoKHR` HOT 2
- Specify in documentation that individual pools can be individually used w/o external synchronization HOT 1
- Compatibility issue with Vulkan 1.2.198 on OSX HOT 3
- Can I batch all allocations in one function call to VMA if I know my memory requirements upfront? HOT 2
- Building VulkanMemoryAllocator for C HOT 2
- Changes to PFN_vmaAllocateDeviceMemoryFunction HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vulkanmemoryallocator.