facebook/igl

Vulkan | Switch between the foreground and background

Closed this issue · 8 comments

JNIEXPORT void JNICALL Java_com_facebook_igl_shell_SampleLib_surfaceDestroyed(JNIEnv* env,
                                                                              jobject /*obj*/,
                                                                              jobject surface) {
  // For Vulkan we deallocate the whole renderer and recreate it when surface is re-created.
  // This is done because we currently don't have an easy way to destroy the surface + swapchain
  // independent of the whole device.
  // This is not needed for GL
  if (activeBackendTypeID == BackendTypeID::Vulkan && renderers[activeBackendTypeID] != nullptr) {
    renderers[activeBackendTypeID]->onSurfaceDestroyed(
        surface ? ANativeWindow_fromSurface(env, surface) : nullptr);
    auto& renderer = renderers[activeBackendTypeID];
    renderer.reset();
    renderers[activeBackendTypeID] = nullptr;
  }
}

When I tried to switch between the foreground and background on Vulkan, I found that it is currently not possible. This is because every time the surface is destroyed, the entire render, including all data and textures, needs to be destroyed. This is unacceptable in a real app. Is it possible to only replace the surface while keeping the device available during the switch between foreground and background?

@corporateshark @rokuz
Is this issue a problem with the sample code or is it due to the current API not supporting it yet?

Hey @vinsentli! Thanks for asking! IGL doesn't limit it in any sense, IGL's device can persist in background for Vulkan for sure (it will not work for OpenGL ES, but it's OpenGL's limitation but not IGL's one). We didn't implement it in samples to keep them as simple as possible.
The task to showcase it is in our backlog.

@rokuz Thanks for your response. Do you have an approximate timeframe for this?

Unfortunately, we don't have defined timeframe for it.

@corporateshark
Please provide us with some support, as it is crucial for us.
Thanks!

@vinsentli As @rokuz mentioned, we do not have any defined timeframe for this. I'm really sorry about that!

I have resolved this issue : recreate swap chain when switch app from background to foreground

Old:

Screen_Recording_20240823_144730_IGL.mp4

New:

Screen_Recording_20240823_151629_IGL.mp4

close