RFC: const-ref based inline helper functions#2671
RFC: const-ref based inline helper functions#2671pdaniell-nv wants to merge 4 commits intostruct-defaultingfrom
Conversation
This comes from: KhronosGroup/Vulkan-Docs#2671
This tweak allows C++20 apps do use temporary arrays as parameters like `vkResetFences(device, {{fence}});`. When C++26 (P2447R4) becomes available apps will be able to do `vkResetFences(device, {fence});` to make it slightly nicer.
|
An excerpt from vulkan-headers: For this code to compile, it needs to not have VK_NO_PROTOTYPES because it needs there to the Extensions defining symbols that have no link-time definition was enough of a problem the Having overloads which only work for some functions (core and the handful of wsi functions that the Vulkan-Loader exports) is very confusing behavior. I do not think this should be included in the headers unless it is possible to use these overloads for all functions. The current situation of some functions being linkable and some not is already confusing enough. |
This builds on the previous default member initialization PR (#2669) and adds inline const-ref variants of the existing Vulkan functions that take const-pointer for info structures and similar. This allows temporary objects to be used as parameters, potentially leading to more concise, convenient and readable code. The output of these changes can be seen here:
In addition this PR adds inline variants of the create and destroy functions without the pAllocator parameter to make those functions more concise for the common use case.
For example, this:
VkFenceCreateInfo fenceInfo{ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT }; vkCreateFence(device, &fenceInfo, nullptr, &fence);Can now look like this:
Finally, this PR adds
const span<VkThing>&variants of functions that take auint_t count, const VkThing*pair to make it easier to work with arrays, vectors and other things that can naturally be viewed as spans.Code that used to look like this:
Can now look like:
vector<VkFence> myFences; ... vkResetFences(device, myFences);With feedback, these API experiments will hopefully evolve into something genuially useful to app developers, make their code more concise, easier to read and maintain, and the Vulkan API more of a joy to use. Other experiments will follow.