Vulkan-Hpp
04_InitCommandBuffer.cpp
Go to the documentation of this file.
1 // Copyright(c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // VulkanHpp Samples : 04_InitCommandBuffer
16 // Create command buffer
17 
18 #include "../utils/utils.hpp"
19 
20 #include <iostream>
21 
22 static char const * AppName = "04_InitCommandBuffer";
23 static char const * EngineName = "Vulkan.hpp";
24 
25 int main( int /*argc*/, char ** /*argv*/ )
26 {
27  try
28  {
29  vk::Instance instance = vk::su::createInstance( AppName, EngineName );
30 #if !defined( NDEBUG )
32 #endif
33 
34  vk::PhysicalDevice physicalDevice = instance.enumeratePhysicalDevices().front();
35 
36  uint32_t graphicsQueueFamilyIndex = vk::su::findGraphicsQueueFamilyIndex( physicalDevice.getQueueFamilyProperties() );
37  vk::Device device = vk::su::createDevice( physicalDevice, graphicsQueueFamilyIndex );
38 
39  /* VULKAN_HPP_KEY_START */
40 
41  // create a CommandPool to allocate a CommandBuffer from
42  vk::CommandPool commandPool = device.createCommandPool( vk::CommandPoolCreateInfo( vk::CommandPoolCreateFlags(), graphicsQueueFamilyIndex ) );
43 
44  // allocate a CommandBuffer from the CommandPool
45  vk::CommandBuffer commandBuffer =
47 
48  // freeing the commandBuffer is optional, as it will automatically freed when the corresponding CommandPool is
49  // destroyed.
50  device.freeCommandBuffers( commandPool, commandBuffer );
51 
52  // destroy the commandPool
53  device.destroyCommandPool( commandPool );
54 
55  /* VULKAN_HPP_KEY_END */
56 
57  device.destroy();
58 #if !defined( NDEBUG )
59  instance.destroyDebugUtilsMessengerEXT( debugUtilsMessenger );
60 #endif
61  instance.destroy();
62  }
63  catch ( vk::SystemError & err )
64  {
65  std::cout << "vk::SystemError: " << err.what() << std::endl;
66  exit( -1 );
67  }
68  catch ( std::exception & err )
69  {
70  std::cout << "std::exception: " << err.what() << std::endl;
71  exit( -1 );
72  }
73  catch ( ... )
74  {
75  std::cout << "unknown error\n";
76  exit( -1 );
77  }
78  return 0;
79 }
int main(int, char **)
void cout(vk::SurfaceCapabilitiesKHR const &surfaceCapabilities)
void destroy(const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void freeCommandBuffers(vk::CommandPool commandPool, uint32_t commandBufferCount, const vk::CommandBuffer *pCommandBuffers, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroyCommandPool(vk::CommandPool commandPool, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result createCommandPool(const vk::CommandPoolCreateInfo *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::CommandPool *pCommandPool, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result allocateCommandBuffers(const vk::CommandBufferAllocateInfo *pAllocateInfo, vk::CommandBuffer *pCommandBuffers, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result createDebugUtilsMessengerEXT(const vk::DebugUtilsMessengerCreateInfoEXT *pCreateInfo, const vk::AllocationCallbacks *pAllocator, vk::DebugUtilsMessengerEXT *pMessenger, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroy(const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
VULKAN_HPP_NODISCARD Result enumeratePhysicalDevices(uint32_t *pPhysicalDeviceCount, vk::PhysicalDevice *pPhysicalDevices, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void destroyDebugUtilsMessengerEXT(vk::DebugUtilsMessengerEXT messenger, const vk::AllocationCallbacks *pAllocator, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
void getQueueFamilyProperties(uint32_t *pQueueFamilyPropertyCount, vk::QueueFamilyProperties *pQueueFamilyProperties, Dispatch const &d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT) const VULKAN_HPP_NOEXCEPT
virtual const char * what() const VULKAN_HPP_NOEXCEPT
Definition: vulkan.hpp:6206
uint32_t findGraphicsQueueFamilyIndex(std::vector< vk::QueueFamilyProperties > const &queueFamilyProperties)
Definition: utils.cpp:409
vk::DebugUtilsMessengerCreateInfoEXT makeDebugUtilsMessengerCreateInfoEXT()
Definition: utils.cpp:1025
vk::Instance createInstance(std::string const &appName, std::string const &engineName, std::vector< std::string > const &layers, std::vector< std::string > const &extensions, uint32_t apiVersion)
Definition: utils.cpp:279
vk::Device createDevice(vk::PhysicalDevice const &physicalDevice, uint32_t queueFamilyIndex, std::vector< std::string > const &extensions, vk::PhysicalDeviceFeatures const *physicalDeviceFeatures, void const *pNext)
Definition: utils.cpp:86