Commit 0116a99c by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Emulate Luminance/Alpha with R8G8B8A8

TextureVk::copySubTextureImpl uses the format's pixelReadFunction and pixelWriteFunction and was using the angle format (i.e. the format the texture was created with) instead of the texture format (i.e. the actual format used by the backend) to read and write pixels. This was specifically to make Luminance/Alpha formats work. However, this was incorrect for any emulated format. This commit fixes the function to use the texture format. To avoid issues with Luminance/Alpha, this commit patches the pixel read/write changes for these formats before using them. Bug: angleproject:2913 Change-Id: I8981882b98502d869156a879bb7b5994943ecd8e Reviewed-on: https://chromium-review.googlesource.com/c/1330261Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent e4634a13
......@@ -643,13 +643,13 @@ angle::Result TextureVk::copySubTextureImpl(ContextVk *contextVk,
uint8_t *sourceData = nullptr;
ANGLE_TRY(source->copyImageDataToBuffer(contextVk, sourceLevel, 1, sourceArea, &sourceData));
// Using the front-end ANGLE format for the colorRead and colorWrite functions. Otherwise
// emulated formats like luminance-alpha would not know how to interpret the data.
const angle::Format &sourceAngleFormat = source->getImage().getFormat().angleFormat();
const angle::Format &destAngleFormat =
renderer->getFormat(destFormat.sizedInternalFormat).angleFormat();
const vk::Format &sourceVkFormat = source->getImage().getFormat();
const vk::Format &destVkFormat = renderer->getFormat(destFormat.sizedInternalFormat);
const angle::Format &sourceTextureFormat = sourceVkFormat.textureFormat();
const angle::Format &destTextureFormat = destVkFormat.textureFormat();
size_t destinationAllocationSize =
sourceArea.width * sourceArea.height * destAngleFormat.pixelBytes;
sourceArea.width * sourceArea.height * destTextureFormat.pixelBytes;
// Allocate memory in the destination texture for the copy/conversion
uint8_t *destData = nullptr;
......@@ -658,14 +658,30 @@ angle::Result TextureVk::copySubTextureImpl(ContextVk *contextVk,
gl::Extents(sourceArea.width, sourceArea.height, 1), destOffset, &destData));
// Source and dest data is tightly packed
GLuint sourceDataRowPitch = sourceArea.width * sourceAngleFormat.pixelBytes;
GLuint destDataRowPitch = sourceArea.width * destAngleFormat.pixelBytes;
CopyImageCHROMIUM(sourceData, sourceDataRowPitch, sourceAngleFormat.pixelBytes, 0,
sourceAngleFormat.pixelReadFunction, destData, destDataRowPitch,
destAngleFormat.pixelBytes, 0, destAngleFormat.pixelWriteFunction,
destFormat.format, destFormat.componentType, sourceArea.width,
sourceArea.height, 1, unpackFlipY, unpackPremultiplyAlpha,
GLuint sourceDataRowPitch = sourceArea.width * sourceTextureFormat.pixelBytes;
GLuint destDataRowPitch = sourceArea.width * destTextureFormat.pixelBytes;
rx::PixelReadFunction pixelReadFunction = sourceTextureFormat.pixelReadFunction;
rx::PixelWriteFunction pixelWriteFunction = destTextureFormat.pixelWriteFunction;
// Fix up the read/write functions for the sake of luminance/alpha that are emulated with
// formats whose channels don't correspond to the original format (alpha is emulated with red,
// and luminance/alpha is emulated with red/green).
GLenum sourceInternalFormat = sourceVkFormat.internalFormat;
GLenum destInternalFormat = destVkFormat.internalFormat;
if (gl::GetSizedInternalFormatInfo(sourceInternalFormat).isLUMA())
{
pixelReadFunction = sourceVkFormat.angleFormat().pixelReadFunction;
}
if (gl::GetSizedInternalFormatInfo(destInternalFormat).isLUMA())
{
pixelWriteFunction = destVkFormat.angleFormat().pixelWriteFunction;
}
CopyImageCHROMIUM(sourceData, sourceDataRowPitch, sourceTextureFormat.pixelBytes, 0,
pixelReadFunction, destData, destDataRowPitch, destTextureFormat.pixelBytes,
0, pixelWriteFunction, destFormat.format, destFormat.componentType,
sourceArea.width, sourceArea.height, 1, unpackFlipY, unpackPremultiplyAlpha,
unpackUnmultiplyAlpha);
// Create a new graph node to store image initialization commands.
......
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