mirror of
https://github.com/opus-tango/IntroductionToVulkan.git
synced 2026-03-20 03:55:26 +00:00
VulkanCommon: removed semaphore creation, added image views for swapchain images, removed transfer_dst usage from swapchain images.
This commit is contained in:
@@ -52,9 +52,6 @@ namespace ApiWithoutSecrets {
|
|||||||
if( !CreateSwapChain() ) {
|
if( !CreateSwapChain() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( !CreateSemaphores() ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,14 +84,6 @@ namespace ApiWithoutSecrets {
|
|||||||
return Vulkan.SwapChain;
|
return Vulkan.SwapChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VkSemaphore VulkanCommon::GetImageAvailableSemaphore() const {
|
|
||||||
return Vulkan.ImageAvailableSemaphore;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VkSemaphore VulkanCommon::GetRenderingFinishedSemaphore() const {
|
|
||||||
return Vulkan.RenderingFinishedSemaphore;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VulkanCommon::LoadVulkanLibrary() {
|
bool VulkanCommon::LoadVulkanLibrary() {
|
||||||
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
#if defined(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
|
VulkanLibrary = LoadLibrary( "vulkan-1.dll" );
|
||||||
@@ -449,6 +438,14 @@ namespace ApiWithoutSecrets {
|
|||||||
vkDeviceWaitIdle( Vulkan.Device );
|
vkDeviceWaitIdle( Vulkan.Device );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
|
||||||
|
if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) {
|
||||||
|
vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr );
|
||||||
|
Vulkan.SwapChain.Images[i].ImageView = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vulkan.SwapChain.Images.clear();
|
||||||
|
|
||||||
VkSurfaceCapabilitiesKHR surface_capabilities;
|
VkSurfaceCapabilitiesKHR surface_capabilities;
|
||||||
if( vkGetPhysicalDeviceSurfaceCapabilitiesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &surface_capabilities ) != VK_SUCCESS ) {
|
if( vkGetPhysicalDeviceSurfaceCapabilitiesKHR( Vulkan.PhysicalDevice, Vulkan.PresentationSurface, &surface_capabilities ) != VK_SUCCESS ) {
|
||||||
std::cout << "Could not check presentation surface capabilities!" << std::endl;
|
std::cout << "Could not check presentation surface capabilities!" << std::endl;
|
||||||
@@ -534,26 +531,50 @@ namespace ApiWithoutSecrets {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Vulkan.SwapChain.Images.resize( image_count );
|
Vulkan.SwapChain.Images.resize( image_count );
|
||||||
if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, &Vulkan.SwapChain.Images[0] ) != VK_SUCCESS ) {
|
|
||||||
|
std::vector<VkImage> images( image_count );
|
||||||
|
if( vkGetSwapchainImagesKHR( Vulkan.Device, Vulkan.SwapChain.Handle, &image_count, &images[0] ) != VK_SUCCESS ) {
|
||||||
std::cout << "Could not get swap chain images!" << std::endl;
|
std::cout << "Could not get swap chain images!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
|
||||||
|
Vulkan.SwapChain.Images[i].Handle = images[i];
|
||||||
|
}
|
||||||
|
Vulkan.SwapChain.Extent = desired_extent;
|
||||||
|
|
||||||
|
return CreateSwapChainImageViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VulkanCommon::CreateSemaphores( ) {
|
bool VulkanCommon::CreateSwapChainImageViews() {
|
||||||
VkSemaphoreCreateInfo semaphore_create_info = {
|
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
|
||||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, // VkStructureType sType
|
VkImageViewCreateInfo image_view_create_info = {
|
||||||
nullptr, // const void* pNext
|
VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType
|
||||||
0 // VkSemaphoreCreateFlags flags
|
nullptr, // const void *pNext
|
||||||
|
0, // VkImageViewCreateFlags flags
|
||||||
|
Vulkan.SwapChain.Images[i].Handle, // VkImage image
|
||||||
|
VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType
|
||||||
|
GetSwapChain().Format, // VkFormat format
|
||||||
|
{ // VkComponentMapping components
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle r
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle g
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY, // VkComponentSwizzle b
|
||||||
|
VK_COMPONENT_SWIZZLE_IDENTITY // VkComponentSwizzle a
|
||||||
|
},
|
||||||
|
{ // VkImageSubresourceRange subresourceRange
|
||||||
|
VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask
|
||||||
|
0, // uint32_t baseMipLevel
|
||||||
|
1, // uint32_t levelCount
|
||||||
|
0, // uint32_t baseArrayLayer
|
||||||
|
1 // uint32_t layerCount
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if( (vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.ImageAvailableSemaphore ) != VK_SUCCESS) ||
|
if( vkCreateImageView( GetDevice(), &image_view_create_info, nullptr, &Vulkan.SwapChain.Images[i].ImageView ) != VK_SUCCESS ) {
|
||||||
(vkCreateSemaphore( Vulkan.Device, &semaphore_create_info, nullptr, &Vulkan.RenderingFinishedSemaphore ) != VK_SUCCESS) ) {
|
std::cout << "Could not create image view for framebuffer!" << std::endl;
|
||||||
std::cout << "Could not create semaphores!" << std::endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -626,10 +647,10 @@ namespace ApiWithoutSecrets {
|
|||||||
VkImageUsageFlags VulkanCommon::GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities ) {
|
VkImageUsageFlags VulkanCommon::GetSwapChainUsageFlags( VkSurfaceCapabilitiesKHR &surface_capabilities ) {
|
||||||
// Color attachment flag must always be supported
|
// Color attachment flag must always be supported
|
||||||
// We can define other usage flags but we always need to check if they are supported
|
// We can define other usage flags but we always need to check if they are supported
|
||||||
if( surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT ) {
|
if( surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ) {
|
||||||
return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||||
}
|
}
|
||||||
std::cout << "VK_IMAGE_USAGE_TRANSFER_DST image usage is not supported by the swap chain!" << std::endl
|
std::cout << "VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT image usage is not supported by the swap chain!" << std::endl
|
||||||
<< "Supported swap chain's image usages include:" << 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_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_TRANSFER_DST_BIT ? " VK_IMAGE_USAGE_TRANSFER_DST\n" : "")
|
||||||
@@ -678,12 +699,12 @@ namespace ApiWithoutSecrets {
|
|||||||
if( Vulkan.Device != VK_NULL_HANDLE ) {
|
if( Vulkan.Device != VK_NULL_HANDLE ) {
|
||||||
vkDeviceWaitIdle( Vulkan.Device );
|
vkDeviceWaitIdle( Vulkan.Device );
|
||||||
|
|
||||||
if( Vulkan.ImageAvailableSemaphore != VK_NULL_HANDLE ) {
|
for( size_t i = 0; i < Vulkan.SwapChain.Images.size(); ++i ) {
|
||||||
vkDestroySemaphore( Vulkan.Device, Vulkan.ImageAvailableSemaphore, nullptr );
|
if( Vulkan.SwapChain.Images[i].ImageView != VK_NULL_HANDLE ) {
|
||||||
|
vkDestroyImageView( GetDevice(), Vulkan.SwapChain.Images[i].ImageView, nullptr );
|
||||||
}
|
}
|
||||||
if( Vulkan.RenderingFinishedSemaphore != VK_NULL_HANDLE ) {
|
|
||||||
vkDestroySemaphore( Vulkan.Device, Vulkan.RenderingFinishedSemaphore, nullptr );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Vulkan.SwapChain.Handle != VK_NULL_HANDLE ) {
|
if( Vulkan.SwapChain.Handle != VK_NULL_HANDLE ) {
|
||||||
vkDestroySwapchainKHR( Vulkan.Device, Vulkan.SwapChain.Handle, nullptr );
|
vkDestroySwapchainKHR( Vulkan.Device, Vulkan.SwapChain.Handle, nullptr );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,21 @@ namespace ApiWithoutSecrets {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ************************************************************ //
|
||||||
|
// ImageParameters //
|
||||||
|
// //
|
||||||
|
// Vulkan Image's parameters container class //
|
||||||
|
// ************************************************************ //
|
||||||
|
struct ImageParameters {
|
||||||
|
VkImage Handle;
|
||||||
|
VkImageView ImageView;
|
||||||
|
|
||||||
|
ImageParameters() :
|
||||||
|
Handle( VK_NULL_HANDLE ),
|
||||||
|
ImageView( VK_NULL_HANDLE ) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ************************************************************ //
|
// ************************************************************ //
|
||||||
// SwapChainParameters //
|
// SwapChainParameters //
|
||||||
// //
|
// //
|
||||||
@@ -40,12 +55,14 @@ namespace ApiWithoutSecrets {
|
|||||||
struct SwapChainParameters {
|
struct SwapChainParameters {
|
||||||
VkSwapchainKHR Handle;
|
VkSwapchainKHR Handle;
|
||||||
VkFormat Format;
|
VkFormat Format;
|
||||||
std::vector<VkImage> Images;
|
std::vector<ImageParameters> Images;
|
||||||
|
VkExtent2D Extent;
|
||||||
|
|
||||||
SwapChainParameters() :
|
SwapChainParameters() :
|
||||||
Handle( VK_NULL_HANDLE ),
|
Handle( VK_NULL_HANDLE ),
|
||||||
Format( VK_FORMAT_UNDEFINED ),
|
Format( VK_FORMAT_UNDEFINED ),
|
||||||
Images() {
|
Images(),
|
||||||
|
Extent() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,8 +79,6 @@ namespace ApiWithoutSecrets {
|
|||||||
QueueParameters PresentQueue;
|
QueueParameters PresentQueue;
|
||||||
VkSurfaceKHR PresentationSurface;
|
VkSurfaceKHR PresentationSurface;
|
||||||
SwapChainParameters SwapChain;
|
SwapChainParameters SwapChain;
|
||||||
VkSemaphore ImageAvailableSemaphore;
|
|
||||||
VkSemaphore RenderingFinishedSemaphore;
|
|
||||||
|
|
||||||
VulkanCommonParameters() :
|
VulkanCommonParameters() :
|
||||||
Instance( VK_NULL_HANDLE ),
|
Instance( VK_NULL_HANDLE ),
|
||||||
@@ -97,8 +112,6 @@ namespace ApiWithoutSecrets {
|
|||||||
const QueueParameters GetPresentQueue() const;
|
const QueueParameters GetPresentQueue() const;
|
||||||
|
|
||||||
const SwapChainParameters GetSwapChain() const;
|
const SwapChainParameters GetSwapChain() const;
|
||||||
const VkSemaphore GetImageAvailableSemaphore() const;
|
|
||||||
const VkSemaphore GetRenderingFinishedSemaphore() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OS::LibraryHandle VulkanLibrary;
|
OS::LibraryHandle VulkanLibrary;
|
||||||
@@ -116,7 +129,7 @@ namespace ApiWithoutSecrets {
|
|||||||
bool LoadDeviceLevelEntryPoints();
|
bool LoadDeviceLevelEntryPoints();
|
||||||
bool GetDeviceQueue();
|
bool GetDeviceQueue();
|
||||||
bool CreateSwapChain();
|
bool CreateSwapChain();
|
||||||
bool CreateSemaphores();
|
bool CreateSwapChainImageViews();
|
||||||
virtual bool ChildOnWindowSizeChanged() = 0;
|
virtual bool ChildOnWindowSizeChanged() = 0;
|
||||||
virtual void ChildClear() = 0;
|
virtual void ChildClear() = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user