diff options
Diffstat (limited to 'runtime/test/vk_queue_test.cpp')
| -rw-r--r-- | runtime/test/vk_queue_test.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/runtime/test/vk_queue_test.cpp b/runtime/test/vk_queue_test.cpp index b62336a07..66ad231f6 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> |
| @@ -32,6 +33,20 @@ VKAPI_ATTR VkResult VKAPI_CALL counting_allocate_command_buffers(VkDevice device | |||
| 32 | return real_allocate_command_buffers(device, info, buffers); | 33 | return real_allocate_command_buffers(device, info, buffers); |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 36 | // Makes the queue's first kStalls waits for room time out at once, as on a GPU that stopped making progress. | ||
| 37 | constexpr std::uint32_t kStalls = 3; | ||
| 38 | PFN_vkWaitSemaphores real_wait_semaphores = nullptr; | ||
| 39 | std::atomic<std::uint32_t> injected_stalls{0}; | ||
| 40 | |||
| 41 | VKAPI_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 | |||
| 35 | const char* flags_text(VkQueueFlags f) { | 50 | const char* flags_text(VkQueueFlags f) { |
| 36 | static char buf[32]; | 51 | static char buf[32]; |
| 37 | 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" : "", |
| @@ -211,7 +226,8 @@ int main() { | |||
| 211 | std::printf("copy and compute queues refuse a render-target clear\n"); | 226 | std::printf("copy and compute queues refuse a render-target clear\n"); |
| 212 | 227 | ||
| 213 | // 5. A caller that submits faster than the GPU finishes must not grow the queue's command buffers without bound: | 228 | // 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. | 229 | // at the cap it waits for the oldest one. Big host-visible copies keep the GPU behind the submitting loop. The first |
| 230 | // waits time out (injected), as on a stalled GPU: the cap must hold through a timeout too. | ||
| 215 | { | 231 | { |
| 216 | constexpr VkDeviceSize kBig = 16u << 20; | 232 | constexpr VkDeviceSize kBig = 16u << 20; |
| 217 | constexpr std::uint32_t kSubmits = 4 * VulkanQueue::kMaxQueuedCommandBuffers; | 233 | constexpr std::uint32_t kSubmits = 4 * VulkanQueue::kMaxQueuedCommandBuffers; |
| @@ -228,14 +244,18 @@ int main() { | |||
| 228 | const CommandList* big_lists[] = {&big_copy}; | 244 | const CommandList* big_lists[] = {&big_copy}; |
| 229 | 245 | ||
| 230 | real_allocate_command_buffers = context.vk.vkAllocateCommandBuffers; | 246 | real_allocate_command_buffers = context.vk.vkAllocateCommandBuffers; |
| 247 | real_wait_semaphores = context.vk.vkWaitSemaphores; | ||
| 231 | context.vk.vkAllocateCommandBuffers = counting_allocate_command_buffers; | 248 | context.vk.vkAllocateCommandBuffers = counting_allocate_command_buffers; |
| 249 | context.vk.vkWaitSemaphores = stalling_wait_semaphores; | ||
| 232 | allocated_command_buffers = 0; | 250 | allocated_command_buffers = 0; |
| 233 | for (std::uint32_t i = 0; i < kSubmits; ++i) EXPECT(direct.execute(big_lists) == ReplayResult::success); | 251 | for (std::uint32_t i = 0; i < kSubmits; ++i) EXPECT(direct.execute(big_lists) == ReplayResult::success); |
| 234 | context.vk.vkAllocateCommandBuffers = real_allocate_command_buffers; | 252 | context.vk.vkAllocateCommandBuffers = real_allocate_command_buffers; |
| 253 | context.vk.vkWaitSemaphores = real_wait_semaphores; | ||
| 235 | EXPECT(direct.signal(fence.semaphore(), 5)); | 254 | EXPECT(direct.signal(fence.semaphore(), 5)); |
| 236 | EXPECT(fence.wait(5, 20'000'000'000ull)); | 255 | 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, | 256 | std::printf("backlog: %u submits, %u command buffers allocated (cap %zu), %u waits timed out\n", kSubmits, |
| 238 | VulkanQueue::kMaxQueuedCommandBuffers); | 257 | allocated_command_buffers, VulkanQueue::kMaxQueuedCommandBuffers, injected_stalls.load()); |
| 258 | EXPECT(injected_stalls.load() == kStalls); // the queue did reach the cap and wait | ||
| 239 | EXPECT(allocated_command_buffers <= VulkanQueue::kMaxQueuedCommandBuffers); | 259 | EXPECT(allocated_command_buffers <= VulkanQueue::kMaxQueuedCommandBuffers); |
| 240 | EXPECT(static_cast<std::uint8_t*>(dst_map)[kBig - 1] == 0x5A); | 260 | EXPECT(static_cast<std::uint8_t*>(dst_map)[kBig - 1] == 0x5A); |
| 241 | } | 261 | } |