Fix component swizzle for uniform texel buffers

Unlike image views, buffer views don't have a component mapping field,
so we were setting the mapping to identity swizzles for uniform texel
buffers. However, we also use the component mapping for assigning 0 or 1
to components not provided by the texel format:
https://swiftshader-review.googlesource.com/c/SwiftShader/+/31388

This change ensures we still get the 0 and 1 in the desired channels for
uniform texel buffers.

Bug: b/168052622
Test: dEQP-VK.texture.texel_buffer.uniform.packed.b10g11r11-ufloat-pack32
Change-Id: I40885f998a53e371e1e2358ed197fc3446916d8c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48268
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkDescriptorSetLayout.cpp b/src/Vulkan/VkDescriptorSetLayout.cpp
index 19615a5..f8a1c24 100644
--- a/src/Vulkan/VkDescriptorSetLayout.cpp
+++ b/src/Vulkan/VkDescriptorSetLayout.cpp
@@ -289,7 +289,8 @@
 
 			sampledImage[i].type = VK_IMAGE_VIEW_TYPE_1D;
 			sampledImage[i].imageViewId = bufferView->id;
-			sampledImage[i].swizzle = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
+			constexpr VkComponentMapping identityMapping = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
+			sampledImage[i].swizzle = ResolveComponentMapping(identityMapping, bufferView->getFormat());
 			sampledImage[i].format = bufferView->getFormat();
 
 			auto numElements = bufferView->getElementCount();
diff --git a/src/Vulkan/VkImageView.cpp b/src/Vulkan/VkImageView.cpp
index f789770..0a51516 100644
--- a/src/Vulkan/VkImageView.cpp
+++ b/src/Vulkan/VkImageView.cpp
@@ -19,11 +19,21 @@
 
 #include <climits>
 
-namespace {
+namespace vk {
 
-VkComponentMapping ResolveComponentMapping(VkComponentMapping m, vk::Format format)
+VkComponentMapping ResolveIdentityMapping(VkComponentMapping mapping)
 {
-	m = vk::ResolveIdentityMapping(m);
+	return {
+		(mapping.r == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_R : mapping.r,
+		(mapping.g == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_G : mapping.g,
+		(mapping.b == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_B : mapping.b,
+		(mapping.a == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_A : mapping.a,
+	};
+}
+
+VkComponentMapping ResolveComponentMapping(VkComponentMapping mapping, vk::Format format)
+{
+	mapping = vk::ResolveIdentityMapping(mapping);
 
 	// Replace non-present components with zero/one swizzles so that the sampler
 	// will give us correct interactions between channel replacement and texel replacement,
@@ -39,7 +49,7 @@
 		format.componentCount() < 4 ? VK_COMPONENT_SWIZZLE_ONE : VK_COMPONENT_SWIZZLE_A,
 	};
 
-	return { table[m.r], table[m.g], table[m.b], table[m.a] };
+	return { table[mapping.r], table[mapping.g], table[mapping.b], table[mapping.a] };
 }
 
 VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange range, const vk::Image *image)
@@ -53,10 +63,6 @@
 	};
 }
 
-}  // anonymous namespace
-
-namespace vk {
-
 Identifier::Identifier(const Image *image, VkImageViewType type, VkFormat fmt, VkComponentMapping mapping)
 {
 	imageViewType = type;
diff --git a/src/Vulkan/VkImageView.hpp b/src/Vulkan/VkImageView.hpp
index 1839cf2..bba9a37 100644
--- a/src/Vulkan/VkImageView.hpp
+++ b/src/Vulkan/VkImageView.hpp
@@ -132,16 +132,9 @@
 	const Identifier id;
 };
 
-// TODO(b/132437008): Also used by SamplerYcbcrConversion. Move somewhere centrally?
-inline VkComponentMapping ResolveIdentityMapping(VkComponentMapping m)
-{
-	return {
-		(m.r == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_R : m.r,
-		(m.g == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_G : m.g,
-		(m.b == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_B : m.b,
-		(m.a == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_A : m.a,
-	};
-}
+VkComponentMapping ResolveIdentityMapping(VkComponentMapping mapping);
+VkComponentMapping ResolveComponentMapping(VkComponentMapping mapping, vk::Format format);
+VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange range, const vk::Image *image);
 
 static inline ImageView *Cast(VkImageView object)
 {