Преглед изворни кода

Fix a bug in texture view creation

Panagiotis Christopoulos Charitos пре 6 година
родитељ
комит
d879c8a49f
2 измењених фајлова са 20 додато и 10 уклоњено
  1. 18 0
      src/anki/gr/vulkan/TextureImpl.cpp
  2. 2 10
      src/anki/gr/vulkan/TextureImpl.h

+ 18 - 0
src/anki/gr/vulkan/TextureImpl.cpp

@@ -708,4 +708,22 @@ const MicroImageView& TextureImpl::getOrCreateView(const TextureSubresourceInfo&
 	return *it;
 }
 
+TextureType TextureImpl::computeNewTexTypeOfSubresource(const TextureSubresourceInfo& subresource) const
+{
+	ANKI_ASSERT(isSubresourceValid(subresource));
+	if(textureTypeIsCube(m_texType))
+	{
+		if(subresource.m_faceCount != 6)
+		{
+			ANKI_ASSERT(subresource.m_faceCount == 1);
+			return (subresource.m_layerCount > 1) ? TextureType::_2D_ARRAY : TextureType::_2D;
+		}
+		else if(subresource.m_layerCount == 1)
+		{
+			return TextureType::CUBE;
+		}
+	}
+	return m_texType;
+}
+
 } // end namespace anki

+ 2 - 10
src/anki/gr/vulkan/TextureImpl.h

@@ -174,11 +174,7 @@ public:
 
 		// Fixup the image view type
 		newTextureType = computeNewTexTypeOfSubresource(subresource);
-		if(newTextureType == TextureType::_2D)
-		{
-			// Change that anyway
-			viewCi.viewType = VK_IMAGE_VIEW_TYPE_2D;
-		}
+		viewCi.viewType = convertTextureViewType(newTextureType);
 	}
 
 	const MicroImageView& getOrCreateView(const TextureSubresourceInfo& subresource) const;
@@ -209,11 +205,7 @@ private:
 	void updateUsageState(TextureUsageBit usage, StackAllocator<U8>& alloc, TextureUsageState& state) const;
 
 	/// Compute the new type of a texture view.
-	TextureType computeNewTexTypeOfSubresource(const TextureSubresourceInfo& subresource) const
-	{
-		ANKI_ASSERT(isSubresourceValid(subresource));
-		return (textureTypeIsCube(m_texType) && subresource.m_faceCount != 6) ? TextureType::_2D : m_texType;
-	}
+	TextureType computeNewTexTypeOfSubresource(const TextureSubresourceInfo& subresource) const;
 
 	ANKI_USE_RESULT Error initInternal(VkImage externalImage, const TextureInitInfo& init);
 };