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:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:12:09 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 23:12:09 -0500
commitc143c207b4f02b880be5a7994057942e1f006b77 (patch)
tree7274872a5cc926df0ca5ebf21d23f9bb0e1c83e2 /runtime/test/vk_queue_test.cpp
parent8428d87d8644b7ddc7d46c29321a04ebb2006f3a (diff)
parenta3481c0a1870b1037085d71a32d4bfecc5bf9db7 (diff)
Merge pull request #4191 from tedin7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/vk_queue_test.cpp')
-rw-r--r--runtime/test/vk_queue_test.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/runtime/test/vk_queue_test.cpp b/runtime/test/vk_queue_test.cpp
index 9df720356..1a73e8d1b 100644
--- a/runtime/test/vk_queue_test.cpp
+++ b/runtime/test/vk_queue_test.cpp
@@ -9,6 +9,7 @@
9#include "../src/vulkan_backend.h" 9#include "../src/vulkan_backend.h"
10 10
11#include <array> 11#include <array>
12#include <atomic>
12#include <cstdint> 13#include <cstdint>
13#include <cstring> 14#include <cstring>
14#include <vector> 15#include <vector>
@@ -22,6 +23,30 @@ namespace {
22using namespace leonida; 23using namespace leonida;
23using Kind = VulkanQueue::QueueKind; 24using Kind = VulkanQueue::QueueKind;
24 25
26// Counts the command buffers a queue allocates, for the backlog check in main().
27PFN_vkAllocateCommandBuffers real_allocate_command_buffers = nullptr;
28std::uint32_t allocated_command_buffers = 0;
29
30VKAPI_ATTR VkResult VKAPI_CALL counting_allocate_command_buffers(VkDevice device, const VkCommandBufferAllocateInfo* info,
31 VkCommandBuffer* buffers) {
32 allocated_command_buffers += info->commandBufferCount;
33 return real_allocate_command_buffers(device, info, buffers);
34}
35
36// Makes the queue's first kStalls waits for room time out at once, as on a GPU that stopped making progress.
37constexpr std::uint32_t kStalls = 3;
38PFN_vkWaitSemaphores real_wait_semaphores = nullptr;
39std::atomic<std::uint32_t> injected_stalls{0};
40
41VKAPI_ATTR VkResult VKAPI_CALL stalling_wait_semaphores(VkDevice device, const VkSemaphoreWaitInfo* info,
42 std::uint64_t timeout) {
43 if (timeout == VulkanQueue::kQueuedWaitNs && injected_stalls.load() < kStalls) {
44 ++injected_stalls;
45 return VK_TIMEOUT;
46 }
47 return real_wait_semaphores(device, info, timeout);
48}
49
25const char* flags_text(VkQueueFlags f) { 50const char* flags_text(VkQueueFlags f) {
26 static char buf[32]; 51 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" : "", 52 std::snprintf(buf, sizeof buf, "%s%s%s", f & VK_QUEUE_GRAPHICS_BIT ? "G" : "", f & VK_QUEUE_COMPUTE_BIT ? "C" : "",
@@ -226,6 +251,41 @@ int main() {
226 EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported); 251 EXPECT(compute.execute(clear_lists) == ReplayResult::unsupported);
227 std::printf("copy and compute queues refuse a render-target clear\n"); 252 std::printf("copy and compute queues refuse a render-target clear\n");
228 253
254 // 5. A caller that submits faster than the GPU finishes must not grow the queue's command buffers without bound:
255 // at the cap it waits for the oldest one. Big host-visible copies keep the GPU behind the submitting loop. The first
256 // waits time out (injected), as on a stalled GPU: the cap must hold through a timeout too.
257 {
258 constexpr VkDeviceSize kBig = 16u << 20;
259 constexpr std::uint32_t kSubmits = 4 * VulkanQueue::kMaxQueuedCommandBuffers;
260 void *src_map = nullptr, *dst_map = nullptr;
261 VkBuffer big_src = d.buffer(kBig, usage, &src_map);
262 VkBuffer big_dst = d.buffer(kBig, usage, &dst_map);
263 EXPECT(big_src && big_dst);
264 add_buffer(7, big_src, kBig);
265 add_buffer(8, big_dst, kBig);
266 std::memset(src_map, 0x5A, kBig);
267 CommandList big_copy;
268 EXPECT(big_copy.copy_buffer({8, 0, 7, 0, kBig}));
269 EXPECT(big_copy.close());
270 const CommandList* big_lists[] = {&big_copy};
271
272 real_allocate_command_buffers = context.vk.vkAllocateCommandBuffers;
273 real_wait_semaphores = context.vk.vkWaitSemaphores;
274 context.vk.vkAllocateCommandBuffers = counting_allocate_command_buffers;
275 context.vk.vkWaitSemaphores = stalling_wait_semaphores;
276 allocated_command_buffers = 0;
277 for (std::uint32_t i = 0; i < kSubmits; ++i) EXPECT(direct.execute(big_lists) == ReplayResult::success);
278 context.vk.vkAllocateCommandBuffers = real_allocate_command_buffers;
279 context.vk.vkWaitSemaphores = real_wait_semaphores;
280 EXPECT(direct.signal(fence.semaphore(), 5));
281 EXPECT(fence.wait(5, 20'000'000'000ull));
282 std::printf("backlog: %u submits, %u command buffers allocated (cap %zu), %u waits timed out\n", kSubmits,
283 allocated_command_buffers, VulkanQueue::kMaxQueuedCommandBuffers, injected_stalls.load());
284 EXPECT(injected_stalls.load() == kStalls); // the queue did reach the cap and wait
285 EXPECT(allocated_command_buffers <= VulkanQueue::kMaxQueuedCommandBuffers);
286 EXPECT(static_cast<std::uint8_t*>(dst_map)[kBig - 1] == 0x5A);
287 }
288
229 EXPECT(direct.idle() && compute.idle() && copy.idle()); 289 EXPECT(direct.idle() && compute.idle() && copy.idle());
230 if (d.validation) { 290 if (d.validation) {
231 std::printf("validation errors: %u\n", d.validation_errors()); 291 std::printf("validation errors: %u\n", d.validation_errors());