NVIDIA / egl-wayland

The EGLStream-based Wayland external platform
MIT License
275 stars 44 forks source link

cannot draw to different `EGLSurface` with the same `EGLContext` #13

Closed xeechou closed 5 years ago

xeechou commented 5 years ago

Hi,

I am currently experience the issues when eglMakeCurrent from EGL_NO_SURFACE to a valid egl surface. The intension is using the same shader to different wl_surface. While EGL_KHR_Surfaceless_context is present and I can successfully create shaders and vao, vbos, I cannot see the drawing result, however, after eglMakeCurrent from EGL_NO_SURFACE to a valid EGLSurface, I see only blank framebuffer on the screen.

This issue however does not present with Mesa implementation, so I think this is a bug with nvidia's implementation.

I hope there is a way to fix it.

Regards, sichem

mvicomoya commented 5 years ago

Hi @xeechou,

If I understand what you are trying to do correctly, your application would do something like:

  1. Make an EGL surfaceless context current
  2. Create a bunch of shaders and whatnot
  3. Make an actual EGL surface current with the same context
  4. Do some rendering

Am I correct?

That should indeed work. Have you checked you are setting the viewport and scissor regions properly after (3) ?

The EGL_KHR_surfaceless_context extension states the following:

Append to the paragraph starting "The first time an OpenGL or OpenGL
ES context is made current..." with

"If the first time <ctx> is made current, it is without a default
framebuffer (e.g. both <draw> and <read> are EGL_NO_SURFACE), then
the viewport and scissor regions are set as though
glViewport(0,0,0,0) and glScissor(0,0,0,0) were called."

Also, if you have a test app that reproduces the issue and you can share it, that would save us some time.

Thanks.

xeechou commented 5 years ago

Thanks for your reply. Yes, it is indeed what I am doing, I call glSicssor every frame. I haven't tried the glViewport though. I will update on this tomorrow.

Before I was using the real EGLSurface and I didn't experience any problem. I also checked the EGL_RENDER_BUFFER it appeared no problem, I hope it could be a simple fix with glViewPort.

xeechou commented 5 years ago

Update:

Applied glScissor and and glViewport to the application, I still got the same result. Here is my code for make current:

    app_surface->eglwin = wl_egl_window_create(app_surface->wl_surface,
                                               app_surface->w,
                                               app_surface->h);
    assert(app_surface->eglwin);
    app_surface->eglsurface =
            eglCreateWindowSurface(env->egl_display,
                                   env->config,
                                   (EGLNativeWindowType)app_surface->eglwin,
                                   NULL);
    assert(app_surface->eglsurface);
    assert(eglMakeCurrent(env->egl_display, app_surface->eglsurface,
                          app_surface->eglsurface, env->egl_context));
    glViewport(0, 0, app_surface->w, app_surface->h);
    glScissor(0, 0, app_surface->w, app_surface->h);

And this is the result I got:

capture d ecran de 2018-08-31 09-55-20

While supposingly I should have:

capture d ecran de 2018-08-31 10-02-01

I am on a ubuntu 18.04 machine with nvidia-390 driver. Hope this helps.

Thanks

mvicomoya commented 5 years ago

@xeechou , in order to try to reproduce this, I hacked into weston-simple-egl to make a surfaceless context current in init_egl(). Then, after init_gl() is called to create the different shaders and whatnot, I create the EGL surface with weston_platform_create_egl_surface(), and make it current.

Everything works fine for me.

I'd double check your application, maybe taking weston-simple-egl as example.

Otherwise, my suggestion would be for you to provide the source code of a minimal application that reproduces the issue so we can work from there.

xeechou commented 5 years ago

Thanks for your patience, I am trying to make an example code that can reproduce this problem. But I didn't try to sue weston's weston_platform_create_egl_surface, instead I use EGLCreateWindowSurface directly.

mvicomoya commented 5 years ago

@xeechou, any updates on this? Are you still running into the issue?

mvicomoya commented 5 years ago

@xeechou, I'm assuming you no longer see this issue, so I'll just close it. Feel free to re-open of you think this isn't resolved yet.