Commit 05883935 authored by Le Hoang Quyen's avatar Le Hoang Quyen Committed by Commit Bot

Fix incorrect 2D YUV textures decoding.

- yuv_to_rgb_converter.cc was only able to correctly handle rectangle
  YUV textures (GL_TEXTURE_RECTANGLE_ARB). However, it couldn't handle
  GL_TEXTURE_2D textures correctly (The Metal backend uses GL_TEXTURE_2D
  for IOSurface unlike the default OpenGL backend).

- The shaders code as well as the OpenGL code were assuming the textures
  are rectangle whereas the 2D scenarios hadn't been tested properly.
  For example, the OpenGL code always passed texture size to
  "a_texScale" uniform to scale the texcoords, regardless of the texture
  being rectangle or 2D. In 2D fragment shader, the texcoords for UV
  texture were reduced by half as if the texcoords are for rectangle
  texture.

- Furthermore, when binding IOSurface to 2D textures, the code forgot
  to disable mipmap filtering. Because by default 2D textures have
  mipmap filtering enabled, and IOSurface bound textures don't have
  mipmap, this led to the YUV textures were reported as incomplete by
  OpenGL. Thus decoding wouldn't be able to sample real results from the
  YUV textures.

Bug: angleproject:4846
Bug: angleproject:2634
Bug: 1122432
Change-Id: Ie43b755c19b3dc149ddca3d68c381fee99479c00
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2378407
Commit-Queue: Le Hoang Quyen <le.hoang.q@gmail.com>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarYuly Novikov <ynovikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804299}
parent b1917744
......@@ -600,6 +600,7 @@ Laszlo Radanyi <bekkra@gmail.com>
Lauren Yeun Kim <lauren.yeun.kim@gmail.com>
Lauri Oherd <lauri.oherd@gmail.com>
Lavar Askew <open.hyperion@gmail.com>
Le Hoang Quyen <le.hoang.q@gmail.com>
Legend Lee <guanxian.li@intel.com>
Leith Bade <leith@leithalweapon.geek.nz>
Lei Li <lli.kernel.kvm@gmail.com>
......
......@@ -848,9 +848,7 @@ crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/ext
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/ext-sRGB.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/oes-texture-float-linear.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/oes-texture-float-with-canvas.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/oes-texture-float-with-video.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/oes-texture-float.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/oes-texture-half-float-with-video.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/extensions/webgl-draw-buffers.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/glsl/functions/glsl-function-distance.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/glsl/misc/shader-varying-packing-restrictions.html [ Failure ]
......@@ -876,13 +874,6 @@ crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_canvas/tex-2d-rgb-rgb-unsigned_short_5_6_5.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_canvas/tex-2d-rgba-rgba-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_canvas/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-luminance-luminance-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-luminance_alpha-luminance_alpha-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-rgb-rgb-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-rgb-rgb-unsigned_short_5_6_5.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-rgba-rgba-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/image_bitmap_from_video/tex-2d-rgba-rgba-unsigned_short_5_5_5_1.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/canvas-teximage-after-multiple-drawimages.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/gl-pixelstorei.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/tex-image-webgl.html [ Failure ]
......@@ -894,17 +885,11 @@ crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/texture-npot-video.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/texture-npot.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/misc/texture-video-transparent.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-luminance-luminance-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-luminance_alpha-luminance_alpha-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-rgb-rgb-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-rgb-rgb-unsigned_short_5_6_5.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-rgba-rgba-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/video/tex-2d-rgba-rgba-unsigned_short_5_5_5_1.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/webgl_canvas/tex-2d-luminance-luminance-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/webgl_canvas/tex-2d-luminance_alpha-luminance_alpha-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/webgl_canvas/tex-2d-rgb-rgb-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/textures/webgl_canvas/tex-2d-rgb-rgb-unsigned_short_5_6_5.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough ] conformance/uniforms/out-of-bounds-uniform-array-access.html [ Failure ]
# Mac/Metal/Intel
......@@ -920,7 +905,6 @@ crbug.com/angleproject/4846 [ mac metal passthrough amd ] conformance/attribs/gl
crbug.com/angleproject/4846 [ mac metal passthrough amd ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough amd ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough amd ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_short_5_5_5_1.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough amd ] conformance/uniforms/out-of-bounds-uniform-array-access.html [ Failure ]
# Mac/Metal/Nvidia
......@@ -930,5 +914,4 @@ crbug.com/angleproject/4846 [ mac metal passthrough nvidia ] conformance/texture
crbug.com/angleproject/4846 [ mac metal passthrough nvidia ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_byte.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough nvidia ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough nvidia ] conformance/textures/webgl_canvas/tex-2d-rgba-rgba-unsigned_short_5_5_5_1.html [ Failure ]
crbug.com/angleproject/4846 [ mac metal passthrough nvidia ] conformance/uniforms/out-of-bounds-uniform-array-access.html [ Failure ]
......@@ -302,6 +302,12 @@ bool GLImageIOSurfaceEGL::CopyTexImage(unsigned target) {
return false;
}
// Disable mipmap filtering since iosurface doesn't have mipmap. Rectangle
// textures have mipmap disabled by default but other types of texture don't.
glTexParameteri(target_gl, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target_gl, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target_gl, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
const EGLint texture_type =
format_ == gfx::BufferFormat::P010 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE;
......@@ -339,6 +345,10 @@ bool GLImageIOSurfaceEGL::CopyTexImage(unsigned target) {
return false;
}
glTexParameteri(target_gl, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(target_gl, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(target_gl, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// clang-format off
const EGLint uvAttribs[] = {
EGL_WIDTH, size_.width() / 2,
......
......@@ -97,7 +97,7 @@ STRINGIZE(
void main() {
vec3 yuv = vec3(
TEX(a_y_texture, v_texCoord).r,
TEX(a_uv_texture, v_texCoord * 0.5).rg);
TEX(a_uv_texture, v_texCoord).rg);
FRAGCOLOR = vec4(DoColorConversion(yuv), 1.0);
}
);
......@@ -249,7 +249,11 @@ void YUVToRGBConverter::CopyYUV420ToRGB(unsigned target,
DCHECK_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
glCheckFramebufferStatusEXT(GL_FRAMEBUFFER));
ScopedUseProgram use_program(program_);
glUniform2f(size_location_, size.width(), size.height());
if (source_texture_target_ == GL_TEXTURE_RECTANGLE_ARB) {
glUniform2f(size_location_, size.width(), size.height());
} else {
glUniform2f(size_location_, 1, 1);
}
// User code may have set up the other vertex attributes in the
// context in unexpected ways, including setting vertex attribute
// divisors which may otherwise cause GL_INVALID_OPERATION during
......
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