MCPcopy Create free account
hub / github.com/PacktPublishing/3D-Graphics-Rendering-Cookbook / createImage

Function createImage

shared/UtilsVulkan.cpp:1350–1385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1348}
1349
1350bool createImage(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory, VkImageCreateFlags flags, uint32_t mipLevels) {
1351 const VkImageCreateInfo imageInfo = {
1352 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1353 .pNext = nullptr,
1354 .flags = flags,
1355 .imageType = VK_IMAGE_TYPE_2D,
1356 .format = format,
1357 .extent = VkExtent3D {.width = width, .height = height, .depth = 1 },
1358 .mipLevels = mipLevels,
1359 .arrayLayers = (uint32_t)((flags == VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ? 6 : 1),
1360 .samples = VK_SAMPLE_COUNT_1_BIT,
1361 .tiling = tiling,
1362 .usage = usage,
1363 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
1364 .queueFamilyIndexCount = 0,
1365 .pQueueFamilyIndices = nullptr,
1366 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED
1367 };
1368
1369 VK_CHECK(vkCreateImage(device, &imageInfo, nullptr, &image));
1370
1371 VkMemoryRequirements memRequirements;
1372 vkGetImageMemoryRequirements(device, image, &memRequirements);
1373
1374 const VkMemoryAllocateInfo allocInfo = {
1375 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
1376 .pNext = nullptr,
1377 .allocationSize = memRequirements.size,
1378 .memoryTypeIndex = findMemoryType(physicalDevice, memRequirements.memoryTypeBits, properties)
1379 };
1380
1381 VK_CHECK(vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory));
1382
1383 vkBindImageMemory(device, image, imageMemory, 0);
1384 return true;
1385}
1386
1387bool createVolume(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t width, uint32_t height, uint32_t depth,
1388 VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory, VkImageCreateFlags flags) {

Callers 6

createDepthResourcesFunction · 0.85
createOffscreenImageFunction · 0.85
addDepthTextureMethod · 0.85
createComputedTextureMethod · 0.85

Calls 1

findMemoryTypeFunction · 0.85

Tested by

no test coverage detected