vo_gpu: hwdec_d3d11egl: adapt to newer ANGLE API

2 years ago, ANGLE removed the old NV12-specific extension, and added
a new one that supports a number of formats, including P010. Actually
they just renamed it and removed their initial annoying and obvious
design error (bravo, Google).

Since it broke 2 years ago, nobody should give a shit about this code,
and it should just be removed. But for some reason I still dived the
shit-tank (Windows development).

I guess Intel code monkeys can't write drivers (or maybe the issue is
because we're doing zero-copy, which probably maybe is not actually
allowed by D3D11 due to array textures, see --d3d11va-zero-copy), so
the P010 path is completely untested. It doesn't work, I'll delete all
this ANGLE hwdec code.

Fixes: #7054
This commit is contained in:
wm4 2019-10-16 23:07:07 +02:00
parent eaa3c1c922
commit a1c7d61393
1 changed files with 33 additions and 24 deletions

View File

@ -58,10 +58,10 @@ struct priv_owner {
EGLBoolean (EGLAPIENTRY *StreamConsumerGLTextureExternalAttribsNV) EGLBoolean (EGLAPIENTRY *StreamConsumerGLTextureExternalAttribsNV)
(EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list); (EGLDisplay dpy, EGLStreamKHR stream, EGLAttrib *attrib_list);
// EGL_ANGLE_stream_producer_d3d_texture_nv12 // EGL_ANGLE_stream_producer_d3d_texture
EGLBoolean (EGLAPIENTRY *CreateStreamProducerD3DTextureNV12ANGLE) EGLBoolean (EGLAPIENTRY *CreateStreamProducerD3DTextureANGLE)
(EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list); (EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
EGLBoolean (EGLAPIENTRY *StreamPostD3DTextureNV12ANGLE) EGLBoolean (EGLAPIENTRY *StreamPostD3DTextureANGLE)
(EGLDisplay dpy, EGLStreamKHR stream, void *texture, (EGLDisplay dpy, EGLStreamKHR stream, void *texture,
const EGLAttrib *attrib_list); const EGLAttrib *attrib_list);
}; };
@ -102,7 +102,7 @@ static int init(struct ra_hwdec *hw)
const char *exts = eglQueryString(egl_display, EGL_EXTENSIONS); const char *exts = eglQueryString(egl_display, EGL_EXTENSIONS);
if (!exts || !strstr(exts, "EGL_ANGLE_d3d_share_handle_client_buffer") || if (!exts || !strstr(exts, "EGL_ANGLE_d3d_share_handle_client_buffer") ||
!strstr(exts, "EGL_ANGLE_stream_producer_d3d_texture_nv12") || !gl_check_extension(exts, "EGL_ANGLE_stream_producer_d3d_texture") ||
!(strstr(gl->extensions, "GL_OES_EGL_image_external_essl3") || !(strstr(gl->extensions, "GL_OES_EGL_image_external_essl3") ||
gl->es == 200) || gl->es == 200) ||
!strstr(exts, "EGL_EXT_device_query") || !strstr(exts, "EGL_EXT_device_query") ||
@ -119,16 +119,16 @@ static int init(struct ra_hwdec *hw)
(void *)eglGetProcAddress("eglStreamConsumerReleaseKHR"); (void *)eglGetProcAddress("eglStreamConsumerReleaseKHR");
p->StreamConsumerGLTextureExternalAttribsNV = p->StreamConsumerGLTextureExternalAttribsNV =
(void *)eglGetProcAddress("eglStreamConsumerGLTextureExternalAttribsNV"); (void *)eglGetProcAddress("eglStreamConsumerGLTextureExternalAttribsNV");
p->CreateStreamProducerD3DTextureNV12ANGLE = p->CreateStreamProducerD3DTextureANGLE =
(void *)eglGetProcAddress("eglCreateStreamProducerD3DTextureNV12ANGLE"); (void *)eglGetProcAddress("eglCreateStreamProducerD3DTextureANGLE");
p->StreamPostD3DTextureNV12ANGLE = p->StreamPostD3DTextureANGLE =
(void *)eglGetProcAddress("eglStreamPostD3DTextureNV12ANGLE"); (void *)eglGetProcAddress("eglStreamPostD3DTextureANGLE");
if (!p->CreateStreamKHR || !p->DestroyStreamKHR || if (!p->CreateStreamKHR || !p->DestroyStreamKHR ||
!p->StreamConsumerAcquireKHR || !p->StreamConsumerReleaseKHR || !p->StreamConsumerAcquireKHR || !p->StreamConsumerReleaseKHR ||
!p->StreamConsumerGLTextureExternalAttribsNV || !p->StreamConsumerGLTextureExternalAttribsNV ||
!p->CreateStreamProducerD3DTextureNV12ANGLE || !p->CreateStreamProducerD3DTextureANGLE ||
!p->StreamPostD3DTextureNV12ANGLE) !p->StreamPostD3DTextureANGLE)
{ {
MP_ERR(hw, "Failed to load some EGLStream functions.\n"); MP_ERR(hw, "Failed to load some EGLStream functions.\n");
goto fail; goto fail;
@ -211,7 +211,15 @@ static int mapper_init(struct ra_hwdec_mapper *mapper)
struct priv *p = mapper->priv; struct priv *p = mapper->priv;
GL *gl = ra_gl_get(mapper->ra); GL *gl = ra_gl_get(mapper->ra);
if (mapper->src_params.hw_subfmt != IMGFMT_NV12) { struct ra_imgfmt_desc desc = {0};
ra_get_imgfmt_desc(mapper->ra, mapper->src_params.hw_subfmt, &desc);
// ANGLE hardcodes the list of accepted formats. This is a subset.
if ((mapper->src_params.hw_subfmt != IMGFMT_NV12 &&
mapper->src_params.hw_subfmt != IMGFMT_P010) ||
desc.num_planes < 1 || desc.num_planes > 2)
{
MP_FATAL(mapper, "Format not supported.\n"); MP_FATAL(mapper, "Format not supported.\n");
return -1; return -1;
} }
@ -223,13 +231,18 @@ static int mapper_init(struct ra_hwdec_mapper *mapper)
// The texture units need to be bound during init only, and are free for // The texture units need to be bound during init only, and are free for
// use again after the initialization here is done. // use again after the initialization here is done.
int texunits = 0; // [texunits, texunits + num_planes) int texunits = 0; // [texunits, texunits + num_planes)
int num_planes = 2; int num_planes = desc.num_planes;
int gl_target = GL_TEXTURE_EXTERNAL_OES; int gl_target = GL_TEXTURE_EXTERNAL_OES;
p->egl_stream = o->CreateStreamKHR(o->egl_display, (EGLint[]){EGL_NONE}); p->egl_stream = o->CreateStreamKHR(o->egl_display, (EGLint[]){EGL_NONE});
if (!p->egl_stream) if (!p->egl_stream)
goto fail; goto fail;
EGLAttrib attrs[(2 + 2 + 1) * 2] = {
EGL_COLOR_BUFFER_TYPE, EGL_YUV_BUFFER_EXT,
EGL_YUV_NUMBER_OF_PLANES_EXT, num_planes,
};
for (int n = 0; n < num_planes; n++) { for (int n = 0; n < num_planes; n++) {
gl->ActiveTexture(GL_TEXTURE0 + texunits + n); gl->ActiveTexture(GL_TEXTURE0 + texunits + n);
gl->GenTextures(1, &p->gl_textures[n]); gl->GenTextures(1, &p->gl_textures[n]);
@ -238,22 +251,18 @@ static int mapper_init(struct ra_hwdec_mapper *mapper)
gl->TexParameteri(gl_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl->TexParameteri(gl_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl->TexParameteri(gl_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl->TexParameteri(gl_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gl->TexParameteri(gl_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl->TexParameteri(gl_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
attrs[(2 + n) * 2 + 0] = EGL_YUV_PLANE0_TEXTURE_UNIT_NV + n;
attrs[(2 + n) * 2 + 1] = texunits + n;
} }
EGLAttrib attrs[] = { attrs[(2 + num_planes) * 2 + 0] = EGL_NONE;
EGL_COLOR_BUFFER_TYPE, EGL_YUV_BUFFER_EXT,
EGL_YUV_NUMBER_OF_PLANES_EXT, num_planes,
EGL_YUV_PLANE0_TEXTURE_UNIT_NV, texunits + 0,
EGL_YUV_PLANE1_TEXTURE_UNIT_NV, texunits + 1,
EGL_NONE,
};
if (!o->StreamConsumerGLTextureExternalAttribsNV(o->egl_display, p->egl_stream, if (!o->StreamConsumerGLTextureExternalAttribsNV(o->egl_display, p->egl_stream,
attrs)) attrs))
goto fail; goto fail;
if (!o->CreateStreamProducerD3DTextureNV12ANGLE(o->egl_display, p->egl_stream, if (!o->CreateStreamProducerD3DTextureANGLE(o->egl_display, p->egl_stream,
(EGLAttrib[]){EGL_NONE})) (EGLAttrib[]){EGL_NONE}))
goto fail; goto fail;
for (int n = 0; n < num_planes; n++) { for (int n = 0; n < num_planes; n++) {
@ -282,12 +291,12 @@ static int mapper_map(struct ra_hwdec_mapper *mapper)
EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, d3d_subindex, EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, d3d_subindex,
EGL_NONE, EGL_NONE,
}; };
if (!o->StreamPostD3DTextureNV12ANGLE(o->egl_display, p->egl_stream, if (!o->StreamPostD3DTextureANGLE(o->egl_display, p->egl_stream,
(void *)d3d_tex, attrs)) (void *)d3d_tex, attrs))
{ {
// ANGLE changed the enum ID of this without warning at one point. // ANGLE changed the enum ID of this without warning at one point.
attrs[0] = attrs[0] == 0x33AB ? 0x3AAB : 0x33AB; attrs[0] = attrs[0] == 0x33AB ? 0x3AAB : 0x33AB;
if (!o->StreamPostD3DTextureNV12ANGLE(o->egl_display, p->egl_stream, if (!o->StreamPostD3DTextureANGLE(o->egl_display, p->egl_stream,
(void *)d3d_tex, attrs)) (void *)d3d_tex, attrs))
return -1; return -1;
} }