| 371 | } |
| 372 | |
| 373 | VkResult MainTest(Result& outResult, const Config& config) |
| 374 | { |
| 375 | assert(config.ThreadCount > 0); |
| 376 | |
| 377 | InitResult(outResult); |
| 378 | |
| 379 | RandomNumberGenerator mainRand{config.RandSeed}; |
| 380 | |
| 381 | time_point timeBeg = std::chrono::high_resolution_clock::now(); |
| 382 | |
| 383 | std::atomic<size_t> allocationCount{ 0 }; |
| 384 | VkResult res = VK_SUCCESS; |
| 385 | |
| 386 | uint32_t memUsageProbabilitySum = |
| 387 | config.MemUsageProbability[0] + config.MemUsageProbability[1] + |
| 388 | config.MemUsageProbability[2] + config.MemUsageProbability[3]; |
| 389 | assert(memUsageProbabilitySum > 0); |
| 390 | |
| 391 | uint32_t allocationSizeProbabilitySum = std::accumulate( |
| 392 | config.AllocationSizes.begin(), |
| 393 | config.AllocationSizes.end(), |
| 394 | 0u, |
| 395 | [](uint32_t sum, const AllocationSize& allocSize) { |
| 396 | return sum + allocSize.Probability; |
| 397 | }); |
| 398 | |
| 399 | struct Allocation |
| 400 | { |
| 401 | VkBuffer Buffer; |
| 402 | VkImage Image; |
| 403 | VmaAllocation Alloc; |
| 404 | }; |
| 405 | |
| 406 | std::vector<Allocation> commonAllocations; |
| 407 | std::mutex commonAllocationsMutex; |
| 408 | |
| 409 | auto Allocate = [&]( |
| 410 | VkDeviceSize bufferSize, |
| 411 | const VkExtent2D imageExtent, |
| 412 | RandomNumberGenerator& localRand, |
| 413 | VkDeviceSize& totalAllocatedBytes, |
| 414 | std::vector<Allocation>& allocations) -> VkResult |
| 415 | { |
| 416 | assert((bufferSize == 0) != (imageExtent.width == 0 && imageExtent.height == 0)); |
| 417 | |
| 418 | uint32_t memUsageIndex = 0; |
| 419 | uint32_t memUsageRand = localRand.Generate() % memUsageProbabilitySum; |
| 420 | while(memUsageRand >= config.MemUsageProbability[memUsageIndex]) |
| 421 | memUsageRand -= config.MemUsageProbability[memUsageIndex++]; |
| 422 | |
| 423 | VmaAllocationCreateInfo memReq = {}; |
| 424 | memReq.usage = (VmaMemoryUsage)(VMA_MEMORY_USAGE_GPU_ONLY + memUsageIndex); |
| 425 | memReq.flags |= config.AllocationStrategy; |
| 426 | |
| 427 | Allocation allocation = {}; |
| 428 | VmaAllocationInfo allocationInfo; |
| 429 | |
| 430 | // Buffer |
no test coverage detected