MCPcopy Create free account
hub / github.com/SFML/SFML / setupDepthImage

Method setupDepthImage

examples/vulkan/Vulkan.cpp:1654–1759  ·  view source on GitHub ↗

Create our depth image and transition it into the proper layout

Source from the content-addressed store, hash-verified

1652
1653 // Create our depth image and transition it into the proper layout
1654 void setupDepthImage()
1655 {
1656 // Create our depth image
1657 if (!createImage(swapchainExtent.width,
1658 swapchainExtent.height,
1659 depthFormat,
1660 VK_IMAGE_TILING_OPTIMAL,
1661 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
1662 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1663 depthImage,
1664 depthImageMemory))
1665 {
1666 vulkanAvailable = false;
1667 return;
1668 }
1669
1670 // Allocate a command buffer
1671 VkCommandBufferAllocateInfo commandBufferAllocateInfo = VkCommandBufferAllocateInfo();
1672 commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
1673 commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
1674 commandBufferAllocateInfo.commandPool = commandPool;
1675 commandBufferAllocateInfo.commandBufferCount = 1;
1676
1677 VkCommandBuffer commandBuffer = nullptr;
1678
1679 if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
1680 {
1681 vulkanAvailable = false;
1682 return;
1683 }
1684
1685 // Begin the command buffer
1686 VkCommandBufferBeginInfo commandBufferBeginInfo = VkCommandBufferBeginInfo();
1687 commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
1688 commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1689
1690 VkSubmitInfo submitInfo = VkSubmitInfo();
1691 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1692 submitInfo.commandBufferCount = 1;
1693 submitInfo.pCommandBuffers = &commandBuffer;
1694
1695 if (vkBeginCommandBuffer(commandBuffer, &commandBufferBeginInfo) != VK_SUCCESS)
1696 {
1697 vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer);
1698
1699 vulkanAvailable = false;
1700 return;
1701 }
1702
1703 // Submit a barrier to transition the image layout to depth stencil optimal
1704 VkImageMemoryBarrier barrier = VkImageMemoryBarrier();
1705 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
1706 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1707 barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
1708 barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1709 barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
1710 barrier.image = depthImage;
1711 barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT |

Callers

nothing calls this directly

Calls 4

VkSubmitInfoClass · 0.70

Tested by

no test coverage detected