mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-02 03:00:24 +01:00
st/mesa: don't use pipe_surface for passing information about EGLImage
Use st_egl_image instead. radeonsi doesn't like when we create a pipe_surface with PIPE_FORMAT_NV12. This fixes NV12 texturing on radeonsi using kmscube. Cc: 17.1 17.2 <mesa-stable@lists.freedesktop.org> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
parent
d50ead53b8
commit
2d62817da9
1 changed files with 50 additions and 46 deletions
|
|
@ -70,46 +70,35 @@ is_format_supported(struct pipe_screen *screen, enum pipe_format format,
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the surface of an EGLImage.
|
||||
* FIXME: I think this should operate on resources, not surfaces
|
||||
* Return the gallium texture of an EGLImage.
|
||||
*/
|
||||
static struct pipe_surface *
|
||||
st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle,
|
||||
unsigned usage, const char *error)
|
||||
static bool
|
||||
st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle,
|
||||
unsigned usage, const char *error, struct st_egl_image *out)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct pipe_screen *screen = st->pipe->screen;
|
||||
struct st_manager *smapi =
|
||||
(struct st_manager *) st->iface.st_context_private;
|
||||
struct st_egl_image stimg;
|
||||
struct pipe_surface *ps, surf_tmpl;
|
||||
|
||||
if (!smapi || !smapi->get_egl_image)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
memset(&stimg, 0, sizeof(stimg));
|
||||
if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg)) {
|
||||
memset(out, 0, sizeof(*out));
|
||||
if (!smapi->get_egl_image(smapi, (void *) image_handle, out)) {
|
||||
/* image_handle does not refer to a valid EGL image object */
|
||||
_mesa_error(ctx, GL_INVALID_VALUE, "%s(image handle not found)", error);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_format_supported(screen, stimg.format, stimg.texture->nr_samples, usage)) {
|
||||
if (!is_format_supported(screen, out->format, out->texture->nr_samples, usage)) {
|
||||
/* unable to specify a texture object using the specified EGL image */
|
||||
pipe_resource_reference(&stimg.texture, NULL);
|
||||
pipe_resource_reference(&out->texture, NULL);
|
||||
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(format not supported)", error);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
u_surface_default_template(&surf_tmpl, stimg.texture);
|
||||
surf_tmpl.format = stimg.format;
|
||||
surf_tmpl.u.tex.level = stimg.level;
|
||||
surf_tmpl.u.tex.first_layer = stimg.layer;
|
||||
surf_tmpl.u.tex.last_layer = stimg.layer;
|
||||
ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
|
||||
pipe_resource_reference(&stimg.texture, NULL);
|
||||
|
||||
return ps;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,11 +137,25 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
|
|||
GLeglImageOES image_handle)
|
||||
{
|
||||
struct st_renderbuffer *strb = st_renderbuffer(rb);
|
||||
struct pipe_surface *ps;
|
||||
struct st_egl_image stimg;
|
||||
|
||||
if (st_get_egl_image(ctx, image_handle, PIPE_BIND_RENDER_TARGET,
|
||||
"glEGLImageTargetRenderbufferStorage",
|
||||
&stimg)) {
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
struct pipe_surface *ps, surf_tmpl;
|
||||
|
||||
u_surface_default_template(&surf_tmpl, stimg.texture);
|
||||
surf_tmpl.format = stimg.format;
|
||||
surf_tmpl.u.tex.level = stimg.level;
|
||||
surf_tmpl.u.tex.first_layer = stimg.layer;
|
||||
surf_tmpl.u.tex.last_layer = stimg.layer;
|
||||
ps = pipe->create_surface(pipe, stimg.texture, &surf_tmpl);
|
||||
pipe_resource_reference(&stimg.texture, NULL);
|
||||
|
||||
if (!ps)
|
||||
return;
|
||||
|
||||
ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_RENDER_TARGET,
|
||||
"glEGLImageTargetRenderbufferStorage");
|
||||
if (ps) {
|
||||
strb->Base.Width = ps->width;
|
||||
strb->Base.Height = ps->height;
|
||||
strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
|
||||
|
|
@ -172,10 +175,10 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
|
|||
}
|
||||
|
||||
static void
|
||||
st_bind_surface(struct gl_context *ctx, GLenum target,
|
||||
struct gl_texture_object *texObj,
|
||||
struct gl_texture_image *texImage,
|
||||
struct pipe_surface *ps)
|
||||
st_bind_egl_image(struct gl_context *ctx,
|
||||
struct gl_texture_object *texObj,
|
||||
struct gl_texture_image *texImage,
|
||||
struct st_egl_image *stimg)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct st_texture_object *stObj;
|
||||
|
|
@ -184,7 +187,8 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
|
|||
mesa_format texFormat;
|
||||
|
||||
/* map pipe format to base format */
|
||||
if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
|
||||
if (util_format_get_component_bits(stimg->format,
|
||||
UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
|
||||
internalFormat = GL_RGBA;
|
||||
else
|
||||
internalFormat = GL_RGB;
|
||||
|
|
@ -198,13 +202,13 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
|
|||
stObj->surface_based = GL_TRUE;
|
||||
}
|
||||
|
||||
texFormat = st_pipe_format_to_mesa_format(ps->format);
|
||||
texFormat = st_pipe_format_to_mesa_format(stimg->format);
|
||||
|
||||
/* TODO RequiredTextureImageUnits should probably be reset back
|
||||
* to 1 somewhere if different texture is bound??
|
||||
*/
|
||||
if (texFormat == MESA_FORMAT_NONE) {
|
||||
switch (ps->format) {
|
||||
switch (stimg->format) {
|
||||
case PIPE_FORMAT_NV12:
|
||||
texFormat = MESA_FORMAT_R_UNORM8;
|
||||
texObj->RequiredTextureImageUnits = 2;
|
||||
|
|
@ -219,15 +223,15 @@ st_bind_surface(struct gl_context *ctx, GLenum target,
|
|||
}
|
||||
|
||||
_mesa_init_teximage_fields(ctx, texImage,
|
||||
ps->width, ps->height, 1, 0, internalFormat,
|
||||
texFormat);
|
||||
stimg->texture->width0, stimg->texture->height0,
|
||||
1, 0, internalFormat, texFormat);
|
||||
|
||||
/* FIXME create a non-default sampler view from the pipe_surface? */
|
||||
pipe_resource_reference(&stObj->pt, ps->texture);
|
||||
/* FIXME create a non-default sampler view from the stimg? */
|
||||
pipe_resource_reference(&stObj->pt, stimg->texture);
|
||||
st_texture_release_all_sampler_views(st, stObj);
|
||||
pipe_resource_reference(&stImage->pt, stObj->pt);
|
||||
|
||||
stObj->surface_format = ps->format;
|
||||
stObj->surface_format = stimg->format;
|
||||
|
||||
_mesa_dirty_texobj(ctx, texObj);
|
||||
}
|
||||
|
|
@ -238,14 +242,14 @@ st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target,
|
|||
struct gl_texture_image *texImage,
|
||||
GLeglImageOES image_handle)
|
||||
{
|
||||
struct pipe_surface *ps;
|
||||
struct st_egl_image stimg;
|
||||
|
||||
ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW,
|
||||
"glEGLImageTargetTexture2D");
|
||||
if (ps) {
|
||||
st_bind_surface(ctx, target, texObj, texImage, ps);
|
||||
pipe_surface_reference(&ps, NULL);
|
||||
}
|
||||
if (!st_get_egl_image(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW,
|
||||
"glEGLImageTargetTexture2D", &stimg))
|
||||
return;
|
||||
|
||||
st_bind_egl_image(ctx, texObj, texImage, &stimg);
|
||||
pipe_resource_reference(&stimg.texture, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue