Commit b1d6624d authored by kylechar's avatar kylechar Committed by Commit Bot

Reset texture sampling params before draw

This fixes an issue where textures sampling parameters are incorrect
when there is a concurrent read of the texture. For example when an
upscaled video texture is read back to draw to a canvas, the texture
will end up pixelated some frames and smooth in others.
GL_TEXTURE_MAG_FILTER is expected to be GL_LINEAR but it's changed to
GL_NEAREST for readback and not reset.

There is no way to know if a concurrent read happened in Chrome today so
we have to always reset GL texture parameters to avoid it. For
GLRenderer always resetting the sampling parameters when binding the
texture fixes the provided examples. With SkiaRenderer texture
parameters are reset right after BeginAccess() is called on the texture.

Bug: 1092080
Change-Id: I968202f3dfff8c3c300c7e98583c55aca8639f81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431550Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826358}
parent 533b09e8
......@@ -586,11 +586,12 @@ GLenum DisplayResourceProvider::BindForSampling(ResourceId resource_id,
ScopedSetActiveTexture scoped_active_tex(gl, unit);
GLenum target = resource->transferable.mailbox_holder.texture_target;
gl->BindTexture(target, resource->gl_id);
if (filter != resource->filter) {
gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
resource->filter = filter;
}
// Texture parameters can be modified by concurrent reads so reset them
// before binding the texture. See https://crbug.com/1092080.
gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
resource->filter = filter;
return target;
}
......
......@@ -905,6 +905,9 @@ void SkiaOutputSurfaceImplOnGpu::BeginAccessImages(
std::vector<GrBackendSemaphore>* end_semaphores) {
TRACE_EVENT0("viz", "SkiaOutputSurfaceImplOnGpu::BeginAccessImages");
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
bool is_gl = gpu_preferences_.gr_context_type == gpu::GrContextType::kGL;
for (auto* context : image_contexts) {
// Prepare for accessing render pass.
if (context->render_pass_id()) {
......@@ -924,6 +927,14 @@ void SkiaOutputSurfaceImplOnGpu::BeginAccessImages(
dependency_->GetMailboxManager(), begin_semaphores, end_semaphores);
if (context->end_access_state())
image_contexts_with_end_access_state_.emplace(context);
// Texture parameters can be modified by concurrent reads so reset them
// before compositing from the texture. See https://crbug.com/1092080.
if (is_gl) {
GrBackendTexture backend_texture =
context->promise_image_texture()->backendTexture();
backend_texture.glTextureParametersModified();
}
}
}
}
......
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