| 1272 | } |
| 1273 | |
| 1274 | static void CreateAllocation(AllocInfo& outAllocation) |
| 1275 | { |
| 1276 | outAllocation.m_Allocation = nullptr; |
| 1277 | outAllocation.m_Buffer = nullptr; |
| 1278 | outAllocation.m_Image = nullptr; |
| 1279 | outAllocation.m_StartValue = (uint32_t)rand(); |
| 1280 | |
| 1281 | VmaAllocationCreateInfo vmaMemReq; |
| 1282 | GetMemReq(vmaMemReq); |
| 1283 | |
| 1284 | VmaAllocationInfo allocInfo; |
| 1285 | |
| 1286 | const bool isBuffer = true;//(rand() & 0x1) != 0; |
| 1287 | const bool isLarge = (rand() % 16) == 0; |
| 1288 | if(isBuffer) |
| 1289 | { |
| 1290 | const uint32_t bufferSize = isLarge ? |
| 1291 | (rand() % 10 + 1) * (1024 * 1024) : // 1 MB ... 10 MB |
| 1292 | (rand() % 1024 + 1) * 1024; // 1 KB ... 1 MB |
| 1293 | |
| 1294 | VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 1295 | bufferInfo.size = bufferSize; |
| 1296 | bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; |
| 1297 | |
| 1298 | VkResult res = vmaCreateBuffer(g_hAllocator, &bufferInfo, &vmaMemReq, &outAllocation.m_Buffer, &outAllocation.m_Allocation, &allocInfo); |
| 1299 | outAllocation.m_BufferInfo = bufferInfo; |
| 1300 | TEST(res == VK_SUCCESS); |
| 1301 | } |
| 1302 | else |
| 1303 | { |
| 1304 | const uint32_t imageSizeX = isLarge ? |
| 1305 | 1024 + rand() % (4096 - 1024) : // 1024 ... 4096 |
| 1306 | rand() % 1024 + 1; // 1 ... 1024 |
| 1307 | const uint32_t imageSizeY = isLarge ? |
| 1308 | 1024 + rand() % (4096 - 1024) : // 1024 ... 4096 |
| 1309 | rand() % 1024 + 1; // 1 ... 1024 |
| 1310 | |
| 1311 | VkImageCreateInfo imageInfo = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO }; |
| 1312 | imageInfo.imageType = VK_IMAGE_TYPE_2D; |
| 1313 | imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM; |
| 1314 | imageInfo.extent.width = imageSizeX; |
| 1315 | imageInfo.extent.height = imageSizeY; |
| 1316 | imageInfo.extent.depth = 1; |
| 1317 | imageInfo.mipLevels = 1; |
| 1318 | imageInfo.arrayLayers = 1; |
| 1319 | imageInfo.samples = VK_SAMPLE_COUNT_1_BIT; |
| 1320 | imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; |
| 1321 | imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED; |
| 1322 | imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 1323 | |
| 1324 | VkResult res = vmaCreateImage(g_hAllocator, &imageInfo, &vmaMemReq, &outAllocation.m_Image, &outAllocation.m_Allocation, &allocInfo); |
| 1325 | outAllocation.m_ImageInfo = imageInfo; |
| 1326 | TEST(res == VK_SUCCESS); |
| 1327 | } |
| 1328 | |
| 1329 | uint32_t* data = (uint32_t*)allocInfo.pMappedData; |
| 1330 | if(allocInfo.pMappedData == nullptr) |
| 1331 | { |
no test coverage detected