upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/vk_queue_test.cpp
diff options
context:
space:
mode:
authortedin7 <tommasoderosa94@gmail.com>2026-11-23 00:46:05 +0100
committertedin7 <tommasoderosa94@gmail.com>2026-11-23 00:46:05 +0100
commitcc068baf8616a8945885eddf458c83fcd1938320 (patch)
tree35e6d68b3c32f0c8ab59d76f629eee7e84c18a86 /runtime/test/vk_queue_test.cpp
parentaa2988cc555bad7ecd508b48a702adbb32fe7c95 (diff)
runtime: cap the command buffers a Vulkan queue keeps in flight
Diffstat (limited to 'runtime/test/vk_queue_test.cpp')
-rw-r--r--runtime/test/vk_queue_test.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/runtime/test/vk_queue_test.cpp b/runtime/test/vk_queue_test.cpp
index 84289198c..b62336a07 100644
--- a/runtime/test/vk_queue_test.cpp
+++ b/runtime/test/vk_queue_test.cpp
@@ -22,6 +22,16 @@ namespace {
22using namespace leonida; 22using namespace leonida;
23using Kind = VulkanQueue::QueueKind; 23using Kind = VulkanQueue::QueueKind;
24 24
25// Counts the command buffers a queue allocates, for the backlog check in main().
26PFN_vkAllocateCommandBuffers real_allocate_command_buffers = nullptr;
27std::uint32_t allocated_command_buffers = 0;
28
29VKAPI_ATTR VkResult VKAPI_CALL counting_allocate_command_buffers(VkDevice device, const VkCommandBufferAllocateInfo* info,
30 VkCommandBuffer* buffers) {
31 allocated_command_buffers += info->commandBufferCount;
32 return real_allocate_command_buffers(device, info, buffers);
33}
34
25const char* flags_text(VkQueueFlags f) { 35const char* flags_text(VkQueueFlags f) {
26 static char buf[32]; 36 static char buf[32];
27 std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "", 37 std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "",
@@ -200,6 +210,36 @@ int main() {
200 EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported); 210 EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported);
201 std::printf("copy and compute queues refuse a render-target clear\n"); 211 std::printf("copy and compute queues refuse a render-target clear\n");
202 212
213 // 5. A caller that submits faster than the GPU finishes must not grow the queue's command buffers without bound:
214 // at the cap it waits for the oldest one. Big host-visible copies keep the GPU behind the submitting loop.
215 {
216 constexpr VkDeviceSize kBig = 16u << 20;
217 constexpr std::uint32_t kSubmits = 4 * VulkanQueue::kMaxQueuedCommandBuffers;
218 void *src_map = nullptr, *dst_map = nullptr;
219 VkBuffer big_src = d.buffer(kBig, usage, &src_map);
220 VkBuffer big_dst = d.buffer(kBig, usage, &dst_map);
221 EXPECT(big_src && big_dst);
222 add_buffer(7, big_src, kBig);
223 add_buffer(8, big_dst, kBig);
224 std::memset(src_map, 0x5A, kBig);
225 CommandList big_copy;
226 EXPECT(big_copy.copy_buffer({8, 0, 7, 0, kBig}));
227 EXPECT(big_copy.close());
228 const CommandList* big_lists[] = {&big_copy};
229
230 real_allocate_command_buffers = context.vk.vkAllocateCommandBuffers;
231 context.vk.vkAllocateCommandBuffers = counting_allocate_command_buffers;
232 allocated_command_buffers = 0;
233 for (std::uint32_t i = 0; i < kSubmits; ++i) EXPECT(direct.execute(big_lists) == ReplayResult::success);
234 context.vk.vkAllocateCommandBuffers = real_allocate_command_buffers;
235 EXPECT(direct.signal(fence.semaphore(), 5));
236 EXPECT(fence.wait(5, 20'000'000'000ull));
237 std::printf("backlog: %u submits, %u command buffers allocated (cap %zu)\n", kSubmits, allocated_command_buffers,
238 VulkanQueue::kMaxQueuedCommandBuffers);
239 EXPECT(allocated_command_buffers <= VulkanQueue::kMaxQueuedCommandBuffers);
240 EXPECT(static_cast<std::uint8_t*>(dst_map)[kBig - 1] == 0x5A);
241 }
242
203 EXPECT(direct.idle() && compute.idle() && copy.idle()); 243 EXPECT(direct.idle() && compute.idle() && copy.idle());
204 if (d.validation) { 244 if (d.validation) {
205 std::printf("validation errors: %u\n", d.validation_errors()); 245 std::printf("validation errors: %u\n", d.validation_errors());