KhronosGroup / KhronosGroup/Vulkan-Hpp

Add a custom allocator(like polymorphic_allocator) when some RAII methods return std containers.

Open
#2,523 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.8k
Forks
374
Avg merge
23h 4m
Merged PRs (30d)
32

Description

Thank you for open-sourcing this modern C++ Vulkan wrapper library. Our project is currently trying to use `vulkan-hpp`, but I noticed that some methods which return std containers use `std::allocator`, as shown below.

```cpp
// wrapper function for command vkEnumerateInstanceExtensionProperties, see
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumerateInstanceExtensionProperties.html
VULKAN_HPP_NODISCARD typename ResultValueType>::type
enumerateInstanceExtensionProperties( Optional layerName VULKAN_HPP_DEFAULT_ASSIGNMENT( nullptr ) ) const;

// wrapper function for command vkEnumerateInstanceLayerProperties, see
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumerateInstanceLayerProperties.html
VULKAN_HPP_NODISCARD typename ResultValueType>::type enumerateInstanceLayerProperties() const;
```

This means that if I need to store this data, I have to copy it into our `pmr` containers to keep the types consistent. It would be ideal if a macro could be added to enable or disable a custom allocator. My personal idea is as follows:

```cpp
template
using VKHppStdContainerAllocator =
#if defined(VULKAN_HPP_USE_PMR_ALLOCATOR)
std::polymorphic_allocator;
#else
std::allocator;
#endif

// wrapper function for command vkEnumerateInstanceExtensionProperties, see
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumerateInstanceExtensionProperties.html
// add allocator
VULKAN_HPP_NODISCARD typename ResultValueType>>::type
enumerateInstanceExtensionProperties( Optional layerName VULKAN_HPP_DEFAULT_ASSIGNMENT( nullptr ) ) const;

// wrapper function for command vkEnumerateInstanceLayerProperties, see
// https://registry.khronos.org/vulkan/specs/latest/man/html/vkEnumerateInstanceLayerProperties.html
VULKAN_HPP_NODISCARD typename ResultValueType>>::type enumerateInstanceLayerProperties() const;
```
PS. If this issue is acceptable and this repository welcomes PRs, I would be happy to try contributing this part of the code.

Contributor guide

Open the contributing guide

Research direction

Start with the wrapper declarations for enumerateInstanceExtensionProperties and enumerateInstanceLayerProperties shown in the issue, then trace how their std::vector return types are generated. Define what allocator selection must cover and verify that PMR-enabled returns use the custom allocator while the default behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.