Create image views and render passes
This commit is contained in:
@@ -19,6 +19,8 @@ namespace PB::Renderer
|
|||||||
VkFormat VulkanManager::s_SwapChainImageFormat = {};
|
VkFormat VulkanManager::s_SwapChainImageFormat = {};
|
||||||
VkExtent2D VulkanManager::s_SwapChainExtent = {};
|
VkExtent2D VulkanManager::s_SwapChainExtent = {};
|
||||||
|
|
||||||
|
VkRenderPass VulkanManager::s_RenderPass = VK_NULL_HANDLE;
|
||||||
|
|
||||||
bool VulkanManager::InitAll(GLFWwindow* window)
|
bool VulkanManager::InitAll(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (const std::optional<VkInstance> instance = VulkanManager::Init(); !instance)
|
if (const std::optional<VkInstance> instance = VulkanManager::Init(); !instance)
|
||||||
@@ -27,11 +29,16 @@ namespace PB::Renderer
|
|||||||
if (const std::optional<VkSurfaceKHR> surface = VulkanManager::CreateSurface(window); !surface)
|
if (const std::optional<VkSurfaceKHR> surface = VulkanManager::CreateSurface(window); !surface)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!VulkanManager::PickPhysicalDevice())
|
if (!(
|
||||||
return false;
|
VulkanManager::PickPhysicalDevice() ||
|
||||||
|
VulkanManager::PickPhysicalDevice() ||
|
||||||
if (!VulkanManager::CreateLogicalDevice())
|
VulkanManager::CreateLogicalDevice() ||
|
||||||
|
VulkanManager::CreateSwapChain(window) ||
|
||||||
|
VulkanManager::CreateImageViews() ||
|
||||||
|
VulkanManager::CreateRenderPass()
|
||||||
|
)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -303,8 +310,8 @@ namespace PB::Renderer
|
|||||||
s_QueueIndices.presentFamily.value()
|
s_QueueIndices.presentFamily.value()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (queueFamilyIndices[0] != queueFamilyIndices[1])
|
if (s_QueueIndices.graphicsFamily.value() != s_QueueIndices.presentFamily.value())
|
||||||
{
|
{
|
||||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||||
createInfo.queueFamilyIndexCount = 2;
|
createInfo.queueFamilyIndexCount = 2;
|
||||||
createInfo.pQueueFamilyIndices = queueFamilyIndices;
|
createInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||||
@@ -323,7 +330,7 @@ namespace PB::Renderer
|
|||||||
createInfo.clipped = VK_TRUE;
|
createInfo.clipped = VK_TRUE;
|
||||||
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||||
|
|
||||||
if (!vkCreateSwapchainKHR(s_Device, &createInfo, nullptr, &s_SwapChain))
|
if (vkCreateSwapchainKHR(s_Device, &createInfo, nullptr, &s_SwapChain) != VK_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cout << "PB::Renderer::VulkanManager::CreateSwapChain(): Failed to create swap chain" << std::endl;
|
std::cout << "PB::Renderer::VulkanManager::CreateSwapChain(): Failed to create swap chain" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@@ -404,4 +411,85 @@ namespace PB::Renderer
|
|||||||
|
|
||||||
return actualExtent;
|
return actualExtent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VulkanManager::CreateImageViews()
|
||||||
|
{
|
||||||
|
s_SwapChainImageViews.resize(s_SwapChainImages.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < s_SwapChainImages.size(); i++)
|
||||||
|
{
|
||||||
|
VkImageViewCreateInfo createInfo = {};
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
|
createInfo.image = s_SwapChainImages[i];
|
||||||
|
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
createInfo.format = s_SwapChainImageFormat;
|
||||||
|
|
||||||
|
createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
|
||||||
|
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
createInfo.subresourceRange.baseMipLevel = 0;
|
||||||
|
createInfo.subresourceRange.levelCount = 1;
|
||||||
|
createInfo.subresourceRange.baseArrayLayer = 0;
|
||||||
|
createInfo.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
|
if (vkCreateImageView(s_Device, &createInfo, nullptr, &s_SwapChainImageViews[i]) != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
std::cout << "PB::Renderer::VulkanManager::CreateImageView(): Failed to create swap chain image views" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VulkanManager::CreateRenderPass()
|
||||||
|
{
|
||||||
|
VkAttachmentDescription colorAttachment{};
|
||||||
|
colorAttachment.format = s_SwapChainImageFormat;
|
||||||
|
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|
||||||
|
VkAttachmentReference colorAttachmentRef{};
|
||||||
|
colorAttachmentRef.attachment = 0;
|
||||||
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
|
VkSubpassDescription subpass{};
|
||||||
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
|
subpass.colorAttachmentCount = 1;
|
||||||
|
subpass.pColorAttachments = &colorAttachmentRef;
|
||||||
|
|
||||||
|
VkSubpassDependency dependency{};
|
||||||
|
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
|
dependency.dstSubpass = 0;
|
||||||
|
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
dependency.srcAccessMask = 0;
|
||||||
|
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
|
||||||
|
VkRenderPassCreateInfo renderPassInfo{};
|
||||||
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||||
|
renderPassInfo.attachmentCount = 1;
|
||||||
|
renderPassInfo.pAttachments = &colorAttachment;
|
||||||
|
renderPassInfo.subpassCount = 1;
|
||||||
|
renderPassInfo.pSubpasses = &subpass;
|
||||||
|
renderPassInfo.dependencyCount = 1;
|
||||||
|
renderPassInfo.pDependencies = &dependency;
|
||||||
|
|
||||||
|
if (VkResult result = vkCreateRenderPass(s_Device, &renderPassInfo, nullptr, &s_RenderPass); result != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
std::cout << "PB::Renderer::VulkanManager::CreateRenderPass(): Failed to create render pass, VkResult = " << result << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ namespace PB::Renderer
|
|||||||
static bool PickPhysicalDevice();
|
static bool PickPhysicalDevice();
|
||||||
static bool CreateLogicalDevice();
|
static bool CreateLogicalDevice();
|
||||||
static bool CreateSwapChain(GLFWwindow* window);
|
static bool CreateSwapChain(GLFWwindow* window);
|
||||||
|
static bool CreateImageViews();
|
||||||
|
static bool CreateRenderPass();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool IsDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface);
|
static bool IsDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface);
|
||||||
@@ -60,5 +62,7 @@ namespace PB::Renderer
|
|||||||
static std::vector<VkImageView> s_SwapChainImageViews;
|
static std::vector<VkImageView> s_SwapChainImageViews;
|
||||||
static VkFormat s_SwapChainImageFormat;
|
static VkFormat s_SwapChainImageFormat;
|
||||||
static VkExtent2D s_SwapChainExtent;
|
static VkExtent2D s_SwapChainExtent;
|
||||||
|
|
||||||
|
static VkRenderPass s_RenderPass;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user