Create this.
Instance a VkSwapchainCreateInfoKHR.
@breif Create SwapChain.
Get Swapchain images created by SwapChain automatically.
@breif Create SwapChianImage Resources.
Create ImageView.
Instance a VkImageViewCreateInfo.
Create Sampler.
Instance a VkSamplerCreateInfo.
Instance a VkSwapchainCreateInfoKHR.
@breif Create SwapChain.
Get Swapchain images created by SwapChain automatically.
@breif Create SwapChianImage Resources.
Create ImageView.
Instance a VkImageViewCreateInfo.
Create Sampler.
Instance a VkSamplerCreateInfo.
96 {
98
102 VkSwapchainCreateInfoKHR createInfo{};
103 createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
106 createInfo.imageFormat =
m_VulkanDevice->GetSwapChainSupport().format.format;
107 createInfo.imageColorSpace =
m_VulkanDevice->GetSwapChainSupport().format.colorSpace;
108 createInfo.imageExtent =
m_VulkanDevice->GetSwapChainSupport().surfaceSize;
109 createInfo.imageArrayLayers = 1;
110 createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
111
112 uint32_t queueFamilyIndices[2] =
113 {
116 };
117
118 if (queueFamilyIndices[0] != queueFamilyIndices[1])
119 {
120 createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
121 createInfo.queueFamilyIndexCount = 2;
122 createInfo.pQueueFamilyIndices = queueFamilyIndices;
123 }
124 else
125 {
126 createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
127 createInfo.queueFamilyIndexCount = 0;
128 createInfo.pQueueFamilyIndices = nullptr;
129 }
130
131 createInfo.preTransform =
m_VulkanDevice->GetSwapChainSupport().capabilities.currentTransform;
132 createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
133 createInfo.presentMode =
m_VulkanDevice->GetSwapChainSupport().presentMode;
134 createInfo.clipped = VK_TRUE;
135 createInfo.oldSwapchain = VK_NULL_HANDLE;
136
142
143
148
153 {
157 {
161 VkImageViewCreateInfo info{};
162 info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
164
165 info.viewType = VK_IMAGE_VIEW_TYPE_2D;
166 info.format =
m_VulkanDevice->GetSwapChainSupport().format.format;
167
168 info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
169 info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
170 info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
171 info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
172
173 info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
174 info.subresourceRange.baseMipLevel = 0;
175 info.subresourceRange.levelCount = 1;
176 info.subresourceRange.baseArrayLayer = 0;
177 info.subresourceRange.layerCount = 1;
178
180
182 DEBUGUTILS_SETOBJECTNAME(VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast<uint64_t>(
m_VulkanState.m_SwapChainImageViews[i]),
m_VulkanState.m_Device, "SwapChainImageView")
183 }
184
188 {
192 VkSamplerCreateInfo samplerInfo{};
193 samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
194 samplerInfo.magFilter = VK_FILTER_LINEAR;
195 samplerInfo.minFilter = VK_FILTER_LINEAR;
196 samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
197 samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
198 samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
199 samplerInfo.anisotropyEnable = VK_TRUE;
200
201 VkPhysicalDeviceProperties properties{};
203
204 samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
205 samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
206 samplerInfo.unnormalizedCoordinates = VK_FALSE;
207 samplerInfo.compareEnable = VK_FALSE;
208 samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
209
210 samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
211 samplerInfo.mipLodBias = 0.0f;
212 samplerInfo.minLod = 0.0f;
213 samplerInfo.maxLod = static_cast<float>(0);
214
217 }
218 }
219 }
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
std::shared_ptr< VulkanDevice > m_VulkanDevice
The shared pointer of VulkanDevice.
constexpr uint32_t MaxFrameInFlight
Max In Flight Frame. 2 buffers are enough in this program.
VkSwapchainKHR m_SwapChain
std::array< VkImage, MaxFrameInFlight > m_SwapChainImages
std::array< VkSampler, MaxFrameInFlight > m_SwapChainImageSamplers
VkPhysicalDevice m_PhysicalDevice