From d34da4e8e0a10ce513d6799986fb01fa2d188d21 Mon Sep 17 00:00:00 2001 From: plapins Date: Wed, 13 Apr 2016 08:59:52 +0200 Subject: [PATCH] Changed all printf() functions to std::cout. Added information about available swap chain image usages. Cleaned included header files. --- Project/Common/OperatingSystem.h | 5 +- Project/Common/Tools.cpp | 38 +++++---- Project/Common/Tools.h | 1 - Project/Common/VulkanCommon.cpp | 124 +++++++++++++++------------ Project/Tutorial01/Tutorial01.cpp | 50 +++++------ Project/Tutorial02/Tutorial02.cpp | 134 +++++++++++++++++------------- Project/Tutorial03/Tutorial03.cpp | 22 ++--- Project/Tutorial04/Tutorial04.cpp | 50 +++++------ 8 files changed, 230 insertions(+), 194 deletions(-) diff --git a/Project/Common/OperatingSystem.h b/Project/Common/OperatingSystem.h index 9b4cab9..e870eba 100644 --- a/Project/Common/OperatingSystem.h +++ b/Project/Common/OperatingSystem.h @@ -18,18 +18,17 @@ #include #include #include -#include #elif defined(VK_USE_PLATFORM_XLIB_KHR) #include #include #include #include -#include #endif -#include +#include +#include namespace OS { diff --git a/Project/Common/Tools.cpp b/Project/Common/Tools.cpp index 47d33a4..43a3b63 100644 --- a/Project/Common/Tools.cpp +++ b/Project/Common/Tools.cpp @@ -8,29 +8,31 @@ // Intel does not assume any responsibility for any errors which may appear in this software // nor any responsibility to update it. +#include +#include #include "Tools.h" namespace Tools { - std::vector GetBinaryFileContents( std::string const &filename ) { + std::vector GetBinaryFileContents( std::string const &filename ) { - std::ifstream file( filename, std::ios::binary ); - if( file.fail() ) { - printf( "Could not open \"%s\" file!\n", filename.c_str() ); - return std::vector(); - } - - std::streampos begin, end; - begin = file.tellg(); - file.seekg( 0, std::ios::end ); - end = file.tellg(); - - std::vector result( static_cast(end - begin) ); - file.seekg( 0, std::ios::beg ); - file.read( &result[0], end - begin ); - file.close(); - - return result; + std::ifstream file( filename, std::ios::binary ); + if( file.fail() ) { + std::cout << "Could not open \"" << filename << "\" file!" << std::endl; + return std::vector(); } + std::streampos begin, end; + begin = file.tellg(); + file.seekg( 0, std::ios::end ); + end = file.tellg(); + + std::vector result( static_cast(end - begin) ); + file.seekg( 0, std::ios::beg ); + file.read( &result[0], end - begin ); + file.close(); + + return result; + } + } \ No newline at end of file diff --git a/Project/Common/Tools.h b/Project/Common/Tools.h index 95acd8a..3ebe1e6 100644 --- a/Project/Common/Tools.h +++ b/Project/Common/Tools.h @@ -13,7 +13,6 @@ #include #include -#include #include "vulkan.h" namespace Tools { diff --git a/Project/Common/VulkanCommon.cpp b/Project/Common/VulkanCommon.cpp index fb4e38d..c6d276b 100644 --- a/Project/Common/VulkanCommon.cpp +++ b/Project/Common/VulkanCommon.cpp @@ -8,7 +8,6 @@ // Intel does not assume any responsibility for any errors which may appear in this software // nor any responsibility to update it. -#include #include "VulkanCommon.h" #include "VulkanFunctions.h" @@ -104,7 +103,7 @@ namespace Tutorial { #endif if( VulkanLibrary == nullptr ) { - printf( "Could not load Vulkan library!\n" ); + std::cout << "Could not load Vulkan library!" << std::endl; return false; } return true; @@ -117,10 +116,10 @@ namespace Tutorial { #define LoadProcAddress dlsym #endif -#define VK_EXPORTED_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ - printf( "Could not load exported function: " #fun "!\n" ); \ - return false; \ +#define VK_EXPORTED_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ + std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -129,10 +128,10 @@ namespace Tutorial { } bool VulkanCommon::LoadGlobalLevelEntryPoints() { -#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ - printf( "Could not load global level function: " #fun "!\n" ); \ - return false; \ +#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ + std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -144,13 +143,13 @@ namespace Tutorial { uint32_t extensions_count = 0; if( (vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, nullptr ) != VK_SUCCESS) || (extensions_count == 0) ) { - printf( "Error occurred during instance extensions enumeration!\n" ); + std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } std::vector available_extensions( extensions_count ); if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { - printf( "Error occurred during instance extensions enumeration!\n" ); + std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } @@ -167,7 +166,7 @@ namespace Tutorial { for( size_t i = 0; i < extensions.size(); ++i ) { if( !CheckExtensionAvailability( extensions[i], available_extensions ) ) { - printf( "Could not find instance extension named \"%s\"!\n", extensions[i] ); + std::cout << "Could not find instance extension named \"" << extensions[i] << "\"!" << std::endl; return false; } } @@ -194,17 +193,17 @@ namespace Tutorial { }; if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) { - printf( "Could not create Vulkan instance!\n" ); + std::cout << "Could not create Vulkan instance!" << std::endl; return false; } return true; } bool VulkanCommon::LoadInstanceLevelEntryPoints() { -#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ - printf( "Could not load instance level function: " #fun "\n" ); \ - return false; \ +#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ + std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -253,7 +252,7 @@ namespace Tutorial { #endif - printf( "Could not create presentation surface!\n" ); + std::cout << "Could not create presentation surface!" << std::endl; return false; } @@ -261,13 +260,13 @@ namespace Tutorial { uint32_t num_devices = 0; if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) || (num_devices == 0) ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } std::vector physical_devices( num_devices ); if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -280,7 +279,7 @@ namespace Tutorial { } } if( Vulkan.PhysicalDevice == VK_NULL_HANDLE ) { - printf( "Could not select physical device based on the chosen properties!\n" ); + std::cout << "Could not select physical device based on the chosen properties!" << std::endl; return false; } @@ -288,12 +287,12 @@ namespace Tutorial { std::vector queue_priorities = { 1.0f }; queue_create_infos.push_back( { - VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType - nullptr, // const void *pNext - 0, // VkDeviceQueueCreateFlags flags - selected_graphics_queue_family_index, // uint32_t queueFamilyIndex - static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType + nullptr, // const void *pNext + 0, // VkDeviceQueueCreateFlags flags + selected_graphics_queue_family_index, // uint32_t queueFamilyIndex + static_cast(queue_priorities.size()), // uint32_t queueCount + &queue_priorities[0] // const float *pQueuePriorities } ); if( selected_graphics_queue_family_index != selected_present_queue_family_index ) { @@ -325,7 +324,7 @@ namespace Tutorial { }; if( vkCreateDevice( Vulkan.PhysicalDevice, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) { - printf( "Could not create Vulkan device!\n" ); + std::cout << "Could not create Vulkan device!" << std::endl; return false; } @@ -338,13 +337,13 @@ namespace Tutorial { uint32_t extensions_count = 0; if( (vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, nullptr ) != VK_SUCCESS) || (extensions_count == 0) ) { - printf( "Error occurred during physical device %p extensions enumeration!\n", physical_device ); + std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } std::vector available_extensions( extensions_count ); if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { - printf( "Error occurred during physical device %p extensions enumeration!\n", physical_device ); + std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } @@ -354,7 +353,7 @@ namespace Tutorial { for( size_t i = 0; i < device_extensions.size(); ++i ) { if( !CheckExtensionAvailability( device_extensions[i], available_extensions ) ) { - printf( "Physical device %p doesn't support extension named \"%s\"!\n", physical_device, device_extensions[i] ); + std::cout << "Physical device " << physical_device << " doesn't support extension named \"" << device_extensions[i] << "\"!" << std::endl; return false; } } @@ -369,14 +368,14 @@ namespace Tutorial { if( (major_version < 1) && (device_properties.limits.maxImageDimension2D < 4096) ) { - printf( "Physical device %p doesn't support required parameters!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl; return false; } uint32_t queue_families_count = 0; vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr ); if( queue_families_count == 0 ) { - printf( "Physical device %p doesn't have any queue families!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl; return false; } @@ -418,7 +417,7 @@ namespace Tutorial { // If this device doesn't support queues with graphics and present capabilities don't use it if( (graphics_queue_family_index == UINT32_MAX) || (present_queue_family_index == UINT32_MAX) ) { - printf( "Could not find queue families with required properties on physical device %p!\n", physical_device ); + std::cout << "Could not find queue families with required properties on physical device " << physical_device << "!" << std::endl; return false; } @@ -428,10 +427,10 @@ namespace Tutorial { } bool VulkanCommon::LoadDeviceLevelEntryPoints() { -#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ - printf( "Could not load device level function: " #fun "!\n" ); \ - return false; \ +#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ + std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -452,33 +451,33 @@ namespace Tutorial { VkSurfaceCapabilitiesKHR surface_capabilities; if( vkGetPhysicalDeviceSurfaceCapabilitiesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &surface_capabilities ) != VK_SUCCESS ) { - printf( "Could not check presentation surface capabilities!\n" ); + std::cout << "Could not check presentation surface capabilities!" << std::endl; return false; } uint32_t formats_count; if( (vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, nullptr ) != VK_SUCCESS) || (formats_count == 0) ) { - printf( "Error occurred during presentation surface formats enumeration!\n" ); + std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } std::vector surface_formats( formats_count ); if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, &surface_formats[0] ) != VK_SUCCESS ) { - printf( "Error occurred during presentation surface formats enumeration!\n" ); + std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } uint32_t present_modes_count; if( (vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, nullptr ) != VK_SUCCESS) || (present_modes_count == 0) ) { - printf( "Error occurred during presentation surface present modes enumeration!\n" ); + std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } std::vector present_modes( present_modes_count ); if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, &present_modes[0] ) != VK_SUCCESS ) { - printf( "Error occurred during presentation surface present modes enumeration!\n" ); + std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } @@ -490,8 +489,10 @@ namespace Tutorial { VkPresentModeKHR desired_present_mode = GetSwapChainPresentMode( present_modes ); VkSwapchainKHR old_swap_chain = Vulkan.SwapChain.Handle; - if( static_cast(desired_usage) == 0 ) { - printf( "TRANSFER_DST image usage is not supported by the swap chain!" ); + if( static_cast(desired_usage) == -1 ) { + return false; + } + if( static_cast(desired_present_mode) == -1 ) { return false; } @@ -517,7 +518,7 @@ namespace Tutorial { }; if( vkCreateSwapchainKHR( Vulkan.Device, &swap_chain_create_info, nullptr, &Vulkan.SwapChain.Handle ) != VK_SUCCESS ) { - printf( "Could not create swap chain!\n" ); + std::cout << "Could not create swap chain!" << std::endl; return false; } if( old_swap_chain != VK_NULL_HANDLE ) { @@ -529,12 +530,12 @@ namespace Tutorial { uint32_t image_count = 0; if( (vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, nullptr ) != VK_SUCCESS) || (image_count == 0) ) { - printf( "Could not get swap chain images!\n" ); + std::cout << "Could not get swap chain images!" << std::endl; return false; } Vulkan.SwapChain.Images.resize( image_count ); if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, &Vulkan.SwapChain.Images[0] ) != VK_SUCCESS ) { - printf( "Could not get swap chain images!\n" ); + std::cout << "Could not get swap chain images!" << std::endl; return false; } @@ -550,7 +551,7 @@ namespace Tutorial { if( (vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.ImageAvailableSemaphore ) != VK_SUCCESS) || (vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.RenderingFinishedSemaphore ) != VK_SUCCESS) ) { - printf( "Could not create semaphores!\n" ); + std::cout << "Could not create semaphores!" << std::endl; return false; } @@ -628,7 +629,18 @@ namespace Tutorial { if( surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT ) { return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; } - return 0; + std::cout << "VK_IMAGE_USAGE_TRANSFER_DST image usage is not supported by the swap chain!" << std::endl + << "Supported swap chain's image usages include:" << std::endl + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT ? " VK_IMAGE_USAGE_TRANSFER_SRC\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT ? " VK_IMAGE_USAGE_TRANSFER_DST\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT ? " VK_IMAGE_USAGE_SAMPLED\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT ? " VK_IMAGE_USAGE_STORAGE\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_COLOR_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_INPUT_ATTACHMENT" : "") + << std::endl; + return static_cast(-1); } VkSurfaceTransformFlagBitsKHR VulkanCommon::GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities ) { @@ -636,7 +648,7 @@ namespace Tutorial { // being other than default orientation) // If the specified transform is other than current transform, presentation engine will transform image // during presentation operation; this operation may hit performance on some platforms - // Here we don't want any transformations to occur so if no transform is supported use it + // Here we don't want any transformations to occur so if the identity transform is supported use it // otherwise just use the same transform as current transform if( surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR ) { return VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; @@ -653,7 +665,13 @@ namespace Tutorial { return present_mode; } } - return VK_PRESENT_MODE_FIFO_KHR; + for( VkPresentModeKHR &present_mode : present_modes ) { + if( present_mode == VK_PRESENT_MODE_FIFO_KHR ) { + return present_mode; + } + } + std::cout << "FIFO present mode is not supported by the swap chain!" << std::endl; + return static_cast(-1); } VulkanCommon::~VulkanCommon() { diff --git a/Project/Tutorial01/Tutorial01.cpp b/Project/Tutorial01/Tutorial01.cpp index d5d040a..2a456e7 100644 --- a/Project/Tutorial01/Tutorial01.cpp +++ b/Project/Tutorial01/Tutorial01.cpp @@ -63,7 +63,7 @@ namespace Tutorial { #endif if( VulkanLibrary == nullptr ) { - printf( "Could not load Vulkan library!\n" ); + std::cout << "Could not load Vulkan library!" << std::endl; return false; } return true; @@ -76,10 +76,10 @@ namespace Tutorial { #define LoadProcAddress dlsym #endif -#define VK_EXPORTED_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ - printf( "Could not load exported function: " #fun "!\n" ); \ - return false; \ +#define VK_EXPORTED_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ + std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -88,10 +88,10 @@ namespace Tutorial { } bool Tutorial01::LoadGlobalLevelEntryPoints() { -#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ - printf( "Could not load global level function: " #fun "!\n" ); \ - return false; \ +#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ + std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -122,17 +122,17 @@ namespace Tutorial { }; if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) { - printf( "Could not create Vulkan instance!\n" ); + std::cout << "Could not create Vulkan instance!" << std::endl; return false; } return true; } bool Tutorial01::LoadInstanceLevelEntryPoints() { -#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ - printf( "Could not load instance level function: " #fun "\n" ); \ - return false; \ +#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ + std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -144,13 +144,13 @@ namespace Tutorial { uint32_t num_devices = 0; if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) || (num_devices == 0) ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } std::vector physical_devices( num_devices ); if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -162,7 +162,7 @@ namespace Tutorial { } } if( selected_physical_device == VK_NULL_HANDLE ) { - printf( "Could not select physical device based on the chosen properties!\n" ); + std::cout << "Could not select physical device based on the chosen properties!" << std::endl; return false; } @@ -191,7 +191,7 @@ namespace Tutorial { }; if( vkCreateDevice( selected_physical_device, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) { - printf( "Could not create Vulkan device!\n" ); + std::cout << "Could not create Vulkan device!" << std::endl; return false; } @@ -212,14 +212,14 @@ namespace Tutorial { if( (major_version < 1) && (device_properties.limits.maxImageDimension2D < 4096) ) { - printf( "Physical device %p doesn't support required parameters!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl; return false; } uint32_t queue_families_count = 0; vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr ); if( queue_families_count == 0 ) { - printf( "Physical device %p doesn't have any queue families!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl; return false; } @@ -233,15 +233,15 @@ namespace Tutorial { } } - printf( "Could not find queue family with required properties on physical device %p!\n", physical_device ); + std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl; return false; } bool Tutorial01::LoadDeviceLevelEntryPoints() { -#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ - printf( "Could not load device level function: " #fun "!\n" ); \ - return false; \ +#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ + std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" diff --git a/Project/Tutorial02/Tutorial02.cpp b/Project/Tutorial02/Tutorial02.cpp index ce85eb7..361479e 100644 --- a/Project/Tutorial02/Tutorial02.cpp +++ b/Project/Tutorial02/Tutorial02.cpp @@ -8,7 +8,6 @@ // Intel does not assume any responsibility for any errors which may appear in this software // nor any responsibility to update it. -#include #include "Tutorial02.h" #include "VulkanFunctions.h" @@ -64,7 +63,7 @@ namespace Tutorial { #endif if( VulkanLibrary == nullptr ) { - printf( "Could not load Vulkan library!\n" ); + std::cout << "Could not load Vulkan library!" << std::endl; return false; } return true; @@ -77,10 +76,10 @@ namespace Tutorial { #define LoadProcAddress dlsym #endif -#define VK_EXPORTED_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ - printf( "Could not load exported function: " #fun "!\n" ); \ - return false; \ +#define VK_EXPORTED_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)LoadProcAddress( VulkanLibrary, #fun )) ) { \ + std::cout << "Could not load exported function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -89,10 +88,10 @@ namespace Tutorial { } bool Tutorial02::LoadGlobalLevelEntryPoints() { -#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ - printf( "Could not load global level function: " #fun "!\n" ); \ - return false; \ +#define VK_GLOBAL_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( nullptr, #fun )) ) { \ + std::cout << "Could not load global level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -104,13 +103,13 @@ namespace Tutorial { uint32_t extensions_count = 0; if( (vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, nullptr ) != VK_SUCCESS) || (extensions_count == 0) ) { - printf( "Error occurred during instance extensions enumeration!\n" ); + std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } std::vector available_extensions( extensions_count ); if( vkEnumerateInstanceExtensionProperties( nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { - printf( "Error occurred during instance extensions enumeration!\n" ); + std::cout << "Error occurred during instance extensions enumeration!" << std::endl; return false; } @@ -127,7 +126,7 @@ namespace Tutorial { for( size_t i = 0; i < extensions.size(); ++i ) { if( !CheckExtensionAvailability( extensions[i], available_extensions ) ) { - printf( "Could not find instance extension named \"%s\"!\n", extensions[i] ); + std::cout << "Could not find instance extension named \"" << extensions[i] << "\"!" << std::endl; return false; } } @@ -154,7 +153,7 @@ namespace Tutorial { }; if( vkCreateInstance( &instance_create_info, nullptr, &Vulkan.Instance ) != VK_SUCCESS ) { - printf( "Could not create Vulkan instance!\n" ); + std::cout << "Could not create Vulkan instance!" << std::endl; return false; } return true; @@ -170,10 +169,10 @@ namespace Tutorial { } bool Tutorial02::LoadInstanceLevelEntryPoints() { -#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ - printf( "Could not load instance level function: " #fun "\n" ); \ - return false; \ +#define VK_INSTANCE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetInstanceProcAddr( Vulkan.Instance, #fun )) ) { \ + std::cout << "Could not load instance level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -222,7 +221,7 @@ namespace Tutorial { #endif - printf( "Could not create presentation surface!\n" ); + std::cout << "Could not create presentation surface!" << std::endl; return false; } @@ -230,13 +229,13 @@ namespace Tutorial { uint32_t num_devices = 0; if( (vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, nullptr ) != VK_SUCCESS) || (num_devices == 0) ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } std::vector physical_devices( num_devices ); if( vkEnumeratePhysicalDevices( Vulkan.Instance, &num_devices, &physical_devices[0] ) != VK_SUCCESS ) { - printf( "Error occurred during physical devices enumeration!\n" ); + std::cout << "Error occurred during physical devices enumeration!" << std::endl; return false; } @@ -249,7 +248,7 @@ namespace Tutorial { } } if( Vulkan.PhysicalDevice == VK_NULL_HANDLE ) { - printf( "Could not select physical device based on the chosen properties!\n" ); + std::cout << "Could not select physical device based on the chosen properties!" << std::endl; return false; } @@ -257,12 +256,12 @@ namespace Tutorial { std::vector queue_priorities = { 1.0f }; queue_create_infos.push_back( { - VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType - nullptr, // const void *pNext - 0, // VkDeviceQueueCreateFlags flags - selected_graphics_queue_family_index, // uint32_t queueFamilyIndex - static_cast(queue_priorities.size()), // uint32_t queueCount - &queue_priorities[0] // const float *pQueuePriorities + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType + nullptr, // const void *pNext + 0, // VkDeviceQueueCreateFlags flags + selected_graphics_queue_family_index, // uint32_t queueFamilyIndex + static_cast(queue_priorities.size()), // uint32_t queueCount + &queue_priorities[0] // const float *pQueuePriorities } ); if( selected_graphics_queue_family_index != selected_present_queue_family_index ) { @@ -294,7 +293,7 @@ namespace Tutorial { }; if( vkCreateDevice( Vulkan.PhysicalDevice, &device_create_info, nullptr, &Vulkan.Device ) != VK_SUCCESS ) { - printf( "Could not create Vulkan device!\n" ); + std::cout << "Could not create Vulkan device!" << std::endl; return false; } @@ -307,13 +306,13 @@ namespace Tutorial { uint32_t extensions_count = 0; if( (vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, nullptr ) != VK_SUCCESS) || (extensions_count == 0) ) { - printf( "Error occurred during physical device %p extensions enumeration!\n", physical_device ); + std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } std::vector available_extensions( extensions_count ); if( vkEnumerateDeviceExtensionProperties( physical_device, nullptr, &extensions_count, &available_extensions[0] ) != VK_SUCCESS ) { - printf( "Error occurred during physical device %p extensions enumeration!\n", physical_device ); + std::cout << "Error occurred during physical device " << physical_device << " extensions enumeration!" << std::endl; return false; } @@ -323,7 +322,7 @@ namespace Tutorial { for( size_t i = 0; i < device_extensions.size(); ++i ) { if( !CheckExtensionAvailability( device_extensions[i], available_extensions ) ) { - printf( "Physical device %p doesn't support extension named \"%s\"!\n", physical_device, device_extensions[i] ); + std::cout << "Physical device " << physical_device << " doesn't support extension named \"" << device_extensions[i] << "\"!" << std::endl; return false; } } @@ -338,14 +337,14 @@ namespace Tutorial { if( (major_version < 1) && (device_properties.limits.maxImageDimension2D < 4096) ) { - printf( "Physical device %p doesn't support required parameters!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't support required parameters!" << std::endl; return false; } uint32_t queue_families_count = 0; vkGetPhysicalDeviceQueueFamilyProperties( physical_device, &queue_families_count, nullptr ); if( queue_families_count == 0 ) { - printf( "Physical device %p doesn't have any queue families!\n", physical_device ); + std::cout << "Physical device " << physical_device << " doesn't have any queue families!" << std::endl; return false; } @@ -387,7 +386,7 @@ namespace Tutorial { // If this device doesn't support queues with graphics and present capabilities don't use it if( (graphics_queue_family_index == UINT32_MAX) || (present_queue_family_index == UINT32_MAX) ) { - printf( "Could not find queue families with required properties on physical device %p!\n", physical_device ); + std::cout << "Could not find queue family with required properties on physical device " << physical_device << "!" << std::endl; return false; } @@ -397,10 +396,10 @@ namespace Tutorial { } bool Tutorial02::LoadDeviceLevelEntryPoints() { -#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ - if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ - printf( "Could not load device level function: " #fun "!\n" ); \ - return false; \ +#define VK_DEVICE_LEVEL_FUNCTION( fun ) \ + if( !(fun = (PFN_##fun)vkGetDeviceProcAddr( Vulkan.Device, #fun )) ) { \ + std::cout << "Could not load device level function: " << #fun << "!" << std::endl; \ + return false; \ } #include "ListOfFunctions.inl" @@ -423,7 +422,7 @@ namespace Tutorial { if( (vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.ImageAvailableSemaphore ) != VK_SUCCESS) || (vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.RenderingFinishedSemaphore ) != VK_SUCCESS) ) { - printf( "Could not create semaphores!\n" ); + std::cout << "Could not create semaphores!" << std::endl; return false; } @@ -437,33 +436,33 @@ namespace Tutorial { VkSurfaceCapabilitiesKHR surface_capabilities; if( vkGetPhysicalDeviceSurfaceCapabilitiesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &surface_capabilities ) != VK_SUCCESS ) { - printf( "Could not check presentation surface capabilities!\n" ); + std::cout << "Could not check presentation surface capabilities!" << std::endl; return false; } uint32_t formats_count; if( (vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, nullptr ) != VK_SUCCESS) || (formats_count == 0) ) { - printf( "Error occurred during presentation surface formats enumeration!\n" ); + std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } std::vector surface_formats( formats_count ); if( vkGetPhysicalDeviceSurfaceFormatsKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &formats_count, &surface_formats[0] ) != VK_SUCCESS ) { - printf( "Error occurred during presentation surface formats enumeration!\n" ); + std::cout << "Error occurred during presentation surface formats enumeration!" << std::endl; return false; } uint32_t present_modes_count; if( (vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, nullptr ) != VK_SUCCESS) || (present_modes_count == 0) ) { - printf( "Error occurred during presentation surface present modes enumeration!\n" ); + std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } std::vector present_modes( present_modes_count ); if( vkGetPhysicalDeviceSurfacePresentModesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &present_modes_count, &present_modes[0] ) != VK_SUCCESS ) { - printf( "Error occurred during presentation surface present modes enumeration!\n" ); + std::cout << "Error occurred during presentation surface present modes enumeration!" << std::endl; return false; } @@ -475,8 +474,10 @@ namespace Tutorial { VkPresentModeKHR desired_present_mode = GetSwapChainPresentMode( present_modes ); VkSwapchainKHR old_swap_chain = Vulkan.SwapChain; - if( static_cast(desired_usage) == 0 ) { - printf( "TRANSFER_DST image usage is not supported by the swap chain!" ); + if( static_cast(desired_usage) == -1 ) { + return false; + } + if( static_cast(desired_present_mode) == -1 ) { return false; } @@ -502,7 +503,7 @@ namespace Tutorial { }; if( vkCreateSwapchainKHR( Vulkan.Device, &swap_chain_create_info, nullptr, &Vulkan.SwapChain ) != VK_SUCCESS ) { - printf( "Could not create swap chain!\n" ); + std::cout << "Could not create swap chain!" << std::endl; return false; } if( old_swap_chain != VK_NULL_HANDLE ) { @@ -574,7 +575,18 @@ namespace Tutorial { if( surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT ) { return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; } - return 0; + std::cout << "VK_IMAGE_USAGE_TRANSFER_DST image usage is not supported by the swap chain!" << std::endl + << "Supported swap chain's image usages include:" << std::endl + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT ? " VK_IMAGE_USAGE_TRANSFER_SRC\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT ? " VK_IMAGE_USAGE_TRANSFER_DST\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT ? " VK_IMAGE_USAGE_SAMPLED\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT ? " VK_IMAGE_USAGE_STORAGE\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_COLOR_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT\n" : "") + << (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT ? " VK_IMAGE_USAGE_INPUT_ATTACHMENT" : "") + << std::endl; + return static_cast(-1); } VkSurfaceTransformFlagBitsKHR Tutorial02::GetSwapChainTransform( VkSurfaceCapabilitiesKHR &surface_capabilities ) { @@ -599,7 +611,13 @@ namespace Tutorial { return present_mode; } } - return VK_PRESENT_MODE_FIFO_KHR; + for( VkPresentModeKHR &present_mode : present_modes ) { + if( present_mode == VK_PRESENT_MODE_FIFO_KHR ) { + return present_mode; + } + } + std::cout << "FIFO present mode is not supported by the swap chain!" << std::endl; + return static_cast(-1); } bool Tutorial02::OnWindowSizeChanged() { @@ -623,14 +641,14 @@ namespace Tutorial { }; if( vkCreateCommandPool( Vulkan.Device, &cmd_pool_create_info, nullptr, &Vulkan.PresentQueueCmdPool ) != VK_SUCCESS ) { - printf( "Could not create a command pool!\n" ); + std::cout << "Could not create a command pool!" << std::endl; return false; } uint32_t image_count = 0; if( (vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain, &image_count, nullptr ) != VK_SUCCESS) || (image_count == 0) ) { - printf( "Could not get the number of swap chain images!\n" ); + std::cout << "Could not get the number of swap chain images!" << std::endl; return false; } @@ -644,12 +662,12 @@ namespace Tutorial { image_count // uint32_t bufferCount }; if( vkAllocateCommandBuffers( Vulkan.Device, &cmd_buffer_allocate_info, &Vulkan.PresentQueueCmdBuffers[0] ) != VK_SUCCESS ) { - printf( "Could not allocate command buffers!\n" ); + std::cout << "Could not allocate command buffers!" << std::endl; return false; } if( !RecordCommandBuffers() ) { - printf( "Could not record command buffers!\n" ); + std::cout << "Could not record command buffers!" << std::endl; return false; } return true; @@ -660,7 +678,7 @@ namespace Tutorial { std::vector swap_chain_images( image_count ); if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain, &image_count, &swap_chain_images[0] ) != VK_SUCCESS ) { - printf( "Could not get swap chain images!\n" ); + std::cout << "Could not get swap chain images!" << std::endl; return false; } @@ -717,7 +735,7 @@ namespace Tutorial { vkCmdPipelineBarrier( Vulkan.PresentQueueCmdBuffers[i], VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier_from_clear_to_present ); if( vkEndCommandBuffer( Vulkan.PresentQueueCmdBuffers[i] ) != VK_SUCCESS ) { - printf( "Could not record command buffers!\n" ); + std::cout << "Could not record command buffers!" << std::endl; return false; } } @@ -751,7 +769,7 @@ namespace Tutorial { case VK_ERROR_OUT_OF_DATE_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during swap chain image acquisition!\n" ); + std::cout << "Problem occurred during swap chain image acquisition!" << std::endl; return false; } @@ -791,7 +809,7 @@ namespace Tutorial { case VK_SUBOPTIMAL_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during image presentation!\n" ); + std::cout << "Problem occurred during image presentation!" << std::endl; return false; } diff --git a/Project/Tutorial03/Tutorial03.cpp b/Project/Tutorial03/Tutorial03.cpp index 274ad8b..c51cc17 100644 --- a/Project/Tutorial03/Tutorial03.cpp +++ b/Project/Tutorial03/Tutorial03.cpp @@ -67,7 +67,7 @@ namespace Tutorial { }; if( vkCreateRenderPass( GetDevice(), &render_pass_create_info, nullptr, &Vulkan.RenderPass ) != VK_SUCCESS ) { - printf( "Could not create render pass!\n" ); + std::cout << "Could not create render pass!" << std::endl; return false; } @@ -102,7 +102,7 @@ namespace Tutorial { }; if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.FramebufferObjects[i].ImageView ) != VK_SUCCESS ) { - printf( "Could not create image view for framebuffer!\n" ); + std::cout << "Could not create image view for framebuffer!" << std::endl; return false; } @@ -119,7 +119,7 @@ namespace Tutorial { }; if( vkCreateFramebuffer( GetDevice(), &framebuffer_create_info, nullptr, &Vulkan.FramebufferObjects[i].Handle ) != VK_SUCCESS ) { - printf( "Could not create a framebuffer!\n" ); + std::cout << "Could not create a framebuffer!" << std::endl; return false; } } @@ -142,7 +142,7 @@ namespace Tutorial { VkShaderModule shader_module; if( vkCreateShaderModule( GetDevice(), &shader_module_create_info, nullptr, &shader_module ) != VK_SUCCESS ) { - printf( "Could not create shader module from a %s file!\n", filename ); + std::cout << "Could not create shader module from a \"" << filename << "\" file!" << std::endl; return Tools::AutoDeleter(); } @@ -162,7 +162,7 @@ namespace Tutorial { VkPipelineLayout pipeline_layout; if( vkCreatePipelineLayout( GetDevice(), &layout_create_info, nullptr, &pipeline_layout ) != VK_SUCCESS ) { - printf( "Could not create pipeline layout!\n" ); + std::cout << "Could not create pipeline layout!" << std::endl; return Tools::AutoDeleter(); } @@ -327,7 +327,7 @@ namespace Tutorial { }; if( vkCreateGraphicsPipelines( GetDevice(), VK_NULL_HANDLE, 1, &pipeline_create_info, nullptr, &Vulkan.GraphicsPipeline ) != VK_SUCCESS ) { - printf( "Could not create graphics pipeline!\n" ); + std::cout << "Could not create graphics pipeline!" << std::endl; return false; } return true; @@ -335,7 +335,7 @@ namespace Tutorial { bool Tutorial03::CreateCommandBuffers() { if( !CreateCommandPool( GetGraphicsQueue().FamilyIndex, &Vulkan.GraphicsCommandPool ) ) { - printf( "Could not create command pool!\n" ); + std::cout << "Could not create command pool!" << std::endl; return false; } @@ -343,7 +343,7 @@ namespace Tutorial { Vulkan.GraphicsCommandBuffers.resize( image_count, VK_NULL_HANDLE ); if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, image_count, &Vulkan.GraphicsCommandBuffers[0] ) ) { - printf( "Could not allocate command buffers!\n" ); + std::cout << "Could not allocate command buffers!" << std::endl; return false; } return true; @@ -462,7 +462,7 @@ namespace Tutorial { vkCmdPipelineBarrier( Vulkan.GraphicsCommandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier_from_draw_to_present ); } if( vkEndCommandBuffer( Vulkan.GraphicsCommandBuffers[i] ) != VK_SUCCESS ) { - printf( "Could not record command buffer!\n" ); + std::cout << "Could not record command buffer!" << std::endl; return false; } } @@ -503,7 +503,7 @@ namespace Tutorial { case VK_ERROR_OUT_OF_DATE_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during swap chain image acquisition!\n" ); + std::cout << "Problem occurred during swap chain image acquisition!" << std::endl; return false; } @@ -543,7 +543,7 @@ namespace Tutorial { case VK_SUBOPTIMAL_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during image presentation!\n" ); + std::cout << "Problem occurred during image presentation!" << std::endl; return false; } diff --git a/Project/Tutorial04/Tutorial04.cpp b/Project/Tutorial04/Tutorial04.cpp index d31d8ee..6d12260 100644 --- a/Project/Tutorial04/Tutorial04.cpp +++ b/Project/Tutorial04/Tutorial04.cpp @@ -67,7 +67,7 @@ namespace Tutorial { }; if( vkCreateRenderPass( GetDevice(), &render_pass_create_info, nullptr, &Vulkan.RenderPass ) != VK_SUCCESS ) { - printf( "Could not create render pass!\n" ); + std::cout << "Could not create render pass!" << std::endl; return false; } @@ -99,17 +99,17 @@ namespace Tutorial { }; if( vkCreateImage( GetDevice(), &image_create_info, nullptr, &Vulkan.Image.Handle ) != VK_SUCCESS ) { - printf( "Could not create an image!\n" ); + std::cout << "Could not create an image!" << std::endl; return false; } if( !AllocateImageMemory( Vulkan.Image.Handle, &Vulkan.Image.Memory ) ) { - printf( "Could not allocate memory for an image!\n" ); + std::cout << "Could not allocate memory for an image!" << std::endl; return false; } if( vkBindImageMemory( GetDevice(), Vulkan.Image.Handle, Vulkan.Image.Memory, 0 ) != VK_SUCCESS ) { - printf( "Could not bind memory for an image!\n" ); + std::cout << "Could not bind memory for an image!" << std::endl; return false; } @@ -165,7 +165,7 @@ namespace Tutorial { }; if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.Image.View ) != VK_SUCCESS ) { - printf( "Could not create an image view!\n" ); + std::cout << "Could not create an image view!" << std::endl; return false; } @@ -182,7 +182,7 @@ namespace Tutorial { }; if( vkCreateFramebuffer( GetDevice(), &framebuffer_create_info, nullptr, &Vulkan.Framebuffer ) != VK_SUCCESS ) { - printf( "Could not create a framebuffer!\n" ); + std::cout << "Could not create a framebuffer!" << std::endl; return false; } return true; @@ -204,7 +204,7 @@ namespace Tutorial { VkShaderModule shader_module; if( vkCreateShaderModule( GetDevice(), &shader_module_create_info, nullptr, &shader_module ) != VK_SUCCESS ) { - printf( "Could not create shader module from a %s file!\n", filename ); + std::cout << "Could not create shader module from a \"" << filename << "\" file!" << std::endl; return Tools::AutoDeleter(); } @@ -224,7 +224,7 @@ namespace Tutorial { VkPipelineLayout pipeline_layout; if( vkCreatePipelineLayout( GetDevice(), &layout_create_info, nullptr, &pipeline_layout ) != VK_SUCCESS ) { - printf( "Could not create pipeline layout!\n" ); + std::cout << "Could not create pipeline layout!" << std::endl; return Tools::AutoDeleter(); } @@ -410,7 +410,7 @@ namespace Tutorial { }; if( vkCreateGraphicsPipelines( GetDevice(), VK_NULL_HANDLE, 1, &pipeline_create_info, nullptr, &Vulkan.GraphicsPipeline ) != VK_SUCCESS ) { - printf( "Could not create graphics pipeline!\n" ); + std::cout << "Could not create graphics pipeline!" << std::endl; return false; } return true; @@ -450,23 +450,23 @@ namespace Tutorial { }; if( vkCreateBuffer( GetDevice(), &buffer_create_info, nullptr, &Vulkan.VertexBuffer.Handle ) != VK_SUCCESS ) { - printf( "Could not create a vertex buffer!\n" ); + std::cout << "Could not create a vertex buffer!" << std::endl; return false; } if( !AllocateBufferMemory( Vulkan.VertexBuffer.Handle, &Vulkan.VertexBuffer.Memory ) ) { - printf( "Could not allocate memory for a vertex buffer!\n" ); + std::cout << "Could not allocate memory for a vertex buffer!" << std::endl; return false; } if( vkBindBufferMemory( GetDevice(), Vulkan.VertexBuffer.Handle, Vulkan.VertexBuffer.Memory, 0 ) != VK_SUCCESS ) { - printf( "Could not bind memory for a vertex buffer!\n" ); + std::cout << "Could not bind memory for a vertex buffer!" << std::endl; return false; } void *vertex_buffer_memory_pointer; if( vkMapMemory( GetDevice(), Vulkan.VertexBuffer.Memory, 0, Vulkan.VertexBuffer.Size, 0, &vertex_buffer_memory_pointer ) != VK_SUCCESS ) { - printf( "Could not map memory and upload data to a vertex buffer!\n" ); + std::cout << "Could not map memory and upload data to a vertex buffer!" << std::endl; return false; } @@ -475,7 +475,7 @@ namespace Tutorial { vkUnmapMemory( GetDevice(), Vulkan.VertexBuffer.Memory ); if( !CommitMemoryChanges( Vulkan.VertexBuffer.Handle, Vulkan.VertexBuffer.Size ) ) { - printf( "Could not setup a barrier for a vertex buffer!\n" ); + std::cout << "Could not setup a barrier for a vertex buffer!" << std::endl; return false; } @@ -533,7 +533,7 @@ namespace Tutorial { vkCmdPipelineBarrier( Vulkan.CopyingCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 1, &barrier_from_host_write_to_attribute_read, 0, nullptr ); if( vkEndCommandBuffer( Vulkan.CopyingCommandBuffer ) != VK_SUCCESS ) { - printf( "Could not record command with buffer barrier!\n" ); + std::cout << "Could not record command with buffer barrier!" << std::endl; return false; } @@ -550,7 +550,7 @@ namespace Tutorial { }; if( vkQueueSubmit( GetGraphicsQueue().Handle, 1, &submit_rendering_info, VK_NULL_HANDLE ) != VK_SUCCESS ) { - printf( "Error occurred during submission of command buffer with vertex buffer barrier!!\n" ); + std::cout << "Error occurred during submission of command buffer with vertex buffer barrier!!" << std::endl; return false; } @@ -566,7 +566,7 @@ namespace Tutorial { VK_FENCE_CREATE_SIGNALED_BIT // VkFenceCreateFlags flags }; if( vkCreateFence( GetDevice(), &fence_create_info, nullptr, &Vulkan.Fence ) != VK_SUCCESS ) { - printf( "Could not create a fence!\n" ); + std::cout << "Could not create a fence!" << std::endl; return false; } return true; @@ -574,15 +574,15 @@ namespace Tutorial { bool Tutorial04::CreateCommandBuffers() { if( !CreateCommandPool( GetGraphicsQueue().FamilyIndex, &Vulkan.GraphicsCommandPool ) ) { - printf( "Could not create command pool!\n" ); + std::cout << "Could not create command pool!" << std::endl; return false; } if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, 1, &Vulkan.RenderingCommandBuffer ) ) { - printf( "Could not allocate rendering command buffer!\n" ); + std::cout << "Could not allocate rendering command buffer!" << std::endl; return false; } if( !AllocateCommandBuffers( Vulkan.GraphicsCommandPool, 1, &Vulkan.CopyingCommandBuffer ) ) { - printf( "Could not allocate copying command buffer!\n" ); + std::cout << "Could not allocate copying command buffer!" << std::endl; return false; } return true; @@ -662,7 +662,7 @@ namespace Tutorial { vkCmdEndRenderPass( Vulkan.RenderingCommandBuffer ); if( vkEndCommandBuffer( Vulkan.RenderingCommandBuffer ) != VK_SUCCESS ) { - printf( "Could not record drawing command buffer!\n" ); + std::cout << "Could not record drawing command buffer!" << std::endl; return false; } return true; @@ -670,7 +670,7 @@ namespace Tutorial { bool Tutorial04::RecordCopyingCommandBuffer( VkImage swap_chain_image ) { if( vkWaitForFences( GetDevice(), 1, &Vulkan.Fence, VK_FALSE, 1000000000 ) != VK_SUCCESS ) { - printf( "Waiting for fence takes too long!\n" ); + std::cout << "Waiting for fence takes too long!" << std::endl; return false; } vkResetFences( GetDevice(), 1, &Vulkan.Fence ); @@ -755,7 +755,7 @@ namespace Tutorial { vkCmdPipelineBarrier( Vulkan.CopyingCommandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrier_from_transfer_dst_to_present ); if( vkEndCommandBuffer( Vulkan.CopyingCommandBuffer ) != VK_SUCCESS ) { - printf( "Could not record copying command buffer!\n" ); + std::cout << "Could not record copying command buffer!" << std::endl; return false; } return true; @@ -779,7 +779,7 @@ namespace Tutorial { case VK_ERROR_OUT_OF_DATE_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during swap chain image acquisition!\n" ); + std::cout << "Problem occurred during swap chain image acquisition!" << std::endl; return false; } @@ -839,7 +839,7 @@ namespace Tutorial { case VK_SUBOPTIMAL_KHR: return OnWindowSizeChanged(); default: - printf( "Problem occurred during image presentation!\n" ); + std::cout << "Problem occurred during image presentation!" << std::endl; return false; }