@@ -3851,6 +3851,16 @@ lvk::Holder<lvk::TextureHandle> lvk::VulkanContext::createTexture(const TextureD
38513851 image.imageView_ = image.createImageView (
38523852 vkDevice_, vkImageViewType, vkFormat, aspect, 0 , VK_REMAINING_MIP_LEVELS, 0 , numLayers, mapping, ycbcrInfo, debugNameImageView);
38533853
3854+ if (image.vkUsageFlags_ & VK_IMAGE_USAGE_STORAGE_BIT) {
3855+ if (desc.swizzle .r != Swizzle_Default || desc.swizzle .g != Swizzle_Default || desc.swizzle .b != Swizzle_Default ||
3856+ desc.swizzle .a != Swizzle_Default) {
3857+ // use identity swizzle for storage images
3858+ image.imageViewStorage_ = image.createImageView (
3859+ vkDevice_, vkImageViewType, vkFormat, aspect, 0 , VK_REMAINING_MIP_LEVELS, 0 , numLayers, {}, ycbcrInfo, debugNameImageView);
3860+ LVK_ASSERT (image.imageViewStorage_ != VK_NULL_HANDLE);
3861+ }
3862+ }
3863+
38543864 if (!LVK_VERIFY (image.imageView_ != VK_NULL_HANDLE)) {
38553865 Result::setResult (outResult, Result::Code::RuntimeError, " Cannot create VkImageView" );
38563866 return {};
@@ -4914,6 +4924,10 @@ void lvk::VulkanContext::destroy(lvk::TextureHandle handle) {
49144924
49154925 deferredTask (std::packaged_task<void ()>(
49164926 [device = getVkDevice (), imageView = tex->imageView_ ]() { vkDestroyImageView (device, imageView, nullptr ); }));
4927+ if (tex->imageViewStorage_ ) {
4928+ deferredTask (std::packaged_task<void ()>(
4929+ [device = getVkDevice (), imageView = tex->imageViewStorage_ ]() { vkDestroyImageView (device, imageView, nullptr ); }));
4930+ }
49174931
49184932 for (size_t i = 0 ; i != LVK_MAX_MIP_LEVELS; i++) {
49194933 for (size_t j = 0 ; j != LVK_ARRAY_NUM_ELEMENTS (tex->imageViewForFramebuffer_ [0 ]); j++) {
@@ -6544,6 +6558,7 @@ void lvk::VulkanContext::checkAndUpdateDescriptorSets() {
65446558 for (const auto & obj : texturesPool_.objects_ ) {
65456559 const VulkanImage& img = obj.obj_ ;
65466560 const VkImageView view = obj.obj_ .imageView_ ;
6561+ const VkImageView storageView = obj.obj_ .imageViewStorage_ ? obj.obj_ .imageViewStorage_ : view;
65476562 // multisampled images cannot be directly accessed from shaders
65486563 const bool isTextureAvailable = (img.vkSamples_ & VK_SAMPLE_COUNT_1_BIT) == VK_SAMPLE_COUNT_1_BIT;
65496564 const bool isYUVImage = isTextureAvailable && img.isSampledImage () && lvk::getNumImagePlanes (img.vkImageFormat_ ) > 1 ;
@@ -6557,7 +6572,7 @@ void lvk::VulkanContext::checkAndUpdateDescriptorSets() {
65576572 LVK_ASSERT (infoSampledImages.back ().imageView != VK_NULL_HANDLE);
65586573 infoStorageImages.push_back (VkDescriptorImageInfo{
65596574 .sampler = VK_NULL_HANDLE,
6560- .imageView = isStorageImage ? view : dummyImageView,
6575+ .imageView = isStorageImage ? storageView : dummyImageView,
65616576 .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
65626577 });
65636578 if (hasYcbcrSamplers) {
0 commit comments