Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why don't multiple contexts of the same group share FBOs ? #82

Open
wxdut opened this issue Jun 23, 2022 · 2 comments
Open

Why don't multiple contexts of the same group share FBOs ? #82

wxdut opened this issue Jun 23, 2022 · 2 comments

Comments

@wxdut
Copy link

wxdut commented Jun 23, 2022

Hi, Le Hoang Quyen, thank you so much for developing MetalANGLE.

I recently used MetalANGLE in my project, found that multiple egl contexts of the same group don't share FBOs, this is inconsistent with standard OpenGLES.

look at this snippet please:

    MGLSharegroup *shareGroup = [[MGLSharegroup alloc] init];
    MGLContext *glCtx1 = [[MGLContext alloc] initWithAPI:kMGLRenderingAPIOpenGLES2 sharegroup:shareGroup];
    MGLContext *glCtx2 = [[MGLContext alloc] initWithAPI:kMGLRenderingAPIOpenGLES2 sharegroup:shareGroup];
    
    [MGLContext setCurrentContext:glCtx1];
    GLuint fbo1 = 0;
    glGenFramebuffers(1, &fbo1);
    
    [MGLContext setCurrentContext:glCtx2];
    GLuint fbo2 = 0;
    glGenFramebuffers(1, &fbo2);
    
    assert(fbo1 + 1 == fbo2);

If you execute this code with MetalANGLE, you'll see that fbo1 and fbo2 are both 1, which is not in line with expectations.
If you execute same code with standard OpenGLES, you'll see that fbo1 is 1 and fbo2 are 2.

I read the source code and found some clues here. the 'mFramebufferManager' isn't shared(not using AllocateOrGetSharedResourceManager).
image

Is this a bug or a feature? If it's a bug, I'd be happy to submit a PR to fix it. If it is a feature, could you please explain the reason.

Thank you again!!

@kakashidinho
Copy link
Owner

Hi,
Fbo is not resource. It is a container object. Hence not shareable. Same as VAO. Pls see https://www.khronos.org/opengl/wiki/OpenGL_Context

Most OpenGL objects are sharable, including Sync Objects and GLSL Objects. Container Objects are not sharable, nor are Query Objects.

you can share textures then reattach them to two different fbos in two contexts though.

@wxdut
Copy link
Author

wxdut commented Jun 23, 2022

Thanks for your quick reply.

But I test this code on iphone, fbos seem to be shared in same group.

    EAGLContext *glCtx1 = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    EAGLContext *glCtx2 = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:glCtx1.sharegroup];
    
    [EAGLContext setCurrentContext:glCtx1];
    GLuint fbo1 = 0;
    glGenFramebuffers(1, &fbo1);
    
    [EAGLContext setCurrentContext:glCtx2];
    GLuint fbo2 = 0;
    glGenFramebuffers(1, &fbo2);
    
    assert(fbo1 + 1 == fbo2); // pass

image

Do you know the reason? Thanks.


Update:

I think I figured it out.

I looked up Apple's documentation, FBOs are shared between contexts of the same group. Apple doesn't seem to follow khronos' specifications exactly.

image

In addition, I also refer to the stackoverflow discussion, there does not have this inconsistency problem on Android platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants