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

Function createVolume

shared/UtilsVulkan.cpp:1387–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {
1389 const VkImageCreateInfo imageInfo = {
1390 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1391 .pNext = nullptr,
1392 .flags = flags,
1393 .imageType = VK_IMAGE_TYPE_3D,
1394 .format = format,
1395 .extent = VkExtent3D {.width = width, .height = height, .depth = depth },
1396 .mipLevels = 1,
1397 .arrayLayers = 1,
1398 .samples = VK_SAMPLE_COUNT_1_BIT,
1399 .tiling = tiling,
1400 .usage = usage,
1401 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
1402 .queueFamilyIndexCount = 0,
1403 .pQueueFamilyIndices = nullptr,
1404 .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED
1405 };
1406
1407 VK_CHECK(vkCreateImage(device, &imageInfo, nullptr, &image));
1408
1409 VkMemoryRequirements memRequirements;
1410 vkGetImageMemoryRequirements(device, image, &memRequirements);
1411
1412 const VkMemoryAllocateInfo allocInfo = {
1413 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
1414 .pNext = nullptr,
1415 .allocationSize = memRequirements.size,
1416 .memoryTypeIndex = findMemoryType(physicalDevice, memRequirements.memoryTypeBits, properties)
1417 };
1418
1419 VK_CHECK(vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory));
1420
1421 vkBindImageMemory(device, image, imageMemory, 0);
1422 return true;
1423}
1424
1425// For volumes use the call
1426// createImageView(device, image, /* whatever the format is */ VK_FORMAT_R32G32B32A32_SFLOAT, VK_IMAGE_ASPECT_COLOR_BIT, VkImageView* imageView, VK_IMAGE_VIEW_TYPE_3D, 1)

Callers 1

Calls 1

findMemoryTypeFunction · 0.85

Tested by

no test coverage detected