Commit 5f71fdf3 by Nicolas Capens Committed by Nicolas Capens

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/+/48268Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 8c0e550c
......@@ -289,7 +289,8 @@ void DescriptorSetLayout::WriteDescriptorSet(Device *device, DescriptorSet *dstS
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();
......
......@@ -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 @@ VkComponentMapping ResolveComponentMapping(VkComponentMapping m, vk::Format form
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 @@ VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange ran
};
}
} // anonymous namespace
namespace vk {
Identifier::Identifier(const Image *image, VkImageViewType type, VkFormat fmt, VkComponentMapping mapping)
{
imageViewType = type;
......
......@@ -132,16 +132,9 @@ public:
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment