summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xengine/xe_device.cpp3
-rwxr-xr-xengine/xe_device.hpp4
-rw-r--r--engine/xe_image.cpp112
-rw-r--r--engine/xe_image.hpp7
-rwxr-xr-xengine/xe_pipeline.cpp4
-rwxr-xr-xengine/xe_pipeline.hpp2
-rw-r--r--engine/xe_render_system.cpp2
-rwxr-xr-xengine/xe_swap_chain.cpp105
-rwxr-xr-xengine/xe_swap_chain.hpp5
9 files changed, 133 insertions, 111 deletions
diff --git a/engine/xe_device.cpp b/engine/xe_device.cpp
index f602e18..dc4d5f1 100755
--- a/engine/xe_device.cpp
+++ b/engine/xe_device.cpp
@@ -131,7 +131,10 @@ void Device::pickPhysicalDevice() {
}
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
+ samplerAnisotropy = properties.limits.maxSamplerAnisotropy;
std::cout << "Physical device: " << properties.deviceName << std::endl;
+ std::cout << "Multisample Count: " << msaaSamples << std::endl;
+ std::cout << "Anisotropic Level: " << samplerAnisotropy << std::endl;
}
VkSampleCountFlagBits Device::getMaxUsableSampleCount() {
diff --git a/engine/xe_device.hpp b/engine/xe_device.hpp
index 9825ff2..85619b8 100755
--- a/engine/xe_device.hpp
+++ b/engine/xe_device.hpp
@@ -42,7 +42,8 @@ class Device {
VkSurfaceKHR surface() { return surface_; }
VkQueue graphicsQueue() { return graphicsQueue_; }
VkQueue presentQueue() { return presentQueue_; }
- VkPhysicalDeviceProperties getProperties() { return properties; }
+ VkSampleCountFlagBits getSamples() { return msaaSamples; }
+ float getAnisotropy() { return samplerAnisotropy; }
SwapChainSupportDetails getSwapChainSupport() { return querySwapChainSupport(physicalDevice); }
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
@@ -101,6 +102,7 @@ class Device {
VkQueue presentQueue_;
VkSampleCountFlagBits msaaSamples = VK_SAMPLE_COUNT_1_BIT;
+ float samplerAnisotropy = 1;
const std::vector<const char *> validationLayers = {"VK_LAYER_KHRONOS_validation"};
const std::vector<const char *> deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_MAINTENANCE1_EXTENSION_NAME};
diff --git a/engine/xe_image.cpp b/engine/xe_image.cpp
index 419cbdd..64538ce 100644
--- a/engine/xe_image.cpp
+++ b/engine/xe_image.cpp
@@ -51,11 +51,10 @@ void Image::createTextureImage(const std::string &filename) {
stbi_image_free(pixels);
- createImage(texWidth, texHeight, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);
+ createImage(xeDevice, texWidth, texHeight, mipLevels, VK_SAMPLE_COUNT_1_BIT, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, textureImage, textureImageMemory);
transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
copyBufferToImage(stagingBuffer, textureImage, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight));
- // transitionImageLayout(textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
vkDestroyBuffer(xeDevice.device(), stagingBuffer, nullptr);
vkFreeMemory(xeDevice.device(), stagingBufferMemory, nullptr);
@@ -64,42 +63,6 @@ void Image::createTextureImage(const std::string &filename) {
}
-void Image::createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
-
- VkImageCreateInfo imageInfo{};
- imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent.width = width;
- imageInfo.extent.height = height;
- imageInfo.extent.depth = 1;
- imageInfo.mipLevels = mipLevels;
- imageInfo.arrayLayers = 1;
- imageInfo.format = format;
- imageInfo.tiling = tiling;
- imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- imageInfo.usage = usage;
- imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
- imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
-
- if (vkCreateImage(xeDevice.device(), &imageInfo, nullptr, &image) != VK_SUCCESS) {
- throw std::runtime_error("failed to create image!");
- }
-
- VkMemoryRequirements memRequirements;
- vkGetImageMemoryRequirements(xeDevice.device(), image, &memRequirements);
-
- VkMemoryAllocateInfo allocInfo{};
- allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- allocInfo.allocationSize = memRequirements.size;
- allocInfo.memoryTypeIndex = xeDevice.findMemoryType(memRequirements.memoryTypeBits, properties);
-
- if (vkAllocateMemory(xeDevice.device(), &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
- throw std::runtime_error("failed to allocate image memory!");
- }
-
- vkBindImageMemory(xeDevice.device(), image, imageMemory, 0);
-}
-
void Image::transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) {
VkCommandBuffer commandBuffer = xeDevice.beginSingleTimeCommands();
@@ -251,20 +214,7 @@ void Image::copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, ui
}
void Image::createTextureImageView() {
- VkImageViewCreateInfo viewInfo{};
- viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- viewInfo.image = textureImage;
- viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
- viewInfo.format = VK_FORMAT_R8G8B8A8_SRGB;
- viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- viewInfo.subresourceRange.baseMipLevel = 0;
- viewInfo.subresourceRange.levelCount = mipLevels;
- viewInfo.subresourceRange.baseArrayLayer = 0;
- viewInfo.subresourceRange.layerCount = 1;
-
- if (vkCreateImageView(xeDevice.device(), &viewInfo, nullptr, &textureImageView) != VK_SUCCESS) {
- throw std::runtime_error("failed to create texture image view!");
- }
+ textureImageView = createImageView(xeDevice, textureImage, VK_FORMAT_R8G8B8A8_SRGB, VK_IMAGE_ASPECT_COLOR_BIT, mipLevels);
}
void Image::createTextureSampler() {
@@ -277,7 +227,7 @@ void Image::createTextureSampler() {
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.anisotropyEnable = VK_TRUE;
- samplerInfo.maxAnisotropy = xeDevice.getProperties().limits.maxSamplerAnisotropy;
+ samplerInfo.maxAnisotropy = xeDevice.getAnisotropy();
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
samplerInfo.unnormalizedCoordinates = VK_FALSE;
samplerInfo.compareEnable = VK_FALSE;
@@ -292,4 +242,60 @@ void Image::createTextureSampler() {
}
}
+void Image::createImage(Device& device, uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
+
+ VkImageCreateInfo imageInfo{};
+ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.extent.width = width;
+ imageInfo.extent.height = height;
+ imageInfo.extent.depth = 1;
+ imageInfo.mipLevels = mipLevels;
+ imageInfo.arrayLayers = 1;
+ imageInfo.format = format;
+ imageInfo.tiling = tiling;
+ imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ imageInfo.usage = usage;
+ imageInfo.samples = numSamples;
+ imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
+
+ if (vkCreateImage(device.device(), &imageInfo, nullptr, &image) != VK_SUCCESS) {
+ throw std::runtime_error("failed to create image!");
+ }
+
+ VkMemoryRequirements memRequirements;
+ vkGetImageMemoryRequirements(device.device(), image, &memRequirements);
+
+ VkMemoryAllocateInfo allocInfo{};
+ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ allocInfo.allocationSize = memRequirements.size;
+ allocInfo.memoryTypeIndex = device.findMemoryType(memRequirements.memoryTypeBits, properties);
+
+ if (vkAllocateMemory(device.device(), &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
+ throw std::runtime_error("failed to allocate image memory!");
+ }
+
+ vkBindImageMemory(device.device(), image, imageMemory, 0);
+}
+
+VkImageView Image::createImageView(Device& device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels) {
+ VkImageViewCreateInfo viewInfo{};
+ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ viewInfo.image = image;
+ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
+ viewInfo.format = format;
+ viewInfo.subresourceRange.aspectMask = aspectFlags;
+ viewInfo.subresourceRange.baseMipLevel = 0;
+ viewInfo.subresourceRange.levelCount = mipLevels;
+ viewInfo.subresourceRange.baseArrayLayer = 0;
+ viewInfo.subresourceRange.layerCount = 1;
+
+ VkImageView imageView;
+ if (vkCreateImageView(device.device(), &viewInfo, nullptr, &imageView) != VK_SUCCESS) {
+ throw std::runtime_error("failed to create texture image view!");
+ }
+
+ return imageView;
+ }
+
} \ No newline at end of file
diff --git a/engine/xe_image.hpp b/engine/xe_image.hpp
index 29f5d58..1b92e2a 100644
--- a/engine/xe_image.hpp
+++ b/engine/xe_image.hpp
@@ -19,22 +19,25 @@ class Image {
private:
void createTextureImage(const std::string &filename);
- void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory);
void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout);
void generateMipmaps(VkImage image, VkFormat imageFormat, int32_t texWidth, int32_t texHeight, uint32_t mipLevels);
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);
void createTextureImageView();
void createTextureSampler();
+ static void createImage(Device& device, uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory);
+ static VkImageView createImageView(Device& device, VkImage image, VkFormat format, VkImageAspectFlags aspectFlags, uint32_t mipLevels);
+
Device &xeDevice;
uint32_t mipLevels;
- VkImage textureImage;
VkSampler textureSampler;
+ VkImage textureImage;
VkImageView textureImageView;
VkDeviceMemory textureImageMemory;
friend class RenderSystem;
+ friend class SwapChain;
};
diff --git a/engine/xe_pipeline.cpp b/engine/xe_pipeline.cpp
index 7479dcb..fb06f7c 100755
--- a/engine/xe_pipeline.cpp
+++ b/engine/xe_pipeline.cpp
@@ -136,7 +136,7 @@ namespace xe {
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
}
- void Pipeline::defaultPipelineConfigInfo(PipelineConfigInfo& configInfo) {
+ void Pipeline::defaultPipelineConfigInfo(PipelineConfigInfo& configInfo, Device& device) {
configInfo.inputAssemblyInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
configInfo.inputAssemblyInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
@@ -162,7 +162,7 @@ namespace xe {
configInfo.multisampleInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
configInfo.multisampleInfo.sampleShadingEnable = VK_FALSE;
- configInfo.multisampleInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ configInfo.multisampleInfo.rasterizationSamples = device.getSamples();
configInfo.multisampleInfo.minSampleShading = 1.0f;
configInfo.multisampleInfo.pSampleMask = nullptr;
configInfo.multisampleInfo.alphaToCoverageEnable = VK_FALSE;
diff --git a/engine/xe_pipeline.hpp b/engine/xe_pipeline.hpp
index 269a171..cfa810a 100755
--- a/engine/xe_pipeline.hpp
+++ b/engine/xe_pipeline.hpp
@@ -44,7 +44,7 @@ class Pipeline {
Pipeline operator=(const Pipeline&) = delete;
void bind(VkCommandBuffer commandBuffer);
- static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo);
+ static void defaultPipelineConfigInfo(PipelineConfigInfo& configInfo, Device& device);
private:
static std::vector<char> readFile(const std::string& filePath);
diff --git a/engine/xe_render_system.cpp b/engine/xe_render_system.cpp
index b7cce7a..cdfe3cb 100644
--- a/engine/xe_render_system.cpp
+++ b/engine/xe_render_system.cpp
@@ -130,7 +130,7 @@ void RenderSystem::createPipeline(VkRenderPass renderPass, std::string vert, std
assert(pipelineLayout != nullptr && "Cannot create pipeline before pipeline layout");
PipelineConfigInfo pipelineConfig{};
- Pipeline::defaultPipelineConfigInfo(pipelineConfig);
+ Pipeline::defaultPipelineConfigInfo(pipelineConfig, xeDevice);
if (cullingEnabled) {
pipelineConfig.rasterizationInfo.cullMode = VK_CULL_MODE_BACK_BIT;
}
diff --git a/engine/xe_swap_chain.cpp b/engine/xe_swap_chain.cpp
index 7044226..67248f4 100755
--- a/engine/xe_swap_chain.cpp
+++ b/engine/xe_swap_chain.cpp
@@ -20,6 +20,7 @@ void SwapChain::init() {
createSwapChain();
createImageViews();
createRenderPass();
+ createColorResources();
createDepthResources();
createFramebuffers();
createSyncObjects();
@@ -37,6 +38,12 @@ SwapChain::~SwapChain() {
swapChain = nullptr;
}
+ for (int i = 0; i < colorImages.size(); i++) {
+ vkDestroyImageView(device.device(), colorImageViews[i], nullptr);
+ vkDestroyImage(device.device(), colorImages[i], nullptr);
+ vkFreeMemory(device.device(), colorImageMemorys[i], nullptr);
+ }
+
for (int i = 0; i < depthImages.size(); i++) {
vkDestroyImageView(device.device(), depthImageViews[i], nullptr);
vkDestroyImage(device.device(), depthImages[i], nullptr);
@@ -202,9 +209,24 @@ void SwapChain::createImageViews() {
}
void SwapChain::createRenderPass() {
+
+ VkAttachmentDescription colorAttachment = {};
+ colorAttachment.format = getSwapChainImageFormat();
+ colorAttachment.samples = device.getSamples();
+ colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ VkAttachmentReference colorAttachmentRef = {};
+ colorAttachmentRef.attachment = 0;
+ colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
VkAttachmentDescription depthAttachment{};
depthAttachment.format = findDepthFormat();
- depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
+ depthAttachment.samples = device.getSamples();
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
@@ -216,25 +238,26 @@ void SwapChain::createRenderPass() {
depthAttachmentRef.attachment = 1;
depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
- VkAttachmentDescription colorAttachment = {};
- colorAttachment.format = getSwapChainImageFormat();
- colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
- colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
- colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
- colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
- colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
- colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ VkAttachmentDescription colorAttachmentResolve{};
+ colorAttachmentResolve.format = getSwapChainImageFormat();
+ colorAttachmentResolve.samples = VK_SAMPLE_COUNT_1_BIT;
+ colorAttachmentResolve.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttachmentResolve.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ colorAttachmentResolve.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttachmentResolve.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ colorAttachmentResolve.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ colorAttachmentResolve.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
- VkAttachmentReference colorAttachmentRef = {};
- colorAttachmentRef.attachment = 0;
- colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ VkAttachmentReference colorAttachmentResolveRef{};
+ colorAttachmentResolveRef.attachment = 2;
+ colorAttachmentResolveRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorAttachmentRef;
subpass.pDepthStencilAttachment = &depthAttachmentRef;
+ subpass.pResolveAttachments = &colorAttachmentResolveRef;
VkSubpassDependency dependency = {};
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
@@ -247,7 +270,7 @@ void SwapChain::createRenderPass() {
dependency.dstAccessMask =
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
- std::array<VkAttachmentDescription, 2> attachments = {colorAttachment, depthAttachment};
+ std::array<VkAttachmentDescription, 3> attachments = {colorAttachment, depthAttachment, colorAttachmentResolve};
VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
@@ -265,7 +288,7 @@ void SwapChain::createRenderPass() {
void SwapChain::createFramebuffers() {
swapChainFramebuffers.resize(imageCount());
for (size_t i = 0; i < imageCount(); i++) {
- std::array<VkImageView, 2> attachments = {swapChainImageViews[i], depthImageViews[i]};
+ std::array<VkImageView, 3> attachments = {colorImageViews[i], depthImageViews[i], swapChainImageViews[i]};
VkExtent2D swapChainExtent = getSwapChainExtent();
VkFramebufferCreateInfo framebufferInfo = {};
@@ -287,6 +310,20 @@ void SwapChain::createFramebuffers() {
}
}
+void SwapChain::createColorResources() {
+ VkFormat colorFormat = getSwapChainImageFormat();
+ VkExtent2D swapChainExtent = getSwapChainExtent();
+
+ colorImages.resize(imageCount());
+ colorImageMemorys.resize(imageCount());
+ colorImageViews.resize(imageCount());
+
+ for (int i = 0; i < colorImages.size(); i++) {
+ Image::createImage(device, swapChainExtent.width, swapChainExtent.height, 1, device.getSamples(), colorFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, colorImages[i], colorImageMemorys[i]);
+ colorImageViews[i] = Image::createImageView(device, colorImages[i], colorFormat, VK_IMAGE_ASPECT_COLOR_BIT, 1);
+ }
+}
+
void SwapChain::createDepthResources() {
VkFormat depthFormat = findDepthFormat();
swapChainDepthFormat = depthFormat;
@@ -297,42 +334,8 @@ void SwapChain::createDepthResources() {
depthImageViews.resize(imageCount());
for (int i = 0; i < depthImages.size(); i++) {
- VkImageCreateInfo imageInfo{};
- imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
- imageInfo.imageType = VK_IMAGE_TYPE_2D;
- imageInfo.extent.width = swapChainExtent.width;
- imageInfo.extent.height = swapChainExtent.height;
- imageInfo.extent.depth = 1;
- imageInfo.mipLevels = 1;
- imageInfo.arrayLayers = 1;
- imageInfo.format = depthFormat;
- imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
- imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- imageInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
- imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
- imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- imageInfo.flags = 0;
-
- device.createImageWithInfo(
- imageInfo,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
- depthImages[i],
- depthImageMemorys[i]);
-
- VkImageViewCreateInfo viewInfo{};
- viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
- viewInfo.image = depthImages[i];
- viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
- viewInfo.format = depthFormat;
- viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
- viewInfo.subresourceRange.baseMipLevel = 0;
- viewInfo.subresourceRange.levelCount = 1;
- viewInfo.subresourceRange.baseArrayLayer = 0;
- viewInfo.subresourceRange.layerCount = 1;
-
- if (vkCreateImageView(device.device(), &viewInfo, nullptr, &depthImageViews[i]) != VK_SUCCESS) {
- throw std::runtime_error("failed to create texture image view!");
- }
+ Image::createImage(device, swapChainExtent.width, swapChainExtent.height, 1, device.getSamples(), depthFormat, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, depthImages[i], depthImageMemorys[i]);
+ depthImageViews[i] = Image::createImageView(device, depthImages[i], depthFormat, VK_IMAGE_ASPECT_DEPTH_BIT, 1);
}
}
diff --git a/engine/xe_swap_chain.hpp b/engine/xe_swap_chain.hpp
index dad3baf..380bd6e 100755
--- a/engine/xe_swap_chain.hpp
+++ b/engine/xe_swap_chain.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "xe_device.hpp"
+#include "xe_image.hpp"
#include <vulkan/vulkan.h>
@@ -52,6 +53,7 @@ class SwapChain {
void init();
void createSwapChain();
void createImageViews();
+ void createColorResources();
void createDepthResources();
void createRenderPass();
void createFramebuffers();
@@ -73,6 +75,9 @@ class SwapChain {
std::vector<VkImage> depthImages;
std::vector<VkDeviceMemory> depthImageMemorys;
std::vector<VkImageView> depthImageViews;
+ std::vector<VkImage> colorImages;
+ std::vector<VkDeviceMemory> colorImageMemorys;
+ std::vector<VkImageView> colorImageViews;
std::vector<VkImage> swapChainImages;
std::vector<VkImageView> swapChainImageViews;