| 27 | static char const * EngineName = "Vulkan.hpp"; |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | try |
| 32 | { |
| 33 | vk::raii::Context context; |
| 34 | vk::raii::Instance instance = vk::raii::su::makeInstance( context, AppName, EngineName, {}, vk::su::getInstanceExtensions() ); |
| 35 | #if !defined( NDEBUG ) |
| 36 | vk::raii::DebugUtilsMessengerEXT debugUtilsMessenger( instance, vk::su::makeDebugUtilsMessengerCreateInfoEXT() ); |
| 37 | #endif |
| 38 | vk::raii::PhysicalDevice physicalDevice = vk::raii::PhysicalDevices( instance ).front(); |
| 39 | |
| 40 | vk::raii::su::SurfaceData surfaceData( instance, AppName, vk::Extent2D( 50, 50 ) ); |
| 41 | |
| 42 | std::pair<uint32_t, uint32_t> graphicsAndPresentQueueFamilyIndex = |
| 43 | vk::raii::su::findGraphicsAndPresentQueueFamilyIndex( physicalDevice, surfaceData.surface ); |
| 44 | vk::raii::Device device = vk::raii::su::makeDevice( physicalDevice, graphicsAndPresentQueueFamilyIndex.first, vk::su::getDeviceExtensions() ); |
| 45 | |
| 46 | vk::raii::CommandPool commandPool = vk::raii::CommandPool( device, { {}, graphicsAndPresentQueueFamilyIndex.first } ); |
| 47 | vk::raii::CommandBuffer commandBuffer = vk::raii::su::makeCommandBuffer( device, commandPool ); |
| 48 | |
| 49 | vk::raii::Queue graphicsQueue( device, graphicsAndPresentQueueFamilyIndex.first, 0 ); |
| 50 | vk::raii::Queue presentQueue( device, graphicsAndPresentQueueFamilyIndex.second, 0 ); |
| 51 | |
| 52 | /* VULKAN_KEY_START */ |
| 53 | |
| 54 | vk::Format format = vk::Format::eR8G8B8A8Unorm; |
| 55 | vk::FormatProperties formatProperties = physicalDevice.getFormatProperties( format ); |
| 56 | |
| 57 | // See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data |
| 58 | bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage ); |
| 59 | |
| 60 | // in order to get a clean desctruction sequence, instantiate the DeviceMemory for the image first |
| 61 | vk::raii::DeviceMemory imageMemory( nullptr ); |
| 62 | |
| 63 | vk::ImageCreateInfo imageCreateInfo( {}, |
| 64 | vk::ImageType::e2D, |
| 65 | format, |
| 66 | vk::Extent3D( surfaceData.extent, 1 ), |
| 67 | 1, |
| 68 | 1, |
| 69 | vk::SampleCountFlagBits::e1, |
| 70 | needsStaging ? vk::ImageTiling::eOptimal : vk::ImageTiling::eLinear, |
| 71 | vk::ImageUsageFlagBits::eSampled | ( needsStaging ? vk::ImageUsageFlagBits::eTransferDst : vk::ImageUsageFlagBits() ), |
| 72 | vk::SharingMode::eExclusive, |
| 73 | {}, |
| 74 | needsStaging ? vk::ImageLayout::eUndefined : vk::ImageLayout::ePreinitialized ); |
| 75 | vk::raii::Image image( device, imageCreateInfo ); |
| 76 | |
| 77 | vk::MemoryRequirements memoryRequirements = image.getMemoryRequirements(); |
| 78 | uint32_t memoryTypeIndex = vk::su::findMemoryType( |
| 79 | physicalDevice.getMemoryProperties(), |
| 80 | memoryRequirements.memoryTypeBits, |
| 81 | needsStaging ? vk::MemoryPropertyFlags() : ( vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ) ); |
| 82 | |
| 83 | // allocate memory |
| 84 | vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex ); |
| 85 | imageMemory = vk::raii::DeviceMemory( device, memoryAllocateInfo ); |
| 86 |
nothing calls this directly
no test coverage detected