Commit 10186cb8 by Chris Forbes

Override imageview swizzles for channel replacement edge cases

When we decompress ETC2 RGB into a 4-channel texture, *almost* everything just works as long as we ensure the alpha channel has the correct values -- except that to the sampler, this is now a 4-channel texture and so no channel replacement will be performed. This interacts badly with border texel replacement, which occurs before channel replacement. When a transparent border mode is used, we end up with non-1 values in the returned alpha channel, which is wrong. Instead, drive missing channels to 0/1 with the swizzle, which we control independently of the texture format. Bug: b/119620767 Test: dEQP-VK.pipeline.sampler.* Change-Id: I2816e18fc1c36bd4de51a3e3871c75c7dc1b8867 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31388Tested-by: 's avatarChris Forbes <chrisforbes@google.com> Presubmit-Ready: Chris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 4d4a190b
...@@ -17,14 +17,28 @@ ...@@ -17,14 +17,28 @@
namespace namespace
{ {
VkComponentMapping ResolveIdentityMapping(VkComponentMapping m) VkComponentMapping ResolveComponentMapping(VkComponentMapping m, vk::Format format)
{ {
return { if (m.r == VK_COMPONENT_SWIZZLE_IDENTITY) m.r = VK_COMPONENT_SWIZZLE_R;
(m.r == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_R : m.r, if (m.g == VK_COMPONENT_SWIZZLE_IDENTITY) m.g = VK_COMPONENT_SWIZZLE_G;
(m.g == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_G : m.g, if (m.b == VK_COMPONENT_SWIZZLE_IDENTITY) m.b = VK_COMPONENT_SWIZZLE_B;
(m.b == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_B : m.b, if (m.a == VK_COMPONENT_SWIZZLE_IDENTITY) m.a = VK_COMPONENT_SWIZZLE_A;
(m.a == VK_COMPONENT_SWIZZLE_IDENTITY) ? VK_COMPONENT_SWIZZLE_A : m.a,
// Replace non-present components with zero/one swizzles so that the sampler
// will give us correct interactions between channel replacement and texel replacement,
// where we've had to invent new channels behind the app's back (eg transparent decompression
// of ETC2 RGB -> BGRA8)
VkComponentSwizzle table[] = {
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_ZERO,
VK_COMPONENT_SWIZZLE_ONE,
VK_COMPONENT_SWIZZLE_R,
format.componentCount() < 2 ? VK_COMPONENT_SWIZZLE_ZERO : VK_COMPONENT_SWIZZLE_G,
format.componentCount() < 3 ? VK_COMPONENT_SWIZZLE_ZERO : VK_COMPONENT_SWIZZLE_B,
format.componentCount() < 4 ? VK_COMPONENT_SWIZZLE_ONE : VK_COMPONENT_SWIZZLE_A,
}; };
return {table[m.r], table[m.g], table[m.b], table[m.a]};
} }
VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange range, const vk::Image *image) VkImageSubresourceRange ResolveRemainingLevelsLayers(VkImageSubresourceRange range, const vk::Image *image)
...@@ -46,7 +60,7 @@ std::atomic<uint32_t> ImageView::nextID(1); ...@@ -46,7 +60,7 @@ std::atomic<uint32_t> ImageView::nextID(1);
ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) : ImageView::ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem) :
image(Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format), image(Cast(pCreateInfo->image)), viewType(pCreateInfo->viewType), format(pCreateInfo->format),
components(ResolveIdentityMapping(pCreateInfo->components)), components(ResolveComponentMapping(pCreateInfo->components, format)),
subresourceRange(ResolveRemainingLevelsLayers(pCreateInfo->subresourceRange, image)) subresourceRange(ResolveRemainingLevelsLayers(pCreateInfo->subresourceRange, image))
{ {
} }
......
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