ETC2 Image decompression and sampling

The ETC2 decoder already existed in SwiftShader, so this cl hooks it
up in vk::Image. In order to be transparent to the user, any time a
compressed image is created, another image is simultaneously created,
which will eventually contain the decompressed image.

Bug b/119620767

Tests: dEQP-VK.pipeline.sampler.view_type.2d.format.etc2_r8g8b8a1_unorm_block.*
Tests: dEQP-VK.pipeline.sampler.view_type.2d.format.etc2_r8g8b8a8_unorm_block.*
Tests: dEQP-VK.pipeline.sampler.view_type.2d.format.eac_r11g11_unorm_block.*

Change-Id: I8bfdccccd9cad30e5b707ba82aac2b581ec2a90e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29428
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkImageView.cpp b/src/Vulkan/VkImageView.cpp
index 23f79c8..9abefd6 100644
--- a/src/Vulkan/VkImageView.cpp
+++ b/src/Vulkan/VkImageView.cpp
@@ -171,7 +171,46 @@
 	image->copyTo(*(resolveAttachment->image), region);
 }
 
-void *ImageView::getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer) const
+const Image* ImageView::getImage(Usage usage) const
+{
+	switch(usage)
+	{
+	case RAW:
+		return image;
+	case SAMPLING:
+		return image->getSampledImage();
+	default:
+		UNIMPLEMENTED("usage %d", int(usage));
+		return nullptr;
+	}
+}
+
+Format ImageView::getFormat(Usage usage) const
+{
+	return ((usage == RAW) || (getImage(usage) == image)) ? format : getImage(usage)->getFormat();
+}
+
+int ImageView::rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel, Usage usage) const
+{
+	return getImage(usage)->rowPitchBytes(aspect, subresourceRange.baseMipLevel + mipLevel);
+}
+
+int ImageView::slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel, Usage usage) const
+{
+	return getImage(usage)->slicePitchBytes(aspect, subresourceRange.baseMipLevel + mipLevel);
+}
+
+int ImageView::layerPitchBytes(VkImageAspectFlagBits aspect, Usage usage) const
+{
+	return static_cast<int>(getImage(usage)->getLayerSize(aspect));
+}
+
+VkExtent3D ImageView::getMipLevelExtent(uint32_t mipLevel) const
+{
+	return image->getMipLevelExtent(subresourceRange.baseMipLevel + mipLevel);
+}
+
+void *ImageView::getOffsetPointer(const VkOffset3D& offset, VkImageAspectFlagBits aspect, uint32_t mipLevel, uint32_t layer, Usage usage) const
 {
 	ASSERT(mipLevel < subresourceRange.levelCount);
 
@@ -182,7 +221,7 @@
 		subresourceRange.baseArrayLayer + layer,
 		subresourceRange.layerCount
 	};
-	return image->getTexelPointer(offset, imageSubresourceLayers);
+	return getImage(usage)->getTexelPointer(offset, imageSubresourceLayers);
 }
 
 }