From 502c1e83aba4101980d75905807da10ea4e1749c Mon Sep 17 00:00:00 2001 From: nikeinikei Date: Thu, 1 Sep 2022 16:10:10 +0200 Subject: [PATCH] vulkan: more reserved usage flags of texture --- src/modules/graphics/vulkan/Texture.cpp | 31 ++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/modules/graphics/vulkan/Texture.cpp b/src/modules/graphics/vulkan/Texture.cpp index 88ed49158..8e29a899e 100644 --- a/src/modules/graphics/vulkan/Texture.cpp +++ b/src/modules/graphics/vulkan/Texture.cpp @@ -25,37 +25,42 @@ bool Texture::loadVolatile() { auto vulkanFormat = Vulkan::getTextureFormat(format); - // fixme: can we cut down these flags? - VkImageUsageFlags usageFlags = + VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | - VK_IMAGE_USAGE_TRANSFER_DST_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | - VK_IMAGE_USAGE_STORAGE_BIT; + VK_IMAGE_USAGE_TRANSFER_DST_BIT; + + if (readable) + usageFlags |= + VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_STORAGE_BIT; + + if (isPixelFormatDepthStencil(format) || isPixelFormatDepth(format)) + usageFlags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + if (renderTarget) + usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; VkImageCreateFlags createFlags = 0; layerCount = 1; - if (texType == TEXTURE_VOLUME) { - layerCount = getDepth(); - } - else if (texType == TEXTURE_2D_ARRAY) { + + if (texType == TEXTURE_2D_ARRAY) { layerCount = getLayerCount(); } else if (texType == TEXTURE_CUBE) { layerCount = 6; createFlags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; } - + VkImageCreateInfo imageInfo{}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageInfo.flags = createFlags; imageInfo.imageType = Vulkan::getImageType(getTextureType()); imageInfo.extent.width = static_cast(pixelWidth); imageInfo.extent.height = static_cast(pixelHeight); - imageInfo.extent.depth = 1; - imageInfo.mipLevels = static_cast(getMipmapCount()); + imageInfo.extent.depth = static_cast(depth); imageInfo.arrayLayers = static_cast(layerCount); + imageInfo.mipLevels = static_cast(getMipmapCount()); imageInfo.format = vulkanFormat.internalFormat; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;