Skip to content

Conversation

@asuessenbach
Copy link
Contributor

Resolves #2315.

@rwols
Copy link

rwols commented Dec 31, 2025

I checked out this branch and I can confirm that this branch has the desired behavior (would close #2315).

I verified this by changing the test in tests/DeviceFunctions/DeviceFunctions.cpp in the below diff. The function createCommandBuffers in this diff does not compile on the main branch while it does compile on the const_ref_allocators branch 👍 perhaps you can add these changes to DeviceFunctions.cpp?

diff --git a/tests/DeviceFunctions/CMakeLists.txt b/tests/DeviceFunctions/CMakeLists.txt
index 718e7ab..ba6d114 100644
--- a/tests/DeviceFunctions/CMakeLists.txt
+++ b/tests/DeviceFunctions/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved.
+# Copyright(c) 2026, NVIDIA CORPORATION. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
diff --git a/tests/DeviceFunctions/DeviceFunctions.cpp b/tests/DeviceFunctions/DeviceFunctions.cpp
index 1c11e8f..2cefc82 100644
--- a/tests/DeviceFunctions/DeviceFunctions.cpp
+++ b/tests/DeviceFunctions/DeviceFunctions.cpp
@@ -1,4 +1,4 @@
-// Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved.
+// Copyright(c) 2026, NVIDIA CORPORATION. All rights reserved.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -41,6 +41,17 @@
 static char const * AppName    = "DeviceFunctions";
 static char const * EngineName = "Vulkan.hpp";
 
+template <
+    class Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE,
+    class Alloc = std::allocator<vk::UniqueHandle<vk::CommandBuffer, Dispatch>>>
+std::vector<vk::UniqueHandle<vk::CommandBuffer, Dispatch>, Alloc>
+createCommandBuffers(const vk::Device &device,
+                     const vk::CommandBufferAllocateInfo &allocateInfo,
+                     const Alloc &alloc = Alloc(),
+                     const Dispatch &d = VULKAN_HPP_DEFAULT_DISPATCHER) {
+  return device.allocateCommandBuffersUnique(allocateInfo, alloc, d);
+}
+
 int main( int /*argc*/, char ** /*argv*/ )
 {
   try
@@ -70,15 +81,15 @@ int main( int /*argc*/, char ** /*argv*/ )
 
     uint64_t handle = device->getAccelerationStructureHandleNV<uint8_t>( {}, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE() );
 
-    std::vector<vk::UniqueCommandBuffer>::allocator_type vectorAllocator;
-    vk::UniqueCommandBuffer                              commandBuffer =
-      std::move( device->allocateCommandBuffersUnique( {}, vectorAllocator, VULKAN_HPP_DISPATCH_LOADER_STATIC_TYPE() ).front() );
-
+    std::vector<vk::UniqueCommandBuffer> vector;
+    vector = createCommandBuffers(device.get(), {}, vector.get_allocator(), VULKAN_HPP_DISPATCH_LOADER_STATIC_TYPE());
+    vk::UniqueCommandBuffer commandBuffer = std::move(vector.front());
     commandBuffer->begin( vk::CommandBufferBeginInfo() );
 
-    std::vector<vk::UniqueHandle<vk::CommandBuffer, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE>>::allocator_type dynamicVectorAllocator;
-    vk::UniqueHandle<vk::CommandBuffer, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE>                              dynamicCommandBuffer =
-      std::move( device->allocateCommandBuffersUnique( {}, dynamicVectorAllocator, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE() ).front() );
+    std::vector<vk::UniqueHandle<vk::CommandBuffer, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE>> dynamicVector;
+    dynamicVector = createCommandBuffers(device.get(), {}, dynamicVector.get_allocator(), VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE());
+
+    vk::UniqueHandle<vk::CommandBuffer, VULKAN_HPP_DISPATCH_LOADER_DYNAMIC_TYPE> dynamicCommandBuffer = std::move(dynamicVector.front());
 
     vk::Buffer       buffer       = device->createBuffer( {} );
     vk::UniqueBuffer uniqueBuffer = vk::UniqueBuffer( buffer, *device );

@rwols
Copy link

rwols commented Dec 31, 2025

Well, when trying to run this test it segfaults at the vector::front() call because we get an empty vector. I guess this is just a compile-time test?

@asuessenbach
Copy link
Contributor Author

Thanks for providing some test code. Added it to the DeviceFunctions test.

And yes, it's a pure compile test, not meant for actually running it.

@asuessenbach asuessenbach merged commit 67158ce into KhronosGroup:main Jan 5, 2026
24 checks passed
@asuessenbach asuessenbach deleted the const_ref_allocator branch January 5, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

const-ref for optional allocator arguments?

2 participants