Creates image views for Vulkan textures only when needed.

This was SVN commit r27495.
This commit is contained in:
Vladislav Belov 2023-01-26 21:38:39 +00:00
parent 6648b1b53c
commit 840dbdd6d8
3 changed files with 15 additions and 6 deletions

View File

@ -251,6 +251,8 @@ VkDescriptorSet CDescriptorManager::GetSingleTypeDescritorSet(
{ {
if (!textures[index]) if (!textures[index])
continue; continue;
ENSURE(textures[index]->GetUsage() & ITexture::Usage::SAMPLED);
VkDescriptorImageInfo descriptorImageInfo{}; VkDescriptorImageInfo descriptorImageInfo{};
descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
descriptorImageInfo.imageView = textures[index]->GetSamplerImageView(); descriptorImageInfo.imageView = textures[index]->GetSamplerImageView();
@ -282,6 +284,7 @@ uint32_t CDescriptorManager::GetUniformSet() const
uint32_t CDescriptorManager::GetTextureDescriptor(CTexture* texture) uint32_t CDescriptorManager::GetTextureDescriptor(CTexture* texture)
{ {
ENSURE(m_UseDescriptorIndexing); ENSURE(m_UseDescriptorIndexing);
ENSURE(texture->GetUsage() & ITexture::Usage::SAMPLED);
uint32_t binding = 0; uint32_t binding = 0;
if (texture->GetType() == ITexture::Type::TEXTURE_2D && if (texture->GetType() == ITexture::Type::TEXTURE_2D &&

View File

@ -61,6 +61,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
if (colorAttachment) if (colorAttachment)
{ {
CTexture* colorAttachmentTexture = colorAttachment->texture->As<CTexture>(); CTexture* colorAttachmentTexture = colorAttachment->texture->As<CTexture>();
ENSURE(colorAttachmentTexture->GetUsage() & ITexture::Usage::COLOR_ATTACHMENT);
framebuffer->m_Width = colorAttachmentTexture->GetWidth(); framebuffer->m_Width = colorAttachmentTexture->GetWidth();
framebuffer->m_Height = colorAttachmentTexture->GetHeight(); framebuffer->m_Height = colorAttachmentTexture->GetHeight();
@ -75,6 +76,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
if (depthStencilAttachment) if (depthStencilAttachment)
{ {
CTexture* depthStencilAttachmentTexture = depthStencilAttachment->texture->As<CTexture>(); CTexture* depthStencilAttachmentTexture = depthStencilAttachment->texture->As<CTexture>();
ENSURE(depthStencilAttachmentTexture->GetUsage() & ITexture::Usage::DEPTH_STENCIL_ATTACHMENT);
framebuffer->m_Width = depthStencilAttachmentTexture->GetWidth(); framebuffer->m_Width = depthStencilAttachmentTexture->GetWidth();
framebuffer->m_Height = depthStencilAttachmentTexture->GetHeight(); framebuffer->m_Height = depthStencilAttachmentTexture->GetHeight();

View File

@ -192,15 +192,19 @@ std::unique_ptr<CTexture> CTexture::Create(
imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
} }
imageViewCreateInfo.subresourceRange.aspectMask = texture->m_AttachmentImageAspectMask; if ((usage & Usage::COLOR_ATTACHMENT) || (usage & Usage::DEPTH_STENCIL_ATTACHMENT))
ENSURE_VK_SUCCESS(vkCreateImageView( {
device->GetVkDevice(), &imageViewCreateInfo, nullptr, &texture->m_AttachmentImageView)); imageViewCreateInfo.subresourceRange.aspectMask = texture->m_AttachmentImageAspectMask;
imageViewCreateInfo.subresourceRange.aspectMask = texture->m_SamplerImageAspectMask; ENSURE_VK_SUCCESS(vkCreateImageView(
ENSURE_VK_SUCCESS(vkCreateImageView( device->GetVkDevice(), &imageViewCreateInfo, nullptr, &texture->m_AttachmentImageView));
device->GetVkDevice(), &imageViewCreateInfo, nullptr, &texture->m_SamplerImageView)); }
if (usage & Usage::SAMPLED) if (usage & Usage::SAMPLED)
{ {
imageViewCreateInfo.subresourceRange.aspectMask = texture->m_SamplerImageAspectMask;
ENSURE_VK_SUCCESS(vkCreateImageView(
device->GetVkDevice(), &imageViewCreateInfo, nullptr, &texture->m_SamplerImageView));
texture->m_Sampler = device->GetSamplerManager().GetOrCreateSampler( texture->m_Sampler = device->GetSamplerManager().GetOrCreateSampler(
defaultSamplerDesc); defaultSamplerDesc);
texture->m_IsCompareEnabled = defaultSamplerDesc.compareEnabled; texture->m_IsCompareEnabled = defaultSamplerDesc.compareEnabled;