GithubHelp home page GithubHelp logo

Comments (20)

renelindsay avatar renelindsay commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

mgrivich avatar mgrivich commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

@mgrivich I've made some fixes in the master branch. Can you please test on Android whether it solves your problem?

from vulkanmemoryallocator.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

mgrivich avatar mgrivich commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

mgrivich avatar mgrivich commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

How about now? Does it work for you?

from vulkanmemoryallocator.

mgrivich avatar mgrivich commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

mgrivich avatar mgrivich commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

JerryMa-SDE avatar JerryMa-SDE commented on May 31, 2024

@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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

Good point, thanks! I made this change.

from vulkanmemoryallocator.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

So, what do you think about the current code? Is it working in your environment?

from vulkanmemoryallocator.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

I'm closing this ticket due to inactivity for a long time. Please let me know if the issue still needs fixing.

from vulkanmemoryallocator.

waruqi avatar waruqi commented on May 31, 2024

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.

adam-sawicki-a avatar adam-sawicki-a commented on May 31, 2024

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.

waruqi avatar waruqi commented on May 31, 2024

ok, thanks!

from vulkanmemoryallocator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.