vrend: fixup views for samplers of eglimage-backed srgb textures

Views on samplers of eglimage-backed rgb* textures cause unintended
red/blue channel-swapping due to the lack of an internalformat that
specifically for BGR* ordering. Since we have control over the
sampler's swizzle parameters, we can still use the texture view to get
automatic colorspace conversion, but need to compensate for the
unintended swizzle with our own to swizzle back. If the view intended
to swap the channels, we just leave the swizzle parameters alone.

With this approach, no shader augmentation is necessary.

Signed-off-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/725>
macos/master
Ryan Neph 3 years ago committed by Marge Bot
parent 383e034a4f
commit c956d0df75
  1. 26
      src/vrend_renderer.c

@ -2333,14 +2333,6 @@ int vrend_create_sampler_view(struct vrend_context *ctx,
swizzle[3] = tex_conv_table[view->format].swizzle[swizzle[3]];
}
if (vrend_resource_is_emulated_bgra(view->texture)) {
uint8_t temp = swizzle[0];
swizzle[0] = swizzle[2];
swizzle[2] = temp;
VREND_DEBUG(dbg_bgra, ctx, "swizzling sampler channels on %s resource: (%d %d %d %d)\n",
util_format_name(view->texture->base.format),
swizzle[0], swizzle[1], swizzle[2], swizzle[3]);
}
for (unsigned i = 0; i < 4; ++i)
view->gl_swizzle[i] = to_gl_swizzle(swizzle[i]);
@ -2383,6 +2375,24 @@ int vrend_create_sampler_view(struct vrend_context *ctx,
int max_level = (view->val1 >> 8) & 0xff;
view->levels = (max_level - base_level) + 1;
/* texture views for eglimage-backed bgr* resources are usually not
* supported since they cause unintended red/blue channel-swapping.
* Since we have control over the swizzle parameters of the sampler, we
* can just compensate in this case by swapping the red/blue channels
* back, and still benefit from automatic srgb decoding.
* If the red/blue swap is intended, we just let it happen and don't
* need to explicit change to the sampler's swizzle parameters. */
if (!vrend_resource_supports_view(view->texture, view->format) &&
vrend_format_is_bgra(view->format)) {
VREND_DEBUG(dbg_tex, ctx, "texture view with red/blue swizzle created for EGL-backed texture sampler"
" (format: %s; view: %s)\n",
util_format_name(view->texture->base.format),
util_format_name(view->format));
GLint temp = view->gl_swizzle[0];
view->gl_swizzle[0] = view->gl_swizzle[2];
view->gl_swizzle[2] = temp;
}
glTextureView(view->id, view->target, view->texture->id, internalformat,
base_level, view->levels,
base_layer, max_layer - base_layer + 1);

Loading…
Cancel
Save