Commit 62ad1eeb by Alexis Hetu Committed by Alexis Hétu

Allow ImageView to cast compressed texture into other formats

If an image is created with flags including the VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT bit, then the compressed image may be used with an image view which has an uncompressed format that is size-compatible with the image's compressed format. Tests: dEQP-VK.image.texel_view_compatible.*.texture_read.e* Bug b/119620767 Change-Id: Ia1af959780af12e9014f7852aaf991d313f75bf1 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31620Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Presubmit-Ready: Alexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 327e488a
...@@ -706,6 +706,21 @@ VkDeviceSize Image::getStorageSize(VkImageAspectFlags aspectMask) const ...@@ -706,6 +706,21 @@ VkDeviceSize Image::getStorageSize(VkImageAspectFlags aspectMask) const
return arrayLayers * getLayerSize(static_cast<VkImageAspectFlagBits>(aspectMask)); return arrayLayers * getLayerSize(static_cast<VkImageAspectFlagBits>(aspectMask));
} }
const Image* Image::getSampledImage(const vk::Format& imageViewFormat) const
{
bool isImageViewCompressed = imageViewFormat.isCompressed();
if(decompressedImage && !isImageViewCompressed)
{
ASSERT(flags & VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT);
ASSERT(format.bytesPerBlock() == imageViewFormat.bytesPerBlock());
}
// If the ImageView's format is compressed, then we do need to decompress the image so that
// it may be sampled properly by texture sampling functions, which don't support compressed
// textures. If the ImageView's format is NOT compressed, then we reinterpret cast the
// compressed image into the ImageView's format, so we must return the compressed image as is.
return (decompressedImage && isImageViewCompressed) ? decompressedImage : this;
}
void Image::blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter) void Image::blit(VkImage dstImage, const VkImageBlit& region, VkFilter filter)
{ {
device->getBlitter()->blit(this, Cast(dstImage), region, filter); device->getBlitter()->blit(this, Cast(dstImage), region, filter);
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
VkDeviceSize getLayerSize(VkImageAspectFlagBits aspect) const; VkDeviceSize getLayerSize(VkImageAspectFlagBits aspect) const;
void prepareForSampling(const VkImageSubresourceRange& subresourceRange); void prepareForSampling(const VkImageSubresourceRange& subresourceRange);
const Image* getSampledImage() const { return decompressedImage ? decompressedImage : this; } const Image* getSampledImage(const vk::Format& imageViewFormat) const;
static Format GetFormat(const vk::Format& format, VkImageAspectFlagBits aspect); static Format GetFormat(const vk::Format& format, VkImageAspectFlagBits aspect);
......
...@@ -192,7 +192,7 @@ const Image* ImageView::getImage(Usage usage) const ...@@ -192,7 +192,7 @@ const Image* ImageView::getImage(Usage usage) const
case RAW: case RAW:
return image; return image;
case SAMPLING: case SAMPLING:
return image->getSampledImage(); return image->getSampledImage(format);
default: default:
UNIMPLEMENTED("usage %d", int(usage)); UNIMPLEMENTED("usage %d", int(usage));
return nullptr; return nullptr;
......
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