-
Notifications
You must be signed in to change notification settings - Fork 362
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
[WIP] Win32 Handle extension #442
[WIP] Win32 Handle extension #442
Conversation
Question: Do I add vkGetMemoryWin32HandleKHR into allocator functions, or do I add it as a function argument? |
I would add it to the struct with functions, just like all other Vulkan functions. |
Is it safe to use an atomic? What if 2 threads want to fetch the handle at the same time? Shouldn't you use a mutex around the whole fetching logic? |
No, atomics are safe. I also did the relax ordering, because we have no memory to make barrier onto.
Actually I could tinker with a lot of atomics in this lib and make it lock free. There are lock free queues there, so maybe one of the next steps :) |
I actually asked Vulkan if that's OK to call on vkGetMemoryWin32HandleKHR multiple times. They pointed out that this is UB and not an error, meaning there is no harm in it, just we have no clue what's gonna be returned. |
Isn't this whole effort about making sure we don't call
If so, isn't your current code unsafe in this regard when called from multiple threads? When talking about an UB, we typically understand that anything can happen, including entire app or system crash, so is there really "no harm" when we trigger an an UB? |
Hmm, you're right, though there was a limitation for me, hence why I chose to use atomics, and that being absence of mutex on dedicated memory. Should I add one? |
Yes please, I think you need a mutex for this to be safe. Another topic to think about: What if an allocation ends up as a dedicated allocation? |
If it has VkDeviceMemory it is not a problem. There is no mutex in this structure, so I think I will add one |
Added a mutex. There is a really low chance in current setup that it will be used, so it imposes little overhead |
It seems you reformatted the entire file with some automatic formatting tool! Please don't do this. It makes it difficult to see what are the real differences you introduce to the code. Can you please surround all your code with an |
crap, reflexes |
Done |
Hopefully I defined correct one. Also, I have a linker error with static function, seems like it is only possible to get the function dynamically |
Yes, functions from extensions can only be fetched dynamically. |
do I set it to null, or try to fetch with dynamic code? |
Please do like the other extensions do - for Static don't do anything, for Dynamic try to fetch the function pointer, for |
Are you willing to develop some simple test for this new functionality? |
Sure |
I wonder, why don't we allow for dedicated allocations to have custom pNext? |
To avoid feature creep and not extend the |
What do I specify at memoryTypeIndex on pool? |
To create a custom pool you need to find the right memory type and choose it explicitly: |
I added code for fetching the extension and creating a pool. Can't launch test, however, it throws at some random point |
Fixed, working like a charm |
Thank you for all this code! I need to analyze it some more, but it looks good overall. There is one more thing I would like to have. I don't want the Would you like to implement such thing? |
Well, I'd take it to the new PR.
Tell me if you are interested in some of them :) |
Also VmaDeviceMemoryBlock has the same |
OK, I'll analyze your code soon and hopefully I merge it. I agree the optimization to extract new structure I am sorry but I am not interested in any of the big changes you proposed. The library is now mature and used by many developers. I don't want to do a revolution that could break anyone's workflow. If you want to introduce such big changes to the code, please feel free to maintain your own fork. I am happy to link to it from README. About the Cmake script especially, I don't want to make more major changes, because this is a never-ending story of pull requests from users with various visions about how it should look like. The more such requests I get, the closer I am to removing the Cmake script completely. I regret adding it in the first place. I agree with the arguments of @ocornut about the value of not having it, as mentioned in ocornut/imgui#7892, section "3.6. Lack Of A Build System Is A Feature". Please also note that VMA ships with the Vulkan SDK as "vk_mem_alloc.h" file only, not the entire repository and no Cmake script. |
|
Ah, ok. I thought about making Wisdom Memory allocator, but that would require me to also get D3D12 MA shredded, which is a ton of work. Maybe one day. |
Do you use D3D12MA library as well? Extracting common code (the core TLSF allocation algorithm) from both libraries is another major refactoring (after splitting the library into multiple source files) that is possible but I don't want to do. If you do it on your fork, that would be great. |
I have Wisdom library, which is super thin compared to others, but super demanding in terms of Vulkan (works no less than 1.3 and requires heavy extensions). I stumbled upon both allocators, and now they are part of its standard. If there is a wish, I could do the Wisdom memory allocator and do the extraction for both. |
It is up to you. From my perspective, it is good if we just have the change to VMA discussed in this PR. |
Will do. I'd also like to have Wisdom mentioned :) |
Thank you very much for this extensive and high quality contribution. You didn't test dedicated allocations. Because of that, you didn't meet the bug that happens because I also made some other fixes and written documentation for the new feature. Please let me know if it looks good to you. |
I need to finish one project, then I will continue. Where can I find new documentation? Glad I could help! |
It is already part of the documentation available online, most notably: |
Ah, I see, you have already implemented the data pointer, well, then if something comes, I could make a feature or two |
Wow, documentation looks awesome! |
No description provided.