mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 00:41:57 +09:00
Compare commits
17
Commits
4ed1c9cef2
...
335637af38
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
335637af38 | ||
|
|
4236b42a57 | ||
|
|
0b6842ac8b | ||
|
|
47db68d557 | ||
|
|
ce11c9accd | ||
|
|
7bb9d9829f | ||
|
|
ccf8eb6571 | ||
|
|
0b314ddae7 | ||
|
|
d5acece005 | ||
|
|
30fef23d52 | ||
|
|
cbb87b968a | ||
|
|
d554c87c45 | ||
|
|
7a48521d37 | ||
|
|
6946ff3a5c | ||
|
|
5a0f13fdfa | ||
|
|
ff2120616d | ||
|
|
5c6399e240 |
+2
-1
@@ -399,6 +399,7 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Util/Texture/TextureFormatProcessor.cpp
|
||||
|
||||
MobileGL/MG_Impl/GLXImpl/Exporting/Definitions.cpp
|
||||
MobileGL/MG_Impl/GLXImpl/Exporting/GlvndVendor.cpp
|
||||
MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp
|
||||
MobileGL/MG_Impl/GLXImpl/LookUp/LookUp.cpp
|
||||
|
||||
@@ -837,7 +838,7 @@ target_compile_definitions(${CMAKE_PROJECT_NAME}
|
||||
|
||||
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
foreach(MOBILEGL_LOADER_ALIAS
|
||||
libEGL.so libEGL.so.1 libGL.so libGL.so.1)
|
||||
libEGL.so libEGL.so.1 libGL.so libGL.so.1 libGLX_mobilegl.so.0)
|
||||
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||
"$<TARGET_FILE_NAME:${CMAKE_PROJECT_NAME}>"
|
||||
|
||||
@@ -200,12 +200,15 @@ namespace MobileGL::MG_Backend {
|
||||
Bool BackendObject::ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
auto surfaceIt = m_eglSurfaces.find(surface);
|
||||
if (surfaceIt == m_eglSurfaces.end() || surfaceIt->second.Kind != SurfaceKind::Window) {
|
||||
if (surfaceIt == m_eglSurfaces.end() || surfaceIt->second.Kind == SurfaceKind::None) {
|
||||
MGLOG_E("ResizeEGLWindowSurface failed: no window surface is initialized");
|
||||
return false;
|
||||
}
|
||||
// A pbuffer-backed window (a Wayland window presented through wl_shm) resizes too.
|
||||
surfaceIt->second.Window.Width = width;
|
||||
surfaceIt->second.Window.Height = height;
|
||||
surfaceIt->second.Width = static_cast<EGLint>(std::max<Uint32>(width, 1));
|
||||
surfaceIt->second.Height = static_cast<EGLint>(std::max<Uint32>(height, 1));
|
||||
if (m_eglSurface == surface) {
|
||||
m_windowHandle.Width = width;
|
||||
m_windowHandle.Height = height;
|
||||
@@ -283,6 +286,7 @@ namespace MobileGL::MG_Backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
m_activatingSurface = surface;
|
||||
if (surfaceState->Kind == SurfaceKind::Window) {
|
||||
SetWindowHandle(surfaceState->Window);
|
||||
if (!InitWindowSurface()) {
|
||||
@@ -302,8 +306,14 @@ namespace MobileGL::MG_Backend {
|
||||
m_eglSurface = surface;
|
||||
m_eglSurfaceInitialized = true;
|
||||
m_eglSurfaceKind = surfaceState->Kind;
|
||||
m_eglCurrentThreads.clear();
|
||||
m_backendCapabilitiesInitialized = false;
|
||||
// NOT m_eglCurrentThreads.clear(): another thread's current context and surface are its
|
||||
// own (a multi-window client renders each window on its own thread), and wiping them made
|
||||
// that thread's next eglSwapBuffers fail with "no current context attached".
|
||||
auto activatedIt = m_eglSurfaces.find(surface);
|
||||
if (activatedIt != m_eglSurfaces.end() && !activatedIt->second.Activated) {
|
||||
activatedIt->second.Activated = true;
|
||||
m_backendCapabilitiesInitialized = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -370,6 +380,14 @@ namespace MobileGL::MG_Backend {
|
||||
m_eglCurrentThreads.clear();
|
||||
}
|
||||
|
||||
void BackendObject::ForgetActiveEGLSurface() {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
m_eglSurfaceInitialized = false;
|
||||
m_eglSurfaceKind = SurfaceKind::None;
|
||||
m_eglSurface = EGL_NO_SURFACE;
|
||||
m_windowHandle = {};
|
||||
}
|
||||
|
||||
Bool BackendObject::SwapEGLBuffers(EGLDisplay dpy, EGLSurface draw) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
if (!m_eglDisplayInitialized || m_eglDisplay != dpy) {
|
||||
@@ -386,10 +404,16 @@ namespace MobileGL::MG_Backend {
|
||||
MGLOG_E("SwapEGLBuffers failed: draw surface is not current on this thread");
|
||||
return false;
|
||||
}
|
||||
if (!m_eglSurfaceInitialized || draw == EGL_NO_SURFACE || draw != m_eglSurface) {
|
||||
if (draw == EGL_NO_SURFACE || !GetRegisteredEGLSurface(draw)) {
|
||||
MGLOG_E("SwapEGLBuffers failed: invalid draw surface");
|
||||
return false;
|
||||
}
|
||||
// The calling thread's surface, which another thread's make-current may have moved the
|
||||
// backend off: bring it back before presenting it.
|
||||
if ((!m_eglSurfaceInitialized || draw != m_eglSurface) && !ActivateEGLSurface(draw)) {
|
||||
MGLOG_E("SwapEGLBuffers failed: the draw surface could not be re-activated");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& backendFunctions = GetBackendFunctions();
|
||||
if (!backendFunctions.Present) {
|
||||
@@ -430,8 +454,9 @@ namespace MobileGL::MG_Backend {
|
||||
m_eglSurfaces.erase(surfaceIt);
|
||||
if (m_eglSurface == surface) {
|
||||
OnEGLSurfaceReleased(surface);
|
||||
ResetEGLRuntimeState();
|
||||
ForgetActiveEGLSurface();
|
||||
}
|
||||
OnEGLSurfaceForgotten(surface);
|
||||
}
|
||||
|
||||
void BackendObject::ReleaseEGLCurrentThread(const std::thread::id& threadKey) {
|
||||
@@ -462,8 +487,9 @@ namespace MobileGL::MG_Backend {
|
||||
m_eglSurfaces.erase(surfaceIt);
|
||||
if (m_eglSurface == surface) {
|
||||
OnEGLSurfaceReleased(surface);
|
||||
ResetEGLRuntimeState();
|
||||
ForgetActiveEGLSurface();
|
||||
}
|
||||
OnEGLSurfaceForgotten(surface);
|
||||
}
|
||||
|
||||
void BackendObject::ReleaseEGLResources() {
|
||||
@@ -496,4 +522,8 @@ namespace MobileGL::MG_Backend {
|
||||
void BackendObject::OnEGLSurfaceReleased(EGLSurface surface) {
|
||||
(void)surface;
|
||||
}
|
||||
|
||||
void BackendObject::OnEGLSurfaceForgotten(EGLSurface surface) {
|
||||
(void)surface;
|
||||
}
|
||||
} // namespace MobileGL::MG_Backend
|
||||
|
||||
@@ -629,18 +629,28 @@ namespace MobileGL {
|
||||
struct EGLSurfaceState {
|
||||
SurfaceKind Kind = SurfaceKind::None;
|
||||
Bool DestroyPending = false;
|
||||
// Activated at least once: a re-activation (a multi-window client switching back)
|
||||
// is a re-bind and does not re-run the backend's capability probe.
|
||||
Bool Activated = false;
|
||||
WindowHandle Window;
|
||||
EGLint Width = 1;
|
||||
EGLint Height = 1;
|
||||
};
|
||||
|
||||
void ResetEGLRuntimeState();
|
||||
// ResetEGLRuntimeState for a released ACTIVE surface: the backend has no active surface
|
||||
// any more, but every OTHER thread's current context and surface stay as they were (a
|
||||
// multi-window client closing one popup must not unbind its other windows' threads).
|
||||
void ForgetActiveEGLSurface();
|
||||
Bool RegisterEGLWindowSurface(EGLSurface surface, const WindowHandle& handle);
|
||||
Bool RegisterEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height);
|
||||
const EGLSurfaceState* GetRegisteredEGLSurface(EGLSurface surface) const;
|
||||
Bool ActivateEGLSurface(EGLSurface surface);
|
||||
virtual Bool InitPbufferSurface(EGLint width, EGLint height);
|
||||
virtual void OnEGLSurfaceReleased(EGLSurface surface);
|
||||
// Every registered surface the base class drops, current or not, after it is gone from
|
||||
// m_eglSurfaces. A backend that keeps a native surface per client surface frees it here.
|
||||
virtual void OnEGLSurfaceForgotten(EGLSurface surface);
|
||||
FormatCapabilityCache& MutableFormatCapabilities();
|
||||
|
||||
mutable std::recursive_mutex m_eglStateMutex;
|
||||
@@ -648,6 +658,10 @@ namespace MobileGL {
|
||||
WindowHandle m_windowHandle;
|
||||
EGLDisplay m_eglDisplay = EGL_NO_DISPLAY;
|
||||
EGLSurface m_eglSurface = EGL_NO_SURFACE;
|
||||
// The client surface ActivateEGLSurface is bringing up while it calls InitWindowSurface /
|
||||
// InitPbufferSurface, which take no surface argument: a backend that maps client surfaces
|
||||
// to native ones reads it to re-bind an existing native surface instead of making another.
|
||||
EGLSurface m_activatingSurface = EGL_NO_SURFACE;
|
||||
Bool m_eglDisplayInitialized = false;
|
||||
Bool m_eglSurfaceInitialized = false;
|
||||
Bool m_backendCapabilitiesInitialized = false;
|
||||
|
||||
@@ -906,13 +906,45 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::RebindNativeSurfaceFor(EGLSurface surface) {
|
||||
const auto it = m_nativeSurfaces.find(surface);
|
||||
if (it == m_nativeSurfaces.end()) return false;
|
||||
if (DirectGLES::BindSessionSurface(it->second)) return true;
|
||||
// The session no longer owns it (destroyed with a window loss): forget and recreate.
|
||||
m_nativeSurfaces.erase(it);
|
||||
return false;
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::RestoreSurfaceAfterCreation(EGLSurface previousNativeDraw) {
|
||||
// The ACTIVE CONTEXT's own surface, exactly: the creation's bind attached the new surface to
|
||||
// whichever context the session had bound (often another window's thread), and putting back
|
||||
// "the surface activated last" instead re-attached THAT context to a third window's surface -
|
||||
// a desktop drawing into and reading back from the panel's pbuffer.
|
||||
if (previousNativeDraw == EGL_NO_SURFACE) return;
|
||||
if (!DirectGLES::BindSessionSurface(previousNativeDraw)) return;
|
||||
for (const auto& [client, native] : m_nativeSurfaces) {
|
||||
if (native != previousNativeDraw) continue;
|
||||
const auto state = m_eglSurfaces.find(client);
|
||||
if (state == m_eglSurfaces.end()) break;
|
||||
m_eglSurface = client;
|
||||
m_eglSurfaceInitialized = true;
|
||||
m_eglSurfaceKind = state->second.Kind;
|
||||
if (state->second.Kind == SurfaceKind::Window) m_windowHandle = state->second.Window;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::InitWindowSurface() {
|
||||
if (RebindNativeSurfaceFor(m_activatingSurface)) return true;
|
||||
// Only use EGL for now
|
||||
auto nativeWindow = reinterpret_cast<NativeWindowType>(m_windowHandle.Handle);
|
||||
if (!DirectGLES::InitWindowSurface(nativeWindow)) {
|
||||
MGLOG_E("Failed to initialize window surface for DirectGLES backend");
|
||||
return false;
|
||||
}
|
||||
if (m_activatingSurface != EGL_NO_SURFACE) {
|
||||
m_nativeSurfaces[m_activatingSurface] = DirectGLES::CurrentSessionDrawSurface();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -986,6 +1018,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// and its objects. ResetEGLRuntimeState still runs because the base class's per-surface
|
||||
// bookkeeping (which surface is active, which threads made it current) does describe the
|
||||
// surface that is being replaced.
|
||||
const EGLSurface previous = m_eglSurfaceInitialized ? m_eglSurface : EGL_NO_SURFACE;
|
||||
const EGLSurface previousNativeDraw = DirectGLES::CurrentContextDrawSurface();
|
||||
if (m_eglSurfaceInitialized) {
|
||||
ResetEGLRuntimeState();
|
||||
}
|
||||
@@ -995,7 +1029,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the first virtual tuple adopts that bind. On failure nothing is known to be bound. The
|
||||
// pull arm below is the original statement, byte for byte (G1).
|
||||
const Bool created = BackendObject::CreateEGLWindowSurface(surface, handle);
|
||||
if (created) {
|
||||
if (created && previous != EGL_NO_SURFACE && previous != surface) {
|
||||
// Another surface was current: the creation must not leave the context that held it
|
||||
// drawing to the new one (P14 multi-window clients).
|
||||
RestoreSurfaceAfterCreation(previousNativeDraw);
|
||||
NoteNativeContextGone();
|
||||
} else if (created) {
|
||||
NoteNativeContextFreshFromSurfaceCreation();
|
||||
} else {
|
||||
NoteNativeContextGone();
|
||||
@@ -1019,6 +1058,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
// P14 S4: as for the window surface above - the native context is the (session, context
|
||||
// token) tuple's and survives a surface switch. This used to be DestroyEGLContext().
|
||||
const EGLSurface previous = m_eglSurfaceInitialized ? m_eglSurface : EGL_NO_SURFACE;
|
||||
const EGLSurface previousNativeDraw = DirectGLES::CurrentContextDrawSurface();
|
||||
if (m_eglSurfaceInitialized) {
|
||||
ResetEGLRuntimeState();
|
||||
}
|
||||
@@ -1027,7 +1068,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// ID-54 / ID-67: as for the window surface - InitPbufferSurface bound natively. The pull
|
||||
// arm below is the original statement, byte for byte (G1).
|
||||
const Bool created = BackendObject::CreateEGLPbufferSurface(surface, width, height);
|
||||
if (created) {
|
||||
if (created && previous != EGL_NO_SURFACE && previous != surface) {
|
||||
RestoreSurfaceAfterCreation(previousNativeDraw);
|
||||
NoteNativeContextGone();
|
||||
} else if (created) {
|
||||
NoteNativeContextFreshFromSurfaceCreation();
|
||||
} else {
|
||||
NoteNativeContextGone();
|
||||
@@ -1038,8 +1082,34 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
const auto state = m_eglSurfaces.find(surface);
|
||||
const auto native = m_nativeSurfaces.find(surface);
|
||||
if (state == m_eglSurfaces.end() || state->second.Kind != SurfaceKind::Pbuffer || native == m_nativeSurfaces.end()) {
|
||||
return BackendObject::ResizeEGLWindowSurface(surface, width, height);
|
||||
}
|
||||
// A pbuffer has no resize: the client surface gets a new native pbuffer at the new size,
|
||||
// and every context that drew to the old one draws to the new one.
|
||||
const EGLint w = static_cast<EGLint>(std::max<Uint32>(width, 1));
|
||||
const EGLint h = static_cast<EGLint>(std::max<Uint32>(height, 1));
|
||||
const EGLSurface replacement = DirectGLES::CreateSessionPbuffer(w, h);
|
||||
if (replacement == EGL_NO_SURFACE) {
|
||||
MGLOG_E("ResizeEGLWindowSurface: no %dx%d pbuffer could replace the old drawable", w, h);
|
||||
return false;
|
||||
}
|
||||
DirectGLES::ReplaceSessionSurface(native->second, replacement);
|
||||
native->second = replacement;
|
||||
return BackendObject::ResizeEGLWindowSurface(surface, width, height);
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::InitPbufferSurface(EGLint width, EGLint height) {
|
||||
return DirectGLES::InitPbufferSurface(width, height);
|
||||
if (RebindNativeSurfaceFor(m_activatingSurface)) return true;
|
||||
if (!DirectGLES::InitPbufferSurface(width, height)) return false;
|
||||
if (m_activatingSurface != EGL_NO_SURFACE) {
|
||||
m_nativeSurfaces[m_activatingSurface] = DirectGLES::CurrentSessionDrawSurface();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
||||
@@ -1099,7 +1169,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
m_eglSurfaceInitialized && m_eglSurface == draw &&
|
||||
DirectGLES::IsBackendContextCurrentOnThisThread() &&
|
||||
NativeBindCanBeSkippedFor(dpy, draw, read, ctx);
|
||||
if (!nativelyCurrentAlready && !DirectGLES::MakeCurrent()) {
|
||||
// The draw surface's own native surface (P14 multi-window): a known one is re-bound, so the
|
||||
// bind goes to it and not to whichever surface the session drew to last.
|
||||
// The real bind still runs whenever the skip above says so (ID-67: a different tuple onto
|
||||
// the same surface needs MakeCurrent's invalidations even though the driver triple is equal).
|
||||
const auto nativeDraw = m_nativeSurfaces.find(draw);
|
||||
if (!nativelyCurrentAlready && nativeDraw != m_nativeSurfaces.end()) {
|
||||
(void)DirectGLES::SelectSessionSurface(nativeDraw->second);
|
||||
}
|
||||
const Bool bound = nativelyCurrentAlready || DirectGLES::MakeCurrent();
|
||||
if (!bound) {
|
||||
NoteNativeContextGone();
|
||||
return false;
|
||||
}
|
||||
@@ -1139,13 +1218,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::OnEGLSurfaceReleased(EGLSurface surface) {
|
||||
// P14: releasing a surface releases THAT SURFACE (OnEGLSurfaceForgotten), never the
|
||||
// contexts. This used to be DestroyEGLContext() - every native context of the session, with
|
||||
// every object the client had built - which a multi-window client hit on its first closed
|
||||
// popup.
|
||||
(void)surface;
|
||||
DestroyEGLContext();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
NoteNativeContextGone();
|
||||
#endif
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::OnEGLSurfaceForgotten(EGLSurface surface) {
|
||||
const auto it = m_nativeSurfaces.find(surface);
|
||||
if (it == m_nativeSurfaces.end()) return;
|
||||
const EGLSurface native = it->second;
|
||||
m_nativeSurfaces.erase(it);
|
||||
DirectGLES::DestroySessionSurface(native);
|
||||
}
|
||||
|
||||
const RendererInfo& BackendObject_DirectGLES::GetRendererInfo() const {
|
||||
return MutableRendererInfo();
|
||||
}
|
||||
@@ -1175,6 +1265,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
V_OpenGL30, V_OpenGL31, V_OpenGL32, V_OpenGL33, V_OpenGL40, V_OpenGL41, V_OpenGL42, V_OpenGL43,
|
||||
V_OpenGL44, V_OpenGL45, V_OpenGL46,
|
||||
E_GL_ARB_draw_buffers_blend,
|
||||
// The GLSL 1.00/1.10-era ARB trio plus NPOT textures: all core since GL 2.0 and
|
||||
// trivially true for every context this backend claims (4.6). KWin 6's
|
||||
// EglContext::checkSupported() gates desktop-GL compositing on exactly these four
|
||||
// strings, so withholding them fails its renderer bring-up on an otherwise capable
|
||||
// implementation.
|
||||
E_GL_ARB_shader_objects, E_GL_ARB_vertex_shader, E_GL_ARB_fragment_shader,
|
||||
E_GL_ARB_texture_non_power_of_two,
|
||||
E_GL_ARB_compute_shader, E_GL_ARB_shader_storage_buffer_object, E_GL_ARB_shader_image_load_store,
|
||||
E_GL_ARB_clear_buffer_object, E_GL_ARB_program_interface_query, E_GL_ARB_framebuffer_object, E_GL_EXT_framebuffer_object,
|
||||
E_GL_ARB_depth_texture, E_GL_ARB_buffer_storage, E_GL_ARB_texture_storage,
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool InitializeEGLDisplay(EGLDisplay dpy, EGLint* major, EGLint* minor) override;
|
||||
Bool CreateEGLWindowSurface(EGLSurface surface, const WindowHandle& handle) override;
|
||||
Bool CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) override;
|
||||
Bool ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) override;
|
||||
Bool MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) override;
|
||||
Bool SwapEGLBuffers(EGLDisplay dpy, EGLSurface draw) override;
|
||||
void ReleaseEGLSurface(EGLSurface surface) override;
|
||||
@@ -57,8 +58,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void UpdateDynamicBackendParameters();
|
||||
Bool InitPbufferSurface(EGLint width, EGLint height) override;
|
||||
void OnEGLSurfaceReleased(EGLSurface surface) override;
|
||||
void OnEGLSurfaceForgotten(EGLSurface surface) override;
|
||||
// An existing native surface for the client surface being activated, re-bound; false when
|
||||
// there is none yet (the caller creates it).
|
||||
Bool RebindNativeSurfaceFor(EGLSurface surface);
|
||||
// EGL: creating a surface does not change what is current. The creation bound the new
|
||||
// surface natively; put the previous one back for the context that held it.
|
||||
void RestoreSurfaceAfterCreation(EGLSurface previousNativeDraw);
|
||||
|
||||
Bool m_initialized = false;
|
||||
// P14: ONE NATIVE SURFACE PER CLIENT SURFACE, created on its first activation and re-bound
|
||||
// on every later one. A multi-window client switches surfaces every frame; making a new
|
||||
// native surface each time leaked them and lost what the window had drawn.
|
||||
UnorderedMap<EGLSurface, EGLSurface> m_nativeSurfaces;
|
||||
MG_External::EGLFunctionsTable m_EGLFunctions;
|
||||
MG_External::GLESFunctionsTable m_GLESFunctions;
|
||||
MG_External::GLESCapabilities m_GLESCapabilities;
|
||||
|
||||
@@ -3408,13 +3408,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the same statement one level down, for the backend that would have papered over
|
||||
// it. Under monolith the fall-back is correct and stays.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith && maxTouchedUnit >= 0) {
|
||||
MGLOG_F("MGPipe: Fatal{ProtocolCorruption, \"SetSamplerViews.Count\"} - a draw "
|
||||
// The windows are the PEER's records, so in a served session this ends THAT
|
||||
// session (the in-process display server serves every client from one
|
||||
// process; an abort here took the compositor down with the offender). The
|
||||
// answer while the latch drains is "no unit is bound": the walk the decline
|
||||
// would run reads client memory, and the session stops at its next record.
|
||||
// Unarmed, SessionLatch is the old abort.
|
||||
if (!MG_Remote::SessionLatch(
|
||||
MG_Remote::MGFatalFamily::ProtocolCorruption,
|
||||
"MGPipe: Fatal{ProtocolCorruption, \"SetSamplerViews.Count\"} - a draw "
|
||||
"touches units 0..%d and neither a sampler-view nor a sampler-state "
|
||||
"window has ever been applied while the sampler subsystem bit is set; "
|
||||
"the pre-handle unit-bindings snapshot walk reads client memory and is "
|
||||
"refused under an active transport (CONTRACT-P5E.md §5.3)",
|
||||
static_cast<int>(maxTouchedUnit));
|
||||
std::abort();
|
||||
static_cast<int>(maxTouchedUnit))) {
|
||||
out = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (maxTouchedUnit >= 0) {
|
||||
@@ -16220,7 +16230,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
struct NativeSessionState {
|
||||
Uint64 SessionKey = 0;
|
||||
// Every native surface this session created, so its teardown destroys its own and only its own.
|
||||
Vector<EGLSurface> Surfaces;
|
||||
// The window is recorded with each entry: a stale surface still bound to a window that a
|
||||
// LATER session wants (a crashed predecessor's server-owned window) is found and destroyed
|
||||
// by InitWindowSurface before the driver refuses the second eglCreateWindowSurface.
|
||||
struct SurfaceEntry {
|
||||
NativeWindowType Window;
|
||||
EGLSurface Surface;
|
||||
};
|
||||
Vector<SurfaceEntry> Surfaces;
|
||||
// The surface the session currently draws to / reads from - what a bind to another context
|
||||
// re-makes current, and what Present/eglSwapBuffers names.
|
||||
EGLSurface Draw = EGL_NO_SURFACE;
|
||||
@@ -16268,6 +16285,27 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
if (resolver != nullptr) (void)resolver(&outSession, &outToken);
|
||||
}
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P14 S6: the twin tables' key. Same probe/fallback shape as the native tuple's above and
|
||||
// for the same reason (the whole single-context world must keep getting one key), and
|
||||
// deliberately a SEPARATE resolver: this one answers for a table that is consulted on paths
|
||||
// the native tuple is not, and a case that drives twins without EGL must be able to set it
|
||||
// alone. See DirectGLES.h for what the two halves mean.
|
||||
static std::atomic<TwinKeyResolver> g_twinKeyResolver{nullptr};
|
||||
|
||||
void SetTwinKeyResolver(TwinKeyResolver resolver) {
|
||||
g_twinKeyResolver.store(resolver, std::memory_order_release);
|
||||
}
|
||||
|
||||
Bool CurrentTwinKey(TwinKey* outKey) {
|
||||
outKey->SessionKey = 0;
|
||||
outKey->ShareGroupKey = 0;
|
||||
const TwinKeyResolver resolver = g_twinKeyResolver.load(std::memory_order_acquire);
|
||||
if (resolver == nullptr) return false;
|
||||
return resolver(outKey);
|
||||
}
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
Uint64 CurrentNativeSessionKey() {
|
||||
Uint64 session = 0;
|
||||
Uint64 token = 0;
|
||||
@@ -16289,6 +16327,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// what makes MakeNativeContextCurrentForBoundToken a no-op when the bind did not actually
|
||||
// change the native context (the single-context world's every bind).
|
||||
thread_local EGLContext t_boundNativeContext = EGL_NO_CONTEXT;
|
||||
// And the surface it was made current with: a bind to the same context on a different
|
||||
// surface (one client context drawing to several windows) is a real switch.
|
||||
thread_local EGLSurface t_boundNativeDraw = EGL_NO_SURFACE;
|
||||
} // namespace
|
||||
|
||||
static NativeSessionState& AcquireNativeSession(Uint64 sessionKey) {
|
||||
@@ -16816,10 +16857,17 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
|
||||
static Bool EnsureNativeContext(NativeContextTuple& tuple, EGLint surfaceBit, NativeWindowType window) {
|
||||
if (!EnsureDisplayInitialized()) return false;
|
||||
if (!EnsureDisplayInitialized()) {
|
||||
MGLOG_E("EnsureNativeContext: the EGL display did not initialize");
|
||||
return false;
|
||||
}
|
||||
if (tuple.Context != EGL_NO_CONTEXT) return true;
|
||||
|
||||
if (tuple.Config == nullptr && !ChooseConfigForSurface(surfaceBit, tuple.Config, window)) return false;
|
||||
if (tuple.Config == nullptr && !ChooseConfigForSurface(surfaceBit, tuple.Config, window)) {
|
||||
MGLOG_E("EnsureNativeContext: no EGL config for surface bit 0x%x (window=%p)",
|
||||
static_cast<unsigned>(surfaceBit), reinterpret_cast<void*>(window));
|
||||
return false;
|
||||
}
|
||||
|
||||
// A share group whose leader has a live native context hands it to eglCreateContext: this is
|
||||
// the whole of "shared contexts see the same objects" on the server. The group is recorded
|
||||
@@ -16833,6 +16881,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P14: AND OTHERWISE ANY LIVE NATIVE CONTEXT IN THE PROCESS. The backend keeps buffers,
|
||||
// textures and syncs of its own in process-wide state (the UBO/unpack/upload rings, the
|
||||
// buffer pool, scratch textures, frame fences) and every session's apply thread uses
|
||||
// them; they are only names in another session's context if all the contexts are one
|
||||
// share group. Client isolation does not come from the driver's namespaces - the twin
|
||||
// tables are bucketed per {session, share group} and never hand one bucket's names to
|
||||
// another - so a process-wide group costs nothing in separation.
|
||||
if (share == EGL_NO_CONTEXT) {
|
||||
for (auto* other : NativeContexts()) {
|
||||
if (other != &tuple && other->Context != EGL_NO_CONTEXT) {
|
||||
share = other->Context;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Negotiate the highest ES 3.x context. Version-strict EGL implementations
|
||||
// (ANGLE) return exactly the requested minor, and a bare CLIENT_VERSION 3
|
||||
@@ -16913,15 +16978,126 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// P14 S4. THE NATIVE HALF OF A CONTEXT SWITCH. See DirectGLES.h; in one line, `bind_context`
|
||||
// moves the session's context attribution and this makes the calling thread's native tuple
|
||||
// follow it, binding the session's current surface to the newly named context's EGLContext.
|
||||
static Bool SessionOwnsSurface(const NativeSessionState& session, EGLSurface surface) {
|
||||
if (surface == EGL_NO_SURFACE) return false;
|
||||
for (const auto& entry : session.Surfaces) {
|
||||
if (entry.Surface == surface) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool MakeNativeContextCurrentForBoundToken() {
|
||||
NativeContextTuple& tuple = ActiveNativeContext();
|
||||
// Nothing to switch to: a session that never sent CreateContext has no native context for
|
||||
// this token, and building one here would bind a context the client does not know it has.
|
||||
if (tuple.Context == EGL_NO_CONTEXT) return true;
|
||||
if (t_boundNativeContext == tuple.Context) return true;
|
||||
// A MULTI-WINDOW CLIENT: each context draws to the surface it was last made current with,
|
||||
// not to whichever surface the session bound most recently - Qt renders each window on its
|
||||
// own thread with its own context, and binding a context back onto another window's
|
||||
// surface drew one window's frame into the other.
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
if (tuple.Draw != session.Draw && SessionOwnsSurface(session, tuple.Draw)) {
|
||||
session.Draw = tuple.Draw;
|
||||
session.Read = SessionOwnsSurface(session, tuple.Read) ? tuple.Read : tuple.Draw;
|
||||
}
|
||||
if (t_boundNativeContext == tuple.Context && t_boundNativeDraw == session.Draw) return true;
|
||||
return MakeCurrent();
|
||||
}
|
||||
|
||||
EGLSurface CurrentSessionDrawSurface() { return ActiveNativeSession().Draw; }
|
||||
|
||||
EGLSurface CurrentContextDrawSurface() { return ActiveNativeContext().Draw; }
|
||||
|
||||
Bool SelectSessionSurface(EGLSurface surface) {
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
if (!SessionOwnsSurface(session, surface)) return false;
|
||||
session.Draw = surface;
|
||||
session.Read = surface;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool BindSessionSurface(EGLSurface surface) {
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
if (!SessionOwnsSurface(session, surface)) return false;
|
||||
session.Draw = surface;
|
||||
session.Read = surface;
|
||||
if (ActiveNativeContext().Context == EGL_NO_CONTEXT) return true;
|
||||
if (t_boundNativeContext == ActiveNativeContext().Context && t_boundNativeDraw == surface) return true;
|
||||
return MakeCurrent();
|
||||
}
|
||||
|
||||
EGLSurface CreateSessionPbuffer(EGLint width, EGLint height) {
|
||||
NativeContextTuple& tuple = ActiveNativeContext();
|
||||
if (!EnsureNativeContext(tuple, EGL_PBUFFER_BIT, static_cast<NativeWindowType>(0))) return EGL_NO_SURFACE;
|
||||
const EGLint attribs[] = {EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE};
|
||||
const EGLSurface surface = g_EGLFuncs.eglCreatePbufferSurface(g_Display, tuple.Config, attribs);
|
||||
if (surface == EGL_NO_SURFACE) return EGL_NO_SURFACE;
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
session.Surfaces.push_back({static_cast<NativeWindowType>(0), surface});
|
||||
g_nativeRegistryEpoch.fetch_add(1, std::memory_order_acq_rel);
|
||||
return surface;
|
||||
}
|
||||
|
||||
void ReplaceSessionSurface(EGLSurface previous, EGLSurface replacement) {
|
||||
if (previous == EGL_NO_SURFACE || replacement == EGL_NO_SURFACE || previous == replacement) return;
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
for (auto* tuple : NativeContexts()) {
|
||||
if (tuple->SessionKey != session.SessionKey) continue;
|
||||
if (tuple->Draw == previous) tuple->Draw = replacement;
|
||||
if (tuple->Read == previous) tuple->Read = replacement;
|
||||
}
|
||||
auto& entries = session.Surfaces;
|
||||
entries.erase(std::remove_if(entries.begin(), entries.end(),
|
||||
[&](const NativeSessionState::SurfaceEntry& entry) {
|
||||
return entry.Surface == previous;
|
||||
}),
|
||||
entries.end());
|
||||
g_nativeRegistryEpoch.fetch_add(1, std::memory_order_acq_rel);
|
||||
}
|
||||
if (session.Draw == previous) session.Draw = replacement;
|
||||
if (session.Read == previous) session.Read = replacement;
|
||||
// The calling thread drew to the old one: draw to the new one from here (the old is then
|
||||
// no longer current, and its destruction below is immediate).
|
||||
if (t_boundNativeDraw == previous && ActiveNativeContext().Context != EGL_NO_CONTEXT) (void)MakeCurrent();
|
||||
if (g_EGLFuncs.eglDestroySurface && g_Display != EGL_NO_DISPLAY) g_EGLFuncs.eglDestroySurface(g_Display, previous);
|
||||
}
|
||||
|
||||
void DestroySessionSurface(EGLSurface surface) {
|
||||
if (surface == EGL_NO_SURFACE) return;
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
auto& entries = session.Surfaces;
|
||||
const auto it = std::find_if(entries.begin(), entries.end(),
|
||||
[&](const NativeSessionState::SurfaceEntry& entry) { return entry.Surface == surface; });
|
||||
if (it == entries.end()) return;
|
||||
entries.erase(it);
|
||||
for (auto* tuple : NativeContexts()) {
|
||||
if (tuple->SessionKey != session.SessionKey) continue;
|
||||
if (tuple->Draw == surface) tuple->Draw = EGL_NO_SURFACE;
|
||||
if (tuple->Read == surface) tuple->Read = EGL_NO_SURFACE;
|
||||
}
|
||||
g_nativeRegistryEpoch.fetch_add(1, std::memory_order_acq_rel);
|
||||
}
|
||||
if (session.Draw == surface || session.Read == surface) {
|
||||
// Fall back onto a surface the session still has, so the next bind has somewhere to go.
|
||||
const EGLSurface fallback = session.Surfaces.empty() ? EGL_NO_SURFACE : session.Surfaces.front().Surface;
|
||||
session.Draw = fallback;
|
||||
session.Read = fallback;
|
||||
if (t_boundNativeDraw == surface && fallback != EGL_NO_SURFACE &&
|
||||
ActiveNativeContext().Context != EGL_NO_CONTEXT) {
|
||||
(void)MakeCurrent();
|
||||
}
|
||||
}
|
||||
// A surface still current on this thread is destroyed by EGL once it is not (EGL 1.5
|
||||
// 3.5.6), so this needs no unbind first.
|
||||
if (g_EGLFuncs.eglDestroySurface && g_Display != EGL_NO_DISPLAY) g_EGLFuncs.eglDestroySurface(g_Display, surface);
|
||||
if (t_boundNativeDraw == surface && session.Draw == EGL_NO_SURFACE) t_boundNativeDraw = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
namespace {
|
||||
// Last swap interval the app requested through eglSwapInterval; -1 = never
|
||||
// requested (keep the EGL default of 1). Re-applied when the window surface
|
||||
@@ -16955,10 +17131,38 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
NativeContextTuple& tuple = ActiveNativeContext();
|
||||
if (!EnsureNativeContext(tuple, EGL_WINDOW_BIT, window)) return false;
|
||||
|
||||
// A crashed predecessor session may have left its surface bound to this window (the
|
||||
// server-owned display window is one ANativeWindow for the process's lifetime, and
|
||||
// several drivers refuse a second eglCreateWindowSurface on it with EGL_BAD_NATIVE_WINDOW).
|
||||
// Teardown is keyed on the session the surface belongs to, so a session that died without
|
||||
// one leaks it; find and destroy those before asking the driver.
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
for (auto* session : NativeSessions()) {
|
||||
auto& entries = session->Surfaces;
|
||||
for (auto it = entries.begin(); it != entries.end();) {
|
||||
if (it->Window == window) {
|
||||
if (g_EGLFuncs.eglDestroySurface) g_EGLFuncs.eglDestroySurface(g_Display, it->Surface);
|
||||
if (session->Draw == it->Surface) session->Draw = EGL_NO_SURFACE;
|
||||
if (session->Read == it->Surface) session->Read = EGL_NO_SURFACE;
|
||||
it = entries.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
g_nativeRegistryEpoch.fetch_add(1, std::memory_order_acq_rel);
|
||||
}
|
||||
|
||||
const EGLSurface surface = g_EGLFuncs.eglCreateWindowSurface(g_Display, tuple.Config, window, nullptr);
|
||||
if (surface == EGL_NO_SURFACE) return false;
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
const EGLint error = g_EGLFuncs.eglGetError ? g_EGLFuncs.eglGetError() : EGL_SUCCESS;
|
||||
MGLOG_E("InitWindowSurface: eglCreateWindowSurface(window=%p) failed with EGL error 0x%x",
|
||||
reinterpret_cast<void*>(window), static_cast<unsigned>(error));
|
||||
return false;
|
||||
}
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
session.Surfaces.push_back(surface);
|
||||
session.Surfaces.push_back({window, surface});
|
||||
session.Draw = surface;
|
||||
session.Read = surface;
|
||||
tuple.Draw = surface;
|
||||
@@ -16996,7 +17200,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const EGLSurface surface = g_EGLFuncs.eglCreatePbufferSurface(g_Display, tuple.Config, surfaceAttribs);
|
||||
if (surface == EGL_NO_SURFACE) return false;
|
||||
NativeSessionState& session = ActiveNativeSession();
|
||||
session.Surfaces.push_back(surface);
|
||||
session.Surfaces.push_back({static_cast<NativeWindowType>(0), surface});
|
||||
session.Draw = surface;
|
||||
session.Read = surface;
|
||||
tuple.Draw = surface;
|
||||
@@ -17074,6 +17278,39 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// EGL verification stamp BEFORE publishing the new owner.
|
||||
void InvalidateEglVerifiedStamp();
|
||||
|
||||
// EVERY SHADOW OF THE CURRENT NATIVE CONTEXT'S BINDINGS, dropped whenever the context the
|
||||
// calling thread renders into may have changed (MakeCurrent, a turn handoff between two
|
||||
// sessions' apply threads). Re-issuing a bind is cheap; trusting a shadow that describes
|
||||
// another context skips one the driver needed (a texture sampled from the wrong unit, a
|
||||
// draw against another context's VAO). Requires a current context: it re-establishes
|
||||
// GL_TEXTURE0 so the active-unit shadow is true rather than guessed.
|
||||
static void InvalidateNativeBindingShadows() {
|
||||
// Conservatively drop the redundant-glUseProgram guard: re-issuing one bind
|
||||
// after a MakeCurrent is cheaper than trusting a possibly-reset context.
|
||||
PrgramImpl::g_lastUsedBackendProgramId = 0;
|
||||
// The GLContext becoming current may be a fresh one whose slot versions
|
||||
// restarted at zero; the broadcast memo's key is only monotonic within one.
|
||||
PrgramImpl::InvalidateBroadcastMemo();
|
||||
BufferImpl::InvalidateArrayBufferBindingCache();
|
||||
BufferImpl::InvalidateIndexedBufferBindingCache();
|
||||
BufferImpl::InvalidatePixelBufferBindingCaches();
|
||||
BufferImpl::InvalidateTransformFeedbackBindingShadows();
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
FramebufferImpl::InvalidateFramebufferHandleArmMemos();
|
||||
#endif
|
||||
VertexArrayImpl::InvalidateVAOBindingCache();
|
||||
PixelStoreImpl::InvalidatePackStateCache();
|
||||
// The render-state shadow belongs in this list for the same reason as the ones above:
|
||||
// it describes the real ES context, which outlives the MobileGL context that is
|
||||
// becoming current. See InvalidateSyncedRenderState.
|
||||
RenderStateImpl::InvalidateSyncedRenderState();
|
||||
TextureImpl::g_boundTexturesCache = {};
|
||||
SamplerImpl::g_boundSamplersCache = {};
|
||||
if (g_GLESFuncs.glActiveTexture) g_GLESFuncs.glActiveTexture(GL_TEXTURE0);
|
||||
TextureImpl::g_activeTextureUnit = 0;
|
||||
}
|
||||
|
||||
Bool MakeCurrent() {
|
||||
// P14 S4: the context comes from the calling thread's tuple (the session's bound token),
|
||||
// the surface from the session. Both halves used to be file-level singletons.
|
||||
@@ -17093,33 +17330,34 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
InvalidateEglVerifiedStamp();
|
||||
t_boundNativeContext = tuple.Context;
|
||||
t_boundNativeDraw = session.Draw;
|
||||
g_backendContextOwnerThread.store(std::this_thread::get_id(), std::memory_order_release);
|
||||
// The ops table may have been unregistered when a previous ES context was
|
||||
// destroyed (e.g. a probe context); re-register now that GL is usable.
|
||||
BufferImpl::RegisterBufferBackendOps();
|
||||
// Conservatively drop the redundant-glUseProgram guard: re-issuing one bind
|
||||
// after a MakeCurrent is cheaper than trusting a possibly-reset context.
|
||||
PrgramImpl::g_lastUsedBackendProgramId = 0;
|
||||
// The GLContext becoming current may be a fresh one whose slot versions
|
||||
// restarted at zero; the broadcast memo's key is only monotonic within one.
|
||||
PrgramImpl::InvalidateBroadcastMemo();
|
||||
BufferImpl::InvalidateIndexedBufferBindingCache();
|
||||
BufferImpl::InvalidatePixelBufferBindingCaches();
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
FramebufferImpl::InvalidateFramebufferHandleArmMemos();
|
||||
#endif
|
||||
PixelStoreImpl::InvalidatePackStateCache();
|
||||
// The render-state shadow belongs in this list for the same reason as the ones above:
|
||||
// it describes the real ES context, which outlives the MobileGL context that is
|
||||
// becoming current. See InvalidateSyncedRenderState.
|
||||
RenderStateImpl::InvalidateSyncedRenderState();
|
||||
InvalidateNativeBindingShadows();
|
||||
// eglSwapInterval requires a current context; a request made while none was
|
||||
// current (and dropped by the driver) is retried here.
|
||||
ApplyRequestedSwapInterval();
|
||||
return true;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P14: THE BACKEND'S TURN MOVED TO ANOTHER APPLY THREAD (ServerLoop's BackendTurn). Each
|
||||
// session's apply thread keeps its own native context current, but the backend's owner
|
||||
// thread and every binding shadow are process-wide and still describe the context of the
|
||||
// thread that held the turn before. Take ownership for this thread and forget them.
|
||||
void OnBackendTurnHandoff() {
|
||||
InvalidateEglVerifiedStamp();
|
||||
if (t_boundNativeContext == EGL_NO_CONTEXT) {
|
||||
g_backendContextOwnerThread.store(std::thread::id{}, std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
g_backendContextOwnerThread.store(std::this_thread::get_id(), std::memory_order_release);
|
||||
InvalidateNativeBindingShadows();
|
||||
}
|
||||
#endif
|
||||
|
||||
Bool ReleaseCurrent() {
|
||||
if (!g_EGLFuncs.eglMakeCurrent || g_Display == EGL_NO_DISPLAY) {
|
||||
InvalidateEglVerifiedStamp();
|
||||
@@ -17136,6 +17374,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// "not current" only defers buffer ops, which is always safe.
|
||||
InvalidateEglVerifiedStamp();
|
||||
t_boundNativeContext = EGL_NO_CONTEXT;
|
||||
t_boundNativeDraw = EGL_NO_SURFACE;
|
||||
g_backendContextOwnerThread.store(std::thread::id{}, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
@@ -17603,7 +17842,20 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
|
||||
// P14 S4: the session's surface, not the process's.
|
||||
g_EGLFuncs.eglSwapBuffers(g_Display, ActiveNativeSession().Draw);
|
||||
//
|
||||
// EXT -> KHR -> plain. The loader fills eglSwapBuffersWithDamageEXT from whichever
|
||||
// spelling the driver provides (Adreno exposes only eglSwapBuffersWithDamageKHR), so
|
||||
// the null check below is the whole chain: a driver with neither presents with plain
|
||||
// eglSwapBuffers. Passing n_rects == 0 is not a partial present - the extension
|
||||
// defines it as "the entire surface is implicitly damaged and the behaviour is
|
||||
// equivalent to calling eglSwapBuffers" - and the wire protocol carries no damage
|
||||
// rectangles for the server to forward, so the full surface is what is meant anyway.
|
||||
const EGLSurface drawSurface = ActiveNativeSession().Draw;
|
||||
if (g_EGLFuncs.eglSwapBuffersWithDamageEXT != nullptr) {
|
||||
g_EGLFuncs.eglSwapBuffersWithDamageEXT(g_Display, drawSurface, nullptr, 0);
|
||||
} else {
|
||||
g_EGLFuncs.eglSwapBuffers(g_Display, drawSurface);
|
||||
}
|
||||
|
||||
if (canFence && g_GLESFuncs.glGetSynciv) {
|
||||
// Fences signal in submission order within one context, so the highest
|
||||
@@ -17648,11 +17900,35 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
//
|
||||
// ONE CONTEXT's teardown is DestroyNativeContextFor (the DestroyContext control frame); this is
|
||||
// the session's.
|
||||
static void DestroyNativeStateOfSession(Uint64 sessionKey);
|
||||
|
||||
void DestroyEGLContext() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith)
|
||||
MG_Pipe::MGPipeServerSetContextLive(false);
|
||||
#endif
|
||||
// P14: ANOTHER SESSION'S CONTEXT STILL LIVES. Every native context is in one share group, so
|
||||
// the buffers, textures and syncs this process's backend holds outlive this session's
|
||||
// contexts: bumping the process-wide generations here told every live session that its
|
||||
// GL objects were dead, and they were rebuilt EMPTY (a client exiting or closing its last
|
||||
// window turned the compositor's textures to noise). Only this session's own state goes;
|
||||
// the process-wide reset below is for the last context in the process.
|
||||
const Uint64 endingSession = CurrentNativeSessionKey();
|
||||
Bool othersLive = false;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
for (auto* tuple : NativeContexts()) {
|
||||
if (tuple->SessionKey != endingSession && tuple->Context != EGL_NO_CONTEXT) {
|
||||
othersLive = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (othersLive) {
|
||||
BufferImpl::OnServerSessionEndedWithOthersLive();
|
||||
DestroyNativeStateOfSession(endingSession);
|
||||
return;
|
||||
}
|
||||
BufferImpl::OnBackendContextDestroyed();
|
||||
XfbImpl::OnBackendContextDestroyed();
|
||||
MultiDrawImpl::OnBackendContextDestroyed();
|
||||
@@ -17680,13 +17956,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
g_completedFrameSerial.store(g_currentFrameSerial.load(std::memory_order_relaxed),
|
||||
std::memory_order_relaxed);
|
||||
|
||||
const Uint64 sessionKey = CurrentNativeSessionKey();
|
||||
DestroyNativeStateOfSession(CurrentNativeSessionKey());
|
||||
}
|
||||
|
||||
// This session's native contexts and surfaces, and the display when they were the last.
|
||||
static void DestroyNativeStateOfSession(Uint64 sessionKey) {
|
||||
if (g_Display == EGL_NO_DISPLAY) return;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_nativeRegistryMutex);
|
||||
if (g_EGLFuncs.eglMakeCurrent) {
|
||||
g_EGLFuncs.eglMakeCurrent(g_Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
}
|
||||
t_boundNativeContext = EGL_NO_CONTEXT;
|
||||
t_boundNativeDraw = EGL_NO_SURFACE;
|
||||
for (auto* tuple : NativeContexts()) {
|
||||
if (tuple->SessionKey != sessionKey || tuple->Context == EGL_NO_CONTEXT) continue;
|
||||
if (g_EGLFuncs.eglDestroyContext) g_EGLFuncs.eglDestroyContext(g_Display, tuple->Context);
|
||||
@@ -17699,8 +17981,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
for (auto* session : NativeSessions()) {
|
||||
if (session->SessionKey != sessionKey) continue;
|
||||
if (g_EGLFuncs.eglDestroySurface) {
|
||||
for (const EGLSurface surface : session->Surfaces) {
|
||||
if (surface != EGL_NO_SURFACE) g_EGLFuncs.eglDestroySurface(g_Display, surface);
|
||||
for (const auto& entry : session->Surfaces) {
|
||||
if (entry.Surface != EGL_NO_SURFACE) g_EGLFuncs.eglDestroySurface(g_Display, entry.Surface);
|
||||
}
|
||||
}
|
||||
session->Surfaces.clear();
|
||||
|
||||
@@ -111,6 +111,25 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void ShaderStorageBlockBinding(GLuint program, const GLchar* storageBlockName, GLuint storageBlockBinding);
|
||||
Bool InitWindowSurface(NativeWindowType window);
|
||||
Bool InitPbufferSurface(EGLint width, EGLint height);
|
||||
// The calling thread's session's current native draw surface (the one the last Init*Surface
|
||||
// created, or the last BindSessionSurface named).
|
||||
EGLSurface CurrentSessionDrawSurface();
|
||||
// The surface the calling thread's ACTIVE context last drew to (EGL_NO_SURFACE for none).
|
||||
EGLSurface CurrentContextDrawSurface();
|
||||
// Makes an EXISTING native surface of the calling thread's session the one it draws to, and
|
||||
// binds it to the active context. False for a surface the session does not own.
|
||||
Bool BindSessionSurface(EGLSurface surface);
|
||||
// The same selection without the bind (the caller binds - MakeCurrent - unconditionally).
|
||||
Bool SelectSessionSurface(EGLSurface surface);
|
||||
// Destroys one native surface of the calling thread's session - and only it; the session's
|
||||
// contexts and other surfaces are untouched.
|
||||
void DestroySessionSurface(EGLSurface surface);
|
||||
// A new pbuffer of the calling thread's session, created with the active context's config and
|
||||
// bound to nothing (EGL: creating a surface changes no binding).
|
||||
EGLSurface CreateSessionPbuffer(EGLint width, EGLint height);
|
||||
// Every context of the session that drew to `previous` draws to `replacement` instead, and
|
||||
// `previous` is destroyed (a pbuffer-backed window's resize).
|
||||
void ReplaceSessionSurface(EGLSurface previous, EGLSurface replacement);
|
||||
Bool MakeCurrent();
|
||||
Bool ReleaseCurrent();
|
||||
// True when the backend ES context is current on the calling thread, i.e.
|
||||
@@ -223,6 +242,47 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
using NativeContextKeyResolver = Bool (*)(Uint64* outSessionKey, Uint64* outContextToken);
|
||||
void SetNativeContextKeyResolver(NativeContextKeyResolver resolver);
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P14 S6 (docs/Disaggregated/design/11-state-ownership.md): THE TWIN TABLES' KEY, AND ITS
|
||||
// SHAPE IS S4's, ONE LEVEL DOWN. A twin is a DRIVER object, so it lives in one native
|
||||
// context's object namespace; the identity a twin table must be keyed on is therefore
|
||||
// {session, share group} - the SAME two words the applier's OBJECT RECORDS are filed under
|
||||
// (PipeApply.h's MGPipeApplierKey, derived by the same probe and the same `0 means its own
|
||||
// group` rule, so the two agree by construction rather than by two conventions).
|
||||
//
|
||||
// Answers, for the CALLING THREAD, which session it belongs to and which share group that
|
||||
// session's current context is in. Installed once by the server layer beside the native and
|
||||
// applier probes; with no probe installed - or on a thread that is no session's own, which
|
||||
// is the client process, the in-process client+server shape and every unit case - the
|
||||
// answer is the single key {0, 0}, exactly the process-wide table this replaces.
|
||||
struct TwinKey {
|
||||
Uint64 SessionKey = 0;
|
||||
Uint64 ShareGroupKey = 0;
|
||||
Bool operator==(const TwinKey& other) const {
|
||||
return SessionKey == other.SessionKey && ShareGroupKey == other.ShareGroupKey;
|
||||
}
|
||||
Bool operator!=(const TwinKey& other) const { return !(*this == other); }
|
||||
};
|
||||
struct TwinKeyHash {
|
||||
SizeT operator()(const TwinKey& key) const {
|
||||
// The 64-bit mix SlotAllocator and the applier's registry already use for their own
|
||||
// pair keys, so every keyed table in this tree hashes a session the same way.
|
||||
Uint64 mixed = key.SessionKey ^ (key.ShareGroupKey + 0x9E3779B97F4A7C15ull +
|
||||
(key.SessionKey << 6) + (key.SessionKey >> 2));
|
||||
mixed ^= mixed >> 33;
|
||||
mixed *= 0xFF51AFD7ED558CCDull;
|
||||
mixed ^= mixed >> 33;
|
||||
return static_cast<SizeT>(mixed);
|
||||
}
|
||||
};
|
||||
using TwinKeyResolver = Bool (*)(TwinKey* outKey);
|
||||
void SetTwinKeyResolver(TwinKeyResolver resolver);
|
||||
// The calling thread's key. Answers false for {0, 0} - the process-wide group - which is
|
||||
// also the answer when no probe has ever been installed.
|
||||
Bool CurrentTwinKey(TwinKey* outKey);
|
||||
#endif
|
||||
|
||||
// Builds the native context for `contextToken` under the calling thread's session. A
|
||||
// `shareGroupToken` whose group already has a live native context in this session hands that
|
||||
// context to eglCreateContext as the share argument - which is what makes two contexts see one
|
||||
@@ -240,6 +300,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// native context already current on this thread IS that one - so the single-context world pays
|
||||
// nothing for it. Called from the bind_context path on the apply thread.
|
||||
Bool MakeNativeContextCurrentForBoundToken();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P14: the server's backend turn moved to the calling apply thread (ServerLoop.cpp's
|
||||
// BackendTurnLock). Takes the backend's GL ownership for this thread and drops every
|
||||
// binding shadow, which still describes the previous holder's native context.
|
||||
void OnBackendTurnHandoff();
|
||||
#endif
|
||||
// How many native contexts this process holds, and how many of them belong to one session. The
|
||||
// test observables for "a second context did not tear the first one down".
|
||||
Uint64 NativeContextCount();
|
||||
|
||||
@@ -416,17 +416,41 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the textures they view, framebuffers before their attachments, VAOs before the buffers they
|
||||
// fetch from), so the last reference to each twin goes here and its destructor - answered
|
||||
// InProcessTeardown() - touches neither the driver nor another TU's statics.
|
||||
//
|
||||
// P14 S6: "EVERY TABLE" IS NOW "EVERY BUCKET OF THIS SESSION". The tables are keyed by
|
||||
// {session, share group}, so the same rebuild of the eight registries would take a NEIGHBOUR
|
||||
// session's twins with it - and with S2's in-process supervisor serving several sessions at
|
||||
// once that is not a hypothetical: this runs from ~BackendObject_DirectGLES, on the apply
|
||||
// thread of the session that is ending. So the drop is scoped to the calling thread's
|
||||
// session when it has one, and is the process-wide drop (key {0, 0} and nothing else) when it
|
||||
// does not - which is the shape every unit case and the fork-worker world still has.
|
||||
void DropEveryTwinForEndedServerSession() {
|
||||
if (g_processTeardown) return;
|
||||
g_serverSessionTwinTeardown = true;
|
||||
SamplerViewImpl::g_backendSamplerViews = {};
|
||||
FramebufferImpl::g_backendFramebufferObjects = {};
|
||||
VertexArrayImpl::g_backendVertexArrayObjects = {};
|
||||
PrgramImpl::g_backendProgramObjects = {};
|
||||
SamplerImpl::g_backendSamplerObjects = {};
|
||||
TextureImpl::g_backendTextureObjects = {};
|
||||
RenderbufferImpl::g_backendRenderbufferObjects = {};
|
||||
BufferImpl::g_backendBufferResources = {};
|
||||
TwinKey key;
|
||||
if (CurrentTwinKey(&key) && key.SessionKey != 0) {
|
||||
Uint32 buckets = 0;
|
||||
buckets += SamplerViewImpl::g_backendSamplerViews.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += FramebufferImpl::g_backendFramebufferObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += VertexArrayImpl::g_backendVertexArrayObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += PrgramImpl::g_backendProgramObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += SamplerImpl::g_backendSamplerObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += TextureImpl::g_backendTextureObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += RenderbufferImpl::g_backendRenderbufferObjects.DropBucketsOfSession(key.SessionKey);
|
||||
buckets += BufferImpl::g_backendBufferResources.DropBucketsOfSession(key.SessionKey);
|
||||
MGLOG_I("DirectGLES: the ended server session dropped %u twin group(s) across eight kinds "
|
||||
"(no driver call); the other sessions in this process keep theirs",
|
||||
buckets);
|
||||
} else {
|
||||
SamplerViewImpl::g_backendSamplerViews.ResetBuckets();
|
||||
FramebufferImpl::g_backendFramebufferObjects.ResetBuckets();
|
||||
VertexArrayImpl::g_backendVertexArrayObjects.ResetBuckets();
|
||||
PrgramImpl::g_backendProgramObjects.ResetBuckets();
|
||||
SamplerImpl::g_backendSamplerObjects.ResetBuckets();
|
||||
TextureImpl::g_backendTextureObjects.ResetBuckets();
|
||||
RenderbufferImpl::g_backendRenderbufferObjects.ResetBuckets();
|
||||
BufferImpl::g_backendBufferResources.ResetBuckets();
|
||||
}
|
||||
// P12 review fix (major): AND THE UNIT SHADOWS THAT POINT AT THEM. A texture or sampler twin
|
||||
// scrubs itself out of g_boundTexturesCache / g_boundSamplersCache in its destructor - but
|
||||
// not under InProcessTeardown(), which answered true for every twin just dropped. Left
|
||||
@@ -438,8 +462,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
TextureImpl::g_activeTextureUnit = 0;
|
||||
SamplerImpl::g_boundSamplersCache = {};
|
||||
g_serverSessionTwinTeardown = false;
|
||||
MGLOG_I("DirectGLES: the ended server session's twins are dropped (every kind, no driver call); the next "
|
||||
"session in this process starts from empty twin tables");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3850,6 +3872,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
g_hasDeferredBufferReleases.store(false, std::memory_order_release);
|
||||
}
|
||||
|
||||
void OnServerSessionEndedWithOthersLive() {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// Only what belongs to the ending session: its staged bytes (both stores are
|
||||
// session-scoped). The rings, the ops table and the buffer generation are the
|
||||
// process's and every other session's GL buffers are still alive in the shared group.
|
||||
MGL_SERVER_STAGED_DROP_ALL();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Remote::Server::ServerStagedTexture().DropAll();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnBackendContextDestroyed() {
|
||||
UnregisterBufferBackendOps(); // also bumps the buffer-mutation epoch
|
||||
++g_bufferContextGeneration;
|
||||
@@ -9675,8 +9709,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// entry's rects are then read out of the SERVER'S WHOLE LEVEL IMAGE -
|
||||
// which is what the derived pointer names - and those piece-relative
|
||||
// offsets are precisely the ones that must not be used here.
|
||||
//
|
||||
// GATED ON regionsAddressable, NOT subRectEligible: the per-region arm
|
||||
// for a level the GPU may have written (m_driverMayHoldGpuWrites below)
|
||||
// reads MGB_RECT_SRC_PTR too, and it runs exactly when the union box is
|
||||
// the whole level - which is what two or more slab pieces always add up
|
||||
// to. Checked only under subRectEligible, a damage rect split across
|
||||
// pieces kept the later pieces' run-relative offsets and read their
|
||||
// rows from the top of the level image (KWin's wl_shm window textures:
|
||||
// the panel repeated down the desktop). bpp is valid whenever the
|
||||
// regions are addressable.
|
||||
Bool pendingOffsetsAgree = true;
|
||||
if (pendingUpload != nullptr && subRectEligible && carriedLayoutApplies) {
|
||||
if (pendingUpload != nullptr && regionsAddressable && carriedLayoutApplies) {
|
||||
for (const auto& region : pendingUpload->Regions) {
|
||||
const SizeT derivedOffset = static_cast<SizeT>(region.Z) * levelSliceBytes +
|
||||
static_cast<SizeT>(region.Y) * levelRowBytes +
|
||||
|
||||
@@ -332,6 +332,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
using const_iterator = typename BackendMap::const_iterator;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
using SlotTable = BackendSlotTable<StateObject, BackendObject, kKind>;
|
||||
// P14 S6: the ONE bucket of this kind the calling thread is in. Every handle-keyed entry
|
||||
// below resolves through it, so the six twin registries answer per {session, share
|
||||
// group} without a single call site naming a bucket.
|
||||
using SlotTables = SlotTableRegistry<StateObject, BackendObject, kKind>;
|
||||
using TwinKey = DirectGLES::TwinKey;
|
||||
#endif
|
||||
|
||||
BackendPtr& GetOrCreate(const StatePtr& stateObj) {
|
||||
@@ -348,7 +353,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// insertion (D13; SlotTables.h) - so a table used outside a registry arms
|
||||
// it too, which is right: it is the twin, not the registry, that owns the
|
||||
// driver id a guarded destructor exists for.
|
||||
return m_slotTable.GetOrCreate(stateObj);
|
||||
return m_slotTables.ForCallingThread().GetOrCreate(stateObj);
|
||||
}
|
||||
#endif
|
||||
// Twin creation is the moment a driver-owned id starts needing a guarded
|
||||
@@ -407,7 +412,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
return m_slotTable.Find(stateObj);
|
||||
return m_slotTables.ForCallingThread().Find(stateObj);
|
||||
}
|
||||
#endif
|
||||
const auto entryIt = m_entries.find(stateObj);
|
||||
@@ -445,7 +450,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// backend memo stores instead of a raw pointer, a GL name or a bare lifetime id.
|
||||
MG_Pipe::MGPipeHandle HandleOf(const StateObject* stateObj) const {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
return m_slotTable.HandleOf(stateObj);
|
||||
return m_slotTables.HandleOf(stateObj);
|
||||
}
|
||||
return MG_Pipe::kMGPipeNullHandle;
|
||||
}
|
||||
@@ -454,7 +459,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the lookup a backend memo that already holds a handle wants: no lifetime-id probe.
|
||||
BackendPtr* FindByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
return m_slotTable.FindByHandle(handle);
|
||||
return m_slotTables.FindByHandle(handle);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -490,7 +495,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
const Uint32 liveGen = m_slotTable.LiveGenAt(handle.Slot);
|
||||
const Uint32 liveGen = m_slotTables.LiveGenAt(handle.Slot);
|
||||
if (liveGen != 0 && liveGen > handle.Gen) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Pipe::MGPipeSessionFail( // @Ph-declined (ID-P7-1): PH-2 stays Fatal, CONTRACT-P7 §12
|
||||
@@ -502,7 +507,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
return &m_slotTable.GetOrCreate(handle);
|
||||
return &m_slotTables.GetOrCreate(handle);
|
||||
}
|
||||
|
||||
// The generation of the LIVE entry at this slot, or 0. It exists so a caller can
|
||||
@@ -510,7 +515,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// performs silently.
|
||||
Uint32 LiveGenAt(Uint32 slot) const {
|
||||
if (!EsprytSlotTablesEnabled()) return 0;
|
||||
return m_slotTable.LiveGenAt(slot);
|
||||
return m_slotTables.LiveGenAt(slot);
|
||||
}
|
||||
|
||||
// P5c (hd): the two halves of SlotTables.h's state note, forwarded. A caller holding
|
||||
@@ -524,12 +529,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// which is the answer the legacy walk's own weak_ptr test already gives.
|
||||
void NoteStateForHandle(MG_Pipe::MGPipeHandle handle, const StatePtr& stateObj) {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
m_slotTable.NoteStateForHandle(handle, stateObj);
|
||||
m_slotTables.NoteStateForHandle(handle, stateObj);
|
||||
}
|
||||
}
|
||||
StatePtr StateForHandle(MG_Pipe::MGPipeHandle handle) const {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
return m_slotTable.StateForHandle(handle);
|
||||
return m_slotTables.StateForHandle(handle);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -591,9 +596,52 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
template <typename Fn>
|
||||
void ForEachLive(Fn&& fn) const {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
m_slotTable.ForEachLive(fn);
|
||||
m_slotTables.ForEachLive(fn);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- P14 S6: the KEYED shape's own controls ----------------------------------------
|
||||
//
|
||||
// Everything above is the shape a CALL SITE sees, and it is deliberately the shape it
|
||||
// saw before the rekey. These four are the shape only a caller that has to reason about
|
||||
// buckets needs: the teardown of a session, a test asking whether two contexts landed in
|
||||
// two namespaces, and a diagnostic.
|
||||
//
|
||||
// THE ONE BUCKET THIS THREAD RESOLVES TO. A by-value copy of it is exactly what a
|
||||
// fixture's saved registry was, and it is what makes `= {}` and "put it back" both mean
|
||||
// something under a key.
|
||||
SlotTable& BucketForCallingThread() {
|
||||
if (EsprytSlotTablesEnabled()) return m_slotTables.ForCallingThread();
|
||||
// The legacy arm has no buckets; the empty table's Reset() is the only honest
|
||||
// answer, and no shipping path asks (the arm is compiled out or the bit is clear).
|
||||
return m_legacyEmptyTable;
|
||||
}
|
||||
|
||||
Vector<SharedPtr<SlotTable>> BucketSnapshot() const {
|
||||
if (EsprytSlotTablesEnabled()) return m_slotTables.Snapshot();
|
||||
return {};
|
||||
}
|
||||
SizeT BucketCount() const {
|
||||
return EsprytSlotTablesEnabled() ? m_slotTables.BucketCount() : 0;
|
||||
}
|
||||
// Drop one {session, share group}. Answers whether such a bucket existed.
|
||||
Bool DropBucket(const TwinKey& key) {
|
||||
return EsprytSlotTablesEnabled() && m_slotTables.Drop(key);
|
||||
}
|
||||
// Drop every bucket of one session - the difference between "this session's twins go"
|
||||
// and "the process's do" - and answer how many groups that took with it.
|
||||
Uint32 DropBucketsOfSession(Uint64 sessionKey) {
|
||||
return EsprytSlotTablesEnabled() ? m_slotTables.DropSession(sessionKey) : 0;
|
||||
}
|
||||
// Empty every bucket. The teardown of a process-shaped world, where the key is {0, 0}.
|
||||
void ResetBuckets() {
|
||||
if (EsprytSlotTablesEnabled()) m_slotTables.Reset();
|
||||
}
|
||||
// Every bucket, walked with its key.
|
||||
template <typename Fn>
|
||||
void ForEachBucket(Fn&& fn) const {
|
||||
if (EsprytSlotTablesEnabled()) m_slotTables.ForEachBucket(fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
// The seven DirectGLES.cpp call sites drive the LEGACY arm and nothing else. On the
|
||||
@@ -664,7 +712,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Uint32 m_creationTick = 0;
|
||||
Bool m_isCollecting = false;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
BackendSlotTable<StateObject, BackendObject, kKind> m_slotTable;
|
||||
// P14 S6: the ONE bucket per {session, share group}, hidden behind the same member names
|
||||
// the single table had, so every handle-keyed call site above and every caller below is
|
||||
// unchanged. See SlotTables.h's SlotTableRegistry for the resolution chain.
|
||||
SlotTables m_slotTables;
|
||||
// The legacy arm's stand-in for BucketForCallingThread(). Never read after a Reset and
|
||||
// never populated: the two entries that could write it are the handle-keyed ones, which
|
||||
// return early on that arm.
|
||||
SlotTable m_legacyEmptyTable;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1081,8 +1136,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// HandleOf, no ForEachLive), and the handle overloads never look at it. Death is
|
||||
// announced by the family's own ResourceDestroy call, not by the shared death notice
|
||||
// (D-L), and the slot is freed by the CLIENT after that call returns.
|
||||
//
|
||||
// P14 S6: A BUCKET REGISTRY, like the six TwinRegistry tables. A buffer twin owns a
|
||||
// driver buffer id, so the SAME {slot, gen} in two contexts that do not share a group
|
||||
// must be two resources - and it was one process-wide table until this slice. The
|
||||
// handle-keyed member-for-member forwarding in SlotTables.h is what leaves every
|
||||
// `g_backendBufferResources.X(...)` call site below untouched.
|
||||
using BackendBufferResourceTable =
|
||||
BackendSlotTable<MG_State::GLState::BufferObject, GLESBufferResource, MG_Pipe::MGPipeKind::Buffer>;
|
||||
SlotTableRegistry<MG_State::GLState::BufferObject, GLESBufferResource, MG_Pipe::MGPipeKind::Buffer>;
|
||||
extern BackendBufferResourceTable g_backendBufferResources;
|
||||
|
||||
// Resolved once per process and latched, exactly like EsprytSlotTablesEnabled() and
|
||||
@@ -1305,6 +1366,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void UnregisterBufferBackendOps();
|
||||
// The ES context died: unregister ops, invalidate all outstanding GL ids
|
||||
// (they belonged to the dead context) and drop deferred deletes.
|
||||
// P14: a server session ended while another session's native context is still alive (one
|
||||
// process-wide share group): drops only the ending session's own staged bytes.
|
||||
void OnServerSessionEndedWithOthersLive();
|
||||
void OnBackendContextDestroyed();
|
||||
|
||||
// Get-or-create the backend resource and bring its storage up to date
|
||||
@@ -2186,10 +2250,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// unconditionally bumps it), the content version on every CPU pixel mutation, and
|
||||
// the params version covers SetSamples/SetFixedSampleLocations, which bump neither
|
||||
// of the other two but feed the shape probe. The context id pins the generation to
|
||||
// the context that produced it - generations restart at 0 with a new context, and a
|
||||
// texture is owned by exactly one context (share groups are not implemented), so a
|
||||
// mutation can never happen under a context this key does not name. 0 = never
|
||||
// stamped (real context ids start at 1). Backend-side invalidation rides on
|
||||
// the context that produced it - generations restart at 0 with a new context, so the
|
||||
// id is part of the key. IT IS NOT AN OWNERSHIP CLAIM: a texture belongs to a SHARE
|
||||
// GROUP (P14 S3/S6 - share groups ARE implemented, `ShareGroupState` holds the object
|
||||
// tables and the twin tables are keyed by {session, share group}), so two contexts of
|
||||
// one group both legitimately mutate this texture. What the id buys is only the
|
||||
// cheaper half of the gate: a mutation made under a context sharing this texture
|
||||
// stamps a different id and re-derives the shape, which is a spurious re-derivation
|
||||
// (safe, and only on a shape mutation) rather than a missed one - the per-mutation
|
||||
// versions below are what actually catch a change, and they are group-independent.
|
||||
// 0 = never stamped (real context ids start at 1). Backend-side invalidation rides on
|
||||
// m_isInitialized: RequireImageBindableStorage and RecreateBackendTexture clear it.
|
||||
Uint64 m_syncedShapeContextId = 0;
|
||||
Uint64 m_syncedShapeGeneration = 0;
|
||||
@@ -3639,7 +3709,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// what makes HandleOf below resolve at all. Not one member that would dereference it is
|
||||
// instantiated - no Find(StateObject*), no ForEachLive - and the handle overloads never
|
||||
// look at it.
|
||||
using BackendSamplerViewTable = BackendSlotTable<MG_State::GLState::ITextureObject,
|
||||
// P14 S6: and a bucket registry for the same reason the buffer one above is - a sampler
|
||||
// view's twin is a driver object of the texture's group.
|
||||
using BackendSamplerViewTable = SlotTableRegistry<MG_State::GLState::ITextureObject,
|
||||
BackendSamplerViewObject,
|
||||
MG_Pipe::MGPipeKind::SamplerViewCso>;
|
||||
extern BackendSamplerViewTable g_backendSamplerViews;
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
|
||||
#include <MG_Pipe/MGPipeHandles.h>
|
||||
|
||||
// P14 S6: the key this table is filed under includes the calling thread's {session, share
|
||||
// group}, and the probe that answers it lives on the backend's public surface beside S4's
|
||||
// native-tuple key (DirectGLES.h). Included here so this header is self-contained for the two
|
||||
// translation units that include it without copying Managers.h's include order.
|
||||
#include "DirectGLES.h"
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include <MG_Impl/Pipe/SlotAllocator.h>
|
||||
#endif
|
||||
@@ -155,6 +161,249 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// P14 S6 (docs/Disaggregated/design/11-state-ownership.md): THE TWIN TABLE IS PER
|
||||
// {session, share group}, NOT PER PROCESS.
|
||||
// =====================================================================================
|
||||
//
|
||||
// WHAT WAS WRONG, in one sentence: a twin is a DRIVER object - a GL buffer id, a program, a
|
||||
// texture, the storage behind them - so it belongs to one native context's object namespace,
|
||||
// and a table keyed by {slot, gen} ALONE resolves the same handle value to the same twin
|
||||
// whichever context asked. The frontend gives two contexts that do NOT share a group two
|
||||
// independent name spaces, so the same {slot, gen} in both is legal and means two different
|
||||
// objects; one process-wide table made the second context adopt the first's twin (including
|
||||
// its driver ids, its persistent map and its pooled store). At the same time two contexts of
|
||||
// ONE group - which must see one set of objects - were served by whichever of them twinned
|
||||
// first, i.e. by luck rather than by the group the two agree on.
|
||||
//
|
||||
// THE KEY IS the same pair the applier files its OBJECT RECORDS under: {session, share
|
||||
// group}. Same probe, same `0 means this context started its own group` rule (see
|
||||
// DirectGLES.h's TwinKey and SessionRuntime.cpp's ResolveThreadTwinKey), so a record and the
|
||||
// twin it describes are always in the same bucket. Session is in the key because a twin
|
||||
// names a driver id and no driver id crosses a connection - two connections in one process
|
||||
// are two clients, and nothing may be shared with either from the other.
|
||||
//
|
||||
// THE HOLDER LIST STAYS PROCESS-WIDE AND THAT IS NOT A COMPROMISE. A notice is about an
|
||||
// OBJECT, not about a bucket: OnFrontendObjectDestroyed and ReleaseTwinByHandle must reach
|
||||
// the by-value copies a fixture or a context reset is holding, whichever bucket they sit in,
|
||||
// and "which bucket holds it" is exactly the question that produced the two-holder leak the
|
||||
// list exists to fix. Each SHARED holder of the list is ONE bucket; the walk therefore covers
|
||||
// every bucket of every table.
|
||||
//
|
||||
// THE SAME TABLE OBJECT IS REUSED, NOT REPLACED, and that is what keeps ~200 call sites
|
||||
// alive: `g_backendTextureObjects.Find(...)` still answers from the bucket the calling thread
|
||||
// is in, because the object the global names multiplexes on the key at each lookup. A caller
|
||||
// that must address a bucket OTHER than the calling thread's - the death walks, the
|
||||
// session-teardown drop - takes Shared() or calls the static entries, which walk buckets;
|
||||
// and a caller that wants the whole process's view (the teardown, the tests) takes Snapshot().
|
||||
// FORWARD-DECLARED, because the registry below is DEFINED before the table it holds; the
|
||||
// members that name the table are defined out of line at the bottom of this header.
|
||||
template <typename StateObject, typename BackendObject, MG_Pipe::MGPipeKind kKind>
|
||||
class BackendSlotTable;
|
||||
|
||||
template <typename StateObject, typename BackendObject, MG_Pipe::MGPipeKind kKind>
|
||||
class SlotTableRegistry {
|
||||
public:
|
||||
using Table = BackendSlotTable<StateObject, BackendObject, kKind>;
|
||||
using Key = TwinKey;
|
||||
using StatePtr = SharedPtr<StateObject>;
|
||||
using BackendPtr = SharedPtr<BackendObject>;
|
||||
// The bound the two tables that ARE a bucket registry have always spelled by name; the
|
||||
// six registries reach it through their own `SlotTable` alias.
|
||||
static constexpr Uint32 kMaxHandleSlot = 1u << 20;
|
||||
|
||||
// One bucket. SHARED, so a caller may keep it across other lookups: the map owns the
|
||||
// pointee and never moves it.
|
||||
SharedPtr<Table> Shared(const Key& key) const {
|
||||
// The common case on the hot path: the same key as last time. One compare, no probe.
|
||||
if (m_memoTable != nullptr && m_memoKey == key) return m_memoTable;
|
||||
const auto found = m_buckets.find(key);
|
||||
if (found != m_buckets.end()) {
|
||||
m_memoKey = key;
|
||||
m_memoTable = found->second;
|
||||
return found->second;
|
||||
}
|
||||
SharedPtr<Table> fresh = MakeShared<Table>();
|
||||
m_buckets.emplace(key, fresh);
|
||||
m_memoKey = key;
|
||||
m_memoTable = fresh;
|
||||
return fresh;
|
||||
}
|
||||
|
||||
// The calling thread's bucket - the ONE entry every in-place call site below resolves
|
||||
// through, and the process-wide answer on a thread that belongs to no session.
|
||||
//
|
||||
// CONST, AND IT ANSWERS A MUTABLE BUCKET: the index is `mutable` because a LOOKUP may
|
||||
// have to create the bucket it is about to miss in (a handle with no twin yet is the
|
||||
// ordinary case), and the bucket's own entries are the table's business rather than the
|
||||
// registry's. The alternative - a const overload returning "no table" - would make every
|
||||
// read-only caller handle a case that cannot arise.
|
||||
Table& ForCallingThread() const {
|
||||
Key key;
|
||||
CurrentTwinKey(&key);
|
||||
return *Shared(key);
|
||||
}
|
||||
|
||||
// Every bucket, in no particular order.
|
||||
Vector<SharedPtr<Table>> Snapshot() const {
|
||||
Vector<SharedPtr<Table>> all;
|
||||
all.reserve(m_buckets.size());
|
||||
for (const auto& bucket : m_buckets) all.push_back(bucket.second);
|
||||
return all;
|
||||
}
|
||||
|
||||
SizeT BucketCount() const { return m_buckets.size(); }
|
||||
|
||||
// THE PER-BUCKET ONE-SHOT, because a bucket held by SharedPtr is never dropped by an
|
||||
// assignment: a caller that means "this context/group is gone" has to be able to say so,
|
||||
// and the key is how it says which one. The bucket LEAVES the index before its twins are
|
||||
// released, so a twin destructor that re-entered Shared() cannot find a half-erased one.
|
||||
Bool Drop(const Key& key) {
|
||||
const auto found = m_buckets.find(key);
|
||||
if (found == m_buckets.end()) return false;
|
||||
SharedPtr<Table> dropped = found->second;
|
||||
m_buckets.erase(found);
|
||||
if (m_memoTable == dropped) {
|
||||
m_memoKey = Key{};
|
||||
m_memoTable = nullptr;
|
||||
}
|
||||
dropped->Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
// EVERY bucket of one session, for the teardown of a session that owned several groups.
|
||||
// The session is the key's high half, so this is one pass and no per-group bookkeeping -
|
||||
// and it is the difference between "this session's twins go" and "the process's do".
|
||||
Uint32 DropSession(Uint64 sessionKey) {
|
||||
Uint32 dropped = 0;
|
||||
for (auto bucket = m_buckets.begin(); bucket != m_buckets.end();) {
|
||||
if (bucket->first.SessionKey != sessionKey) {
|
||||
++bucket;
|
||||
continue;
|
||||
}
|
||||
SharedPtr<Table> table = bucket->second;
|
||||
if (m_memoTable == table) {
|
||||
m_memoKey = Key{};
|
||||
m_memoTable = nullptr;
|
||||
}
|
||||
bucket = m_buckets.erase(bucket);
|
||||
table->Reset();
|
||||
++dropped;
|
||||
}
|
||||
return dropped;
|
||||
}
|
||||
|
||||
// Replace this registry with an empty one, releasing every bucket's twins. This is what
|
||||
// `registry = {}` meant when the registry WAS one table; a caller that must keep the
|
||||
// tables alive past the call takes a Snapshot() first.
|
||||
void Reset() {
|
||||
const Vector<SharedPtr<Table>> all = Snapshot();
|
||||
m_buckets.clear();
|
||||
m_memoKey = Key{};
|
||||
m_memoTable = nullptr;
|
||||
for (const SharedPtr<Table>& table : all) table->Reset();
|
||||
}
|
||||
|
||||
// ---- the calling thread's bucket, member for member ---------------------------------
|
||||
//
|
||||
// THIS IS WHY THE SHAPE COST THE CALL SITES NOTHING. Every handle-keyed entry the table
|
||||
// has is repeated here and forwarded to the bucket the calling thread resolves to, so
|
||||
// `g_backendTextureObjects.FindByHandle(h)` and `g_backendBufferResources.GetOrCreate(h)`
|
||||
// - unchanged source - answer from the right context's object namespace. A caller that
|
||||
// must name a bucket OTHER than its own (a death walk, a case) takes Shared()/Snapshot()
|
||||
// and calls the table directly.
|
||||
BackendPtr& GetOrCreate(MG_Pipe::MGPipeHandle handle) {
|
||||
return ForCallingThread().GetOrCreate(handle);
|
||||
}
|
||||
BackendPtr* FindByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
return ForCallingThread().FindByHandle(handle);
|
||||
}
|
||||
const BackendPtr* FindByHandle(MG_Pipe::MGPipeHandle handle) const {
|
||||
return ForCallingThread().FindByHandle(handle);
|
||||
}
|
||||
// Resolve-or-create in a bucket the caller NAMES rather than the one it is in. The
|
||||
// monolith-glue frontend-keyed entry (StateBackendObjectRegistry::GetOrCreate below)
|
||||
// needs it: a state object handed over on the client side of a sync is described by a
|
||||
// record in the CALLING thread's group, and a twin built for it must land in the same
|
||||
// bucket as that record.
|
||||
BackendPtr& GetOrCreateIn(const Key& key, MG_Pipe::MGPipeHandle handle) {
|
||||
return Shared(key)->GetOrCreate(handle);
|
||||
}
|
||||
Uint32 LiveGenAt(Uint32 slot) const { return ForCallingThread().LiveGenAt(slot); }
|
||||
MG_Pipe::MGPipeHandle HandleOf(const StateObject* stateObj) const {
|
||||
return ForCallingThread().HandleOf(stateObj);
|
||||
}
|
||||
void NoteStateForHandle(MG_Pipe::MGPipeHandle handle, const StatePtr& stateObj) {
|
||||
ForCallingThread().NoteStateForHandle(handle, stateObj);
|
||||
}
|
||||
StatePtr StateForHandle(MG_Pipe::MGPipeHandle handle) const {
|
||||
return ForCallingThread().StateForHandle(handle);
|
||||
}
|
||||
template <typename Fn>
|
||||
void ForEachLive(Fn&& fn) const {
|
||||
// THE CALLING THREAD'S BUCKET, not every bucket, and that is the semantic answer
|
||||
// rather than a shortcut: a caller walking twins is asking "which of the objects I
|
||||
// can see need this", and what it can see is its own share group. Every bucket in
|
||||
// one process would walk a neighbour session's objects.
|
||||
ForCallingThread().ForEachLive(fn);
|
||||
}
|
||||
// Every bucket, in one pass. The caller receives the key with the handle so it can tell
|
||||
// which context a twin belongs to - the only walks that need the whole process's view
|
||||
// are a diagnostic and a teardown.
|
||||
template <typename Fn>
|
||||
void ForEachBucket(Fn&& fn) const {
|
||||
for (const auto& bucket : m_buckets) {
|
||||
bucket.second->ForEachLive(
|
||||
[&](MG_Pipe::MGPipeHandle handle, const BackendPtr& twin) { fn(bucket.first, handle, twin); });
|
||||
}
|
||||
}
|
||||
// The process-wide answer for the two statics: a notice is about an OBJECT, so it must
|
||||
// reach the twin in EVERY bucket of EVERY holder. They forward to the table's own
|
||||
// statics, which walk the holder list - each SHARED holder of it is one bucket.
|
||||
static Bool ReleaseTwinByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
return Table::ReleaseTwinByHandle(handle);
|
||||
}
|
||||
static Bool OnFrontendObjectDestroyed(Uint64 lifetimeId) {
|
||||
return Table::OnFrontendObjectDestroyed(lifetimeId);
|
||||
}
|
||||
// The instance spelling, and it HANDS THE TWIN OUT rather than answering a Bool: the two
|
||||
// tables that ARE a bucket registry (buffers, sampler views) have always been called as
|
||||
// `g_backendBufferResources.ReleaseByHandle(res)` and their callers still have to decide
|
||||
// what happens to the driver id the twin owns. The bucket is the CALLING THREAD'S, which
|
||||
// is the bucket that twin was created in.
|
||||
BackendPtr ReleaseByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
return ForCallingThread().ReleaseByHandle(handle);
|
||||
}
|
||||
static Uint32 HolderCount() { return Table::HolderCount(); }
|
||||
Uint32 LiveCount() const { return ForCallingThread().LiveCount(); }
|
||||
Uint32 CompositeLiveCount() const { return ForCallingThread().CompositeLiveCount(); }
|
||||
SizeT OrdinaryCapacityForTest() const { return ForCallingThread().OrdinaryCapacityForTest(); }
|
||||
SizeT CompositeCapacityForTest() const { return ForCallingThread().CompositeCapacityForTest(); }
|
||||
|
||||
// ---- the bucket index's own controls, for the two tables that ARE a registry --------
|
||||
//
|
||||
// The six TwinRegistry registries carry the same three under the names in Managers.h
|
||||
// (DropBucket / DropBucketsOfSession / ResetBuckets); they are repeated here because
|
||||
// SlotTableRegistry IS the public type of the buffer and sampler-view tables, so a caller
|
||||
// of those has no registry object in between.
|
||||
Bool DropBucket(const Key& key) { return Drop(key); }
|
||||
// Drop every bucket of one session; answers how many groups that took with it.
|
||||
Uint32 DropBucketsOfSession(Uint64 sessionKey) { return DropSession(sessionKey); }
|
||||
// Empty every bucket (the process-shaped world's teardown, key {0, 0}).
|
||||
void ResetBuckets() { Reset(); }
|
||||
|
||||
private:
|
||||
// ONE BUCKET PER LIVE {session, share group}, held by SHARED pointer so a caller may
|
||||
// snapshot one across other lookups and so `Drop` can take a bucket's twins away
|
||||
// explicitly - an embedded table could do neither. `std::unordered_map` rather than the
|
||||
// tree's own flat Vector: this map is probed once per twin lookup on the draw path.
|
||||
mutable std::unordered_map<Key, SharedPtr<Table>, TwinKeyHash> m_buckets;
|
||||
// Hot-path memo. A registry is per KIND and each kind is touched several times per draw;
|
||||
// a thread only ever moves between buckets when its session binds another context.
|
||||
mutable SharedPtr<Table> m_memoTable;
|
||||
mutable Key m_memoKey;
|
||||
};
|
||||
|
||||
template <typename StateObject, typename BackendObject, MG_Pipe::MGPipeKind kKind>
|
||||
class BackendSlotTable {
|
||||
public:
|
||||
@@ -616,6 +865,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
}
|
||||
|
||||
// Empty this table, releasing every twin it holds. THE SPACES ARE MOVED OUT FIRST and
|
||||
// that is the whole of the care taken here: a twin's destructor is a driver call that
|
||||
// could re-enter GetOrCreate on this table (SlotTables.h's ReleaseTwinAt says why), and
|
||||
// destroying the entries in place would leave that re-entry resizing the vector the
|
||||
// destructors are being walked out of. Here the table is already empty when the entries
|
||||
// die, so a re-entrant insert grows a fresh vector.
|
||||
//
|
||||
// This is what `table = {}` used to mean, spelled so a caller cannot miss the ordering.
|
||||
void Reset() {
|
||||
Vector<Entry> slots = std::move(m_slots);
|
||||
Vector<Entry> band = std::move(m_band);
|
||||
BackendPtr nullTwin = std::move(m_nullTwin);
|
||||
ForgetHandle();
|
||||
slots.clear();
|
||||
band.clear();
|
||||
nullTwin.reset();
|
||||
}
|
||||
|
||||
Uint32 LiveCount() const {
|
||||
Uint32 count = 0;
|
||||
for (const Entry& entry : m_slots) {
|
||||
|
||||
@@ -339,6 +339,8 @@ namespace MobileGL::MG_Pipe {
|
||||
inputs.m_live = live;
|
||||
inputs.m_contextIdentity = identity;
|
||||
}
|
||||
static void SetServerContextLive(PipeInputs& inputs, Bool live) { inputs.m_serverContextLive = live; }
|
||||
static Bool ServerContextLive(const PipeInputs& inputs) { return inputs.m_serverContextLive; }
|
||||
};
|
||||
|
||||
// ---- P5f (f1): the dual-block rehearsal's selection functions (PipeInputs.h) -----------
|
||||
@@ -397,14 +399,13 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeStampAccess::SetServerStamped(MGPipeClientInputs(), false);
|
||||
}
|
||||
|
||||
namespace { Bool g_serverContextLive = false; }
|
||||
|
||||
// The calling thread's block, so the calling session's (PipeInputs.h's m_serverContextLive).
|
||||
void MGPipeServerSetContextLive(Bool live) {
|
||||
g_serverContextLive = live;
|
||||
MGPipeStampAccess::SetServerContextLive(gPipeInputs, live);
|
||||
MGPipeServerBlockNoteIdentity();
|
||||
}
|
||||
|
||||
Bool MGPipeServerContextIsLive() { return g_serverContextLive; }
|
||||
Bool MGPipeServerContextIsLive() { return MGPipeStampAccess::ServerContextLive(gPipeInputs); }
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace { const void* g_serverOwnedWindow = nullptr; }
|
||||
@@ -433,7 +434,7 @@ namespace MobileGL::MG_Pipe {
|
||||
// hands out a null slot - an unnamed crash where the rehearsal exists to produce a
|
||||
// named one.
|
||||
const Uint64 serial = MGPipeApplierContextSerial();
|
||||
MGPipeStampAccess::SetIdentity(gPipeInputs, g_serverContextLive,
|
||||
MGPipeStampAccess::SetIdentity(gPipeInputs, MGPipeServerContextIsLive(),
|
||||
reinterpret_cast<const void*>(static_cast<std::uintptr_t>(
|
||||
(serial << 1) | Uint64{1})));
|
||||
}
|
||||
|
||||
@@ -748,6 +748,12 @@ namespace MobileGL::MG_Pipe {
|
||||
// ---- identity ----
|
||||
const void* m_contextIdentity = nullptr;
|
||||
Bool m_live = false;
|
||||
// MGPipeServerSetContextLive's flag. In the block, not in a process global, because the
|
||||
// in-process display server runs several sessions at once and each has its own served
|
||||
// context: one session's teardown or eglMakeCurrent(NO_CONTEXT) must not mark a
|
||||
// neighbour's context dead mid-frame (P14; the per-thread block resolution below is
|
||||
// what makes this the calling session's).
|
||||
Bool m_serverContextLive = false;
|
||||
MGPipeVerb m_currentVerb = MGPipeVerb::kVerbCount;
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
MGPipeFilledState m_filled{};
|
||||
|
||||
@@ -76,15 +76,22 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
//
|
||||
// An unchanged token emits NOTHING: an identical eglMakeCurrent is a legal no-op in
|
||||
// EGL and the session is already bound to that context.
|
||||
//
|
||||
// THE COMPARISON IS AGAINST THE BINDING LAST SENT, NOT THIS THREAD'S PREVIOUS CONTEXT
|
||||
// (GLStreamScope in EGLImpl.h): the session has one current context and another thread
|
||||
// may have moved it since this one last bound. The caller holds EGLOperationMutex.
|
||||
thread_local Uint64 t_threadContextToken = 0;
|
||||
Uint64 g_boundContextToken = 0; // guarded by EGLOperationMutex
|
||||
|
||||
void EmitContextBinding(EGLStateContext* state, EGLContext switched, Uint64 previousToken) {
|
||||
(void)previousToken;
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
// The apply thread IS the server in this process; a record emitted there would
|
||||
// wait on the thread that has to apply it (EmitAndWait), which is a deadlock and
|
||||
// not a slow path.
|
||||
if (MG_Remote::Client::RunsAsTheServerRole()) return;
|
||||
const Uint64 token = switched == EGL_NO_CONTEXT ? 0 : state->GetContextClientToken(switched);
|
||||
if (token == previousToken) return;
|
||||
(void)MG_Remote::Client::EmitBindContextRecord(token);
|
||||
t_threadContextToken = switched == EGL_NO_CONTEXT ? 0 : state->GetContextClientToken(switched);
|
||||
StreamBindCallingThreadLocked();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -93,6 +100,24 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
} // namespace
|
||||
|
||||
Bool StreamGateActive() {
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
!MG_Remote::Client::RunsAsTheServerRole();
|
||||
}
|
||||
|
||||
std::recursive_mutex& StreamMutex() { return EGLOperationMutex(); }
|
||||
|
||||
void StreamBindCallingThreadLocked() {
|
||||
const Uint64 token = t_threadContextToken;
|
||||
if (token == g_boundContextToken) return;
|
||||
if (MG_Remote::Client::EmitBindContextRecord(token)) g_boundContextToken = token;
|
||||
}
|
||||
|
||||
namespace {
|
||||
#endif
|
||||
String CurrentThreadIdString() {
|
||||
std::ostringstream stream;
|
||||
stream << std::this_thread::get_id();
|
||||
@@ -169,6 +194,19 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// reads the frame back and attaches it to the wl_surface (WaylandWindow.h). Answers false
|
||||
// when the display is not a Wayland one; otherwise *out is the surface, or EGL_NO_SURFACE
|
||||
// with the error set.
|
||||
// A gbm_surface is scanout memory of a device this library does not draw with; a window
|
||||
// on a GBM display is refused rather than taken for some other kind of window.
|
||||
template <typename State>
|
||||
Bool RefuseGbmWindow(State* state, EGLDisplay dpy) {
|
||||
constexpr EGLenum kPlatformGbm = 0x31D7; // EGL_PLATFORM_GBM_KHR == EGL_PLATFORM_GBM_MESA
|
||||
Uint64 nativeDisplay = 0;
|
||||
EGLenum platform = EGL_NONE;
|
||||
if (!state->GetDisplayNative(dpy, &nativeDisplay, &platform) || platform != kPlatformGbm) return false;
|
||||
MGLOG_W_ONCE("EGL: window surfaces on a GBM display are not supported (offscreen display only)");
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename State>
|
||||
Bool CreateWaylandWindowSurface(State* state, EGLDisplay dpy, EGLConfig config, void* window,
|
||||
Bool platformWindow, EGLSurface* out) {
|
||||
@@ -220,6 +258,25 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
*out = surface;
|
||||
return true;
|
||||
}
|
||||
|
||||
// A WAYLAND WINDOW THE APPLICATION RESIZED (wl_egl_window_resize). As with a driver's own
|
||||
// window surface, the new size takes effect at the next make-current or swap: the EGL
|
||||
// surface reports it, the wl_shm presentation adopts it, and the drawable behind it is
|
||||
// resized so the frame rendered at the new size is the frame read back. Qt resizes the
|
||||
// window and then makes the context current, so the make-current arm is the one it hits.
|
||||
void ApplyWaylandResize(EGLStateContext* state, EGLDisplay dpy, EGLSurface surface) {
|
||||
const auto it = WaylandSurfaces().find(surface);
|
||||
if (it == WaylandSurfaces().end()) return;
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
if (!it->second->TakeResize(&width, &height)) return;
|
||||
(void)state->ResizeSurface(dpy, surface, width, height);
|
||||
auto* backendObject = MG_Backend::pActiveBackendObject.get();
|
||||
if (backendObject == nullptr ||
|
||||
!backendObject->ResizeEGLWindowSurface(surface, static_cast<Uint32>(width), static_cast<Uint32>(height))) {
|
||||
MGLOG_E("Wayland: the drawable behind a %dx%d window could not be resized", width, height);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
@@ -230,6 +287,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
if (RefuseGbmWindow(state, dpy)) return EGL_NO_SURFACE;
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
@@ -321,6 +379,10 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
|
||||
EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface draw) {
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The present is this thread's context's (GLStreamScope in EGLImpl.h).
|
||||
if (StreamGateActive()) StreamBindCallingThreadLocked();
|
||||
#endif
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_FALSE;
|
||||
@@ -348,6 +410,10 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
state->SetError(EGL_BAD_SURFACE);
|
||||
return EGL_FALSE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// A resize made between frames takes effect for the next one.
|
||||
ApplyWaylandResize(state, dpy, draw);
|
||||
#endif
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
@@ -455,6 +521,9 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MGLOG_D("eglMakeCurrent begin thread=%s dpy=%p draw=%p read=%p ctx=%p oldDpy=%p oldDraw=%p oldRead=%p oldCtx=%p",
|
||||
threadId.c_str(), dpy, draw, read, ctx, oldDisplay, oldDraw, oldRead, oldContext);
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
if (draw != EGL_NO_SURFACE) ApplyWaylandResize(state, dpy, draw);
|
||||
#endif
|
||||
if (!state->MakeCurrent(dpy, draw, read, ctx)) {
|
||||
const EGLint error = state->ConsumeError();
|
||||
MGLOG_D("eglMakeCurrent rejected by EGLState thread=%s error=0x%04x", threadId.c_str(), error);
|
||||
@@ -520,6 +589,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (contextToken != 0 && MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
!MG_Remote::Client::RunsAsTheServerRole()) {
|
||||
const std::lock_guard<std::recursive_mutex> streamLock(EGLOperationMutex());
|
||||
// The server drops its binding to 0 when the current context is destroyed
|
||||
// (ServerSession::DestroyContext's compare-and-swap); the gate mirrors it so the next
|
||||
// write re-binds.
|
||||
if (g_boundContextToken == contextToken) g_boundContextToken = 0;
|
||||
const auto emitted = MG_Remote::Client::SendDestroyContextFrame(contextToken);
|
||||
if (emitted == MG_Remote::Client::ContextFrameEmit::Refused) {
|
||||
MGLOG_E_ONCE("eglDestroyContext: the server holds no context token %llu; the "
|
||||
@@ -576,10 +650,10 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
}
|
||||
|
||||
EGLBoolean ReleaseThread() {
|
||||
// Always succeeds (EGL 1.4 §3.11): after the last eglTerminate tore MobileGL down there is
|
||||
// simply nothing of this thread's left to release.
|
||||
if (!MG_State::pEGLContext) return EGL_TRUE;
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (auto* backendObject = MG_Backend::pActiveBackendObject.get()) {
|
||||
(void)backendObject->MakeEGLCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
}
|
||||
@@ -900,6 +974,16 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state) {
|
||||
return EGL_NO_DISPLAY;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// A "GBM" display whose native display is a wl_display is a Wayland one: Chromium's
|
||||
// Wayland GL layer names the GBM platform for every display it asks for, including the
|
||||
// one on its own Wayland connection whose windows are wl_egl_windows.
|
||||
constexpr EGLenum kPlatformGbm = 0x31D7;
|
||||
if (platform == kPlatformGbm && native_display != nullptr &&
|
||||
Wayland::IsWaylandDisplay(reinterpret_cast<Uint64>(native_display), EGL_NONE)) {
|
||||
platform = Wayland::kPlatformWayland;
|
||||
}
|
||||
#endif
|
||||
return state->GetPlatformDisplay(platform, native_display);
|
||||
}
|
||||
|
||||
@@ -910,6 +994,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
if (RefuseGbmWindow(state, dpy)) return EGL_NO_SURFACE;
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
const EGLint* attrib_list);
|
||||
@@ -62,4 +64,62 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
const EGLAttrib* attrib_list);
|
||||
EGLBoolean WaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags);
|
||||
__eglMustCastToProperFunctionPointerType GetProcAddress(const char* name);
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE CLIENT'S STREAM GATE. Under a split transport every thread of the process writes into
|
||||
// ONE ring, and the server attributes each record to the context the last applied
|
||||
// `bind_context` named - one current context per SESSION. A context, though, is current per
|
||||
// THREAD, and Qt renders each window on its own QSGRenderThread: two threads' records then
|
||||
// interleave on the ring with no binding between them and land in the wrong context's
|
||||
// applier (empty sampler windows at a Clear, another context's buffers under an upload).
|
||||
//
|
||||
// So every GL entry point and every EGL operation that writes to the stream runs under one
|
||||
// process-wide lock (EGLOperationMutex, which the EGL side already held), and before it
|
||||
// writes, the server is re-bound to the CALLING thread's context whenever the last binding
|
||||
// actually sent names a different one. A no-op scope on a monolith transport and on the
|
||||
// server's own apply thread.
|
||||
Bool StreamGateActive();
|
||||
std::recursive_mutex& StreamMutex();
|
||||
void StreamBindCallingThreadLocked();
|
||||
|
||||
class GLStreamScope {
|
||||
public:
|
||||
GLStreamScope() {
|
||||
if (!StreamGateActive()) return;
|
||||
m_mutex = &StreamMutex();
|
||||
m_mutex->lock();
|
||||
StreamBindCallingThreadLocked();
|
||||
}
|
||||
~GLStreamScope() {
|
||||
if (m_mutex != nullptr) m_mutex->unlock();
|
||||
}
|
||||
GLStreamScope(const GLStreamScope&) = delete;
|
||||
GLStreamScope& operator=(const GLStreamScope&) = delete;
|
||||
|
||||
private:
|
||||
std::recursive_mutex* m_mutex = nullptr;
|
||||
};
|
||||
// The lock alone, for every EGL entry point: an EGL call may publish into the ring too (a
|
||||
// surface forwarder's catch-up wait, a present, a context frame), and a second thread's GL
|
||||
// record written into the middle of it is a torn record the server latches the session on.
|
||||
class StreamLockScope {
|
||||
public:
|
||||
StreamLockScope() {
|
||||
if (!StreamGateActive()) return;
|
||||
m_mutex = &StreamMutex();
|
||||
m_mutex->lock();
|
||||
}
|
||||
~StreamLockScope() {
|
||||
if (m_mutex != nullptr) m_mutex->unlock();
|
||||
}
|
||||
StreamLockScope(const StreamLockScope&) = delete;
|
||||
StreamLockScope& operator=(const StreamLockScope&) = delete;
|
||||
|
||||
private:
|
||||
std::recursive_mutex* m_mutex = nullptr;
|
||||
};
|
||||
#else
|
||||
class GLStreamScope {};
|
||||
class StreamLockScope {};
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl
|
||||
|
||||
@@ -6,7 +6,12 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// are absent until their entry points and image paths exist.
|
||||
inline constexpr const char* kDeviceExtensionString = "";
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS " EGL_KHR_platform_wayland EGL_EXT_platform_wayland"
|
||||
// GBM is claimed as a display platform only: a display on a gbm_device is an offscreen display
|
||||
// like a surfaceless one (the frames come from the backend, not from the device), and window
|
||||
// surfaces on it are refused. Chromium's Wayland GPU process hands its GL implementation nothing
|
||||
// but a GBM display, so without the claim it never reaches this library at all.
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS \
|
||||
" EGL_KHR_platform_wayland EGL_EXT_platform_wayland EGL_KHR_platform_gbm EGL_MESA_platform_gbm"
|
||||
#else
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS ""
|
||||
#endif
|
||||
|
||||
@@ -9,14 +9,34 @@
|
||||
#include <Includes.h>
|
||||
#include "../EGLImpl.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
// The KHR/EXT spellings take EGLint attribute lists where the core 1.5 entry points take
|
||||
// EGLAttrib (pointer-sized). Reinterpreting one as the other reads two EGLints as one
|
||||
// attribute on 64-bit, so the list is widened instead.
|
||||
std::vector<EGLAttrib> WidenAttribList(const EGLint* attribs) {
|
||||
std::vector<EGLAttrib> widened;
|
||||
if (attribs == nullptr) return widened;
|
||||
for (; *attribs != EGL_NONE; attribs += 2) {
|
||||
widened.push_back(static_cast<EGLAttrib>(attribs[0]));
|
||||
widened.push_back(static_cast<EGLAttrib>(attribs[1]));
|
||||
}
|
||||
widened.push_back(EGL_NONE);
|
||||
return widened;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreateWindowSurface(dpy=%p, config=%p, window=%p, attrib_list=%p)", dpy, config, window, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs,
|
||||
EGLint config_size, EGLint* num_config) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglChooseConfig(dpy=%p, attrib_list=%p, configs=%p, config_size=%d, num_config=%p)", dpy, attrib_list,
|
||||
configs, config_size, num_config);
|
||||
return MobileGL::MG_Impl::EGLImpl::ChooseConfig(dpy, attrib_list, configs, config_size, num_config);
|
||||
@@ -24,6 +44,7 @@ MOBILEGL_EGL_API EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib
|
||||
|
||||
MOBILEGL_EGL_API EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx,
|
||||
const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreateContext(dpy=%p, config=%p, shareCtx=%p, attrib_list=%p)", dpy, config, shareCtx, attrib_list);
|
||||
#ifdef TRACY_ENABLE
|
||||
tracy::StartupProfiler();
|
||||
@@ -32,26 +53,31 @@ MOBILEGL_EGL_API EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, E
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglInitialize(dpy=%p, major=%p, minor=%p)", dpy, major, minor);
|
||||
return MobileGL::MG_Impl::EGLImpl::Initialize(dpy, major, minor);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetDisplay(NativeDisplayType display) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetDisplay(display=%p)", display);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetDisplay(display);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLint eglGetError() {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetError()");
|
||||
return MobileGL::MG_Impl::EGLImpl::GetError();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglMakeCurrent(dpy=%p, draw=%p, read=%p, ctx=%p)", dpy, draw, read, ctx);
|
||||
return MobileGL::MG_Impl::EGLImpl::MakeCurrent(dpy, draw, read, ctx);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglDestroyContext(dpy=%p, ctx=%p)", dpy, ctx);
|
||||
#ifdef TRACY_ENABLE
|
||||
tracy::ShutdownProfiler();
|
||||
@@ -60,56 +86,67 @@ MOBILEGL_EGL_API EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglDestroySurface(dpy=%p, surface=%p)", dpy, surface);
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroySurface(dpy, surface);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglTerminate(EGLDisplay dpy) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglTerminate(dpy=%p)", dpy);
|
||||
return MobileGL::MG_Impl::EGLImpl::Terminate(dpy);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglReleaseThread(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglReleaseThread()");
|
||||
return MobileGL::MG_Impl::EGLImpl::ReleaseThread();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLContext eglGetCurrentContext(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetCurrentContext()");
|
||||
return MobileGL::MG_Impl::EGLImpl::GetCurrentContext();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetConfigAttrib(dpy=%p, config=%p, attribute=%d, value=%p)", dpy, config, attribute, value);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetConfigAttrib(dpy, config, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglBindAPI(EGLenum api) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglBindAPI(api=%u)", api);
|
||||
return MobileGL::MG_Impl::EGLImpl::BindAPI(api);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglGetCurrentSurface(EGLint readdraw) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetCurrentSurface(readdraw=%d)", readdraw);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetCurrentSurface(readdraw);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQuerySurface(EGLDisplay display, EGLSurface surface, EGLint attribute, EGLint* value) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglQuerySurface(display=%p, surface=%p, attribute=%d, value=%p)", display, surface, attribute, value);
|
||||
return MobileGL::MG_Impl::EGLImpl::QuerySurface(display, surface, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API char const* eglQueryString(EGLDisplay display, EGLint name) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglQueryString(display=%p, name=%d)", display, name);
|
||||
return MobileGL::MG_Impl::EGLImpl::QueryString(display, name);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglSwapInterval(dpy=%p, interval=%d)", dpy, interval);
|
||||
return MobileGL::MG_Impl::EGLImpl::SwapInterval(dpy, interval);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglSwapBuffers(dpy=%p, draw=%p)", dpy, draw);
|
||||
#ifdef TRACY_ENABLE
|
||||
FrameMark;
|
||||
@@ -118,32 +155,38 @@ MOBILEGL_EGL_API EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) {
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreatePbufferSurface(dpy=%p, config=%p, attrib_list=%p)", dpy, config, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePbufferSurface(dpy, config, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char* name) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetProcAddress(name=%s)", name ? name : "null");
|
||||
return MobileGL::MG_Impl::EGLImpl::GetProcAddress(name);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglBindTexImage(dpy=%p, surface=%p, buffer=%d)", dpy, surface, buffer);
|
||||
return MobileGL::MG_Impl::EGLImpl::BindTexImage(dpy, surface, buffer);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglReleaseTexImage(dpy=%p, surface=%p, buffer=%d)", dpy, surface, buffer);
|
||||
return MobileGL::MG_Impl::EGLImpl::ReleaseTexImage(dpy, surface, buffer);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCopyBuffers(dpy=%p, surface=%p, target=%p)", dpy, surface, target);
|
||||
return MobileGL::MG_Impl::EGLImpl::CopyBuffers(dpy, surface, target);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
|
||||
EGLConfig config, const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreatePbufferFromClientBuffer(dpy=%p, buftype=%u, buffer=%p, config=%p, attrib_list=%p)", dpy, buftype,
|
||||
buffer, config, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePbufferFromClientBuffer(dpy, buftype, buffer, config, attrib_list);
|
||||
@@ -151,85 +194,119 @@ MOBILEGL_EGL_API EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGL
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap,
|
||||
const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreatePixmapSurface(dpy=%p, config=%p, pixmap=%p, attrib_list=%p)", dpy, config, pixmap, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePixmapSurface(dpy, config, pixmap, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig* configs, EGLint config_size, EGLint* num_config) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetConfigs(dpy=%p, configs=%p, config_size=%d, num_config=%p)", dpy, configs, config_size, num_config);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetConfigs(dpy, configs, config_size, num_config);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetCurrentDisplay(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetCurrentDisplay()");
|
||||
return MobileGL::MG_Impl::EGLImpl::GetCurrentDisplay();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLenum eglQueryAPI(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglQueryAPI()");
|
||||
return MobileGL::MG_Impl::EGLImpl::QueryAPI();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglQueryContext(dpy=%p, ctx=%p, attribute=%d, value=%p)", dpy, ctx, attribute, value);
|
||||
return MobileGL::MG_Impl::EGLImpl::QueryContext(dpy, ctx, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglSurfaceAttrib(dpy=%p, surface=%p, attribute=%d, value=%d)", dpy, surface, attribute, value);
|
||||
return MobileGL::MG_Impl::EGLImpl::SurfaceAttrib(dpy, surface, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitClient(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglWaitClient()");
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitClient();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitGL(void) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglWaitGL()");
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitGL();
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitNative(EGLint engine) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglWaitNative(engine=%d)", engine);
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitNative(engine);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSync eglCreateSync(EGLDisplay dpy, EGLenum type, const EGLAttrib* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreateSync(dpy=%p, type=%u, attrib_list=%p)", dpy, type, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateSync(dpy, type, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroySync(EGLDisplay dpy, EGLSync sync) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglDestroySync(dpy=%p, sync=%p)", dpy, sync);
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroySync(dpy, sync);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLint eglClientWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime timeout) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglClientWaitSync(dpy=%p, sync=%p, flags=%d, timeout=%llu)", dpy, sync, flags,
|
||||
static_cast<unsigned long long>(timeout));
|
||||
return MobileGL::MG_Impl::EGLImpl::ClientWaitSync(dpy, sync, flags, timeout);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglGetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib* value) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetSyncAttrib(dpy=%p, sync=%p, attribute=%d, value=%p)", dpy, sync, attribute, value);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetSyncAttrib(dpy, sync, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLImage eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLAttrib* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreateImage(dpy=%p, ctx=%p, target=%u, buffer=%p, attrib_list=%p)", dpy, ctx, target, buffer,
|
||||
attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateImage(dpy, ctx, target, buffer, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroyImage(EGLDisplay dpy, EGLImage image) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglDestroyImage(dpy=%p, image=%p)", dpy, image);
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
// EGL_KHR_image_base's spellings. KWin loads these two by name and calls eglDestroyImageKHR
|
||||
// for every cached client buffer when it dies, wl_shm ones included; a null answer from
|
||||
// eglGetProcAddress made that a jump to address 0.
|
||||
MOBILEGL_EGL_API EGLImage eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreateImageKHR(dpy=%p, ctx=%p, target=%u, buffer=%p, attrib_list=%p)", dpy, ctx, target, buffer,
|
||||
attrib_list);
|
||||
const std::vector<EGLAttrib> attribs = WidenAttribList(attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateImage(dpy, ctx, target, buffer, attrib_list ? attribs.data() : nullptr);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImage image) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglDestroyImageKHR(dpy=%p, image=%p)", dpy, image);
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetPlatformDisplay(EGLenum platform, void* native_display,
|
||||
const EGLAttrib* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetPlatformDisplay(platform=%u, native_display=%p, attrib_list=%p)", platform, native_display,
|
||||
attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetPlatformDisplay(platform, native_display, attrib_list);
|
||||
@@ -237,14 +314,17 @@ MOBILEGL_EGL_API EGLDisplay eglGetPlatformDisplay(EGLenum platform, void* native
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetPlatformDisplayEXT(EGLenum platform, void* native_display,
|
||||
const EGLint* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglGetPlatformDisplayEXT(platform=%u, native_display=%p, attrib_list=%p)", platform, native_display,
|
||||
attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetPlatformDisplay(
|
||||
platform, native_display, reinterpret_cast<const EGLAttrib*>(attrib_list));
|
||||
const std::vector<EGLAttrib> attribs = WidenAttribList(attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::GetPlatformDisplay(platform, native_display,
|
||||
attrib_list ? attribs.data() : nullptr);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
const EGLAttrib* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreatePlatformWindowSurface(dpy=%p, config=%p, native_window=%p, attrib_list=%p)", dpy, config,
|
||||
native_window, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
@@ -252,12 +332,14 @@ MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLCo
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglCreatePlatformPixmapSurface(dpy=%p, config=%p, native_pixmap=%p, attrib_list=%p)", dpy, config,
|
||||
native_pixmap, attrib_list);
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePlatformPixmapSurface(dpy, config, native_pixmap, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitSync(EGLDisplay dpy, EGLSync sync, EGLint flags) {
|
||||
const MobileGL::MG_Impl::EGLImpl::StreamLockScope mglStreamLock;
|
||||
MGLOG_D("eglWaitSync(dpy=%p, sync=%p, flags=%d)", dpy, sync, flags);
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitSync(dpy, sync, flags);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
#include "../EGLImpl.h"
|
||||
#include "../EGLPlatformExtensions.h"
|
||||
|
||||
// Defined in Definitions.cpp; eglext.h declares them only under EGL_EGLEXT_PROTOTYPES.
|
||||
extern "C" EGLImage eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImage image);
|
||||
|
||||
namespace {
|
||||
using namespace MobileGL;
|
||||
|
||||
@@ -221,6 +226,8 @@ namespace {
|
||||
{"eglWaitSync", reinterpret_cast<void*>(eglWaitSync)},
|
||||
{"eglCreateImage", reinterpret_cast<void*>(eglCreateImage)},
|
||||
{"eglDestroyImage", reinterpret_cast<void*>(eglDestroyImage)},
|
||||
{"eglCreateImageKHR", reinterpret_cast<void*>(eglCreateImageKHR)},
|
||||
{"eglDestroyImageKHR", reinterpret_cast<void*>(eglDestroyImageKHR)},
|
||||
{"eglCreatePlatformWindowSurface", reinterpret_cast<void*>(eglCreatePlatformWindowSurface)},
|
||||
{"eglCreatePlatformPixmapSurface", reinterpret_cast<void*>(eglCreatePlatformPixmapSurface)},
|
||||
// The platform and current-state queries: not in glvnd's required list, but the names an
|
||||
|
||||
@@ -23,8 +23,48 @@
|
||||
#include <fcntl.h>
|
||||
#include <mutex>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
void ReadBackFrameBGRA(EGLint width, EGLint height, Vector<Uint8>& scratch, Uint8* dst, SizeT dstStride) {
|
||||
namespace GL = MG_Impl::GLImpl;
|
||||
GLint readFramebuffer = 0, packBuffer = 0, alignment = 4, rowLength = 0, skipRows = 0, skipPixels = 0;
|
||||
GL::GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer);
|
||||
GL::GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
|
||||
GL::GetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
GL::GetIntegerv(GL_PACK_ROW_LENGTH, &rowLength);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_ROWS, &skipRows);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_PIXELS, &skipPixels);
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
const SizeT rowBytes = static_cast<SizeT>(width) * 4;
|
||||
scratch.resize(rowBytes * static_cast<SizeT>(height));
|
||||
GL::ReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, scratch.data());
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, alignment);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, rowLength);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, skipRows);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, skipPixels);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, static_cast<GLuint>(packBuffer));
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer));
|
||||
|
||||
for (EGLint y = 0; y < height; ++y) {
|
||||
const Uint8* src = scratch.data() + static_cast<SizeT>(height - 1 - y) * rowBytes;
|
||||
Uint8* row = dst + static_cast<SizeT>(y) * dstStride;
|
||||
for (EGLint x = 0; x < width; ++x) {
|
||||
row[x * 4 + 0] = src[x * 4 + 2];
|
||||
row[x * 4 + 1] = src[x * 4 + 1];
|
||||
row[x * 4 + 2] = src[x * 4 + 0];
|
||||
row[x * 4 + 3] = src[x * 4 + 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
namespace {
|
||||
// libwayland-client's types are opaque here: everything goes through wl_proxy_* and the
|
||||
@@ -263,12 +303,32 @@ namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
void OnWindowDestroyed(void* data) { static_cast<WindowSurface::Impl*>(data)->window = nullptr; }
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
// Copies `size` bytes at `address` of this process, or answers false where nothing is
|
||||
// mapped - the kernel does the reading, so a wild pointer is an error code, not a fault.
|
||||
Bool ReadOwnMemory(const void* address, void* out, SizeT size) {
|
||||
iovec local{out, size};
|
||||
iovec remote{const_cast<void*>(address), size};
|
||||
return process_vm_readv(getpid(), &local, 1, &remote, 1, 0) == static_cast<ssize_t>(size);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform) {
|
||||
if (platform == kPlatformWayland) return true;
|
||||
if (nativeDisplay == 0 || (platform != EGL_NONE && platform != 0)) return false;
|
||||
const Api& api = WaylandApi();
|
||||
if (!api.loaded) return false;
|
||||
return *reinterpret_cast<const void* const*>(static_cast<uintptr_t>(nativeDisplay)) == api.displayInterface;
|
||||
const void* interface = *reinterpret_cast<const void* const*>(static_cast<uintptr_t>(nativeDisplay));
|
||||
if (interface == api.displayInterface) return true;
|
||||
// AN APPLICATION WITH ITS OWN COPY OF LIBWAYLAND-CLIENT (Chromium links one in statically)
|
||||
// has its own wl_display_interface, at its own address. The interface is still the
|
||||
// protocol's: a wl_interface whose first member names it "wl_display". Whatever else the
|
||||
// first word of a native display is (a gbm_device's is a function address), the probe
|
||||
// only reads through the kernel.
|
||||
const char* name = nullptr;
|
||||
char text[sizeof("wl_display")] = {};
|
||||
return interface != nullptr && ReadOwnMemory(interface, &name, sizeof(name)) && name != nullptr &&
|
||||
ReadOwnMemory(name, text, sizeof(text)) && std::memcmp(text, "wl_display", sizeof(text)) == 0;
|
||||
}
|
||||
|
||||
Bool IsWaylandWindow(const void* window) {
|
||||
@@ -324,6 +384,17 @@ namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
return UniquePtr<WindowSurface>(new WindowSurface(std::move(impl)));
|
||||
}
|
||||
|
||||
Bool WindowSurface::TakeResize(EGLint* width, EGLint* height) {
|
||||
Impl& impl = *m_impl;
|
||||
if (impl.window == nullptr || impl.window->width <= 0 || impl.window->height <= 0) return false;
|
||||
if (impl.window->width == impl.width && impl.window->height == impl.height) return false;
|
||||
impl.width = impl.window->width;
|
||||
impl.height = impl.window->height;
|
||||
*width = impl.width;
|
||||
*height = impl.height;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool WindowSurface::Present() {
|
||||
Impl& impl = *m_impl;
|
||||
if (impl.window == nullptr) return false;
|
||||
@@ -334,45 +405,9 @@ namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The frame, out of the default framebuffer, through this library's own entry points: the
|
||||
// application's read framebuffer, pack buffer and pack state are saved and put back, so
|
||||
// the readback is invisible to it.
|
||||
namespace GL = MG_Impl::GLImpl;
|
||||
GLint readFramebuffer = 0, packBuffer = 0, alignment = 4, rowLength = 0, skipRows = 0, skipPixels = 0;
|
||||
GL::GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer);
|
||||
GL::GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
|
||||
GL::GetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
GL::GetIntegerv(GL_PACK_ROW_LENGTH, &rowLength);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_ROWS, &skipRows);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_PIXELS, &skipPixels);
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
const SizeT rowBytes = static_cast<SizeT>(impl.width) * 4;
|
||||
impl.scratch.resize(rowBytes * static_cast<SizeT>(impl.height));
|
||||
GL::ReadPixels(0, 0, impl.width, impl.height, GL_RGBA, GL_UNSIGNED_BYTE, impl.scratch.data());
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, alignment);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, rowLength);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, skipRows);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, skipPixels);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, static_cast<GLuint>(packBuffer));
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer));
|
||||
|
||||
// GL's rows run bottom-up and RGBA; a wl_shm buffer's run top-down and B, G, R, A.
|
||||
auto* dst = static_cast<Uint8*>(buffer->map);
|
||||
for (EGLint y = 0; y < impl.height; ++y) {
|
||||
const Uint8* src = impl.scratch.data() + static_cast<SizeT>(impl.height - 1 - y) * rowBytes;
|
||||
Uint8* row = dst + static_cast<SizeT>(y) * static_cast<SizeT>(buffer->stride);
|
||||
for (EGLint x = 0; x < impl.width; ++x) {
|
||||
row[x * 4 + 0] = src[x * 4 + 2];
|
||||
row[x * 4 + 1] = src[x * 4 + 1];
|
||||
row[x * 4 + 2] = src[x * 4 + 0];
|
||||
row[x * 4 + 3] = src[x * 4 + 3];
|
||||
}
|
||||
}
|
||||
ReadBackFrameBGRA(impl.width, impl.height, impl.scratch, static_cast<Uint8*>(buffer->map),
|
||||
static_cast<SizeT>(buffer->stride));
|
||||
|
||||
wl_proxy* surface = impl.window->surface;
|
||||
const uint32_t surfaceVersion = api.getVersion(surface);
|
||||
|
||||
@@ -29,13 +29,23 @@
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// The current context's default-framebuffer frame, `width` x `height`, written top-down in
|
||||
// B, G, R, A byte order (a wl_shm ARGB8888 buffer and a 24/32-bit little-endian X image both
|
||||
// hold that) to `dst`, one row every `dstStride` bytes. Through this library's own entry
|
||||
// points: the application's read framebuffer, pack buffer and pack state are saved and put
|
||||
// back, so the readback is invisible to it. `scratch` is the caller's, reused across frames.
|
||||
void ReadBackFrameBGRA(EGLint width, EGLint height, Vector<Uint8>& scratch, Uint8* dst, SizeT dstStride);
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
// EGL_PLATFORM_WAYLAND_KHR and EGL_PLATFORM_WAYLAND_EXT are the same enum.
|
||||
inline constexpr EGLenum kPlatformWayland = 0x31D8;
|
||||
|
||||
// Whether a display is a Wayland one: asked for as EGL_PLATFORM_WAYLAND, or (eglGetDisplay with
|
||||
// no platform) a native display that is a wl_display - recognised the way Mesa does, by its
|
||||
// first word being libwayland-client's wl_display_interface.
|
||||
// first word being libwayland-client's wl_display_interface (or, for an application with its
|
||||
// own copy of libwayland, an interface named "wl_display").
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform);
|
||||
|
||||
// Whether `window` looks like a wl_egl_window this library can present to.
|
||||
@@ -61,6 +71,11 @@ namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
// window; the swap itself goes on regardless.
|
||||
Bool Present();
|
||||
|
||||
// wl_egl_window_resize's effect, taken: true (with the new size) when the application gave
|
||||
// its wl_egl_window a size this presentation is not at yet. The presentation adopts it -
|
||||
// its next wl_shm buffer is that size - and the caller resizes the drawable behind it.
|
||||
Bool TakeResize(EGLint* width, EGLint* height);
|
||||
|
||||
struct Impl;
|
||||
|
||||
private:
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "../Sync/GL_Sync.h"
|
||||
#include "../Debug/GL_Debug.h"
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#include <MG_Impl/EGLImpl/EGLImpl.h>
|
||||
|
||||
#define DECLARE_GL_FUNCTION_STUB_HEAD(type, name, ...) MOBILEGL_GL_API type gl##name(__VA_ARGS__) {
|
||||
|
||||
@@ -40,22 +41,26 @@
|
||||
#define DECLARE_GL_FUNCTION_END(type, name, ...) \
|
||||
ZoneScopedC(TRACY_ZONECOLOR_ENTRY); \
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__); \
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope; \
|
||||
return MobileGL::MG_Impl::GLImpl::name(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define DECLARE_GL_FUNCTION_END_NO_RETURN(type, name, ...) \
|
||||
ZoneScopedC(TRACY_ZONECOLOR_ENTRY); \
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__); \
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope; \
|
||||
MobileGL::MG_Impl::GLImpl::name(__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DECLARE_GL_FUNCTION_END(type, name, ...) \
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__); \
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope; \
|
||||
return MobileGL::MG_Impl::GLImpl::name(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define DECLARE_GL_FUNCTION_END_NO_RETURN(type, name, ...) \
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__); \
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope; \
|
||||
MobileGL::MG_Impl::GLImpl::name(__VA_ARGS__); \
|
||||
}
|
||||
#endif
|
||||
@@ -116,12 +121,14 @@ DECLARE_GL_FUNCTION_HEAD(void, EnableVertexAttribArray, GLuint index) DECLARE_GL
|
||||
// call really did have nothing to do; MGPipeClientFinish answers false-cheap there too.
|
||||
MOBILEGL_GL_API void glFinish() {
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__);
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MobileGL::MG_Pipe::MGPipeClientFinish();
|
||||
#endif
|
||||
}
|
||||
MOBILEGL_GL_API void glFlush() {
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__);
|
||||
const MobileGL::MG_Impl::EGLImpl::GLStreamScope mglStreamScope;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MobileGL::MG_Pipe::MGPipeClientFlush();
|
||||
#endif
|
||||
@@ -149,7 +156,7 @@ DECLARE_GL_FUNCTION_HEAD(void, GetProgramInfoLog, GLuint program, GLsizei bufSiz
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetRenderbufferParameteriv, GLenum target, GLenum pname, GLint* params) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetRenderbufferParameteriv, target, pname, params)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetShaderiv, GLuint shader, GLenum pname, GLint* params) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetShaderiv, shader, pname, params)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetShaderInfoLog, GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetShaderInfoLog, shader, bufSize, length, infoLog)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetShaderPrecisionFormat, GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetShaderPrecisionFormat, shadertype, precisiontype, range, precision)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetShaderPrecisionFormat, GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetShaderPrecisionFormat, shadertype, precisiontype, range, precision)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetShaderSource, GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetShaderSource, shader, bufSize, length, source)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetTexParameterfv, GLenum target, GLenum pname, GLfloat* params) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetTexParameterfv, target, pname, params)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, GetTexParameteriv, GLenum target, GLenum pname, GLint* params) DECLARE_GL_FUNCTION_END_NO_RETURN(void, GetTexParameteriv, target, pname, params)
|
||||
|
||||
@@ -617,11 +617,19 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
MGLOG_D("vendorString: %s", vendorString.c_str());
|
||||
return (const GLubyte*)vendorString.c_str();
|
||||
case GL_VERSION: {
|
||||
// "OpenGL ES" must not appear anywhere in a desktop GL_VERSION: some callers (ANGLE's GL
|
||||
// backend among them) search the whole string for it rather than its prefix, and
|
||||
// then take this for an ES driver, read the version from the wrong offsets and look
|
||||
// for ES-named extensions. The backend is named "GLES" here for that reason only.
|
||||
String backendName = rendererInfo.BackendName;
|
||||
if (const auto at = backendName.find("OpenGL ES"); at != String::npos) {
|
||||
backendName.replace(at, sizeof("OpenGL ES") - 1, "GLES");
|
||||
}
|
||||
versionStr =
|
||||
std::format("{} {} {}, {} Backend, GIT@" GIT_COMMIT_HASH_SHORT,
|
||||
rendererInfo.RendererGLInfo.TargetGLVersion.toString(), MG_Config::ProjectName,
|
||||
MG_Config::CoreVersion.toFormattedString(MG_Config::DefaultVersionStringFormatAttrib),
|
||||
rendererInfo.BackendName);
|
||||
backendName);
|
||||
MGLOG_D("versionStr: %s", versionStr.c_str());
|
||||
return (const GLubyte*)versionStr.c_str();
|
||||
}
|
||||
|
||||
@@ -2405,6 +2405,47 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
ShaderBinary_State(count, shaders, binaryformat, binary, length);
|
||||
}
|
||||
|
||||
// GL 4.6 core 7.13 (ARB_ES2_compatibility). The shading language here is desktop GLSL, whose
|
||||
// float and int are 32-bit IEEE-754 / two's complement at every precision qualifier, so every
|
||||
// precision answers the same: log2 of the range and the mantissa bits. A silent stub answered
|
||||
// zeros, which an ES-on-GL layer reads as "no highp" and refuses ES 2.0 outright.
|
||||
void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) {
|
||||
if (shadertype != GL_VERTEX_SHADER && shadertype != GL_FRAGMENT_SHADER) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidEnum,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"shadertype must be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER."));
|
||||
return;
|
||||
}
|
||||
GLint rangeLow = 0, rangeHigh = 0, bits = 0;
|
||||
switch (precisiontype) {
|
||||
case GL_LOW_FLOAT:
|
||||
case GL_MEDIUM_FLOAT:
|
||||
case GL_HIGH_FLOAT:
|
||||
rangeLow = 127;
|
||||
rangeHigh = 127;
|
||||
bits = 23;
|
||||
break;
|
||||
case GL_LOW_INT:
|
||||
case GL_MEDIUM_INT:
|
||||
case GL_HIGH_INT:
|
||||
rangeLow = 31;
|
||||
rangeHigh = 30;
|
||||
bits = 0;
|
||||
break;
|
||||
default:
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidEnum,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", __func__, "precisiontype is not a precision."));
|
||||
return;
|
||||
}
|
||||
if (range) {
|
||||
range[0] = rangeLow;
|
||||
range[1] = rangeHigh;
|
||||
}
|
||||
if (precision) *precision = bits;
|
||||
}
|
||||
|
||||
void SpecializeShader(GLuint shader, const GLchar* pEntryPoint, GLuint numSpecializationConstants,
|
||||
const GLuint* pConstantIndex, const GLuint* pConstantValue) {
|
||||
SpecializeShader_State(shader, pEntryPoint, numSpecializationConstants, pConstantIndex, pConstantValue);
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
void GetShaderiv(GLuint shader, GLenum pname, GLint* params);
|
||||
void GetShaderInfoLog(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
|
||||
void GetShaderSource(GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* source);
|
||||
void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
|
||||
GLint GetUniformLocation(GLuint program, const GLchar* name);
|
||||
void GetUniformfv(GLuint program, GLint location, GLfloat* params);
|
||||
void GetUniformiv(GLuint program, GLint location, GLint* params);
|
||||
|
||||
@@ -8,12 +8,20 @@
|
||||
|
||||
#include <Includes.h>
|
||||
#include "../LookUp/LookUp.h"
|
||||
#include "../../EGLImpl/EGLImpl.h"
|
||||
|
||||
// Every GLX entry point holds the client's stream lock, as every EGL and GL one does: they are EGL
|
||||
// calls underneath (and a swap reads the frame back), so they cannot interleave with another
|
||||
// thread's GL records.
|
||||
using GLXStreamLock = MobileGL::MG_Impl::EGLImpl::StreamLockScope;
|
||||
|
||||
MOBILEGL_GLX_API void* glXGetProcAddress(const char* name) {
|
||||
GLXStreamLock streamLock;
|
||||
return MG_Impl::GLXImpl::GetProcAddress(name);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXGetProcAddressARB(const char* name) {
|
||||
GLXStreamLock streamLock;
|
||||
return MG_Impl::GLXImpl::GetProcAddressARB(name);
|
||||
}
|
||||
|
||||
@@ -27,149 +35,184 @@ namespace GLXImpl = MobileGL::MG_Impl::GLXImpl;
|
||||
// and XVisualInfo* crosses as void*.
|
||||
|
||||
MOBILEGL_GLX_API int glXQueryExtension(Display* dpy, int* errorBase, int* eventBase) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::QueryExtension(dpy, errorBase, eventBase);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXQueryVersion(Display* dpy, int* major, int* minor) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::QueryVersion(dpy, major, minor);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API const char* glXQueryExtensionsString(Display* dpy, int screen) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::QueryExtensionsString(dpy, screen);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API const char* glXGetClientString(Display* dpy, int name) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetClientString(dpy, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API const char* glXQueryServerString(Display* dpy, int screen, int name) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::QueryServerString(dpy, screen, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void** glXGetFBConfigs(Display* dpy, int screen, int* nelements) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetFBConfigs(dpy, screen, nelements);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void** glXChooseFBConfig(Display* dpy, int screen, const int* attribList,
|
||||
int* nelements) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::ChooseFBConfig(dpy, screen, attribList, nelements);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXGetFBConfigAttrib(Display* dpy, void* config, int attribute, int* value) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetFBConfigAttrib(dpy, config, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXGetVisualFromFBConfig(Display* dpy, void* config) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetVisualFromFBConfig(dpy, config);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXChooseVisual(Display* dpy, int screen, int* attribList) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::ChooseVisual(dpy, screen, attribList);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXGetConfig(Display* dpy, void* visualInfo, int attribute, int* value) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetConfig(dpy, visualInfo, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXCreateContext(Display* dpy, void* visualInfo, void* shareList, int direct) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::CreateContext(dpy, visualInfo, shareList, direct);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXCreateNewContext(Display* dpy, void* config, int renderType,
|
||||
void* shareList, int direct) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::CreateNewContext(dpy, config, renderType, shareList, direct);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXCreateContextAttribsARB(Display* dpy, void* config, void* shareContext,
|
||||
int direct, const int* attribList) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::CreateContextAttribsARB(dpy, config, shareContext, direct, attribList);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXDestroyContext(Display* dpy, void* context) {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::DestroyContext(dpy, context);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXMakeCurrent(Display* dpy, unsigned long drawable, void* context) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::MakeCurrent(dpy, drawable, context);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXMakeContextCurrent(Display* dpy, unsigned long draw, unsigned long read,
|
||||
void* context) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::MakeContextCurrent(dpy, draw, read, context);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXSwapBuffers(Display* dpy, unsigned long drawable) {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::SwapBuffers(dpy, drawable);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXCreateWindow(Display* dpy, void* config, unsigned long window,
|
||||
const int* attribList) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::CreateWindow(dpy, config, window, attribList);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXDestroyWindow(Display* dpy, unsigned long window) {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::DestroyWindow(dpy, window);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void* glXGetCurrentContext() {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetCurrentContext();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXGetCurrentDrawable() {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetCurrentDrawable();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXGetCurrentReadDrawable() {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetCurrentReadDrawable();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API Display* glXGetCurrentDisplay() {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetCurrentDisplay();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXIsDirect(Display* dpy, void* context) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::IsDirect(dpy, context);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXWaitGL() {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::WaitGL();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXWaitX() {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::WaitX();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXQueryContext(Display* dpy, void* context, int attribute, int* value) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::QueryContext(dpy, context, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXQueryDrawable(Display* dpy, unsigned long drawable, int attribute,
|
||||
unsigned int* value) {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::QueryDrawable(dpy, drawable, attribute, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXSwapIntervalEXT(Display* dpy, unsigned long drawable, int interval) {
|
||||
GLXStreamLock streamLock;
|
||||
GLXImpl::SwapIntervalEXT(dpy, drawable, interval);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXSwapIntervalMESA(unsigned int interval) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::SwapIntervalMESA(interval);
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXGetSwapIntervalMESA() {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::GetSwapIntervalMESA();
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API int glXSwapIntervalSGI(int interval) {
|
||||
GLXStreamLock streamLock;
|
||||
return GLXImpl::SwapIntervalSGI(interval);
|
||||
}
|
||||
|
||||
// Legacy entry points some loaders probe for; harmless no-op stubs.
|
||||
MOBILEGL_GLX_API void glXCopyContext(Display*, void*, void*, unsigned long) {
|
||||
GLXStreamLock streamLock;
|
||||
MGLOG_W_ONCE("glx: glXCopyContext is not supported");
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXCreateGLXPixmap(Display*, void*, unsigned long) {
|
||||
GLXStreamLock streamLock;
|
||||
MGLOG_W_ONCE("glx: glXCreateGLXPixmap is not supported");
|
||||
return 0;
|
||||
}
|
||||
@@ -177,6 +220,7 @@ MOBILEGL_GLX_API unsigned long glXCreateGLXPixmap(Display*, void*, unsigned long
|
||||
MOBILEGL_GLX_API void glXDestroyGLXPixmap(Display*, unsigned long) {}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXCreatePixmap(Display*, void*, unsigned long, const int*) {
|
||||
GLXStreamLock streamLock;
|
||||
MGLOG_W_ONCE("glx: glXCreatePixmap is not supported");
|
||||
return 0;
|
||||
}
|
||||
@@ -184,6 +228,7 @@ MOBILEGL_GLX_API unsigned long glXCreatePixmap(Display*, void*, unsigned long, c
|
||||
MOBILEGL_GLX_API void glXDestroyPixmap(Display*, unsigned long) {}
|
||||
|
||||
MOBILEGL_GLX_API unsigned long glXCreatePbuffer(Display*, void*, const int*) {
|
||||
GLXStreamLock streamLock;
|
||||
MGLOG_W_ONCE("glx: glXCreatePbuffer is not supported");
|
||||
return 0;
|
||||
}
|
||||
@@ -191,12 +236,14 @@ MOBILEGL_GLX_API unsigned long glXCreatePbuffer(Display*, void*, const int*) {
|
||||
MOBILEGL_GLX_API void glXDestroyPbuffer(Display*, unsigned long) {}
|
||||
|
||||
MOBILEGL_GLX_API void glXUseXFont(unsigned long, int, int, int) {
|
||||
GLXStreamLock streamLock;
|
||||
MGLOG_W_ONCE("glx: glXUseXFont is not supported");
|
||||
}
|
||||
|
||||
MOBILEGL_GLX_API void glXSelectEvent(Display*, unsigned long, unsigned long) {}
|
||||
|
||||
MOBILEGL_GLX_API void glXGetSelectedEvent(Display*, unsigned long, unsigned long* eventMask) {
|
||||
GLXStreamLock streamLock;
|
||||
if (eventMask) {
|
||||
*eventMask = 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
// MobileGL - MobileGL/MG_Impl/GLXImpl/Exporting/GlvndVendor.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// MOBILEGL AS A GLVND GLX VENDOR.
|
||||
//
|
||||
// The libGL.so.1 / libGLX.so.0 an X11 application links on a glvnd system is a dispatcher: it
|
||||
// picks a vendor library per X screen - the one the X server names, or the one
|
||||
// __GLX_VENDOR_LIBRARY_NAME names - loads it as libGLX_<name>.so.0 and routes every GLX call and,
|
||||
// once a context is current, every GL call to it. Under a Wayland compositor the X server is
|
||||
// Xwayland, which names the distribution's driver; that driver then needs a GPU device this
|
||||
// machine's X clients do not have, and glxinfo ends in "failed to retrieve device information".
|
||||
// Installed as libGLX_mobilegl.so.0 and named by __GLX_VENDOR_LIBRARY_NAME=mobilegl, this library
|
||||
// is the one asked instead, through the same entry points it exports directly.
|
||||
//
|
||||
// The ABI (libglvnd's libglxabi.h, vendor ABI 1.0) is mirrored here rather than included: that
|
||||
// header includes GL/glx.h and Xlib.h, and this library's GLX layer is built without X headers.
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#include "../GLXImpl.h"
|
||||
#include "../../GetProcAddress.h"
|
||||
|
||||
namespace {
|
||||
using namespace MobileGL;
|
||||
|
||||
struct GLXVendorInfo;
|
||||
using XBool = int;
|
||||
|
||||
// __GLXapiExportsRec, field for field.
|
||||
struct GLXApiExports {
|
||||
GLXVendorInfo* (*getDynDispatch)(Display* dpy, int screen);
|
||||
GLXVendorInfo* (*getCurrentDynDispatch)();
|
||||
void* (*fetchDispatchEntry)(GLXVendorInfo* dynDispatch, int index);
|
||||
void* (*getCurrentContext)();
|
||||
int (*addVendorContextMapping)(Display* dpy, void* context, GLXVendorInfo* vendor);
|
||||
void (*removeVendorContextMapping)(Display* dpy, void* context);
|
||||
GLXVendorInfo* (*vendorFromContext)(void* context);
|
||||
int (*addVendorFBConfigMapping)(Display* dpy, void* config, GLXVendorInfo* vendor);
|
||||
void (*removeVendorFBConfigMapping)(Display* dpy, void* config);
|
||||
GLXVendorInfo* (*vendorFromFBConfig)(Display* dpy, void* config);
|
||||
int (*addVendorDrawableMapping)(Display* dpy, XID drawable, GLXVendorInfo* vendor);
|
||||
void (*removeVendorDrawableMapping)(Display* dpy, XID drawable);
|
||||
GLXVendorInfo* (*vendorFromDrawable)(Display* dpy, XID drawable);
|
||||
};
|
||||
|
||||
// __GLXapiImportsRec, field for field; the patch hooks are optional and left null.
|
||||
struct GLXApiImports {
|
||||
XBool (*isScreenSupported)(Display* dpy, int screen);
|
||||
void* (*getProcAddress)(const unsigned char* procName);
|
||||
void* (*getDispatchAddress)(const unsigned char* procName);
|
||||
void (*setDispatchIndex)(const unsigned char* procName, int index);
|
||||
XBool (*notifyError)(Display* dpy, unsigned char error, XID resid, unsigned char opcode, XBool coreX11error);
|
||||
unsigned char (*isPatchSupported)(int type, int stubSize);
|
||||
unsigned char (*initiatePatch)(int type, int stubSize, void* lookupStubOffset);
|
||||
void (*releasePatch)();
|
||||
void (*patchThreadAttach)();
|
||||
};
|
||||
|
||||
constexpr Uint32 kGLXVendorABIMajor = 1;
|
||||
|
||||
const GLXApiExports* g_glxExports = nullptr;
|
||||
GLXVendorInfo* g_glxVendor = nullptr;
|
||||
|
||||
XBool VendorIsScreenSupported(Display*, int) { return 1; }
|
||||
|
||||
// GLX names are the exported entry points (each holds the stream lock); GL names are the
|
||||
// implementation's, as eglGetProcAddress hands them out.
|
||||
void* VendorGetProcAddress(const unsigned char* procName) {
|
||||
const char* name = reinterpret_cast<const char*>(procName);
|
||||
if (std::strncmp(name, "glX", 3) == 0) return MG_Impl::GLXImpl::GetGLXEntryPoint(name);
|
||||
return MG_Impl::GetProcAddress(name);
|
||||
}
|
||||
|
||||
// A context made by an extension is one libGLX did not see created, so it is told whose it is
|
||||
// - or glXMakeCurrent on it finds no vendor and fails.
|
||||
void* VendorCreateContextAttribsARB(Display* dpy, void* config, void* share, int direct, const int* attribs) {
|
||||
using Create = void* (*)(Display*, void*, void*, int, const int*);
|
||||
auto* create = reinterpret_cast<Create>(MG_Impl::GLXImpl::GetGLXEntryPoint("glXCreateContextAttribsARB"));
|
||||
void* context = create ? create(dpy, config, share, direct, attribs) : nullptr;
|
||||
if (context && g_glxExports && g_glxExports->addVendorContextMapping(dpy, context, g_glxVendor) != 0) {
|
||||
using Destroy = void (*)(Display*, void*);
|
||||
if (auto* destroy = reinterpret_cast<Destroy>(MG_Impl::GLXImpl::GetGLXEntryPoint("glXDestroyContext"))) {
|
||||
destroy(dpy, context);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
// libGLX asks for the GLX functions it has no dispatcher of its own for (the extensions). This
|
||||
// is the only vendor in the process that answers for its screens, so the "dispatcher" is the
|
||||
// implementation itself; only context creation has bookkeeping to do on the way.
|
||||
void* VendorGetDispatchAddress(const unsigned char* procName) {
|
||||
const char* name = reinterpret_cast<const char*>(procName);
|
||||
if (std::strcmp(name, "glXCreateContextAttribsARB") == 0) {
|
||||
return reinterpret_cast<void*>(&VendorCreateContextAttribsARB);
|
||||
}
|
||||
return MG_Impl::GLXImpl::GetGLXEntryPoint(name);
|
||||
}
|
||||
|
||||
void VendorSetDispatchIndex(const unsigned char*, int) {}
|
||||
} // namespace
|
||||
|
||||
extern "C" MOBILEGL_API int __glx_Main(Uint32 version, const void* exportsTable, void* vendor, void* importsTable) {
|
||||
const auto* exports = static_cast<const GLXApiExports*>(exportsTable);
|
||||
auto* imports = static_cast<GLXApiImports*>(importsTable);
|
||||
if ((version >> 16) != kGLXVendorABIMajor || exports == nullptr || imports == nullptr) return 0;
|
||||
g_glxExports = exports;
|
||||
g_glxVendor = static_cast<GLXVendorInfo*>(vendor);
|
||||
imports->isScreenSupported = &VendorIsScreenSupported;
|
||||
imports->getProcAddress = &VendorGetProcAddress;
|
||||
imports->getDispatchAddress = &VendorGetDispatchAddress;
|
||||
imports->setDispatchIndex = &VendorSetDispatchIndex;
|
||||
imports->notifyError = nullptr;
|
||||
imports->isPatchSupported = nullptr;
|
||||
imports->initiatePatch = nullptr;
|
||||
imports->releasePatch = nullptr;
|
||||
imports->patchThreadAttach = nullptr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // __linux__ && !__ANDROID__
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#include "../EGLImpl/EGLImpl.h"
|
||||
#include "../EGLImpl/WaylandWindow.h"
|
||||
#include "../GetProcAddress.h"
|
||||
#include <Init.h>
|
||||
#include <Config.h>
|
||||
@@ -157,6 +158,53 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
return *functions;
|
||||
}
|
||||
|
||||
// ---- X11 presentation of a remote drawable (libxcb through libX11's own connection,
|
||||
// dlopen'd like the rest; xcb's request is plain arguments, no struct layouts) ----
|
||||
struct XcbVoidCookie {
|
||||
unsigned int Sequence;
|
||||
};
|
||||
struct XcbFunctions {
|
||||
void* (*GetXCBConnection)(Display*) = nullptr;
|
||||
Uint32 (*GenerateId)(void*) = nullptr;
|
||||
XcbVoidCookie (*CreateGC)(void*, Uint32, Uint32, Uint32, const void*) = nullptr;
|
||||
XcbVoidCookie (*FreeGC)(void*, Uint32) = nullptr;
|
||||
XcbVoidCookie (*PutImage)(void*, Uint8, Uint32, Uint32, Uint16, Uint16, Int16, Int16, Uint8, Uint8,
|
||||
Uint32, const Uint8*) = nullptr;
|
||||
Uint32 (*MaximumRequestLength)(void*) = nullptr;
|
||||
int (*Flush)(void*) = nullptr;
|
||||
|
||||
Bool Valid() const {
|
||||
return GetXCBConnection && GenerateId && CreateGC && FreeGC && PutImage && MaximumRequestLength &&
|
||||
Flush;
|
||||
}
|
||||
};
|
||||
|
||||
const XcbFunctions& Xcb() {
|
||||
static const XcbFunctions* functions = [] {
|
||||
auto* fns = new XcbFunctions();
|
||||
void* x11xcb = dlopen("libX11-xcb.so.1", RTLD_LOCAL | RTLD_NOW);
|
||||
void* xcb = dlopen("libxcb.so.1", RTLD_LOCAL | RTLD_NOW);
|
||||
if (x11xcb && xcb) {
|
||||
fns->GetXCBConnection =
|
||||
reinterpret_cast<decltype(fns->GetXCBConnection)>(dlsym(x11xcb, "XGetXCBConnection"));
|
||||
fns->GenerateId = reinterpret_cast<decltype(fns->GenerateId)>(dlsym(xcb, "xcb_generate_id"));
|
||||
fns->CreateGC = reinterpret_cast<decltype(fns->CreateGC)>(dlsym(xcb, "xcb_create_gc"));
|
||||
fns->FreeGC = reinterpret_cast<decltype(fns->FreeGC)>(dlsym(xcb, "xcb_free_gc"));
|
||||
fns->PutImage = reinterpret_cast<decltype(fns->PutImage)>(dlsym(xcb, "xcb_put_image"));
|
||||
fns->MaximumRequestLength = reinterpret_cast<decltype(fns->MaximumRequestLength)>(
|
||||
dlsym(xcb, "xcb_get_maximum_request_length"));
|
||||
fns->Flush = reinterpret_cast<decltype(fns->Flush)>(dlsym(xcb, "xcb_flush"));
|
||||
}
|
||||
if (!fns->Valid()) {
|
||||
MGLOG_E_ONCE("glx: libX11-xcb/libxcb entry points missing; remote windows are not shown");
|
||||
}
|
||||
return fns;
|
||||
}();
|
||||
return *functions;
|
||||
}
|
||||
|
||||
constexpr Uint8 kXcbImageFormatZPixmap = 2;
|
||||
|
||||
// ---- FBConfigs: mirror the two EGLState configs, stencil-8 first so
|
||||
// stencil-wanting choosers (GLFW's default hints) match config 1 ----
|
||||
struct FBConfigInfo {
|
||||
@@ -189,6 +237,13 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
Uint32 Height = 0;
|
||||
std::chrono::steady_clock::time_point LastSizePoll{};
|
||||
Bool RemotePbuffer = false;
|
||||
// A remote drawable's presentation: the window's depth, the GC its frames are put
|
||||
// with (0 until the first one) and the readback buffers.
|
||||
::Display* XDisplay = nullptr;
|
||||
Uint32 Depth = 0;
|
||||
Uint32 Gc = 0;
|
||||
Vector<Uint8> Scratch;
|
||||
Vector<Uint8> Image;
|
||||
};
|
||||
|
||||
std::recursive_mutex& RegistryMutex() {
|
||||
@@ -257,7 +312,8 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
return it == contexts.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
Bool QueryDrawableSize(Display* dpy, GLXDrawableHandle drawable, Uint32& width, Uint32& height) {
|
||||
Bool QueryDrawableSize(Display* dpy, GLXDrawableHandle drawable, Uint32& width, Uint32& height,
|
||||
Uint32* depthOut = nullptr) {
|
||||
const auto& x11 = X11();
|
||||
if (!x11.Valid() || !dpy || drawable == 0) {
|
||||
return false;
|
||||
@@ -274,9 +330,59 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
}
|
||||
width = std::max(w, 1u);
|
||||
height = std::max(h, 1u);
|
||||
if (depthOut) *depthOut = depth;
|
||||
return true;
|
||||
}
|
||||
|
||||
// A REMOTE DRAWABLE IS A PBUFFER, AND NOTHING OF IT REACHES THE X WINDOW BY ITSELF: the
|
||||
// backend draws in another process (another OS), where an XID means nothing. So at every
|
||||
// swap the frame is read back and put on the window with PutImage - the same contract as
|
||||
// the Wayland windows' wl_shm presentation. Called with the drawable current.
|
||||
void PresentRemoteDrawable(GLXDrawableHandle drawable, DrawableSurface& surface) {
|
||||
const EGLImpl::GLStreamScope stream; // the readback is GL records of this thread's context
|
||||
const auto& xcb = Xcb();
|
||||
if (!xcb.Valid() || !surface.XDisplay) return;
|
||||
if (surface.Depth != 24 && surface.Depth != 32) {
|
||||
MGLOG_W_ONCE("glx: a depth-%u window cannot be shown (24/32-bit only)", surface.Depth);
|
||||
return;
|
||||
}
|
||||
void* connection = xcb.GetXCBConnection(surface.XDisplay);
|
||||
if (!connection) return;
|
||||
if (surface.Gc == 0) {
|
||||
surface.Gc = xcb.GenerateId(connection);
|
||||
(void)xcb.CreateGC(connection, surface.Gc, static_cast<Uint32>(drawable), 0, nullptr);
|
||||
}
|
||||
const EGLint width = static_cast<EGLint>(surface.Width);
|
||||
const EGLint height = static_cast<EGLint>(surface.Height);
|
||||
const SizeT rowBytes = static_cast<SizeT>(width) * 4;
|
||||
surface.Image.resize(rowBytes * static_cast<SizeT>(height));
|
||||
EGLImpl::ReadBackFrameBGRA(width, height, surface.Scratch, surface.Image.data(), rowBytes);
|
||||
|
||||
// A request over the server's maximum length closes the connection, so the image goes
|
||||
// in bands of whole rows that each fit (the request header is 24 bytes).
|
||||
const SizeT maxBytes = static_cast<SizeT>(xcb.MaximumRequestLength(connection)) * 4;
|
||||
const SizeT budget = maxBytes > 64 ? maxBytes - 64 : rowBytes;
|
||||
const EGLint bandRows = std::max<EGLint>(1, static_cast<EGLint>(budget / rowBytes));
|
||||
for (EGLint y = 0; y < height; y += bandRows) {
|
||||
const EGLint rows = std::min(bandRows, height - y);
|
||||
(void)xcb.PutImage(connection, kXcbImageFormatZPixmap, static_cast<Uint32>(drawable), surface.Gc,
|
||||
static_cast<Uint16>(width), static_cast<Uint16>(rows), 0, static_cast<Int16>(y), 0,
|
||||
static_cast<Uint8>(surface.Depth), static_cast<Uint32>(rowBytes * rows),
|
||||
surface.Image.data() + rowBytes * static_cast<SizeT>(y));
|
||||
}
|
||||
(void)xcb.Flush(connection);
|
||||
}
|
||||
|
||||
void ReleaseDrawableSurface(DrawableSurface& surface) {
|
||||
if (surface.Gc != 0 && surface.XDisplay) {
|
||||
const auto& xcb = Xcb();
|
||||
if (void* connection = xcb.Valid() ? xcb.GetXCBConnection(surface.XDisplay) : nullptr) {
|
||||
(void)xcb.FreeGC(connection, surface.Gc);
|
||||
}
|
||||
}
|
||||
EGLImpl::DestroySurface(surface.Display, surface.Surface);
|
||||
}
|
||||
|
||||
// The backends never query the X window size themselves; the GLX layer
|
||||
// owns size discovery and pushes changes through the internal resize hook
|
||||
// (same contract as the WGL and CGL layers). Polling XGetGeometry is a
|
||||
@@ -296,10 +402,7 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
if (width == surface.Width && height == surface.Height) {
|
||||
return;
|
||||
}
|
||||
// A remote X drawable is backed by a pbuffer; an XID has no meaning
|
||||
// to the Android worker. Its allocation cannot be resized by the
|
||||
// native-window hook. Keep the current allocation until recreated.
|
||||
if (surface.RemotePbuffer) return;
|
||||
// A remote X drawable is a pbuffer; resizing it gives it a new one at the new size.
|
||||
if (EGLImpl::ResizePlatformWindowSurface(surface.Display, surface.Surface,
|
||||
static_cast<EGLint>(width),
|
||||
static_cast<EGLint>(height))) {
|
||||
@@ -319,7 +422,8 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
|
||||
Uint32 width = 0;
|
||||
Uint32 height = 0;
|
||||
if (!QueryDrawableSize(dpy, drawable, width, height)) {
|
||||
Uint32 depth = 0;
|
||||
if (!QueryDrawableSize(dpy, drawable, width, height, &depth)) {
|
||||
MGLOG_E_ONCE("glx: XGetGeometry failed for drawable 0x%lx", drawable);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -329,7 +433,8 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
EGL_HEIGHT, static_cast<EGLAttrib>(height),
|
||||
EGL_NONE,
|
||||
};
|
||||
const Bool remotePbuffer = MG_Config::Transport == MG_Config::TransportMode::Spawn;
|
||||
const Bool remotePbuffer = MG_Config::Transport == MG_Config::TransportMode::Spawn ||
|
||||
MG_Config::Transport == MG_Config::TransportMode::UnixSocket;
|
||||
const EGLint pbufferAttribs[] = {EGL_WIDTH, static_cast<EGLint>(width),
|
||||
EGL_HEIGHT, static_cast<EGLint>(height), EGL_NONE};
|
||||
EGLSurface surface = remotePbuffer
|
||||
@@ -348,6 +453,8 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
record.Width = width;
|
||||
record.Height = height;
|
||||
record.RemotePbuffer = remotePbuffer;
|
||||
record.XDisplay = dpy;
|
||||
record.Depth = depth;
|
||||
record.LastSizePoll = std::chrono::steady_clock::now();
|
||||
auto [inserted, _] = surfaces.emplace(drawable, record);
|
||||
return &inserted->second;
|
||||
@@ -973,8 +1080,14 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
MGLOG_W_ONCE("glx: glXSwapBuffers with no surface for drawable 0x%lx", drawable);
|
||||
return;
|
||||
}
|
||||
SyncSurfaceSize(dpy, drawable, it->second);
|
||||
// What the window shows is the frame the swap finishes, read back while it is still the
|
||||
// drawable's content (only from the thread it is current to: the readback is a GL call).
|
||||
if (it->second.RemotePbuffer && t_current.Draw == drawable && t_current.Context) {
|
||||
PresentRemoteDrawable(drawable, it->second);
|
||||
}
|
||||
EGLImpl::SwapBuffers(it->second.Display, it->second.Surface);
|
||||
// A resize takes effect for the next frame.
|
||||
SyncSurfaceSize(dpy, drawable, it->second);
|
||||
}
|
||||
|
||||
GLXDrawableHandle CreateWindow(Display*, GLXFBConfigHandle config, GLXDrawableHandle window,
|
||||
@@ -1000,7 +1113,7 @@ namespace MobileGL::MG_Impl::GLXImpl {
|
||||
if (it == surfaces.end()) {
|
||||
return;
|
||||
}
|
||||
EGLImpl::DestroySurface(it->second.Display, it->second.Surface);
|
||||
ReleaseDrawableSurface(it->second);
|
||||
surfaces.erase(it);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#endif
|
||||
|
||||
extern "C" EGLDisplay eglGetPlatformDisplayEXT(EGLenum platform, void* native_display, const EGLint* attrib_list);
|
||||
extern "C" EGLImage eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImage image);
|
||||
|
||||
#define GETPROC(name, var) \
|
||||
if (strcmp(#name, var) == 0) { \
|
||||
@@ -64,6 +67,8 @@ namespace MobileGL::MG_Impl {
|
||||
GETPROC(eglGetSyncAttrib, name);
|
||||
GETPROC(eglCreateImage, name);
|
||||
GETPROC(eglDestroyImage, name);
|
||||
GETPROC(eglCreateImageKHR, name);
|
||||
GETPROC(eglDestroyImageKHR, name);
|
||||
GETPROC(eglGetPlatformDisplay, name);
|
||||
GETPROC(eglGetPlatformDisplayEXT, name);
|
||||
GETPROC(eglCreatePlatformWindowSurface, name);
|
||||
|
||||
@@ -303,9 +303,15 @@ namespace MobileGL::MG_Pipe {
|
||||
// A different context is a different server: nothing the tracker latched about
|
||||
// the old one says anything about this one, and the first walk on a fresh
|
||||
// context must publish a COMPLETE state rather than an increment.
|
||||
if (m_context != &ctx) {
|
||||
//
|
||||
// KEYED ON THE CONTEXT'S NEVER-REUSED ID, NOT ITS ADDRESS: a context destroyed and
|
||||
// remade at the same heap address (Qt does this) is a fresh server-side applier
|
||||
// with empty windows, and an address compare would skip the re-prime that refills
|
||||
// them.
|
||||
if (m_context != &ctx || m_contextId != ctx.GetTextureContextId()) {
|
||||
Reset();
|
||||
m_context = &ctx;
|
||||
m_contextId = ctx.GetTextureContextId();
|
||||
}
|
||||
const Bool wasPrimed = m_primed;
|
||||
|
||||
@@ -811,6 +817,7 @@ namespace MobileGL::MG_Pipe {
|
||||
m_staged = RenderStateParameters{};
|
||||
m_stagedAttribs = AttribDefaults{};
|
||||
m_context = nullptr;
|
||||
m_contextId = 0;
|
||||
m_lastDirty = 0;
|
||||
m_primed = false;
|
||||
m_freshlyPrimed = false;
|
||||
@@ -917,6 +924,7 @@ namespace MobileGL::MG_Pipe {
|
||||
AttribDefaults m_stagedAttribs{};
|
||||
|
||||
const void* m_context = nullptr;
|
||||
Uint64 m_contextId = 0;
|
||||
Uint32 m_lastDirty = 0;
|
||||
Bool m_primed = false;
|
||||
Bool m_freshlyPrimed = false;
|
||||
|
||||
@@ -643,6 +643,18 @@ namespace MobileGL::MG_Pipe {
|
||||
return sessionIt == g_applierSessions.end() ? 0 : static_cast<Uint64>(sessionIt->second.Groups.size());
|
||||
}
|
||||
|
||||
Uint64 MGPipeApplierShareGroupKeyFor(Uint64 sessionKey, Uint64 contextToken) {
|
||||
std::lock_guard<std::mutex> guard(g_applierSessionsMutex);
|
||||
const auto sessionIt = g_applierSessions.find(sessionKey);
|
||||
if (sessionIt != g_applierSessions.end()) {
|
||||
const auto groupIt = sessionIt->second.ContextGroup.find(contextToken);
|
||||
if (groupIt != sessionIt->second.ContextGroup.end()) return groupIt->second;
|
||||
}
|
||||
// Not registered - the same fallback FindApplierForKey takes, spelled by the same one
|
||||
// function so the two cannot drift.
|
||||
return ApplierShareGroupKey(contextToken, 0);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// The installed handle-shaped resource table. Null until a backend registers one,
|
||||
|
||||
@@ -1056,6 +1056,16 @@ namespace MobileGL::MG_Pipe {
|
||||
// "shared" apart from the behaviour they exist to explain.
|
||||
Uint64 MGPipeApplierShareGroupCountForTesting(Uint64 sessionKey);
|
||||
|
||||
// P14 S6: THE SHARE-GROUP BUCKET A {session, context token} PAIR IS FILED UNDER, answered
|
||||
// from the registry rather than re-derived. The backend's twin tables are keyed by the same
|
||||
// pair (DirectGLES.h's TwinKey), and a record and the twin describing it must never land in
|
||||
// different buckets - so there is ONE spelling of the rule, here. A registered context
|
||||
// answers its group; anything else (token 0, the 0 of a session that has not bound one yet,
|
||||
// a context no CreateContext ever named) answers the group that context starts itself,
|
||||
// exactly as FindApplierForKey mints it. Never fails, so a caller has no third answer to
|
||||
// invent.
|
||||
Uint64 MGPipeApplierShareGroupKeyFor(Uint64 sessionKey, Uint64 contextToken);
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P5e: THE BARRIERED PREDICATE (MG_Remote/CONTRACT-P5E.md §2.1, ruling 3)
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
@@ -367,7 +367,14 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// InitCapabilities' answer comes from a snapshot the server can only publish once its
|
||||
// own InitCapabilities has run - and ServerMakeEGLCurrent is what publishes it.
|
||||
WaitForApplyBeforeEglForwarder("MakeEGLCurrent");
|
||||
if (!Server::ServerMakeEGLCurrent(dpy, draw, read, ctx)) return false;
|
||||
// The frame carries the context's CLIENT TOKEN rather than its handle (the server's
|
||||
// MakeCurrent arm binds the session to it before the native bind). Identity is all the
|
||||
// server reads from the field otherwise, and a token is as unique as a handle.
|
||||
const Uint64 contextToken =
|
||||
(ctx != EGL_NO_CONTEXT && MG_State::pEGLContext) ? MG_State::pEGLContext->GetContextClientToken(ctx) : 0;
|
||||
const EGLContext wireContext =
|
||||
contextToken != 0 ? reinterpret_cast<EGLContext>(static_cast<std::uintptr_t>(contextToken)) : ctx;
|
||||
if (!Server::ServerMakeEGLCurrent(dpy, draw, read, wireContext)) return false;
|
||||
if (!MG_Backend::BackendObject::MakeEGLCurrent(dpy, draw, read, ctx)) return false;
|
||||
|
||||
// R-12 ARM (a) ON EVERY SUCCESSFUL MAKE-CURRENT (codex 12). ServerMakeEGLCurrent above
|
||||
|
||||
@@ -24,9 +24,12 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
|
||||
#if defined(__linux__) || defined(__ANDROID__)
|
||||
@@ -38,6 +41,67 @@ namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
namespace {
|
||||
|
||||
// P14: THE BACKEND'S TURN. The in-process display server runs one apply thread per
|
||||
// session, and the backend those threads drive was written for one GL thread: one owner
|
||||
// thread, one set of binding shadows, process-wide rings and pools. Two sessions applying
|
||||
// at once raced all of it - a session's buffer ops were deferred while the other thread
|
||||
// owned the backend, and a texture bind was skipped because the shadow described the
|
||||
// other session's context. So an apply thread holds the turn while it does backend work
|
||||
// (control requests, a drain batch, fence reports, teardown) and gives it up before it
|
||||
// parks. FIFO, so a session with a busy ring cannot starve its neighbours; reentrant for
|
||||
// the thread that holds it. When the turn moves to a different thread the backend takes
|
||||
// ownership for it and drops its binding shadows (DirectGLES::OnBackendTurnHandoff).
|
||||
class BackendTurnLock {
|
||||
public:
|
||||
void Lock() {
|
||||
const std::thread::id self = std::this_thread::get_id();
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
if (m_owner == self) {
|
||||
++m_depth;
|
||||
return;
|
||||
}
|
||||
const Uint64 ticket = m_nextTicket++;
|
||||
m_turn.wait(lock, [&] { return m_serving == ticket; });
|
||||
m_owner = self;
|
||||
m_depth = 1;
|
||||
if (m_lastOwner != self) {
|
||||
const Bool handoff = m_lastOwner != std::thread::id{};
|
||||
m_lastOwner = self;
|
||||
lock.unlock();
|
||||
if (handoff) MG_Backend::DirectGLES::OnBackendTurnHandoff();
|
||||
}
|
||||
}
|
||||
void Unlock() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (--m_depth > 0) return;
|
||||
m_owner = std::thread::id{};
|
||||
++m_serving;
|
||||
m_turn.notify_all();
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
std::condition_variable m_turn;
|
||||
Uint64 m_nextTicket = 0;
|
||||
Uint64 m_serving = 0;
|
||||
std::thread::id m_owner{};
|
||||
std::thread::id m_lastOwner{};
|
||||
Uint32 m_depth = 0;
|
||||
};
|
||||
|
||||
BackendTurnLock& BackendTurn() {
|
||||
static BackendTurnLock& turn = *new BackendTurnLock(); // leaked at exit (ID-8)
|
||||
return turn;
|
||||
}
|
||||
|
||||
class ScopedBackendTurn {
|
||||
public:
|
||||
ScopedBackendTurn() { BackendTurn().Lock(); }
|
||||
~ScopedBackendTurn() { BackendTurn().Unlock(); }
|
||||
ScopedBackendTurn(const ScopedBackendTurn&) = delete;
|
||||
ScopedBackendTurn& operator=(const ScopedBackendTurn&) = delete;
|
||||
};
|
||||
|
||||
// The bounded join. InProcessTransportTest.cpp:344 uses five seconds for the same
|
||||
// reason: a lost wakeup must be a RED TEST and not a hung CI job.
|
||||
constexpr Uint32 kJoinTimeoutMs = 5000;
|
||||
@@ -533,6 +597,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
};
|
||||
|
||||
for (;;) {
|
||||
std::optional<ScopedBackendTurn> turn(std::in_place);
|
||||
PumpControlRequest();
|
||||
if (stopOrForfeit()) break;
|
||||
if (eventRingHasRoom()) DrainRing();
|
||||
@@ -557,6 +622,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (ready()) continue;
|
||||
}
|
||||
|
||||
// Never park holding the turn: a neighbour session may be waiting for it.
|
||||
turn.reset();
|
||||
const Uint64 waits = m_parks.fetch_add(1, std::memory_order_acq_rel) + 1;
|
||||
// THE WAIT LEDGER'S SERVER HALF (P5d round 3, package T item 4). The client may not
|
||||
// name this counter - CONTRACT-P5C rule E, layer 2: a GL-thread read of
|
||||
@@ -622,6 +689,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// AND AFTER AbandonQueuedRecords (P12 review fix), for the forfeit's reason: the server is
|
||||
// stopping under a client that may still be streaming, and draining what it keeps queuing
|
||||
// is the unbounded hold Stop()'s bounded join turns into an abort.
|
||||
std::optional<ScopedBackendTurn> exitTurn(std::in_place);
|
||||
const Bool forfeited = session.ReverseChannelForfeited();
|
||||
const Bool abandoned = m_abandonQueue.load(std::memory_order_acquire);
|
||||
PumpControlRequest();
|
||||
@@ -650,6 +718,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
"which is the context owner");
|
||||
m_backend.reset();
|
||||
}
|
||||
exitTurn.reset();
|
||||
// P12 (D6): the backend - and with it every surface on the server's window - is gone, so the
|
||||
// session's lease on that window ends here, AFTER the reset. A Detach waiting on it returns
|
||||
// now; one that arrives later finds no lease and releases the window at once.
|
||||
@@ -1418,6 +1487,14 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// already current on this thread is skipped one layer down
|
||||
// (BackendObject_DirectGLES's ID-54 arm), which is what makes "the owner slot is
|
||||
// written once" TRUE and measured (ServerLoopTest's C7 control) rather than claimed.
|
||||
//
|
||||
// P14 MULTI-WINDOW: the frame names the client's CONTEXT TOKEN (BackendObject_Remote's
|
||||
// MakeEGLCurrent), and the native bind below resolves the context through the session's
|
||||
// current token - which still names whatever another thread bound last, since this
|
||||
// thread's own bind_context follows the frame. Bound first, so the surface is made
|
||||
// current with ITS context and not attached to a neighbour's. A frame from a client
|
||||
// that sends a handle names no token and leaves the binding alone.
|
||||
if (m_session != nullptr && frame.context != 0) (void)m_session->BindContext(frame.context);
|
||||
const MakeCurrentOutcome outcome =
|
||||
ApplyMakeCurrent(backend, HandleFromToken<EGLDisplay>(frame.display),
|
||||
HandleFromToken<EGLSurface>(frame.surface),
|
||||
|
||||
@@ -461,9 +461,18 @@ int RunSession(std::unique_ptr<SocketTransport> control, std::vector<std::uint8_
|
||||
if (ValidatePeerHandshake(*control, hello->abiMajor(), hello->abiMinor(),
|
||||
hello->wireFingerprint(), hello->buildFingerprint() ? hello->buildFingerprint()->c_str() : nullptr,
|
||||
hello->dialMode()) != MOBILEGL_OK) return LeaveBeforeAccept(sourceFd, sourceKind, 0);
|
||||
MobileGL::MG_ConfigLoader::Init();
|
||||
MobileGL::MG_Config::Transport = MobileGL::MG_Config::TransportMode::Spawn;
|
||||
MobileGL::MG_Pipe::MGPipeSetServerProcessRole(true);
|
||||
// ONCE PER PROCESS, NOT PER SESSION. The configuration is the process's environment, the same
|
||||
// for every session it serves, and re-reading it is not a no-op: Init() rewrites the globals
|
||||
// in place - Transport first falls back to Monolith before the line below puts Spawn back - so
|
||||
// a second session accepted while the first is applying showed that session's apply thread a
|
||||
// monolith process for a moment. It then skipped the server stamp on a draw and died on
|
||||
// Fatal{UnmigratedPipeInput}, taking every session in the process with it.
|
||||
static std::once_flag s_serverConfigured;
|
||||
std::call_once(s_serverConfigured, [] {
|
||||
MobileGL::MG_ConfigLoader::Init();
|
||||
MobileGL::MG_Config::Transport = MobileGL::MG_Config::TransportMode::Spawn;
|
||||
MobileGL::MG_Pipe::MGPipeSetServerProcessRole(true);
|
||||
});
|
||||
// PH-1 (3), ID-P7-1: THIS PROCESS IS THE SESSION, so a named fault on the peer's bytes may end
|
||||
// it cleanly instead of aborting it (FatalFunnel.h's latch block). Armed here and nowhere
|
||||
// else: inproc keeps every Fatal (client and server share that process), and the supervisor
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <MG_Backend/DirectGLES/DirectGLES.h>
|
||||
#include <MG_Remote/FatalFunnel.h>
|
||||
#include <MG_Remote/Server/StagedShadow.h>
|
||||
#include <MG_Remote/Wire/PipeWireCodec.h>
|
||||
|
||||
#include <atomic>
|
||||
@@ -62,6 +63,35 @@ namespace MobileGL::MG_Remote::Server {
|
||||
outKey->ContextToken = runtime->Session().CurrentContextToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
// P14 S6 (docs/Disaggregated/design/11-state-ownership.md). WHICH TWIN TABLE DOES THIS
|
||||
// THREAD'S BACKEND OBJECT BELONG TO? The backend's twin tables are per {session, share
|
||||
// group} - a twin owns a DRIVER id, and a driver id belongs to one native context's
|
||||
// object namespace - so this answers the same two words the applier's OBJECT RECORDS are
|
||||
// filed under, resolved through the same `CurrentContextToken()` and the same
|
||||
// MGPipeApplierShareGroupKeyFor rule the applier itself uses. Sharing a helper rather
|
||||
// than re-deriving the rule is the point: a record and the twin it describes must always
|
||||
// land in the same bucket, and a second spelling of "0 means its own group" is exactly
|
||||
// how they would stop doing that.
|
||||
Bool ResolveThreadTwinKey(MG_Backend::DirectGLES::TwinKey* outKey) {
|
||||
SessionRuntime* runtime = t_runtime;
|
||||
if (runtime == nullptr) return false;
|
||||
outKey->SessionKey = reinterpret_cast<Uint64>(&runtime->Session());
|
||||
outKey->ShareGroupKey = MG_Pipe::MGPipeApplierShareGroupKeyFor(
|
||||
outKey->SessionKey, runtime->Session().CurrentContextToken());
|
||||
return true;
|
||||
}
|
||||
|
||||
// The server's staged stores (StagedShadow.h) file their entries under the same two
|
||||
// words as the twin tables, for the same reason one level up: the bytes they hold belong
|
||||
// to one session's group, and a session's teardown may drop only its own.
|
||||
Bool ResolveThreadStagedBucket(StagedBucket* outBucket) {
|
||||
MG_Backend::DirectGLES::TwinKey key;
|
||||
if (!ResolveThreadTwinKey(&key)) return false;
|
||||
outBucket->SessionKey = key.SessionKey;
|
||||
outBucket->ShareGroupKey = key.ShareGroupKey;
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Detail::InstallSessionRuntimeHooks() {
|
||||
@@ -70,6 +100,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
MG_Backend::DirectGLES::SetNativeContextKeyResolver(&ResolveThreadNativeContextKey);
|
||||
MG_Pipe::MGPipeSetApplierKeyResolver(&ResolveThreadApplierKey);
|
||||
// P14 S6: the twin tables' key. Same probe, one level down, installed beside the two it
|
||||
// is the twin of (the native tuple's and the applier's).
|
||||
MG_Backend::DirectGLES::SetTwinKeyResolver(&ResolveThreadTwinKey);
|
||||
SetStagedBucketResolver(&ResolveThreadStagedBucket);
|
||||
}
|
||||
|
||||
SessionRuntime* Detail::CurrentRuntime() { return t_runtime; }
|
||||
|
||||
@@ -45,12 +45,44 @@
|
||||
#include <MG_Util/Math/VectorTypes.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
// P14: WHOSE STAGED BYTES ARE THESE? The two server stores below are one per process, but the
|
||||
// in-process display server serves several sessions in that process at once, and a session's
|
||||
// end (DestroyEGLContext's OnBackendContextDestroyed) used to DropAll() them - every live
|
||||
// neighbour's declared texture levels and buffer shadows with it. The neighbour's next upload
|
||||
// into a texture it had declared long ago then read as "resource_subdata arrived before the
|
||||
// server declared texture level", a Fatal that took the whole display process (and so every
|
||||
// session in it) down. The texture store is also keyed by the client's {slot, gen}, which two
|
||||
// clients - or two non-shared groups of one client - hand out independently.
|
||||
//
|
||||
// So both stores file their entries under the calling thread's {session, share group}: the
|
||||
// SAME two words the S6 twin tables are keyed on, answered by the same probe (installed by
|
||||
// SessionRuntime.cpp beside the twin-key one). With no probe, or on a thread that is no
|
||||
// session's, the answer is {0, 0} - the single process-wide bucket these stores always were.
|
||||
struct StagedBucket {
|
||||
Uint64 SessionKey = 0;
|
||||
Uint64 ShareGroupKey = 0;
|
||||
};
|
||||
using StagedBucketResolver = Bool (*)(StagedBucket* outBucket);
|
||||
inline std::atomic<StagedBucketResolver> g_stagedBucketResolver{nullptr};
|
||||
|
||||
inline void SetStagedBucketResolver(StagedBucketResolver resolver) {
|
||||
g_stagedBucketResolver.store(resolver, std::memory_order_release);
|
||||
}
|
||||
|
||||
inline StagedBucket CurrentStagedBucket() {
|
||||
StagedBucket bucket;
|
||||
const StagedBucketResolver resolver = g_stagedBucketResolver.load(std::memory_order_acquire);
|
||||
if (resolver != nullptr && !resolver(&bucket)) bucket = StagedBucket{};
|
||||
return bucket;
|
||||
}
|
||||
|
||||
// Keyed by the resource twin's ADDRESS, which is stable: the twins are heap-allocated and
|
||||
// held by SharedPtr in the backend slot table, and every event that ends a base's life -
|
||||
// an orphaning respecify, a successful map_persistent, destroy, context death - already has
|
||||
@@ -72,6 +104,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (!m_copies) return raw - offset;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
Shadow& shadow = m_shadows[key];
|
||||
// A twin's address is already unique across buckets (each bucket owns its twins), so
|
||||
// the session rides along only for DropAll's sake.
|
||||
shadow.SessionKey = CurrentStagedBucket().SessionKey;
|
||||
const SizeT needed = std::max<SizeT>(width, offset + size);
|
||||
if (shadow.Bytes.size() < needed) shadow.Bytes.resize(needed, 0);
|
||||
if (size != 0 && raw != nullptr) {
|
||||
@@ -91,10 +126,23 @@ namespace MobileGL::MG_Remote::Server {
|
||||
m_shadows.erase(key);
|
||||
}
|
||||
|
||||
// The calling thread's SESSION's shadows (every group of it: a session's teardown ends
|
||||
// all its contexts), or every shadow on a thread that is no session's.
|
||||
void DropAll() {
|
||||
if (!m_any.load(std::memory_order_acquire)) return;
|
||||
const Uint64 session = CurrentStagedBucket().SessionKey;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_shadows.clear();
|
||||
if (session == 0) {
|
||||
m_shadows.clear();
|
||||
return;
|
||||
}
|
||||
for (auto it = m_shadows.begin(); it != m_shadows.end();) {
|
||||
if (it->second.SessionKey == session) {
|
||||
it = m_shadows.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fatal when a drain reaches bytes no record staged. It fires ONLY for a base that is
|
||||
@@ -187,6 +235,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Vector<Uint8> Bytes;
|
||||
// Sorted, disjoint, EXACT.
|
||||
Vector<Range1D> Covered;
|
||||
Uint64 SessionKey = 0;
|
||||
};
|
||||
|
||||
const Bool m_copies;
|
||||
|
||||
@@ -333,8 +333,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const Uint8* AdoptRun(Uint64 key, Uint16 uploadTarget, Uint16 level, const IntVec3& extent,
|
||||
Uint64 imageOffset, const void* bytes, SizeT byteSize) {
|
||||
if (!m_copies) return nullptr;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
LevelShadow& shadow = m_shadows[key].Levels[PackLevel(uploadTarget, level)];
|
||||
LevelShadow& shadow = m_shadows[bucketed].Levels[PackLevel(uploadTarget, level)];
|
||||
RequireDeclaredLevel(shadow, key, uploadTarget, level, extent);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A run can be the first piece of a redefined level. Old coverage
|
||||
@@ -354,7 +355,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// P8-E: a run landed whole over a followed copy (AdoptClientBoxes is the spelling
|
||||
// that keeps it), so the bytes no longer hold what the driver does.
|
||||
shadow.HoldsFollowedCopy = false;
|
||||
m_driverWritten[key] = true;
|
||||
m_driverWritten[bucketed] = true;
|
||||
}
|
||||
shadow.GpuDirty = false;
|
||||
return CopyRunInto(shadow, key, uploadTarget, level, imageOffset, bytes, byteSize);
|
||||
@@ -369,8 +370,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const Uint8* Adopt(Uint64 key, Uint16 uploadTarget, Uint16 level, const IntVec3& extent,
|
||||
const void* bytes, SizeT byteSize) {
|
||||
if (!m_copies) return nullptr;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
LevelShadow& shadow = m_shadows[key].Levels[PackLevel(uploadTarget, level)];
|
||||
LevelShadow& shadow = m_shadows[bucketed].Levels[PackLevel(uploadTarget, level)];
|
||||
RequireDeclaredLevel(shadow, key, uploadTarget, level, extent);
|
||||
shadow.GpuDirty = false;
|
||||
// P8-E: the caller states these bytes ARE the level, which a followed copy is part of.
|
||||
@@ -407,6 +409,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Uint8 resourceTarget = static_cast<Uint8>(MG_Pipe::MGPipeResourceTarget::Tex2D),
|
||||
Uint32 internalFormat = static_cast<Uint32>(TextureInternalFormat::RGBA8)) {
|
||||
if (!m_copies) return;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
Uint64 byteBound = 0;
|
||||
const Bool supportsSubData = StagedTextureTargetSupportsSubData(resourceTarget);
|
||||
@@ -424,7 +427,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
static_cast<unsigned long long>(key), uploadTarget, level,
|
||||
extent.x(), extent.y(), extent.z(), internalFormat);
|
||||
}
|
||||
LevelShadow& shadow = m_shadows[key].Levels[PackLevel(uploadTarget, level)];
|
||||
LevelShadow& shadow = m_shadows[bucketed].Levels[PackLevel(uploadTarget, level)];
|
||||
if (!shadow.Defined || shadow.Extent != extent || shadow.InternalFormat != internalFormat ||
|
||||
shadow.ResourceTarget != resourceTarget || shadow.DeclaredByteBound != byteBound) {
|
||||
shadow.Bytes.clear();
|
||||
@@ -447,8 +450,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// chain defined level by level afterwards where the call defines one.
|
||||
void ResetLevels(Uint64 key) {
|
||||
if (!m_any.load(std::memory_order_acquire)) return;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_shadows.erase(key);
|
||||
m_shadows.erase(bucketed);
|
||||
}
|
||||
|
||||
// T5's dirty mark: a GPU-side generation made this level's texels newer than any
|
||||
@@ -457,23 +461,35 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// upload" without asking the client (§2.2's last row).
|
||||
void MarkLevelGpuDirty(Uint64 key, Uint16 uploadTarget, Uint16 level, Bool dirty) {
|
||||
if (!m_copies) return;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_shadows[key].Levels[PackLevel(uploadTarget, level)].GpuDirty = dirty;
|
||||
m_shadows[bucketed].Levels[PackLevel(uploadTarget, level)].GpuDirty = dirty;
|
||||
m_any.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
void Drop(Uint64 key) {
|
||||
if (!m_any.load(std::memory_order_acquire)) return;
|
||||
const ShadowKey bucketed = Bucketed(key);
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_shadows.erase(key);
|
||||
m_driverWritten.erase(key);
|
||||
m_shadows.erase(bucketed);
|
||||
m_driverWritten.erase(bucketed);
|
||||
}
|
||||
|
||||
// The calling thread's SESSION's levels (every group of it - the callers are a session's
|
||||
// context teardown and its applier release), or every level on a thread that is no
|
||||
// session's. A live neighbour session's declared levels are not this caller's to drop:
|
||||
// that is the P14 Fatal StagedShadow.h's StagedBucket describes.
|
||||
void DropAll() {
|
||||
if (!m_any.load(std::memory_order_acquire)) return;
|
||||
const Uint64 session = CurrentStagedBucket().SessionKey;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_shadows.clear();
|
||||
m_driverWritten.clear();
|
||||
if (session == 0) {
|
||||
m_shadows.clear();
|
||||
m_driverWritten.clear();
|
||||
return;
|
||||
}
|
||||
EraseSession(m_shadows, session);
|
||||
EraseSession(m_driverWritten, session);
|
||||
}
|
||||
|
||||
// ---- P8-E (docs/Disaggregated/notes/p8/E.md): WHEN THESE BYTES ARE THE LEVEL'S CONTENT ----
|
||||
@@ -496,13 +512,13 @@ namespace MobileGL::MG_Remote::Server {
|
||||
void MarkDriverWritten(Uint64 key) {
|
||||
if (!m_copies) return;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_driverWritten[key] = true;
|
||||
m_driverWritten[Bucketed(key)] = true;
|
||||
m_any.store(true, std::memory_order_release);
|
||||
}
|
||||
Bool IsDriverWritten(Uint64 key) const {
|
||||
if (!m_any.load(std::memory_order_acquire)) return false;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_driverWritten.find(key) != m_driverWritten.end();
|
||||
return m_driverWritten.find(Bucketed(key)) != m_driverWritten.end();
|
||||
}
|
||||
Bool LevelHoldsFollowedCopy(Uint64 key, Uint16 uploadTarget, Uint16 level) const {
|
||||
if (!m_any.load(std::memory_order_acquire)) return false;
|
||||
@@ -521,7 +537,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const IntVec3& size) {
|
||||
if (!m_copies) return false;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_driverWritten.find(srcKey) != m_driverWritten.end()) return false;
|
||||
if (m_driverWritten.find(Bucketed(srcKey)) != m_driverWritten.end()) return false;
|
||||
const LevelShadow* src = FindLevel(srcKey, srcTarget, srcLevel);
|
||||
LevelShadow* dst = FindLevelMutable(dstKey, dstTarget, dstLevel);
|
||||
if (src == nullptr || dst == nullptr || !LevelComplete(*src)) return false;
|
||||
@@ -709,7 +725,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Bool HasShadow(Uint64 key) const {
|
||||
if (!m_any.load(std::memory_order_acquire)) return false;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_shadows.find(key) != m_shadows.end();
|
||||
return m_shadows.find(Bucketed(key)) != m_shadows.end();
|
||||
}
|
||||
SizeT TrackedResources() const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
@@ -717,10 +733,48 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
SizeT TrackedLevelCount(Uint64 key) const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
const auto it = m_shadows.find(key);
|
||||
const auto it = m_shadows.find(Bucketed(key));
|
||||
return it == m_shadows.end() ? 0 : it->second.Levels.size();
|
||||
}
|
||||
|
||||
// THE ENTRY KEY: the caller's key filed under the calling thread's {session, share group}
|
||||
// (StagedShadow.h's StagedBucket). Two clients' {slot, gen} - or two non-shared groups'
|
||||
// of one client - are two textures and must be two entries; with no probe the bucket is
|
||||
// {0, 0} and this is the bare key the store always used.
|
||||
struct ShadowKey {
|
||||
Uint64 SessionKey = 0;
|
||||
Uint64 ShareGroupKey = 0;
|
||||
Uint64 Key = 0;
|
||||
Bool operator==(const ShadowKey& other) const {
|
||||
return SessionKey == other.SessionKey && ShareGroupKey == other.ShareGroupKey &&
|
||||
Key == other.Key;
|
||||
}
|
||||
};
|
||||
struct ShadowKeyHash {
|
||||
SizeT operator()(const ShadowKey& key) const {
|
||||
Uint64 mixed = key.Key ^ (key.ShareGroupKey + 0x9E3779B97F4A7C15ull + (key.Key << 6) + (key.Key >> 2));
|
||||
mixed ^= key.SessionKey + 0x9E3779B97F4A7C15ull + (mixed << 6) + (mixed >> 2);
|
||||
mixed ^= mixed >> 33;
|
||||
mixed *= 0xFF51AFD7ED558CCDull;
|
||||
mixed ^= mixed >> 33;
|
||||
return static_cast<SizeT>(mixed);
|
||||
}
|
||||
};
|
||||
static ShadowKey Bucketed(Uint64 key) {
|
||||
const StagedBucket bucket = CurrentStagedBucket();
|
||||
return ShadowKey{bucket.SessionKey, bucket.ShareGroupKey, key};
|
||||
}
|
||||
template <typename Map>
|
||||
static void EraseSession(Map& map, Uint64 session) {
|
||||
for (auto it = map.begin(); it != map.end();) {
|
||||
if (it->first.SessionKey == session) {
|
||||
it = map.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Uint32 PackLevel(Uint16 uploadTarget, Uint16 level) {
|
||||
return (static_cast<Uint32>(uploadTarget) << 16) | static_cast<Uint32>(level);
|
||||
}
|
||||
@@ -833,13 +887,13 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
|
||||
const LevelShadow* FindLevel(Uint64 key, Uint16 uploadTarget, Uint16 level) const {
|
||||
const auto textureIt = m_shadows.find(key);
|
||||
const auto textureIt = m_shadows.find(Bucketed(key));
|
||||
if (textureIt == m_shadows.end()) return nullptr;
|
||||
const auto levelIt = textureIt->second.Levels.find(PackLevel(uploadTarget, level));
|
||||
return levelIt == textureIt->second.Levels.end() ? nullptr : &levelIt->second;
|
||||
}
|
||||
LevelShadow* FindLevelMutable(Uint64 key, Uint16 uploadTarget, Uint16 level) {
|
||||
const auto textureIt = m_shadows.find(key);
|
||||
const auto textureIt = m_shadows.find(Bucketed(key));
|
||||
if (textureIt == m_shadows.end()) return nullptr;
|
||||
const auto levelIt = textureIt->second.Levels.find(PackLevel(uploadTarget, level));
|
||||
return levelIt == textureIt->second.Levels.end() ? nullptr : &levelIt->second;
|
||||
@@ -879,10 +933,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const Bool m_copies;
|
||||
mutable std::mutex m_mutex;
|
||||
StagedTextureDeviceLimits m_deviceLimits{};
|
||||
ska::flat_hash_map<Uint64, TextureShadow> m_shadows;
|
||||
ska::flat_hash_map<ShadowKey, TextureShadow, ShadowKeyHash> m_shadows;
|
||||
// P8-E: MarkDriverWritten's keys (the value is always true). Apart from m_shadows on purpose,
|
||||
// because ResetLevels erases a key's levels and must not forget this.
|
||||
ska::flat_hash_map<Uint64, Bool> m_driverWritten;
|
||||
ska::flat_hash_map<ShadowKey, Bool, ShadowKeyHash> m_driverWritten;
|
||||
// Read on every IsLevelGpuDirty / LevelExtentOrUndefined, so the monolith cost is one
|
||||
// acquire load of a never-written flag rather than a mutex and two hash lookups.
|
||||
std::atomic<Bool> m_any{false};
|
||||
|
||||
@@ -1588,3 +1588,34 @@ TEST(ComputeWorkGroupCapabilities, TakesEveryAxisFromTheIndexedQuery) {
|
||||
EXPECT_GT(caps.MaxComputeWorkGroupCount[0], 65535);
|
||||
EXPECT_GT(caps.MaxComputeWorkGroupSize[2], 64);
|
||||
}
|
||||
|
||||
namespace {
|
||||
EGLBoolean FakeSwapBuffersWithDamage(EGLDisplay dpy, EGLSurface surface, const EGLint* rects, EGLint nRects) {
|
||||
(void)dpy;
|
||||
(void)surface;
|
||||
(void)rects;
|
||||
(void)nRects;
|
||||
return EGL_TRUE;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// EXT -> KHR -> nothing, the whole policy behind the loader's single damage-present slot.
|
||||
//
|
||||
// EGL_EXT_swap_buffers_with_damage and EGL_KHR_swap_buffers_with_damage define the same entry
|
||||
// point with the same signature, and a driver may expose either, both or neither - Adreno
|
||||
// exposes only the KHR spelling, which is why resolving the EXT name alone reported the entry
|
||||
// point missing on a driver that has one. A null answer is not a failure either: the caller
|
||||
// (DirectGLES::Present) reads it as "present with plain eglSwapBuffers", and a zero-rectangle
|
||||
// call to either spelling is defined to be equivalent to that anyway.
|
||||
TEST(SwapBuffersWithDamageResolution, PrefersExtThenKhrThenAnswersNothing) {
|
||||
using namespace MobileGL;
|
||||
MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR ext = &FakeSwapBuffersWithDamage;
|
||||
MG_External::EGL::eglSwapBuffersWithDamageKHR_PTR khr = &FakeSwapBuffersWithDamage;
|
||||
|
||||
EXPECT_EQ(MG_Util::BackendLoader::ResolveSwapBuffersWithDamage(ext, khr), ext)
|
||||
<< "a driver that exports both spellings is answered with the EXT one";
|
||||
EXPECT_EQ(MG_Util::BackendLoader::ResolveSwapBuffersWithDamage(nullptr, khr), khr)
|
||||
<< "the KHR spelling alone must still fill the slot";
|
||||
EXPECT_EQ(MG_Util::BackendLoader::ResolveSwapBuffersWithDamage(nullptr, nullptr), nullptr)
|
||||
<< "neither spelling stays null, so the caller keeps eglSwapBuffers";
|
||||
}
|
||||
|
||||
@@ -1706,6 +1706,22 @@ TEST_F(ProgramTest, CompileAndLinkWithExplicitFragmentOut) {
|
||||
ASSERT_TRUE(strstr(resultIndexed, indexNeedle) != nullptr)
|
||||
<< "Expected dual-source color index in generated shader.\n(Searching for \"" << indexNeedle << "\")";
|
||||
|
||||
// The ESSL the GLES backend hands the driver keeps index 1, and ESSL accepts it only with
|
||||
// GL_EXT_blend_func_extended enabled in the shader itself.
|
||||
MG_Util::ShaderTranspiler::SpvcSession spvcSessionEs(fragSpirvIndexed,
|
||||
MG_Util::ShaderTranspiler::SessionUsageBit::Transpile);
|
||||
spvc_compiler_options optionsEs;
|
||||
spvcSessionEs.CreateOptions(&optionsEs);
|
||||
spvc_compiler_options_set_uint(optionsEs, SPVC_COMPILER_OPTION_GLSL_VERSION, 320);
|
||||
spvc_compiler_options_set_bool(optionsEs, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_TRUE);
|
||||
spvcSessionEs.SetOptions(optionsEs);
|
||||
spvcSessionEs.DropDefaultFragmentOutputColorIndex();
|
||||
const char* resultEs = nullptr;
|
||||
spvcSessionEs.Compile(&resultEs);
|
||||
ASSERT_NE(resultEs, nullptr);
|
||||
EXPECT_NE(strstr(resultEs, indexNeedle), nullptr) << resultEs;
|
||||
EXPECT_NE(strstr(resultEs, "#extension GL_EXT_blend_func_extended : require"), nullptr) << resultEs;
|
||||
|
||||
// glBindFragDataLocation is equivalent to index 0 and resets it.
|
||||
BindFragDataLocation(program, 0, "fragColor");
|
||||
LinkProgram(program);
|
||||
|
||||
@@ -3389,6 +3389,33 @@ TEST_F(TextureTest, NormalizePixelFormatKeepsPackedTransferTypesForPackedSizedFo
|
||||
}
|
||||
}
|
||||
|
||||
// Stencil-only storage is the third single-channel case NormalizePixelFormat has to answer for
|
||||
// (the depth and RED families are the others), and the one the format-capability probe asks
|
||||
// about on every session bring-up: PopulateFormatCapabilities walks the whole logical-format
|
||||
// table through BuildNativeProbeFormatInfo, which takes this function's format/type pair and
|
||||
// hands it to glTexImage2D. Left to the switch defaults, GL_STENCIL_INDEX8 was reported as an
|
||||
// unhandled internal format and answered with GL_RGBA/GL_UNSIGNED_BYTE - a pair no driver can
|
||||
// pair with stencil-only storage - so every probe and every upload of it was an error whose
|
||||
// cause the log blamed on the format table instead of on the pair.
|
||||
//
|
||||
// GL_STENCIL_INDEX / GL_UNSIGNED_BYTE is the pair the rest of the pipeline already uses for
|
||||
// this storage: the frontend's ValidateTextureInternalFormatCompatibleWithInput requires
|
||||
// STENCIL_INDEX to pair with a stencil-only internal format, the canonical shadow layout for
|
||||
// StencilIndex8 is one UInt8 component, and the stencil readback path issues exactly this pair.
|
||||
TEST_F(TextureTest, NormalizePixelFormatMapsStencilOnlyStorageToStencilIndex) {
|
||||
using MG_Util::TextureFormatProcessor::NormalizePixelFormat;
|
||||
// GL_STENCIL_INDEX is the unsized spelling that resolves to the same storage (see
|
||||
// ConvertGLEnumToTextureInternalFormat), so both must answer together.
|
||||
for (const GLenum internalFormat : {GL_STENCIL_INDEX8, GL_STENCIL_INDEX}) {
|
||||
GLenum outInternal = 0, outFormat = 0, outType = 0;
|
||||
NormalizePixelFormat(internalFormat, PixelFormatNormalizeOptionBit::None, &outInternal, &outFormat,
|
||||
&outType);
|
||||
EXPECT_EQ(outInternal, internalFormat) << "internalformat 0x" << std::hex << internalFormat;
|
||||
EXPECT_EQ(outFormat, GL_STENCIL_INDEX) << "internalformat 0x" << std::hex << internalFormat;
|
||||
EXPECT_EQ(outType, GL_UNSIGNED_BYTE) << "internalformat 0x" << std::hex << internalFormat;
|
||||
}
|
||||
}
|
||||
|
||||
// The packed16 field-order quirk (PixelFormatNormalizeOptionBit::WidenPacked16Norm): where the
|
||||
// driver stores some packed16 allocations with a mirrored field order (the Mali defect
|
||||
// behind the KHR-GL4x.copy_image rgb5/rgb5_a1/rgba4 x *2d_array* failures), the
|
||||
|
||||
@@ -24,6 +24,10 @@ set(MOBILEGL_WIRE_TESTS
|
||||
# the key they resolve under - {session, context} for the working state, {session, share
|
||||
# group} for the object records. Drives the registry directly: no EGL, no wire.
|
||||
ApplierOwnershipTest
|
||||
# P14 S6 (same doc): the twin tables' key - {session, share group}, the same pair, so a
|
||||
# record and the twin it describes cannot land in different buckets. Drives the real
|
||||
# twin tables directly: no EGL, no wire.
|
||||
TwinOwnershipTest
|
||||
)
|
||||
|
||||
if (NOT WIN32)
|
||||
@@ -182,7 +186,7 @@ gtest_discover_tests(PipeWireCodecTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS un
|
||||
# THIS FILE IS THE PHASE'S ONE RECURRING MERGE CONFLICT, and it is the same-point-append shape
|
||||
# BRIEF §5's ownership table exists to prevent: three packages, three targets, one end-of-file.
|
||||
# The loop is what stops there being a fourth: a package adding a suite adds a NAME.
|
||||
foreach (wiretest IN ITEMS RemoteClientTest ServerLoopTest SessionHandshakeTest StagedTextureStoreTest SurfaceControlFrameTest PersistentMapFaultTest)
|
||||
foreach (wiretest IN ITEMS RemoteClientTest ServerLoopTest SessionHandshakeTest StagedTextureStoreTest SurfaceControlFrameTest PersistentMapFaultTest ServerContextLiveTest)
|
||||
add_executable(${wiretest} ${wiretest}.cpp)
|
||||
|
||||
target_include_directories(${wiretest} PRIVATE
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// MobileGL - MobileGL/MG_Test/Wire/ServerContextLiveTest.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// P14: MGPipeServerSetContextLive is the calling SESSION's flag. The in-process display server
|
||||
// runs KWin and every Plasma client in one process; a Qt client's eglMakeCurrent(NO_CONTEXT)
|
||||
// (ServerLoop's ClientRelease arm) or a session's teardown used to clear one process global, and
|
||||
// KWin's next draw then read its own served context as dead (Fatal{UnmigratedPipeInput,
|
||||
// "GetFramebufferBindingSlot@DrawArrays"} on the device). Each session thread resolves its own
|
||||
// PipeInputs block; the flag lives there.
|
||||
|
||||
#include <Config.h>
|
||||
#include <MG_Backend/MGPipe/PipeInputs.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <thread>
|
||||
|
||||
using namespace MobileGL;
|
||||
|
||||
namespace {
|
||||
thread_local MG_Pipe::PipeInputs* t_sessionBlock = nullptr;
|
||||
|
||||
MG_Pipe::PipeInputs* ResolveTestSessionBlock() { return t_sessionBlock; }
|
||||
|
||||
// A fresh thread, bound to `block` before its first touch of gPipeInputs - the order
|
||||
// ThreadSessionScope keeps on a real session thread.
|
||||
template <typename Fn>
|
||||
void OnSessionThread(MG_Pipe::PipeInputs& block, Fn fn) {
|
||||
std::thread thread([&] {
|
||||
t_sessionBlock = █
|
||||
fn();
|
||||
});
|
||||
thread.join();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(ServerContextLiveTest, OneSessionsReleaseDoesNotKillANeighboursContext) {
|
||||
const MG_Pipe::PipeInputsThreadResolver previous = MG_Pipe::g_pipeInputsThreadResolver;
|
||||
MG_Pipe::g_pipeInputsThreadResolver = &ResolveTestSessionBlock;
|
||||
auto* kwinBlock = new MG_Pipe::PipeInputs();
|
||||
auto* appBlock = new MG_Pipe::PipeInputs();
|
||||
|
||||
OnSessionThread(*kwinBlock, [] { MG_Pipe::MGPipeServerSetContextLive(true); });
|
||||
OnSessionThread(*appBlock, [] { MG_Pipe::MGPipeServerSetContextLive(true); });
|
||||
OnSessionThread(*appBlock, [] { MG_Pipe::MGPipeServerSetContextLive(false); });
|
||||
|
||||
Bool kwinLive = false;
|
||||
Bool appLive = true;
|
||||
OnSessionThread(*kwinBlock, [&] { kwinLive = MG_Pipe::MGPipeServerContextIsLive(); });
|
||||
OnSessionThread(*appBlock, [&] { appLive = MG_Pipe::MGPipeServerContextIsLive(); });
|
||||
EXPECT_TRUE(kwinLive) << "a neighbour session's release marked this session's context dead";
|
||||
EXPECT_FALSE(appLive);
|
||||
|
||||
MG_Pipe::g_pipeInputsThreadResolver = previous;
|
||||
// Leaked on purpose, like every PipeInputs block (ID-8): no thread may outlive its block.
|
||||
}
|
||||
|
||||
// The Wire suites link gtest without gtest_main (MG_Test/Wire/CMakeLists.txt); nothing here
|
||||
// needs a log file, so this is the plain runner.
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -279,6 +279,106 @@ TEST(StagedTextureStoreTest, ResetDropAndDropAllForgetExactlyWhatTheyName) {
|
||||
EXPECT_FALSE(store.HasShadow(b));
|
||||
}
|
||||
|
||||
// P14: the in-process display server serves several sessions from one store. A test-installed
|
||||
// bucket probe stands in for SessionRuntime's: a thread "in" a bucket answers it, a thread in
|
||||
// none answers false (the process-wide bucket).
|
||||
namespace {
|
||||
thread_local Server::StagedBucket t_testBucket;
|
||||
thread_local Bool t_testBucketSet = false;
|
||||
|
||||
Bool TestStagedBucket(Server::StagedBucket* outBucket) {
|
||||
if (!t_testBucketSet) return false;
|
||||
*outBucket = t_testBucket;
|
||||
return true;
|
||||
}
|
||||
|
||||
void EnterBucket(Uint64 session, Uint64 group) {
|
||||
t_testBucket = Server::StagedBucket{session, group};
|
||||
t_testBucketSet = true;
|
||||
}
|
||||
|
||||
struct ScopedTestBucketProbe {
|
||||
Server::StagedBucketResolver Previous;
|
||||
ScopedTestBucketProbe() : Previous(Server::g_stagedBucketResolver.load()) {
|
||||
Server::SetStagedBucketResolver(&TestStagedBucket);
|
||||
}
|
||||
~ScopedTestBucketProbe() {
|
||||
t_testBucketSet = false;
|
||||
Server::SetStagedBucketResolver(Previous);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// The anland Plasma crash, at unit scope: KWin and another client both hold texture {38, 0};
|
||||
// the other client's session ends (DestroyEGLContext -> DropAll), and KWin's next upload into
|
||||
// the level it declared long ago used to read "arrived before the server declared texture
|
||||
// level" and abort the display process. Each session's {slot, gen} is its own texture, and a
|
||||
// session's DropAll takes only its own levels.
|
||||
TEST(StagedTextureStoreTest, TwoSessionsHoldTheSameHandleAndOneSessionsDropAllSparesTheOther) {
|
||||
ScopedTestBucketProbe probe;
|
||||
Server::StagedTextureStore store(/*copies=*/true);
|
||||
const Uint64 key = Server::StagedTextureStore::KeyForHandle(TestHandle(38, 0));
|
||||
Vector<Uint8> kwinBytes(64, 0x11);
|
||||
Vector<Uint8> appBytes(16, 0x22);
|
||||
|
||||
EnterBucket(/*session=*/1, /*group=*/10);
|
||||
store.NoteLevelDefined(key, kTex2DTarget, 0, IntVec3{4, 4, 1});
|
||||
store.Adopt(key, kTex2DTarget, 0, IntVec3{4, 4, 1}, kwinBytes.data(), kwinBytes.size());
|
||||
|
||||
EnterBucket(/*session=*/2, /*group=*/20);
|
||||
EXPECT_FALSE(store.IsLevelDefined(key, kTex2DTarget, 0))
|
||||
<< "another session's {slot, gen} answered for this one's";
|
||||
store.NoteLevelDefined(key, kTex2DTarget, 0, IntVec3{2, 2, 1});
|
||||
store.Adopt(key, kTex2DTarget, 0, IntVec3{2, 2, 1}, appBytes.data(), appBytes.size());
|
||||
|
||||
EnterBucket(1, 10);
|
||||
EXPECT_EQ(store.LevelExtentOrUndefined(key, kTex2DTarget, 0), (IntVec3{4, 4, 1}))
|
||||
<< "the second session's definition redefined the first's level";
|
||||
|
||||
EnterBucket(2, 20);
|
||||
store.DropAll();
|
||||
EXPECT_FALSE(store.HasShadow(key));
|
||||
|
||||
EnterBucket(1, 10);
|
||||
ASSERT_TRUE(store.IsLevelDefined(key, kTex2DTarget, 0))
|
||||
<< "a neighbour session's teardown dropped this session's declared level";
|
||||
EXPECT_TRUE(store.IsCovered(key, kTex2DTarget, 0));
|
||||
EXPECT_NE(store.AdoptRun(key, kTex2DTarget, 0, IntVec3{4, 4, 1}, 0, kwinBytes.data(), kwinBytes.size()),
|
||||
nullptr);
|
||||
|
||||
EnterBucket(1, 11);
|
||||
EXPECT_FALSE(store.HasShadow(key)) << "a non-shared group of the same session is its own name space";
|
||||
|
||||
t_testBucketSet = false;
|
||||
store.DropAll();
|
||||
EnterBucket(1, 10);
|
||||
EXPECT_FALSE(store.HasShadow(key)) << "a thread that is no session's drops the whole store";
|
||||
}
|
||||
|
||||
// The buffer half: its shadows are keyed by twin address (already unique), but DropAll ran the
|
||||
// same process-wide clear on a session's teardown.
|
||||
TEST(StagedTextureStoreTest, OneSessionsBufferDropAllSparesTheOthersShadows) {
|
||||
ScopedTestBucketProbe probe;
|
||||
Server::StagedShadowStore store(/*copies=*/true);
|
||||
const int kwinTwin = 0;
|
||||
const int appTwin = 0;
|
||||
Vector<Uint8> bytes(32, 0x33);
|
||||
|
||||
EnterBucket(1, 10);
|
||||
store.Adopt(&kwinTwin, bytes.size(), bytes.data(), 0, bytes.size());
|
||||
EnterBucket(2, 20);
|
||||
store.Adopt(&appTwin, bytes.size(), bytes.data(), 0, bytes.size());
|
||||
|
||||
store.DropAll();
|
||||
EXPECT_FALSE(store.HasShadow(&appTwin));
|
||||
EXPECT_TRUE(store.HasShadow(&kwinTwin)) << "a neighbour session's teardown dropped this session's bytes";
|
||||
EXPECT_TRUE(store.IsCovered(&kwinTwin, 0, bytes.size()));
|
||||
|
||||
t_testBucketSet = false;
|
||||
store.DropAll();
|
||||
EXPECT_FALSE(store.HasShadow(&kwinTwin));
|
||||
}
|
||||
|
||||
// T5's dirty mark: a GPU-side generation dirties the SERVER's shadow, and the mark - not the
|
||||
// client - answers "dirty region, level has no pending upload". It is settable and clearable
|
||||
// per (uploadTarget, level), independent of bytes, and inert on a monolith store.
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
// MobileGL - MobileGL/MG_Test/Wire/TwinOwnershipTest.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// P14 S6 (docs/Disaggregated/design/11-state-ownership.md): WHOSE TWIN IS THIS?
|
||||
//
|
||||
// WHAT THIS SUITE OWNS. A backend twin is a DRIVER object - a GL buffer id, a texture, a
|
||||
// program, the storage behind them - so it belongs to one native context's object namespace.
|
||||
// Until this slice the six twin registries were keyed by {slot, gen} ALONE, process-wide, which
|
||||
// is wrong in both directions:
|
||||
//
|
||||
// * two contexts of one session that do NOT share a share group have independent name spaces,
|
||||
// so the same handle value in both is legal and means two different objects. One table gave
|
||||
// the second context the FIRST one's twin - the same driver ids, the same persistent map,
|
||||
// the same pooled store, addressed as if they were its own;
|
||||
// * two contexts that DO share a group must see one set of objects. They were served by
|
||||
// whichever of them twinned first, which is right by accident and wrong as soon as the
|
||||
// other one asks first under a different key.
|
||||
//
|
||||
// This suite drives the twin tables directly - no EGL, no wire, no transport - because that is
|
||||
// exactly what the slice is: `g_backendSamplerViews` (and the six TwinRegistry registries)
|
||||
// resolve per {session, share group}, and every case below is a way of using two contexts that
|
||||
// the process-wide table got wrong.
|
||||
//
|
||||
// HOW IT INSTALLS A KEY. The production resolver is the server's (SessionRuntime.cpp's
|
||||
// `ResolveThreadTwinKey`, installed by ThreadSessionScope beside the native-tuple and applier
|
||||
// probes, and deriving the group through MGPipeApplierShareGroupKeyFor so a twin and the record
|
||||
// that describes it cannot land in different buckets). Here the resolver is this file's,
|
||||
// driven by two thread_locals, so a case can be in whichever session and share group it means
|
||||
// without standing up a transport. The session keys are large sentinels no real
|
||||
// ServerSession address can collide with, and every case drops what it created on the way out.
|
||||
//
|
||||
// THE NEGATIVE CONTROL, run once and reverted (S5's shape, and the reason these cases are not
|
||||
// an empty green): make SlotTableRegistry::ForCallingThread answer a single fixed {0, 0} bucket
|
||||
// - i.e. restore the process-wide table this slice replaces - and FOUR of the five cases go red
|
||||
// at their first per-group assertion: the nonshared pair, the per-session drop, the
|
||||
// no-session case (which then cannot be told from a session's) and the six-registry one.
|
||||
// `TwoContextsOfOneGroupShareTheGroupsTwins` STAYS GREEN under the control, and that is the
|
||||
// correct answer rather than a gap: with ONE key both shapes agree, which is why the case
|
||||
// asserts what sharing must do and not merely that two buckets exist.
|
||||
|
||||
#include <MG_Backend/DirectGLES/Managers.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
|
||||
// The twin tables run on the handle arm only while kMGPipeSubsystemEsprytSlots is set, and a
|
||||
// unit binary never runs ConfigLoader's default (which sets every migrated subsystem). Same
|
||||
// drive as ServerLoopTest's EGL fixture: set the bit, restore it on the way out.
|
||||
#include <Config.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace {
|
||||
|
||||
namespace GL = MobileGL::MG_Backend::DirectGLES;
|
||||
namespace P = MobileGL::MG_Pipe;
|
||||
using MobileGL::Bool;
|
||||
using MobileGL::SizeT;
|
||||
using MobileGL::Uint32;
|
||||
using MobileGL::Uint64;
|
||||
|
||||
// The calling thread's {session, share group}, exactly the shape the production resolver
|
||||
// fills in. A zero session key is "not a session's thread" - the client process, the inproc
|
||||
// one-process shape, every unit case - and that is what keeps the process-wide bucket the
|
||||
// answer there.
|
||||
thread_local Uint64 t_sessionKey = 0;
|
||||
thread_local Uint64 t_shareGroupKey = 0;
|
||||
|
||||
Bool TestTwinKeyResolver(GL::TwinKey* outKey) {
|
||||
if (t_sessionKey == 0) return false;
|
||||
outKey->SessionKey = t_sessionKey;
|
||||
outKey->ShareGroupKey = t_shareGroupKey;
|
||||
return true;
|
||||
}
|
||||
|
||||
// A twin with no driver id and a trivial destructor, so a case can create and drop entries
|
||||
// on a REAL production table without a GL context and without a driver call at teardown.
|
||||
// (BackendSamplerViewObject's own comment says the same thing about itself; the alias keeps
|
||||
// the cases readable.)
|
||||
using Twin = GL::SamplerViewImpl::BackendSamplerViewObject;
|
||||
using RealTable = GL::SamplerViewImpl::BackendSamplerViewTable;
|
||||
|
||||
// The six-registry shape, on the same trivial twin and on a kind no shipping path twins
|
||||
// (Query), so a case can instantiate it without touching a real slot space.
|
||||
using RegistryShapedTable = GL::TwinRegistry<MobileGL::MG_State::GLState::ITextureObject, Twin,
|
||||
P::MGPipeKind::Query>;
|
||||
|
||||
class TwinOwnershipTest : public ::testing::Test {
|
||||
protected:
|
||||
// Sentinels no real ServerSession address can be, so a stray registration elsewhere in
|
||||
// the process can never be what a case reads.
|
||||
static constexpr Uint64 kSessionA = 0x5E5510C000000000ull;
|
||||
static constexpr Uint64 kSessionB = 0x5E5510D000000000ull;
|
||||
// Share-group tokens are minted by the frontend (EGLState::CreateContext), dense and
|
||||
// 0-free: two contexts that share pass the SAME number, two that do not pass different
|
||||
// ones - which is why the key can be the group itself.
|
||||
static constexpr Uint64 kGroupOne = 0x2001;
|
||||
static constexpr Uint64 kGroupTwo = 0x2002;
|
||||
|
||||
Uint64 m_savedPush = 0;
|
||||
|
||||
void SetUp() override {
|
||||
m_savedPush = MobileGL::MG_Config::Features.PipePush;
|
||||
MobileGL::MG_Config::Features.PipePush |= P::kMGPipeSubsystemEsprytSlots;
|
||||
GL::SetTwinKeyResolver(&TestTwinKeyResolver);
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
MobileGL::MG_Config::Features.PipePush = m_savedPush;
|
||||
GL::SamplerViewImpl::g_backendSamplerViews.DropBucketsOfSession(kSessionA);
|
||||
GL::SamplerViewImpl::g_backendSamplerViews.DropBucketsOfSession(kSessionB);
|
||||
// The process-wide bucket the no-session case writes ({0, 0}): nothing else in this
|
||||
// binary uses it, and leaving it would make that case order-dependent.
|
||||
GL::SamplerViewImpl::g_backendSamplerViews.DropBucket(GL::TwinKey{0, 0});
|
||||
t_sessionKey = 0;
|
||||
t_shareGroupKey = 0;
|
||||
GL::SetTwinKeyResolver(nullptr);
|
||||
}
|
||||
|
||||
static void BindKey(Uint64 session, Uint64 shareGroup) {
|
||||
t_sessionKey = session;
|
||||
t_shareGroupKey = shareGroup;
|
||||
}
|
||||
|
||||
// Resolve-or-create on the real table, then stamp the twin so a case can tell WHICH
|
||||
// object it got back. The pointer is the twin the driver ids would hang off.
|
||||
static Twin* Mint(RealTable& table, P::MGPipeHandle handle, Uint64 stamp) {
|
||||
MobileGL::SharedPtr<Twin>& slot = table.GetOrCreate(handle);
|
||||
slot = MobileGL::MakeShared<Twin>();
|
||||
slot->SyncedSerial = stamp;
|
||||
return slot.get();
|
||||
}
|
||||
};
|
||||
|
||||
// THE DEFECT THIS SLICE EXISTS FOR, in its first direction. Two contexts of one session that
|
||||
// do NOT share a group have independent name spaces, so the same handle value in both is
|
||||
// legal and means two different objects. One process-wide table answered both handles with
|
||||
// one twin, and the second context was handed the first one's driver ids.
|
||||
TEST_F(TwinOwnershipTest, TheSameHandleInTwoNonsharedGroupsIsTwoTwins) {
|
||||
const P::MGPipeHandle handle{7u, 1u};
|
||||
RealTable& table = GL::SamplerViewImpl::g_backendSamplerViews;
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr) << "the group began with a twin it never built";
|
||||
Twin* const first = Mint(table, handle, 11u);
|
||||
ASSERT_NE(first, nullptr);
|
||||
|
||||
BindKey(kSessionA, kGroupTwo);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr)
|
||||
<< "a context of a group the object was NOT made in resolved the other group's twin - the "
|
||||
"same {slot, gen} in two name spaces is two objects, and this answers one";
|
||||
Twin* const second = Mint(table, handle, 22u);
|
||||
ASSERT_NE(second, nullptr);
|
||||
EXPECT_NE(first, second) << "two groups that do not share were given one twin";
|
||||
|
||||
// AND THE FIRST GROUP'S OBJECT IS UNTOUCHED - the direction the old shape fails hardest,
|
||||
// because the second create overwrote the first twin's contents in place.
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
const MobileGL::SharedPtr<Twin>* const back = table.FindByHandle(handle);
|
||||
ASSERT_NE(back, nullptr) << "returning to the first group lost its twin";
|
||||
EXPECT_EQ(back->get(), first) << "a twin was minted for a group that already had one";
|
||||
EXPECT_EQ((*back)->SyncedSerial, 11u)
|
||||
<< "the other group's sync rewrote this group's twin - the two contexts were one name space";
|
||||
EXPECT_EQ(table.BucketCount(), 2u) << "two groups resolved to one bucket";
|
||||
}
|
||||
|
||||
// THE SECOND DIRECTION, and the half a literal per-context keying would break: two contexts
|
||||
// that DO share a group must see ONE set of objects. That is what makes
|
||||
// `eglCreateContext(share = ...)` mean anything at the driver.
|
||||
TEST_F(TwinOwnershipTest, TwoContextsOfOneGroupShareTheGroupsTwins) {
|
||||
const P::MGPipeHandle handle{9u, 1u};
|
||||
RealTable& table = GL::SamplerViewImpl::g_backendSamplerViews;
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
Twin* const first = Mint(table, handle, 33u);
|
||||
|
||||
// The same group, reached by the sibling context. Same key, therefore same bucket: the
|
||||
// resolver's group half is what decides, not the context that happens to be current.
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
const MobileGL::SharedPtr<Twin>* const found = table.FindByHandle(handle);
|
||||
ASSERT_NE(found, nullptr)
|
||||
<< "a sharing context cannot see the object its group already has - driver-level sharing "
|
||||
"is impossible without this";
|
||||
EXPECT_EQ(found->get(), first) << "the sharing context was given a twin of its own";
|
||||
EXPECT_EQ((*found)->SyncedSerial, 33u) << "the sharing context resolved an empty object";
|
||||
EXPECT_EQ(table.BucketCount(), 1u) << "one share group was split into two buckets";
|
||||
}
|
||||
|
||||
// A SHARE GROUP DOES NOT CROSS A SESSION. Two served sessions are two connections and no
|
||||
// driver id crosses between them, so the same group token and the same handle in both must
|
||||
// be two objects - and a session's teardown must take ITS twins and no one else's.
|
||||
TEST_F(TwinOwnershipTest, ASessionDropTakesOnlyThatSessionsTwins) {
|
||||
const P::MGPipeHandle handle{5u, 1u};
|
||||
RealTable& table = GL::SamplerViewImpl::g_backendSamplerViews;
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
Twin* const inA = Mint(table, handle, 44u);
|
||||
BindKey(kSessionB, kGroupOne);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr)
|
||||
<< "session B resolved the twin session A built under the same names";
|
||||
Twin* const inB = Mint(table, handle, 55u);
|
||||
EXPECT_NE(inA, inB);
|
||||
|
||||
// This is what DropEveryTwinForEndedServerSession now does, and the reason it is scoped:
|
||||
// it runs on the apply thread of the session that is ENDING, while a neighbour session
|
||||
// may still be rendering in this process (P14 S2).
|
||||
EXPECT_EQ(table.DropBucketsOfSession(kSessionA), 1u) << "the ended session's group was not dropped";
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr)
|
||||
<< "the ended session still resolves a twin it built";
|
||||
BindKey(kSessionB, kGroupOne);
|
||||
const MobileGL::SharedPtr<Twin>* const survivor = table.FindByHandle(handle);
|
||||
ASSERT_NE(survivor, nullptr)
|
||||
<< "ending one session dropped another session's twin - the process-wide drop this slice "
|
||||
"replaces would have done exactly that";
|
||||
EXPECT_EQ(survivor->get(), inB);
|
||||
}
|
||||
|
||||
// THE PROCESS-WIDE TABLE IS STILL THE ANSWER FOR EVERY THREAD THAT BELONGS TO NO SESSION,
|
||||
// and a session's twins must not leak into it or out of it. This is the property the whole
|
||||
// single-context world - the monolith, the client process, every unit case - depends on.
|
||||
TEST_F(TwinOwnershipTest, AThreadWithNoSessionStillGetsTheProcessWideTwinTable) {
|
||||
const P::MGPipeHandle handle{3u, 1u};
|
||||
RealTable& table = GL::SamplerViewImpl::g_backendSamplerViews;
|
||||
|
||||
t_sessionKey = 0;
|
||||
t_shareGroupKey = 0;
|
||||
GL::TwinKey key;
|
||||
EXPECT_FALSE(GL::CurrentTwinKey(&key)) << "the resolver claimed a thread that is no session's";
|
||||
EXPECT_EQ(key.SessionKey, 0u);
|
||||
EXPECT_EQ(key.ShareGroupKey, 0u);
|
||||
Twin* const processWide = Mint(table, handle, 66u);
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr)
|
||||
<< "a served context resolved the process-wide twin";
|
||||
EXPECT_NE(Mint(table, handle, 77u), processWide);
|
||||
|
||||
t_sessionKey = 0;
|
||||
const MobileGL::SharedPtr<Twin>* const back = table.FindByHandle(handle);
|
||||
ASSERT_NE(back, nullptr);
|
||||
EXPECT_EQ(back->get(), processWide) << "the process-wide bucket followed the session's";
|
||||
}
|
||||
|
||||
// THE SIX REGISTRIES ARE THE SAME SHAPE. The cases above drive the buffer/sampler-view
|
||||
// table, which IS a SlotTableRegistry; the six TwinRegistry registries reach the same
|
||||
// resolution through their own forwarding members, and this is what pins that they do -
|
||||
// including the generation gate, which must still refuse a handle from a slot's past.
|
||||
TEST_F(TwinOwnershipTest, TheSixTwinRegistriesResolvePerGroupToo) {
|
||||
RegistryShapedTable table;
|
||||
const P::MGPipeHandle handle{21u, 1u};
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
MobileGL::SharedPtr<Twin>* slot = table.GetOrCreateByHandle(handle);
|
||||
ASSERT_NE(slot, nullptr);
|
||||
*slot = MobileGL::MakeShared<Twin>();
|
||||
(*slot)->SyncedSerial = 88u;
|
||||
Twin* const first = slot->get();
|
||||
ASSERT_EQ(table.LiveGenAt(handle.Slot), handle.Gen);
|
||||
|
||||
BindKey(kSessionA, kGroupTwo);
|
||||
EXPECT_EQ(table.FindByHandle(handle), nullptr)
|
||||
<< "the six-registry shape is still one process-wide table";
|
||||
EXPECT_EQ(table.LiveGenAt(handle.Slot), 0u) << "the other group's slot reads as live";
|
||||
MobileGL::SharedPtr<Twin>* const other = table.GetOrCreateByHandle(handle);
|
||||
ASSERT_NE(other, nullptr);
|
||||
*other = MobileGL::MakeShared<Twin>();
|
||||
(*other)->SyncedSerial = 99u;
|
||||
EXPECT_NE(other->get(), first);
|
||||
EXPECT_EQ(table.BucketCount(), 2u);
|
||||
|
||||
BindKey(kSessionA, kGroupOne);
|
||||
MobileGL::SharedPtr<Twin>* const back = table.FindByHandle(handle);
|
||||
ASSERT_NE(back, nullptr);
|
||||
EXPECT_EQ(back->get(), first);
|
||||
EXPECT_EQ((*back)->SyncedSerial, 88u);
|
||||
|
||||
// The generation gate is per bucket, because a bucket is a name space: a handle behind
|
||||
// THIS group's live generation is still refused.
|
||||
const P::MGPipeHandle stale{handle.Slot, handle.Gen - 1u};
|
||||
EXPECT_EQ(table.FindByHandle(stale), nullptr) << "a stale generation resolved a live twin";
|
||||
|
||||
EXPECT_EQ(table.DropBucketsOfSession(kSessionA), 2u);
|
||||
EXPECT_EQ(table.BucketCount(), 0u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -127,6 +127,57 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
#endif
|
||||
}
|
||||
|
||||
// True when a symbol resolved through dlsym lives in the module this code is compiled into.
|
||||
//
|
||||
// That happens when MobileGL is installed under a GLES soname (a drop-in libGLESv2.so, which
|
||||
// is how a replacement driver reaches an application), and there dlsym hands back MobileGL's
|
||||
// OWN exported entry point: the backend would call it as if it were the driver's and land
|
||||
// straight back in the frontend, once per call, for ever. Such a symbol is not the driver's.
|
||||
static Bool ResolvesIntoOwnModule(void* symbol) {
|
||||
#if defined(_WIN32)
|
||||
(void)symbol;
|
||||
return false;
|
||||
#else
|
||||
Dl_info symbolInfo{};
|
||||
Dl_info ownInfo{};
|
||||
if (dladdr(symbol, &symbolInfo) == 0 ||
|
||||
dladdr(reinterpret_cast<const void*>(&ResolvesIntoOwnModule), &ownInfo) == 0) {
|
||||
return false;
|
||||
}
|
||||
return symbolInfo.dli_fname != nullptr && ownInfo.dli_fname != nullptr &&
|
||||
std::strcmp(symbolInfo.dli_fname, ownInfo.dli_fname) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// The GLES library the dlsym fallback in AcquireGLESFunctions reads from. Only ever opened
|
||||
// once, and only when eglGetProcAddress has already failed for something: on a driver that
|
||||
// answers eglGetProcAddress completely this handle is never taken.
|
||||
static void* OpenFallbackGlesLibrary() {
|
||||
if (UseAngle()) {
|
||||
// The same library AcquireEGLFunctions loaded the EGL functions from: resolving an
|
||||
// entry point off the vendor's driver while the current context is ANGLE's would
|
||||
// hand the backend two different implementations.
|
||||
return OpenLib({"libGLESv2_angle.so"});
|
||||
}
|
||||
#if defined(__ANDROID__)
|
||||
// Android's soname; the libGLESv3.so of older releases aliases the same library.
|
||||
return OpenLib({"libGLESv2.so", "libGLESv3.so"});
|
||||
#else
|
||||
// Versioned first: the unversioned name is a development symlink and is absent from
|
||||
// runtime-only images, the same trap the libEGL lookup documents.
|
||||
return OpenLib({"libGLESv2.so.2", "libGLESv2.so", "libGLESv3.so"});
|
||||
#endif
|
||||
}
|
||||
|
||||
MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR
|
||||
ResolveSwapBuffersWithDamage(MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR ext,
|
||||
MG_External::EGL::eglSwapBuffersWithDamageKHR_PTR khr) {
|
||||
if (ext != nullptr) {
|
||||
return ext;
|
||||
}
|
||||
return (MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR)khr;
|
||||
}
|
||||
|
||||
void AcquireGLESFunctions(MG_External::GLESFunctionsTable& funcs,
|
||||
MG_External::EGL::eglGetProcAddress_PTR procAddress) {
|
||||
if (!procAddress) {
|
||||
@@ -134,19 +185,53 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
// THE SECOND CHANCE. eglGetProcAddress is the mechanism the spec defines for finding an
|
||||
// entry point, and it is what this loader used to use exclusively - but it is not
|
||||
// complete on every driver. Measured on an Adreno 750 (ES 3.2, 125 extensions):
|
||||
// eglGetProcAddress("glShaderStorageBlockBinding") - an ES 3.1 core function - answers
|
||||
// NULL, while the driver's own libGLESv2.so exports the symbol. The load failure that
|
||||
// produced was reported for a function the driver actually has, on every session.
|
||||
//
|
||||
// So anything eglGetProcAddress does not answer gets one more look through dlsym on the
|
||||
// GLES library itself, opened lazily and only if some entry point needed it.
|
||||
void* fallbackLib = nullptr;
|
||||
Bool fallbackLibOpened = false;
|
||||
const auto dlsymFallback = [&fallbackLib, &fallbackLibOpened](const char* name) -> void* {
|
||||
if (!fallbackLibOpened) {
|
||||
fallbackLibOpened = true;
|
||||
fallbackLib = OpenFallbackGlesLibrary();
|
||||
}
|
||||
if (fallbackLib == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
void* symbol = ProcAddress(fallbackLib, name);
|
||||
if (symbol != nullptr && ResolvesIntoOwnModule(symbol)) {
|
||||
return nullptr;
|
||||
}
|
||||
return symbol;
|
||||
};
|
||||
|
||||
#define INIT_GLES_FUNC(name) \
|
||||
do { \
|
||||
funcs.name = (MG_External::GLES::name##_PTR)procAddress(#name); \
|
||||
if (!funcs.name) { \
|
||||
funcs.name = (MG_External::GLES::name##_PTR)dlsymFallback(#name); \
|
||||
} \
|
||||
if (!funcs.name) { \
|
||||
MGLOG_E("Failed to load GLES function: %s", #name); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
// Optional (extension-provided) entry points: a null pointer is expected on drivers that lack the
|
||||
// extension, so absence is not an error. The call site null-checks before use.
|
||||
// extension, so absence is not an error. The call site null-checks before use. The dlsym fallback
|
||||
// applies here too - an extension entry point is exactly the kind a vendor's eglGetProcAddress is
|
||||
// most likely to hide.
|
||||
#define INIT_GLES_FUNC_OPTIONAL(name) \
|
||||
do { \
|
||||
funcs.name = (MG_External::GLES::name##_PTR)procAddress(#name); \
|
||||
if (!funcs.name) { \
|
||||
funcs.name = (MG_External::GLES::name##_PTR)dlsymFallback(#name); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
{
|
||||
@@ -407,7 +492,15 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
INIT_GLES_FUNC(glFramebufferParameteri)
|
||||
INIT_GLES_FUNC(glGetFramebufferParameteriv)
|
||||
INIT_GLES_FUNC(glGetProgramInterfaceiv)
|
||||
INIT_GLES_FUNC(glShaderStorageBlockBinding)
|
||||
// ES 3.1 core, but NOT every driver answers eglGetProcAddress for it: measured on
|
||||
// an Adreno 750, the call returns NULL here while the driver's own libGLESv2.so
|
||||
// exports the symbol - which the dlsym fallback in this function now finds. A
|
||||
// driver that genuinely lacks it is not a load failure either: the only caller
|
||||
// (ApplyShaderStorageBlockBinding in DirectGLES/Managers.cpp) null-checks, and
|
||||
// DirectGLES's actual mechanism for moving a storage block's binding is the
|
||||
// layout(binding=) qualifier it prints into the generated ESSL - this call can
|
||||
// only ever add a redundant rebinding on a driver that does expose it.
|
||||
INIT_GLES_FUNC_OPTIONAL(glShaderStorageBlockBinding)
|
||||
INIT_GLES_FUNC(glGetProgramResourceIndex)
|
||||
INIT_GLES_FUNC(glGetProgramResourceName)
|
||||
INIT_GLES_FUNC(glGetProgramResourceiv)
|
||||
@@ -608,6 +701,18 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
// THE EXTENSION MECHANISM, RESOLVED BEFORE THE TABLE. The EGL 1.x core entry points are
|
||||
// exported symbols of the library, so dlsym finds them; the EXTENSION ones are not.
|
||||
// Android's libEGL.so exports none of eglSwapBuffersWithDamageEXT/KHR or
|
||||
// eglUnlockSurfaceKHR even though the Adreno driver behind it implements them - the
|
||||
// spec has extension entry points reached through eglGetProcAddress, never through the
|
||||
// library's symbol table. Resolving them by dlsym alone therefore reported them missing
|
||||
// on a driver that has them, at FATAL, on every session bring-up. So dlsym stays the
|
||||
// first leg (an eglGetProcAddress dispatch stub would be wrong for the core functions)
|
||||
// and eglGetProcAddress is the second.
|
||||
MG_External::EGL::eglGetProcAddress_PTR getProcAddress =
|
||||
reinterpret_cast<MG_External::EGL::eglGetProcAddress_PTR>(ProcAddress(eglLib, "eglGetProcAddress"));
|
||||
|
||||
auto resolveEGLProc = [&](const char* name) -> void* {
|
||||
#if defined(MOBILEGL_TRACE_ANGLE_VARIANTS) && defined(__ANDROID__)
|
||||
if (UseAngle()) {
|
||||
@@ -615,10 +720,18 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
// resolve its forwarding target from the verified variant.
|
||||
String target = "EGL_";
|
||||
target += name + 3;
|
||||
return ProcAddress(angleGlesLib, target.c_str());
|
||||
if (void* resolved = ProcAddress(angleGlesLib, target.c_str())) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ProcAddress(eglLib, name);
|
||||
if (void* resolved = ProcAddress(eglLib, name)) {
|
||||
return resolved;
|
||||
}
|
||||
if (getProcAddress != nullptr) {
|
||||
return reinterpret_cast<void*>(getProcAddress(name));
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
#define INIT_EGL_FUNC(name) \
|
||||
@@ -632,6 +745,18 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
// Extension-provided entry points. A driver that has neither the extension nor a forwarding
|
||||
// alias answers NULL, which is the ordinary answer there rather than a defect, so it is
|
||||
// reported at INFO and left to the caller - which null-checks (see Present's swap in
|
||||
// DirectGLES.cpp). Reached through eglGetProcAddress by resolveEGLProc's second leg.
|
||||
#define INIT_EGL_FUNC_OPTIONAL(name) \
|
||||
do { \
|
||||
funcs.name = (MG_External::EGL::name##_PTR)resolveEGLProc(#name); \
|
||||
if (!funcs.name) { \
|
||||
MGLOG_I("Optional EGL entry point not provided by this driver: %s", #name); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
{
|
||||
INIT_EGL_FUNC(eglBindAPI)
|
||||
INIT_EGL_FUNC(eglBindTexImage)
|
||||
@@ -665,10 +790,9 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
INIT_EGL_FUNC(eglReleaseThread)
|
||||
INIT_EGL_FUNC(eglSurfaceAttrib)
|
||||
INIT_EGL_FUNC(eglSwapBuffers)
|
||||
INIT_EGL_FUNC(eglSwapBuffersWithDamageEXT)
|
||||
INIT_EGL_FUNC(eglSwapInterval)
|
||||
INIT_EGL_FUNC(eglTerminate)
|
||||
INIT_EGL_FUNC(eglUnlockSurfaceKHR)
|
||||
INIT_EGL_FUNC_OPTIONAL(eglUnlockSurfaceKHR)
|
||||
INIT_EGL_FUNC(eglWaitClient)
|
||||
INIT_EGL_FUNC(eglWaitGL)
|
||||
INIT_EGL_FUNC(eglWaitNative)
|
||||
@@ -681,6 +805,26 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
INIT_EGL_FUNC(eglGetPlatformDisplay)
|
||||
INIT_EGL_FUNC(eglWaitSync)
|
||||
}
|
||||
|
||||
{
|
||||
// One slot, two names. EGL_EXT_swap_buffers_with_damage and
|
||||
// EGL_KHR_swap_buffers_with_damage define the same entry point with the same
|
||||
// signature, and a driver may expose either, both or neither - Adreno exposes only
|
||||
// the KHR spelling - so the winner of the EXT -> KHR chain lands in the EXT slot.
|
||||
// Null when the driver offers neither, which is the normal "no damage-based present
|
||||
// here" answer: the caller keeps plain eglSwapBuffers (and note that a call with
|
||||
// n_rects == 0 is defined to be equivalent to eglSwapBuffers anyway).
|
||||
funcs.eglSwapBuffersWithDamageEXT = ResolveSwapBuffersWithDamage(
|
||||
reinterpret_cast<MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR>(
|
||||
resolveEGLProc("eglSwapBuffersWithDamageEXT")),
|
||||
reinterpret_cast<MG_External::EGL::eglSwapBuffersWithDamageKHR_PTR>(
|
||||
resolveEGLProc("eglSwapBuffersWithDamageKHR")));
|
||||
if (funcs.eglSwapBuffersWithDamageEXT == nullptr) {
|
||||
MGLOG_I_ONCE("This driver has no damage-based present entry point (neither "
|
||||
"eglSwapBuffersWithDamageEXT nor eglSwapBuffersWithDamageKHR); "
|
||||
"present calls fall back to eglSwapBuffers");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detects whether indirect draws leak the command's baseInstance word ("reserved, must
|
||||
|
||||
@@ -63,8 +63,15 @@ namespace MobileGL {
|
||||
typedef EGLBoolean (*eglSurfaceAttrib_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint attribute,
|
||||
EGLint value);
|
||||
typedef EGLBoolean (*eglSwapBuffers_PTR)(EGLDisplay dpy, EGLSurface surface);
|
||||
typedef EGLBoolean (*eglSwapBuffersWithDamageEXT_PTR)(EGLDisplay dpy, EGLSurface surface, EGLint* rects,
|
||||
EGLint n_rects);
|
||||
// The damage-based present entry point, in both spellings a driver may expose it
|
||||
// under. EGL_EXT_swap_buffers_with_damage and EGL_KHR_swap_buffers_with_damage
|
||||
// define the same function with the same signature, so the two pointers are
|
||||
// interchangeable and one slot can hold either - see
|
||||
// BackendLoader::ResolveSwapBuffersWithDamage.
|
||||
typedef EGLBoolean (*eglSwapBuffersWithDamageEXT_PTR)(EGLDisplay dpy, EGLSurface surface,
|
||||
const EGLint* rects, EGLint n_rects);
|
||||
typedef EGLBoolean (*eglSwapBuffersWithDamageKHR_PTR)(EGLDisplay dpy, EGLSurface surface,
|
||||
const EGLint* rects, EGLint n_rects);
|
||||
typedef EGLBoolean (*eglSwapInterval_PTR)(EGLDisplay dpy, EGLint interval);
|
||||
typedef EGLBoolean (*eglTerminate_PTR)(EGLDisplay dpy);
|
||||
typedef EGLBoolean (*eglUnlockSurfaceKHR_PTR)(EGLDisplay display, EGLSurface surface);
|
||||
@@ -116,6 +123,8 @@ namespace MobileGL {
|
||||
EGL_FUNC_DECL(eglReleaseThread)
|
||||
EGL_FUNC_DECL(eglSurfaceAttrib)
|
||||
EGL_FUNC_DECL(eglSwapBuffers)
|
||||
// Holds whichever spelling of the damage-based present the driver provided, EXT
|
||||
// preferred; null when it provides neither (see AcquireEGLFunctions).
|
||||
EGL_FUNC_DECL(eglSwapBuffersWithDamageEXT)
|
||||
EGL_FUNC_DECL(eglSwapInterval)
|
||||
EGL_FUNC_DECL(eglTerminate)
|
||||
@@ -1358,6 +1367,14 @@ namespace MobileGL {
|
||||
void AcquireGLESFunctions(MG_External::GLESFunctionsTable& funcs,
|
||||
MG_External::EGL::eglGetProcAddress_PTR procAddress);
|
||||
void AcquireEGLFunctions(MG_External::EGLFunctionsTable& funcs);
|
||||
// The EXT -> KHR -> nothing chain for the damage-based present entry point. A null
|
||||
// result is not a failure: it means this driver offers neither spelling, and the
|
||||
// caller presents with plain eglSwapBuffers, which a zero-rectangle call to either
|
||||
// spelling is defined to be equivalent to anyway. Exposed so MG_Test can pin the
|
||||
// preference order without a driver.
|
||||
MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR
|
||||
ResolveSwapBuffersWithDamage(MG_External::EGL::eglSwapBuffersWithDamageEXT_PTR ext,
|
||||
MG_External::EGL::eglSwapBuffersWithDamageKHR_PTR khr);
|
||||
Bool FillInGLESCapabilities(MG_External::GLESCapabilities& caps,
|
||||
const MG_External::GLESFunctionsTable& glesFuncs);
|
||||
// Detects whether indirect draws leak the command's baseInstance word into
|
||||
|
||||
@@ -470,12 +470,22 @@ namespace MobileGL {
|
||||
size_t count = 0;
|
||||
SPVC_CHK_RESULT(spvc_resources_get_resource_list_for_type(
|
||||
resources, SPVC_RESOURCE_TYPE_STAGE_OUTPUT, &list, &count));
|
||||
Bool dualSourceIndex = false;
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const spvc_reflected_resource& resource = list[i];
|
||||
if (!spvc_compiler_has_decoration(compiler, resource.id, SpvDecorationIndex)) continue;
|
||||
if (spvc_compiler_get_decoration(compiler, resource.id, SpvDecorationIndex) != 0u) continue;
|
||||
if (spvc_compiler_get_decoration(compiler, resource.id, SpvDecorationIndex) != 0u) {
|
||||
dualSourceIndex = true;
|
||||
continue;
|
||||
}
|
||||
spvc_compiler_unset_decoration(compiler, resource.id, SpvDecorationIndex);
|
||||
}
|
||||
// The index that stays is printed as `layout(index = 1)`, which ESSL accepts only
|
||||
// with the extension enabled in the shader itself: the driver having it is not
|
||||
// enough, and without the directive the stage is refused exactly as above.
|
||||
if (dualSourceIndex) {
|
||||
SPVC_CHK_RESULT(spvc_compiler_require_extension(compiler, "GL_EXT_blend_func_extended"));
|
||||
}
|
||||
SPVC_CHK_RETURN
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,8 @@ namespace MobileGL {
|
||||
// A NON-zero index is left exactly as it is: that one really does select the
|
||||
// second dual-source input and cannot be expressed without the extension, so it
|
||||
// must keep reaching the driver (the frontend's own glBindFragDataLocationIndexed
|
||||
// path already emits only non-zero indices for the same reason).
|
||||
// path already emits only non-zero indices for the same reason) - and the stage
|
||||
// then requires GL_EXT_blend_func_extended, which ESSL wants enabled by name.
|
||||
spvc_result DropDefaultFragmentOutputColorIndex();
|
||||
// Drops `readonly` and `writeonly` from every shader storage block - and every
|
||||
// block member - that carries BOTH of them.
|
||||
|
||||
@@ -552,6 +552,18 @@ namespace MobileGL::MG_Util::TextureFormatProcessor {
|
||||
*outFormat = GL_DEPTH_STENCIL;
|
||||
break;
|
||||
|
||||
// Stencil-only. GL_STENCIL_INDEX8 is the one storage ES has (glRenderbufferStorage
|
||||
// accepts it outright, and a texture takes it under EXT/OES_texture_stencil8), and
|
||||
// GL_STENCIL_INDEX is the transfer format that goes with it - the same pairing the
|
||||
// frontend's validator demands (Validators.cpp:
|
||||
// "STENCIL_INDEX requires a stencil-only internal format") and the same one the
|
||||
// stencil readback path hands the driver. The unsized spelling is here for the same
|
||||
// reason the unsized depth and colour formats are: it resolves to this storage.
|
||||
case GL_STENCIL_INDEX8:
|
||||
case GL_STENCIL_INDEX:
|
||||
*outFormat = GL_STENCIL_INDEX;
|
||||
break;
|
||||
|
||||
default:
|
||||
MGLOG_E_ONCE("NormalizePixelFormat: outFormat: unhandled internalFormat: %s",
|
||||
MG_Util::ConvertGLEnumToString(internalFormat).c_str());
|
||||
@@ -776,6 +788,14 @@ namespace MobileGL::MG_Util::TextureFormatProcessor {
|
||||
*outType = GL_UNSIGNED_INT_24_8;
|
||||
break;
|
||||
|
||||
// Stencil-only: eight unsigned index bits per texel, which is the layout the
|
||||
// canonical shadow holds for it (PixelStoreProcessor's StencilIndex8 row: one
|
||||
// UInt8 component) and the type the stencil readback path uses.
|
||||
case GL_STENCIL_INDEX8:
|
||||
case GL_STENCIL_INDEX:
|
||||
*outType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
|
||||
default:
|
||||
MGLOG_E_ONCE("NormalizePixelFormat: outType: unhandled internalFormat: %s",
|
||||
MG_Util::ConvertGLEnumToString(internalFormat).c_str());
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
|
||||
1. **native tuple per context**。`g_Display` 保留进程级(native display 一次 initialize 合理);`g_Context`/`g_Surface`/`g_Config`(`DirectGLES.cpp:16183-16186`)改为 per-(session, contextSlot) 表,native context 按 share group 用 `eglCreateContext(share=…)` 建。
|
||||
2. **拆掉无条件 teardown**。`InitDisplayAndContext` 首句 `DestroyEGLContext()`(`DirectGLES.cpp:16569`)与 `BackendObject_DirectGLES` 建 surface 前的 `DestroyEGLContext()+ResetEGLRuntimeState()`(`BackendObject_DirectGLES.cpp:972-982`、`:1007-1014`)改为:目标 context 已存在则复用其 native context,仅换绑 surface;pbuffer→window→pbuffer 不丢资源。`DestroyEGLContext` 只拆指定 context;最后一个 context 走了才 `eglTerminate`。
|
||||
3. **Managers 按 share group / context 分表**。六个 twin registry(`Managers.cpp:6895`、`:11035`、`:12835`、`:13188`、`:16255`、`:16580`)按 share group 实例化;`g_activeTextureUnit`/`g_boundTexturesCache`/sampler cache(`Managers.cpp:11031-11032` 等)按 context 实例化;`DropEveryTwinForEndedServerSession`(`Managers.cpp:425-443`)只清本 session。`g_backendContextGeneration` 改为 per-context 世代。
|
||||
3. **Managers 按 share group / context 分表**。六个 twin registry(`Managers.cpp:6895`、`:11035`、`:12835`、`:13188`、`:16255`、`:16580`)按 share group 实例化;`g_activeTextureUnit`/`g_boundTexturesCache`/sampler cache(`Managers.cpp:11031-11032` 等)按 context 实例化;`DropEveryTwinForEndedServerSession`(`Managers.cpp:425-443`)只清本 session。`g_backendContextGeneration` 改为 per-context 世代。**(twin 键与 per-session 清理已落地,见 S6;单元影子与 context 世代仍欠。)**
|
||||
4. **DirectVulkan 同步审视**。Magma 的 per-device/per-queue 结构也要按 session 分;本阶段先保证不编译退化,多 session 下 Magma 的验收单列。
|
||||
|
||||
### S4 已落地形状(每 context 原生 tuple + share-group 键控)
|
||||
@@ -152,7 +152,7 @@
|
||||
**本切片明确没做(下一层的账)**:
|
||||
|
||||
- **`g_applier` 没有改成 {shareGroup → applier}**(上面 server 第 3 条)。原因不是时间,是**形状**:`MGPipeApplierState` 把「share group 的对象记录」和「每 context 的 working state」混在一个结构里(`PipeApply.h:515-933`,其自身注释第 101 行已指出该二分),照字面把它按 share group 键控会让**同一 share group 的两个 context 共用 working state**——bindings、current program、unit 集互相覆盖,比不改更错。正确的做法是先按该二分拆结构(对象表进 share group、working state 进 context),那是独立的一刀。今天 `g_applier` 与 `gMGPipeApplierReset` 逐字未动。**(S5 已做,见下节。)**
|
||||
- **六个 twin registry 与 twin 键 `{shareGroup, slot, gen}` 未改**(`Managers.cpp`)。twin 仍按引用活着的后端 context 复用,多 context 下的正确性依赖「一个原生 context 一个 twin 世代」,这在两个 context 都活着时成立(本次测到的),在跨 context 迁移 twin 的路径上还没有证据。**(S5 仍未做,见 S5 的未做项。)**
|
||||
- **六个 twin registry 与 twin 键 `{shareGroup, slot, gen}` 未改**(`Managers.cpp`)。twin 仍按引用活着的后端 context 复用,多 context 下的正确性依赖「一个原生 context 一个 twin 世代」,这在两个 context 都活着时成立(本次测到的),在跨 context 迁移 twin 的路径上还没有证据。**(S5 仍未做;S6 已做,见「S6 已落地形状」。)**
|
||||
- **share group 的驱动级证明未落地**。`eglCreateContext(share=…)` 已接线,但用 headless EGL 直接问 `glIsBuffer` 的探针在本机没有得到可用的控制(同 context 内 `glGenBuffers` 后 `glIsBuffer` 即返回 false),没有作为「跑了个空的绿」收进来。要证到驱动层,需要先弄清该探针,再补一个用例。**(S5 也没弄清:见 S5 的未做项与「为什么没做」。)**
|
||||
- **Wire 第 1 条的逐记录 `ContextSlot` 未做**,仍是 S1 的边沿宣告 + `bind_context`。
|
||||
- **`g_backendContextGeneration`/`g_syncContextGeneration` 仍是进程级**:销毁单个 context 会推进全局世代,其他 context 的旧 fence/query 句柄因此读作「已 signal」。安全方向(最坏是多等),但不是每 context 世代,属 P14b/c。
|
||||
@@ -188,15 +188,69 @@ S4 留下的最后一块:`PipeApply.cpp` 的进程级 `g_applier` 现在是一
|
||||
**负控**(必做,否则是空绿):把测试装的解析探针改成 null(即回到 S5 前的「谁都拿进程级 applier」),5 个用例**全红**;换回即全绿。
|
||||
- `MultiSessionTest.TwoSessionsInterleaveTwoContextsEachWithoutCrossTalk`:真实 `--serve` 前身(in-process unix supervisor)上两个 session,各自两个 context(同名 token 与同名 group token),**8 轮交错**:每轮先各发一条 `bind_context` 切 context,再跑一整趟 clear + 真读回。绿/红两种颜色互为证人;日志里 0 条 `SessionLatch{`。这条用例同时压的是**生产**解析链(`ThreadSessionScope` 装的探针)与并发(两个 apply 线程同时跑)。
|
||||
- 既有集合零回归:本切片点名的 97 个用例与 `MultiSessionFixture` 原有的 4 个全绿(含 `ServerLoopEglTest` 的 11 个、`ContextStateOwnershipTest` 6 个)。`SanityTest` 的两个用例因 `MGPipeApplierState` 不再可拷贝改为保存/恢复它真正改动的 working 字段。
|
||||
- **全量 host ctest 与基线的逐名对比**(不是"看起来差不多"):先 `git stash` 掉本切片的全部改动、重建、跑一遍全量(`ctest -j 8`,2735 个用例)留下失败名单,再恢复本切片、重建、跑同一遍,两份名单 `comm`:
|
||||
|
||||
| | 数量 |
|
||||
|---|---|
|
||||
| 基线失败 | 266 |
|
||||
| 本切片失败 | 265 |
|
||||
| **本切片新增失败** | **0** |
|
||||
| 基线失败而本切片不失败 | 1(`ProgramTest.CompileVertex`,glslang 那批的已知抖动) |
|
||||
|
||||
失败名单全部落在 glslang / 着色器编译族(`ProgramTest`、`ProgramInterfaceTest`、`AsyncLinkTest`、`GlslangCaptureProbeTest`、`TranslationCacheTest`…),与 `3rdparty/glslang` 这个 dirty submodule 的既有基线一致。
|
||||
|
||||
**S5 明确没做(下一层的账)**:
|
||||
|
||||
- **六个 twin registry 与 twin 键 `{shareGroup, slot, gen}` 仍未改**(`Managers.cpp`)。后果是 S5 **不能**声称「两个 nonshared context 的同名 handle 在驱动层是两个对象」:applier 的两条记录是对的(已有测试),但 twin 表按 handle 键,`Ensure(handle)` 会给两个 context 的同一个 handle 值返回同一个 twin。`ServerLoopTest` 里那条 `glIsBuffer` 探针仍然没有可用控制,所以**驱动级共享/隔离的证据仍是缺的**,本次没有以「跑了个空的绿」收进来。
|
||||
- **wire 第 1 条的逐记录 `ContextSlot`** 仍未做,仍是 S1 的边沿宣告 + `bind_context`。这意味着「同一 ring 上两个 context 的记录交错」只在 client 按 make-current 顺序发射时正确。
|
||||
- **六个 twin registry 与 twin 键仍未改**(`MG_Backend/DirectGLES/Managers.cpp` 的六个 `g_backend*` 静态注册表;键在 `Managers.h:315` 的 `StateBackendObjectRegistry` → `SlotTables.h` 的 `BackendSlotTable<MGPipeHandle{Slot,Gen}>`)。**这是 S5 之后"两个 nonshared context 的同名 handle"剩下的那一半**:applier 里两条记录是对的(有测试),但 twin 层按 `{slot, gen}` 键,两个 context 的同一个 handle 值会解析到同一个 twin;反向也一样,跨 context 复用 twin 的路径没有按 share group 分组。S4 报告里那条 `glIsBuffer` 探针本机仍无可用控制,所以**驱动级的 shared / nonshared 证据仍然是缺的**,本次没有以"跑了个空的绿"收进来(这是本切片最该被下一刀补上的证据)。改形状是把 `BackendSlotTable` 加一个 group 维度或按组实例化那六个注册表,触及 `Managers.cpp` 里全部调用点,不是本轮时间能稳妥做完的一刀。**(S6 已做,见下节;驱动级探针仍未弄清,S6 走的是 twin 身份这条替代证据。)**
|
||||
- **pbuffer→pbuffer→pbuffer 的资源保留**只到 S4 已落地的程度(`ServerLoopEglTest.CreatingAnotherSurfaceKeepsTheSameNativeContext`:换 surface 不动 tuple 的 `EGLContext` 句柄)。真正的"三个 pbuffer 之间来回且资源都在"要 window 半边,本机 headless 验不了;按 S4 的口径只记录。
|
||||
- **wire 第 1 条的逐记录 `ContextSlot`** 仍未做,仍是 S1 的边沿宣告 + `bind_context`。所以"同一 ring 上两个 context 的记录交错"只在 client 按 make-current 顺序发射时成立(本轮的交错压力用例走的正是这个顺序)。
|
||||
- **`MGPipeApplierShareGroupCountForTesting`** 是测试观测面,不是生产 API。
|
||||
- **`MGPipeApplierState` 的九张表名与 `Objects.X` 两种拼法并存**,是刻意换取 ~200 个读点不动的代价;改名的机会在 twin registry 一起做的那一刀。
|
||||
- **`MGPipeApplierState` 的九张表名与 `Objects.X` 两种拼法并存**是刻意换取 ~200 个读点不动的代价;改名的机会在 twin registry 一起做的那一刀。
|
||||
- **`g_backendContextGeneration`/`g_syncContextGeneration`、ServerLoop 的 MakeCurrent 去重**同 S4 一节所列,仍未动。
|
||||
|
||||
### S6 已落地形状(twin 表按 {session, shareGroup} 键控)
|
||||
|
||||
S5 留下的最后一块:八个后端 twin 表(六个 `StateBackendObjectRegistry`,加 `BackendBufferResourceTable` 与 `BackendSamplerViewTable`)从 `{slot, gen}` 的进程级表变成**按 `{session, shareGroup}` 分桶**的表。这是「两个 nonshared context 的同名 handle」剩下的那一半——applier 的记录已经分开了(S5),但记录指向的 twin 还是一条。
|
||||
|
||||
**键结构(`MG_Backend/DirectGLES/DirectGLES.h`)**。`TwinKey{ SessionKey, ShareGroupKey }`,与 applier 的 `MGPipeApplierKey` 是**同一个二元组的后一半**:`SessionKey` 是 `ServerSession*` 的地址(S5 注册时用的也是同一个值,两侧按构造一致),`ShareGroupKey` 走 `MGPipeApplierShareGroupKeyFor(session, currentToken)`——**共享一个函数而不是各写一遍规则**,因为记录与它描述的 twin 必须永远落在同一个桶里,而「0 表示这个 context 自己起了一个组」的第二处拼写正是它们会分开的原因。`{0,0}` 保留给「不属于任何 session 的线程」,也就是被替换掉的进程单例。
|
||||
|
||||
**解析链(`MG_Remote/Server/SessionRuntime.cpp`)**。第三层同构探针:`ResolveThreadTwinKey` 读 `ThreadSessionScope` 装好的 `t_runtime` → `runtime->Session().CurrentContextToken()` → `MGPipeApplierShareGroupKeyFor`;由 `InstallSessionRuntimeHooks` 用 `SetTwinKeyResolver` 装一次(与 S2 的 PipeInputs 探针、S4 的 native tuple 键、S5 的 applier 键并列)。没有探针的线程(monolith、纯客户端、inproc 单进程形状、单元用例)答案恒为 `{0,0}`。**探针只读 server session 侧的状态,不碰 `MG_State`**:`CurrentContextToken()` 是 apply 线程自己维护的原子,`MGPipeApplierShareGroupKeyFor` 读的是 applier 的注册表,所以 apply 线程那条「禁止前端键控查找」的约束(`Managers.h:341/406/430-436`)原样成立。
|
||||
|
||||
**表形状(`SlotTables.h` 的 `SlotTableRegistry`)**。桶是 `SharedPtr<BackendSlotTable<…, kKind>>`,按 key 存在一张 unordered_map 里,带一个「上次的 key → 桶」的线程本地 memo(热路径是一次比较)。**~150 个调用点一行没动**:`SlotTableRegistry` 把表上每一个 handle-keyed 入口(`GetOrCreate` / `FindByHandle` / `LiveGenAt` / `HandleOf` / `StateForHandle` / `NoteStateForHandle` / `ReleaseByHandle` / `ForEachLive` / `LiveCount` / 两个 capacity 观测)按**调用线程的桶**转发一遍,所以 `g_backendTextureObjects.FindByHandle(h)` 还是那行字,答的却是本 context 的名字空间;`StateBackendObjectRegistry` 内同样把 `m_slotTable` 换成 `m_slotTables` 并转发。两处刻意的取舍:
|
||||
|
||||
- **holder 列表仍是进程级**。notice 是关于**对象**的,不是关于桶的:`OnFrontendObjectDestroyed` / `ReleaseTwinByHandle` 必须走到 fixture 或 context reset 持有的 by-value 拷贝,无论它在哪个桶里——「哪个桶持有它」正是当初造成双 holder 泄漏的那个问题。每个共享 holder 就是一个桶,所以死亡通知天然覆盖全部桶。
|
||||
- **`ForEachLive` 走调用线程的桶**,不是全部桶。调用者问的是「我能看见的对象里哪些需要这个」,而它能看见的就是它自己的 share group;遍历全部桶会走到邻居 session 的对象。需要全进程视野的两处(死亡、诊断)走新的 `ForEachBucket(fn)`(回调带 key)。
|
||||
|
||||
**新增的控制面**:`Drop(key)`(一个组)、`DropSession(sessionKey)`(一个 session 的全部组)、`ResetBuckets()`(全部,即 `= {}` 在旧形状下的意思)、`BucketCount()` / `BucketSnapshot()` / `BucketForCallingThread()`(测试与 fixture 的观测面)。`BackendSlotTable::Reset()` 是「把两个空间先移出去再析构」的写法,理由与 `ReleaseTwinAt` 相同:twin 的析构是驱动调用,可能重入 `GetOrCreate`。
|
||||
|
||||
**`DropEveryTwinForEndedServerSession` 变成 per-session**(`Managers.cpp`)。它跑在**正在结束的那个 session 的 apply 线程**上,而 S2 之后同一个进程里可能有别的 session 还在渲染,所以现在是「按调用线程的 session 删它全部桶」;没有 session 的线程(单元用例、`SanityTest` 的 `Transport=Spawn` 形状、fork worker)执行全量清理,与旧形状逐字相同。`g_boundTexturesCache` / `g_boundSamplersCache` / `g_activeTextureUnit` 这三个单元影子仍是进程级、仍在这里整体清空(见下面的欠债)。
|
||||
|
||||
**`Managers.h:2190` 的注释一并改正**:那里过去写着「a texture is owned by exactly one context (share groups are not implemented)」。真正成立的说法是**texture 属于一个 share group**(S3 的 `ShareGroupState` 持有对象表,S6 之后 twin 表也按组键控),同组两个 context 都会合法地改它;`m_syncedShapeContextId` 因此只是廉价门禁的一半——同组的另一个 context 改了 shape 会 stamp 一个新 id 并(多余地、但安全地)重推一次,而真正兜住变化的是那几个 per-mutation version,它们与 context 无关。
|
||||
|
||||
**验收证据**(本次新增):
|
||||
|
||||
- `MG_Test/Wire/TwinOwnershipTest.cpp`,5 个用例,直接驱动**真实** twin 表(无 EGL、无 wire):同 session 两个不共享的组、同名 handle 是两个 twin 且互不覆盖;同组两个 context 解析**同一个** twin(驱动级共享在 twin 层的等价物——twin 就是持有 driver id 的那个对象);一个 session 的 `DropBucketsOfSession` 只带走自己的 twin,邻居 session 的不受影响;不属于任何 session 的线程仍拿进程级那张表且与 session 的互不串;第六个用例在 `TwinRegistry` 模板(六个注册表同型)上重复前三条并顺带钉住 per-bucket 的世代门禁。
|
||||
**负控**(必做):把 `SlotTableRegistry::ForCallingThread` 改成恒答 `{0,0}`(即恢复 S6 前的进程级表),5 个用例里**4 个变红**;`TwoContextsOfOneGroupShareTheGroupsTwins` 保持绿——一个键时两种形状答案相同,这正是该用例断言的是「共享必须发生」而不是「存在两个桶」的原因。改回即全绿。
|
||||
- 既有集合零回归:本切片点名的 103 个用例(`EmbeddedServerTest`、`ServerDisplayTest`、`UnixSupervisor`、`InProcessServer`、`SupervisorChildren`、`ServerLoopTest`、`ServerLoopEglTest`、`MultiSessionFixture`、`PeerLatch`、`SurfaceControlFrameTest`、`ContextStateOwnershipTest`、`ApplierOwnershipTest`)全绿,其中 `MultiSessionFixture` 的两个真渲染用例现在跑在按 session 隔离的 twin 表上。
|
||||
- **全量 host ctest 与基线的逐名对比**(同 S5 的做法:`git stash push -u -- MobileGL docs` 掉本切片、重建、跑全量留失败名单,恢复后再跑一遍,两份名单按**用例名**`comm` 而不是按行号——本切片多了一个测试文件,行号会整体错位):
|
||||
|
||||
| | 数量 |
|
||||
|---|---|
|
||||
| 基线失败 | 277 |
|
||||
| 本切片失败 | 278 |
|
||||
| **本切片新增失败** | **0** |
|
||||
| 基线失败而本切片不失败 | 0 |
|
||||
|
||||
两份名单的差集只有一个名字:`LogForwardChannel.APeerThatStopsReadingCostsWarnLinesNotTheCallersTime`,它**基线也抖**——同一台机器上单独重复跑,基线 4/60 失败、本切片 2/40 失败,两边的失败断言逐字相同(`LogForwardTest.cpp:446` 的 `Dropped` 行数与 `counters.lossyDropped` 不等、`:448` 的 `counters.notices == 2` 而非 1),是那个用例自己的日志通道竞态:它让对端停止读取然后断言「掉线通知只发一条」,而通知本身由后台线程按队列水位发。该用例不建 backend、不碰 twin,与本切片无关,按既有基线口径记为抖动。其余失败名单全部落在 glslang / 着色器编译族(`ProgramTest` 80、`ProgramInterfaceTest` 32、`AsyncLinkTest` 17、`GlslangCaptureProbeTest` 15、`ShaderCompileAdoptionTest` 14…),与 `3rdparty/glslang` 这个 dirty submodule 的既有基线一致。
|
||||
|
||||
**S6 明确没做(下一层的账)**:
|
||||
|
||||
- **单元影子仍是进程级**:`g_activeTextureUnit`、`g_boundTexturesCache`、`g_boundSamplersCache` 与 sampler cache(`Managers.cpp:11031-11032` 等)是 §3 第 3 条留给 P14b/c 的另一半。它们与 twin 键控**不冲突但也不互补**:缓存做的是指针同一性比较,所以按组分开的 twin 只会让「另一组的 twin」比较不相等并重新绑定(安全方向);真正的残留问题是「同一个 twin 在一次原生 context 切换之后被缓存命中而跳过绑定」,那在 S4 把原生 context 变成 per-context 时就已经存在,属于同一笔账。
|
||||
- **驱动级的 `glIsBuffer` 探针仍未弄清**(S4/S5 都记录的同一件事)。S6 因此没有走「真驱动上问一句」那条路,而是按 S5 报告的允许口径在 twin 层断言身份:twin 就是持有 driver id 的对象,两个 context 拿到不同的 twin 就是两个 driver 对象。要做成驱动级证据,需要先把 S4 报告里「同 context 内 `glGenBuffers` 后 `glIsBuffer` 即返回 false」这个探针问题弄清楚。
|
||||
- **`g_backendContextGeneration`/`g_syncContextGeneration` 仍是进程级**,同 S4/S5 一节所列。
|
||||
- **`MGPipeApplierState` 的两种拼法(`Objects.X` 与表名)仍未收敛**;S5 说「改名的机会在 twin registry 一起做的那一刀」,S6 选择了不动它(那一刀的价值是整洁,而 S6 的 diff 已经在改 8 张表的行为,把重命名捆进来只增风险)。
|
||||
- **wire 第 1 条的逐记录 `ContextSlot`** 仍未做。
|
||||
|
||||
|
||||
## 分期与验收
|
||||
|
||||
|
||||
@@ -1,486 +1,88 @@
|
||||
# Handoff:anland 5.x + 内置 MobileGL SHM server
|
||||
# Handoff:anland 5.x + 内置 MobileGL 统一 server(post-P14)
|
||||
|
||||
更新时间:2026-10-01(用户时区 America/Cuiaba)。用户要求暂停实现,先写交接文档,由新的 agent 继续。
|
||||
更新时间:2026-10-02。本文替换旧的 handoff-legacy-mobilegl-unified.md(那份描述的是 P14 之前的状态,已被事实淘汰)。
|
||||
|
||||
## 先读:用户最新纠正与当前完成度
|
||||
## 任务与路线
|
||||
|
||||
**任务没有完成。KWin、Konsole、eglinfo、glxinfo、Plasma 均未通过 MobileGL 真机验收。构建成功不能当成验收成功。**
|
||||
anland 5.x 用 MobileGL:容器(Droidspaces,arch-kde-mgl)里的 Linux client 经 SHM pipe 连到 anland APK 内嵌的统一 server(`:mobilegl` 私有 Service,同 APK 同 UID),server 在 anland 自己的 Surface 上直接渲染(路线 B:`kgsl-as-server.md`)。不按应用 fork 渲染进程——session/context/share-group 状态归属在 MobileGL 库内解决(P14,[`../design/11-state-ownership.md`](../design/11-state-ownership.md))。
|
||||
|
||||
用户原始目标:
|
||||
## 远端与分支
|
||||
|
||||
1. 在 anland 新建 `legacy-mobilegl-unified`,让 anland 5.x 使用 MobileGL。
|
||||
2. SHM split server **必须是 anland APK 的一部分,由 anland 管理**,client 在 Droidspaces 容器内。
|
||||
3. 在联想 Y700 TB321FU 上复制 `arch-kde` 为 `arch-kde-mgl`,作为实验环境。
|
||||
4. 依次调通 KWin → Konsole → eglinfo → glxinfo → Plasma。
|
||||
5. 阶段成果形成可二分的 commits,推送 anland fork 和 MobileGL `feat/disaggregated`。
|
||||
6. 开始前阅读此目录调研,尤其 [`kgsl-as-server.md`](kgsl-as-server.md),技术路线接近 B:anland 自己的 Surface 交给 MobileGL server 直接渲染。
|
||||
- MobileGL:<https://github.com/MobileGL-Dev/MobileGL> 分支 `feat/disaggregated`
|
||||
- anland:<https://github.com/MobileGL-Dev/anland> 分支 `legacy-mobilegl-unified`
|
||||
|
||||
用户已明确排除两种路线:
|
||||
### MobileGL 关键提交(新→旧)
|
||||
|
||||
> anland fork 的 `legacy-mobilegl` 路径是配合 MobileGL feat/disaggregated-container-gbm 的错误路径。MobileGL server 不应该活在独立的 plugin app 里,应该成为 anland 的一部分。
|
||||
|
||||
> 说起来,为什么会有实现一个应用离屏 Service?如果 MobileGL 有全局状态需要解决,那应该处理的是 MobileGL 自己的全局状态,而不是想办法制造多个 MobileGL peer。
|
||||
|
||||
第二条纠正针对本轮草稿:曾添加 `MobileGLAppsService`,exec 一个离屏 supervisor,给每个应用 fork 一个独立 worker,以隔离 MobileGL 全局状态。**用户否定了这个绕法;不要把它继续打包、部署或宣称为最终设计。**
|
||||
|
||||
应在 MobileGL 内解决 session/context/surface 状态归属与共享资源问题。anland 内置的 renderer 可以由私有 Service 管理,但不能用额外“应用离屏 Service”或按应用 fork 渲染进程来代替这个工作。多应用的正常 client 连接与人为制造 worker 来绕过全局状态,要区分清楚。具体统一 server 的设计尚未完成。
|
||||
|
||||
已发给各子 agent 的最新指令是暂停实现与部署,仅报告状态。**纠正后的架构还没有实现;草稿仍包含被否定代码。** 本文的状态说明优先于草稿中的旧启动说明。
|
||||
|
||||
## 工作区、分支、保留事项
|
||||
|
||||
### MobileGL
|
||||
|
||||
```text
|
||||
C:\Users\Swung0x48\repos\FoldCraftLauncher\MobileGL
|
||||
origin: https://github.com/MobileGL-Dev/MobileGL.git
|
||||
显示分支: feat/disaggregated
|
||||
当前实现 HEAD: 2f64ede8c65e9577676e658e82017672ad58f03e
|
||||
```
|
||||
|
||||
Windows 上真实本地 ref 的大小写是 `refs/heads/Feat/disaggregated`。推送使用:
|
||||
|
||||
```powershell
|
||||
git push origin HEAD:refs/heads/feat/disaggregated
|
||||
```
|
||||
|
||||
不要用失败的 `git push origin feat/disaggregated` 重复排查网络。
|
||||
|
||||
用户原有 dirty submodule `3rdparty/glslang` 必须保留,不能提交、重置或当成本任务成果。为 split 构建初始化过缺失的 `3rdparty/flatbuffers`,没有修改 gitlink。
|
||||
|
||||
本任务未提交改动仅有:
|
||||
|
||||
| 文件 | 改动与状态 |
|
||||
| Commit | 内容 |
|
||||
|---|---|
|
||||
| `CMakeLists.txt` | Linux 增加 `libGL.so`、`libGL.so.1` 别名 |
|
||||
| `MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp` | Wayland `Present()` 失败返回 `EGL_BAD_SURFACE`;原代码忽略失败 |
|
||||
| `MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp` | spawn 模式 X drawable 使用远端 pbuffer,避免把 XID 当 Android ANativeWindow;**没有 X11 像素上屏、没有远端 resize** |
|
||||
| `4236b42a` | server:配置只在进程内第一个 session 接入时初始化一次——此前每个新 session 接入都重跑 `MG_ConfigLoader::Init()`,它先把 `Transport` 写回 Monolith 再被改回 Spawn,正在 apply 的别的 session 恰好读到就跳过 server stamp,`Fatal{UnmigratedPipeInput, "GetBoundVertexArray@DrawArrays"}` 带走整个 server 进程(整个桌面);转译:保留下来的非零 `layout(index = 1)`(双源混合)在 ESSL 里加 `#extension GL_EXT_blend_func_extended : require`(此前 Adreno 拒绝该 stage,程序整体不画) |
|
||||
| `0b6842ac` | 让 ANGLE 的 GL 后端跑在 MobileGL 上:EGL 声明 `EGL_KHR_platform_gbm`/`EGL_MESA_platform_gbm`(GBM display 当离屏 display,拒绝 gbm 窗口 surface;Chrome 的 Wayland GL 层对每个 display 都标 GBM 平台);平台标 GBM 但 native display 实为 wl_display 时按 Wayland 处理,wl_display 识别兼容自带一份 libwayland 的程序(按接口名 "wl_display" 判断,经 `process_vm_readv` 读,野指针不会崩);实现 `glGetShaderPrecisionFormat`(此前是空 stub,ANGLE 读到 0 精度即拒绝 ES 2.0);`GL_VERSION` 里不再出现 "OpenGL ES" 子串(ANGLE 用子串搜索判断 ES 驱动,"Direct (OpenGL ES) Backend" 让它把 MobileGL 当 ES 驱动、按 ES 扩展名查 BGRA 等能力,Chrome 的 shared image 全部创建失败) |
|
||||
| `47db68d5` | GLX:MobileGL 同时是 glvnd 的 GLX vendor(`__glx_Main`,装成 `/usr/lib/libGLX_mobilegl.so.0`,会话设 `__GLX_VENDOR_LIBRARY_NAME=mobilegl`;此前 X11 客户端经 Xwayland 拿到 Mesa vendor,报 `MESA-LOADER: failed to retrieve device information`);远端 X drawable(pbuffer)每次 `glXSwapBuffers` 回读并用 `xcb_put_image`(按服务器最大请求长度分带)上屏,resize 换新 pbuffer;GLX 出口持流锁;`eglReleaseThread` 在 MobileGL 已被 `eglTerminate` 拆掉后也返回 TRUE(glmark2 退出时的 "eglReleaseThread failed") |
|
||||
| `ccf8eb65` | 客户端:多线程 GL 流串行化——每个 GL/EGL 出口持同一把流锁,写入前按「最后真正发出的 `bind_context`」把 server 绑到调用线程的 context(Qt 每个窗口一个 QSGRenderThread,此前两线程记录在同一 ring 上交错、落进错的 applier、甚至撕裂记录);`MGPipeTracker` 按 context 的永不复用 id 判断换 context(指针 ABA);导出 `eglCreateImageKHR`/`eglDestroyImageKHR`(KWin 在 shm client 断开时调空指针 → 首个 KWin 约 2 秒必 SEGV);`eglGetPlatformDisplayEXT` 的 EGLint 属性表加宽;多窗口:surface 激活不再清空别的线程的 current 记录,swap 呈现本线程的 surface;Wayland 窗口 `wl_egl_window_resize` 在下一次 make-current/swap 生效 |
|
||||
| `0b314dda` | server:所有 session 的 apply 线程在一把 FIFO「backend turn」上串行(DirectGLES 是按单 GL 线程写的:单一 owner 线程、进程级绑定影子),换手时接管 owner 并清掉绑定影子;全部原生 context 进同一 share group(环、池、scratch 纹理是进程级 GL 对象);每个客户端 surface 一个原生 surface(激活时重绑而非新建),建 surface 后恢复当前 context 自己原来的 surface,释放 surface 只销毁它(此前 `DestroyEGLContext` 带走整个 session 的 context),`bind_context` 恢复 context 自己的 surface;pbuffer 背后的窗口 resize = 换新 pbuffer;session 结束时若别的 session 的 context 还活着,只清本 session 的东西(此前进程级 generation 被推进,所有活 session 的纹理/缓冲被当成死的空重建 → 关弹窗/退出 client 后全屏噪点);分块上传(stage chunk 切片)的 region 偏移按整层图像校验(此前 KWin 的 wl_shm 纹理在第 819 行后读到第 0 行);`SetSamplerViews.Count` 改为 per-session latch |
|
||||
| `30fef23d` | P14 收尾(统一 server 的两处进程级状态):server 的两个 staged store(纹理 level 声明、buffer shadow)按调用线程的 {session, share group} 分桶(与 S6 twin 表同一个探针),`DropAll` 只清本 session;`MGPipeServerSetContextLive` 的 live 标志从进程全局移进本 session 的 PipeInputs 块。各带单测(`StagedTextureStoreTest` 两例、`ServerContextLiveTest`) |
|
||||
| `d554c87c` | EGL loader 缺 `eglSwapBuffersWithDamageEXT` 不再 FATAL(EXT→KHR→eglSwapBuffers 回退 + GLES 符号 dlsym 回退防自指);stencil-only 存储格式配对修复;各带测试 |
|
||||
| `7a48521d` | DirectGLES:创建 server-owned window surface 前先销毁同窗口的残留 surface(此前第二个起的 session 必死 EGL_BAD_NATIVE_WINDOW) |
|
||||
| `5a0f13fd` | 广告 GL_ARB_shader_objects/vertex_shader/fragment_shader/texture_non_power_of_two(KWin `checkSupported` 的硬门槛) |
|
||||
| `ff212061` | P14 S6:后端 twin 表按 {session, share group} 键控 |
|
||||
| `4ed1c9ce` | P14 S1–S5:`bind_context`(opcode 84)+ CreateContext/DestroyContext 控制帧(control revision 6);同进程多 session(`SessionRuntime`、线程域解析、per-session latch,inproc unix supervisor 并发上限 `MOBILEGL_IPC_INPROC_MAX_SESSIONS`=16);前端 ShareGroupState/per-context GLContext/TLS pGLContext;DirectGLES per-(session,context) native tuple(不再无条件 teardown);applier 按 {session,context}/{session,shareGroup} 分桶 |
|
||||
| `ebc552a0`/`6fb880cd` | Wayland Present 失败回 EGL_BAD_SURFACE;GLX drawable 走远端 pbuffer;Linux libGL 别名 |
|
||||
| `d52c031c` | P14 设计文档 |
|
||||
|
||||
DirectGLES/BackendObject 的“保留一个 native context、切换多个 surface”实现曾被讨论,但**没有产生代码改动**,也没有产生测试成果。不要误以为它已经实现。
|
||||
### anland 关键提交(新→旧)
|
||||
|
||||
### anland
|
||||
|
||||
原工作区:
|
||||
|
||||
```text
|
||||
C:\Users\Swung0x48\repos\anland
|
||||
origin: https://github.com/MobileGL-Dev/anland.git
|
||||
原分支: main
|
||||
```
|
||||
|
||||
原工作区用户 dirty submodules `pulseaudio`、`wayland`、`xserver` 没有修改。继续保留。
|
||||
|
||||
本任务使用独立 worktree,**后续 anland 编辑必须在这里进行**:
|
||||
|
||||
```text
|
||||
C:\Users\Swung0x48\repos\anland-legacy-mobilegl-unified
|
||||
branch: legacy-mobilegl-unified
|
||||
base: origin/legacy = 9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46
|
||||
当前本地/远端 HEAD: 6e1fa653314956f57948b93abff08724c97c779c
|
||||
```
|
||||
|
||||
不要重新 checkout 远端分支来替代工作区;大量实现仍在未提交文件中。
|
||||
|
||||
## 已推送 commits 与适用性
|
||||
|
||||
### MobileGL `feat/disaggregated`
|
||||
|
||||
| Commit | 内容 | 适用性 |
|
||||
|---|---|---|
|
||||
| `57781688` | GLVND EGL vendor ABI headers,来自 `6a702afa` | 可复用的独立 client 能力 |
|
||||
| `75f83b20` | EGL extension strings,来自 `dfbda7cc` | 可复用 |
|
||||
| `0dad3fca` | EGL GLVND vendor,来自 `c9206dd9` | 可复用 |
|
||||
| `f4589243` | multiple display/vendor lookup,来自 `2860d090` | 可复用 |
|
||||
| `32c79f41` | Wayland wl_shm WSI,来自 `7fd7f71d` | 初步 client 能力;有下述限制 |
|
||||
| `a5b463a5` | package-neutral embedded display C ABI | 14 项 ownership/lifecycle 测试通过,可复用 |
|
||||
| `2f64ede8` | Unix `--serve --max-sessions 1..64`,fork worker 并发 | **已推送,但用户随后否定用它解决 anland 全局状态的方案。最终架构需移除/替换这个依赖,不能把它当任务完成。** |
|
||||
|
||||
这些独立 client 改动来自旧分支,但没有 cherry-pick 独立 plugin/GBM/host-frame 整体架构。`32c79f41` 冲突处理中移除了尚未实现的 device/GBM 扩展广告。
|
||||
|
||||
### anland `legacy-mobilegl-unified`
|
||||
|
||||
`6e1fa65 Add a no-fd MobileGL Surface mode to the display protocol` 已推送。
|
||||
|
||||
它添加 `DATA_MSG_MOBILEGL_SURFACE=201`、`ANLAND_FORMAT_MOBILEGL_SURFACE=0x4d474c53`。metadata 没有 fd,保留一 pacing slot(fd=-1、idx=0)。真实 daemon + producer + consumer 测试验证 metadata、frame ack、输入事件。没有假造 dma-buf。
|
||||
|
||||
其他 APK、JNI、KWin、launcher 草稿都还没有提交。
|
||||
|
||||
## 未提交 anland 草稿:保留有用部分,移除被否定部分
|
||||
|
||||
### Android APK/JNI
|
||||
|
||||
改动文件:
|
||||
|
||||
```text
|
||||
consumers/anland_v5/android_consumer/app/build.gradle
|
||||
consumers/anland_v5/android_consumer/app/src/main/AndroidManifest.xml
|
||||
consumers/anland_v5/android_consumer/app/src/main/java/com/anland/consumer/MainActivity.java
|
||||
consumers/anland_v5/android_consumer/app/src/main/java/com/anland/consumer/Native.java
|
||||
consumers/anland_v5/android_consumer/app/src/main/jni/CMakeLists.txt
|
||||
consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c
|
||||
```
|
||||
|
||||
未跟踪文件:
|
||||
|
||||
```text
|
||||
consumers/anland_v5/android_consumer/MOBILEGL.md
|
||||
consumers/anland_v5/android_consumer/app/src/main/java/com/anland/consumer/MobileGLWorker.java
|
||||
consumers/anland_v5/android_consumer/app/src/main/java/com/anland/consumer/MobileGLConnection.java
|
||||
consumers/anland_v5/android_consumer/app/src/main/java/com/anland/consumer/MobileGLAppsService.java
|
||||
consumers/anland_v5/android_consumer/app/src/main/jni/mobilegl_worker.c
|
||||
```
|
||||
|
||||
有用设计:
|
||||
|
||||
- `MobileGLWorker` 是同 APK、同 UID 的私有 `:mobilegl` Service(不是 isolatedProcess),接收 anland 自己的 Surface,JNI 通过 `dlopen/dlsym` 使用中立 ABI。
|
||||
- 主 UI 进程不加载 MobileGL 的 GL 导出;避免影响 Android framework/UI 的 EGL。
|
||||
- `MainActivity` 等待 worker attach 后才启动 native display consumer。
|
||||
- MobileGL 模式 native consumer **不连接 ANW_API_CPU、不 dequeue/queue Surface buffer**,EGL 是唯一生产者;输入、音频、显示协议继续保留。
|
||||
- 新 Surface parcel 每次会产生不同 native wrapper。最新草稿保留同一 window owner/generation 的 Java Surface,尺寸更新使用保留的 ANativeWindow,避免 resume/resize 把活动 session detach。
|
||||
- native geometry callback → one-way Binder → UI SurfaceHolder;`surfaceChanged` 先报告尺寸,再等待 native transport 停止,避免 geometry/ack 互等。
|
||||
- `Surface.getGenerationId()` 是隐藏 API,曾导致编译失败;改为 NDK native identity token + 本地生命周期 generation。
|
||||
- CMake 使用仓库根下的 authoritative common/libdisplay 源码,避免 Windows 把 symlink checkout 成 target-text 文件。
|
||||
- `mobileglDist` staging 需在切回 unbundled 时清除旧 libs;**Gradle Sync 没有 sources 时会 NO-SOURCE,不自动删除旧文件**,草稿已改为显式 cleanup。
|
||||
|
||||
必须撤掉/重设计:`MobileGLAppsService`、manifest/binding/health check、第二个应用 endpoint、`libMobileGLServer.so --serve --max-sessions 16` 依赖以及相关文档。
|
||||
|
||||
当前 `MobileGLConnection`、APK 文档仍包含这条被否定路径。不要只读注释就继续部署。
|
||||
|
||||
### KWin 6.7.4 后端
|
||||
|
||||
**anland 5.x 是宿主协议版本,容器当前 KWin 实际为 6.7.4。**
|
||||
|
||||
草稿:
|
||||
|
||||
```text
|
||||
producers/kde/Arch_v5/kwin.patch
|
||||
producers/kde/anland_backend_Arch_v5/src/backends/anland/anland_backend.cpp
|
||||
producers/kde/anland_backend_Arch_v5/src/backends/anland/anland_backend.h
|
||||
producers/kde/anland_backend_Arch_v5/src/backends/anland/anland_egl_backend.cpp
|
||||
producers/kde/anland_backend_Arch_v5/src/backends/anland/anland_egl_backend.h
|
||||
producers/kde/Arch_v5/mobilegl-startup.sh # untracked
|
||||
producers/kde/Arch_v5/mobilegl.md # untracked
|
||||
```
|
||||
|
||||
`CMakeLists.txt` 也可能显示 dirty(曾尝试 PUBLIC include,已撤销语义改动;检查实际 diff/行尾)。
|
||||
|
||||
`ANLAND_MOBILEGL=1` 路径:跳过 GPU/DRM probing,不广告 dma-buf/syncobj,不要求 GBM/no_config/surfaceless。先选择 RGBA window config,创建 server-owned EGL window,再创建 RenderDevice/shared contexts。默认 makeCurrent 使用该 Surface。output layer marker 走 default FBO 0、full damage 和 eglSwapBuffers,不导入 consumer dma-buf。Mesa 路径保留。
|
||||
|
||||
full repaint 是因为 Android BufferQueue 自己轮换 buffers,而 client 暂未提供 buffer age。RenderTarget transform 保持原 Anland FlipY/output transform 语义。
|
||||
|
||||
native 构建已通过。最后修了 public backend headers 的 include 路径:`main_wayland.cpp` 包含它们时也必须找到 producer/protocol header,不能靠 backend PRIVATE include dirs。两个 header 已改为自足的相对 include。
|
||||
|
||||
launcher 有 `compositor`/`plasma` modes,原先按两个 endpoints 分配环境,**这部分要随新统一 server 设计修改**。提交新 shell helper 时须设置 git executable bit `100755`。
|
||||
|
||||
## MobileGL 状态问题:已知事实与未完成设计
|
||||
|
||||
不能用“每进程隔离”掩盖同一应用的多 context/share-group 缺陷:
|
||||
|
||||
- `MG_State::pGLContext` 是进程全局,bindings/errors/object registries 被不同 EGLContext 共用。
|
||||
- EGL `shareCtx` 当前只是 metadata,不能据此声称真正支持 shared contexts。
|
||||
- DirectGLES `g_Display/g_Context/g_Surface` 和 Managers/cache/twin 状态是全局;不能只把三个 handle 改 TLS 就声称完成隔离。
|
||||
- 多个虚拟 EGLContext 在**同一个已创建 Surface**上切换,不会直接销毁 native context;ServerLoop 检测 context token 变化后重新绑定同一 native triple、失效 caches。因此简单串行 KWin 单 Surface 有可能工作,但没有真机证据。
|
||||
- 创建第二个 pbuffer/window 会 `DestroyEGLContext()`,`InitDisplayAndContext()` 又销毁 context/terminate,原资源丢失。Qt 的 offscreen probe + 实际窗口、多窗口会碰到这个问题。
|
||||
- 只给 native `eglCreateContext` 添加 share 参数,不会自动解决 frontend object registries、context-local bindings 或 wire 上的 context/share-group 归属。
|
||||
- `ServerDisplayInstance` 当前只有一个 display/window lease;现有 inprocess server 接一个活动 session;多 client 真正共存需要重新审视其状态与路由。
|
||||
- ServerLoop 当前把 server-owned window 与 pbuffer session mode 闩定,混用会返回 `SurfaceModeMismatch`。新架构要在明确的 session/context/surface 所有权下处理 compositor 与应用。
|
||||
|
||||
后续应先审计 `MG_State`、`MG_Backend`、`MG_Pipe`、DirectGLES Managers、Init/Destroy、ServerSession/ServerLoop 的全局状态。确定 per-session/per-context 的 state owner、GL share group、原生 EGLContext/Surface 生命周期、apply-thread 绑定,再实施和测试。这个设计审计只开始了,没有完成代码。
|
||||
|
||||
以下是 runtime agent 补充的源码定位(行号针对当前实现 HEAD;以后可能移动):
|
||||
|
||||
| 定位 | 问题 |
|
||||
| Commit | 内容 |
|
||||
|---|---|
|
||||
| `MG_State/GLState/Core.cpp:1565` | 全局 `pGLContext`,EGL CreateContext 不创建独立 GLContext |
|
||||
| `MG_State/EGLState/Core.cpp:1496` | 全局 `pEGLContext`;已有 threadCurrents/contextOwners/互斥,但 ContextObject 只是元数据,没有 GL 状态/share group |
|
||||
| `MG_Backend/BackendObjects.h:16` | 全局 `pActiveBackendObject`,Init 的 `gBackendFunctionsTable` 也全局 |
|
||||
| `MG_Remote/Server/ServerSession.cpp`、`ServerLoop.h:129` | singleton session/loop、全局 active/sessionOwner、唯一 g_applyThreadKey |
|
||||
| `MG_Pipe/MGPipe.h:264`、`MGPipeCallbacks.h:77,97`、`MGPipeHostSpan.h` | screen/context、callbacks、event capacity hook、segment resolver 全局 |
|
||||
| `MG_Pipe/PipeApply.cpp:484,490` | 全局 g_applier 与 g_resourceOps,会覆盖不同 session 的表、绑定与后端 ops |
|
||||
| `DirectGLES.cpp:16183,16568` | 唯一 native tuple,无条件 context teardown |
|
||||
| `DirectGLES/Managers.h`、`Managers.cpp` | resource/twin registries、memo、texture units、context generations 混在全局 |
|
||||
|
||||
建议的真正状态边界:
|
||||
|
||||
- **Session**:SHM rings/segments、staged stores、reply/event 路由、failure、资源 handle空间、backend/Pipe runtime;关闭一个 session 不得破坏另一个。
|
||||
- **Context**:独立 GLContext、bindings/render state/errors、VAO/FBO/query/pipeline/transform-feedback 等局部状态、native EGLContext、cache/scratch/owner/generation。
|
||||
- **Share group**:buffer/texture/renderbuffer/sampler/shader/program/sync 的共享对象 registry 与名称分配、native object映射。不能直接共享整个 BufferState/TextureState,因为它们还包含局部 bindings。
|
||||
- **Thread current**:TLS 指向 context/session,**owner 本身不应简单放 TLS**;context 移交线程仍应保留状态。server apply显式设置 runtime scope。
|
||||
|
||||
当前 wire SurfaceOp 没有真正 Create/DestroyContext、share-group语义。多client线程的GL records可能交错,提交记录或不可拆分批次必须有准确 context身份,不能只靠最后一个 MakeCurrent决定归属。统一 embedded server可以顺序schedule多个session/context,但仍要创建正确的native contexts并遵守share-group,不等于把所有contexts别名到一个native context。
|
||||
|
||||
需要的真实验证:相同handle值的两个session隔离与独立关闭;shared contexts访问同一buffer/texture;nonshared contexts同名资源隔离;每context的viewport/FBO/bindings/error独立;跨线程移交;pbuffer→window→pbuffer保留资源。
|
||||
|
||||
### WSI 现有限制
|
||||
|
||||
- Wayland:server pbuffer → readback RGBA → flip/swizzle → 三槽 wl_shm buffer → wl_surface;有独立 release event queue。
|
||||
- 未跟随 `wl_egl_window` resize;也没有隐藏窗口/pacing 完整验收。
|
||||
- 当前 GLES frontend 的版本/precision 等能力尚不能当完整 GLES 支持;`GL_VERSION` 仍 desktop 4.6,precisionformat 有 stub。KWin 优先 desktop GL,但 Plasma QtQuick 必须实际验证。
|
||||
- GLX 草稿仅让 glxinfo 的 X drawable 可以用远端 pbuffer查询;**没有 X11 readback/present,所以不能声称通用 GLX 窗口上屏**。
|
||||
- Surface loss 当前会结束活动 session;无损挂起/重连尚未实现。
|
||||
|
||||
## 设备与容器:只操作 HA27Q3LQ
|
||||
|
||||
```text
|
||||
ADB serial: HA27Q3LQ
|
||||
型号: Lenovo Y700 TB321FU
|
||||
root: 可用,su context u:r:su:s0
|
||||
SELinux: Enforcing
|
||||
Droidspaces: v6.4.5
|
||||
CLI: /data/local/Droidspaces/bin/droidspaces
|
||||
clone: /data/local/Droidspaces/Containers/arch-kde-mgl
|
||||
mount root: /mnt/Droidspaces/arch-kde-mgl
|
||||
desktop user: swung0x48,uid1000
|
||||
clone UUID: bc34a4c0a69e424a8890836ed61e4a1d
|
||||
clone init PID: 27123(继续前重新确认)
|
||||
boot_id: 3f4027fc-50de-400a-8751-cc925d61e99d
|
||||
```
|
||||
|
||||
有另外三台 ADB 设备,所有命令必须带 `-s HA27Q3LQ`。设备多次短暂 offline,`adb -s HA27Q3LQ reconnect` 后恢复;uptime 与 boot_id 证实没有重启。不重启全部 adb server、不操作其他设备。
|
||||
|
||||
原 `arch-kde` 保持停止、配置未改。clone 从其 128GiB sparse ext4 image 拷贝约 7.7GB allocated extents;因为 Toybox/Busybox 不支持 `conv=sparse`,用 NDK SEEK_DATA/HOLE helper。不要重复全量复制。
|
||||
|
||||
clone Mesa 基线曾实测:freedreno FD750,OpenGL 4.6 Mesa 26.3.0,1280×800、scale2、120Hz。这是 **Mesa 基线,不是 MobileGL 成果**。
|
||||
|
||||
仅 clone 安装过构建依赖 GCC16.1.1/cmake/ninja/base-devel;没有 clang。clone 的 patched Xwayland `24.1.13-1.1` 为安装依赖降到仓库 `-1`,原容器未动。实验 backend 对 Xwayland 使用 `-shm` 并清除其 MobileGL loader 环境。
|
||||
|
||||
### 当前停止状态与目录 bind
|
||||
|
||||
clone 仍运行,`desktop-session.service`、`mobilegl-kwin-build.service` 均 inactive/dead(构建 ExecMainStatus=0),没有实验 KWin/Plasma/Konsole/MobileGL server 运行。
|
||||
|
||||
已在 clone config 追加:
|
||||
|
||||
```text
|
||||
bind_mounts=/data/local/tmp/display_daemon.sock:/run/display.sock,/data/local/tmp/anland-mobilegl:/run/anland-mobilegl
|
||||
```
|
||||
|
||||
配置备份:`/data/local/Droidspaces/Containers/arch-kde-mgl/container.config.mobilegl-before`。
|
||||
|
||||
**追加的目录 bind 尚未生效:clone 没有重启。** 使用目录 bind 是为了 daemon unlink/recreate socket 时不留下 file-bind 的旧 inode。
|
||||
|
||||
clone service override 已准备、尚未启动:
|
||||
|
||||
```text
|
||||
/etc/systemd/system/desktop-session.service.d/mobilegl.conf
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/opt/mobilegl/bin/mobilegl-startup.sh compositor
|
||||
Environment=ANLAND_SOCKET=/run/anland-mobilegl/display.sock
|
||||
```
|
||||
|
||||
原 service 的 `User=swung0x48`、`PAMName=login` 保留。单纯 `droidspaces --user=... run` 不会建立正常 logind/user D-Bus session,Plasma mode 要借此 service 或等效正常登录。
|
||||
|
||||
实验 display daemon 已启动(不是 MobileGL renderer,只是原有协议 broker):
|
||||
|
||||
```text
|
||||
host socket: /data/local/tmp/anland-mobilegl/display.sock
|
||||
binary: /data/adb/modules/anland-daemon/display_daemon
|
||||
log: /data/local/tmp/anland-mobilegl/display-daemon.log
|
||||
实验 PID: 13993(继续前确认)
|
||||
原 daemon PID: 2315,socket /data/local/tmp/display_daemon.sock(未停止)
|
||||
```
|
||||
|
||||
实验 APK 启动时 `--es socket_path /data/local/tmp/anland-mobilegl/display.sock`;KWin 使用容器 `/run/anland-mobilegl/display.sock`,在目录 bind 生效后才成立。
|
||||
|
||||
### Android 安装与尚未解决的权限
|
||||
|
||||
原有 `com.anland.consumer`(uid10253)、`com.anlandnext`、`com.droidspaces.app` 未覆盖。
|
||||
|
||||
已并排安装实验 APK `com.anland.consumer.mobilegl`(uid10269)。安装的是**早期双 Service 草稿**,不是最新 source 的生命周期修正版。它启动后因没有 KernelSU root grant,socket root helper 探测失败,转到 Settings;PID12420。**没有 MobileGL renderer 启动、没有 GPU 连接测试。**
|
||||
|
||||
KernelSU `ksud profile` CLI 仅支持 sepolicy/template,没有直接 root allow grant。已查 manager 对应源码,GET/SET_APP_PROFILE ioctl 是 manager UID 专用,root 本身也不能直接调用。授予实验包权限仍未解决;没有编辑 opaque allowlist,没有改变 manager 注册,没有完成 grant。
|
||||
|
||||
对应 upstream SHA `4d396fda53e510d75f2608a184df56ccd33aac9c`。临时源在 `C:\Users\Swung0x48\AppData\Local\Temp\anland-mobilegl-device`,包括 `manager-ksu.h`、`manager-ksu.cc`、`kernel-supercalls.c`、`kernel-manager.h`、`kernel-allowlist.c`、`ksucalls.rs`、`app_profile.h`。普通 `ksu.h` 被 kernel版本覆盖,用户态ABI应读 `manager-ksu.h`。ioctl11/12分别 GET/SET_APP_PROFILE,only_manager 检查 current UID。尚未编译/执行profile mutation helper。
|
||||
|
||||
Android 全局 Enforcing,但已安装 Droidspaces module 的 `sepolicy.rule` 包含 `permissive droidspacesd`。这不是本任务设置的。该 module 已有双向 fd use 与部分 unix_stream read/write 规则。容器 → APK abstract socket、SCM_RIGHTS/memfd 的实际 AVC 尚未采集。不要先全局 setenforce0;待统一 server 上线后精确实测。
|
||||
|
||||
## 构建产物、日志、复用方法
|
||||
|
||||
### WSL
|
||||
|
||||
发行版名称 **`archlinux`**,16CPU、约14GiB RAM。
|
||||
|
||||
```powershell
|
||||
wsl -d archlinux -- bash -lc '...'
|
||||
```
|
||||
|
||||
Linux NDK `/root/builds/android-ndk-r27c`(27.2.12479018),Linux Android SDK `/root/anland-mgl-sdk`,JDK17 task-specific 使用(默认 JDK25 未改)。
|
||||
|
||||
Windows Gradle 在 Zulu21 和 Android Studio jbr 都因 `PipeImpl/WEPollSelector` AF_UNIX “Invalid argument” 在 daemon 前失败,属于本机 Java 环境。**已用 WSL JDK17 成功构建,不要再次浪费时间试 Windows flags。**
|
||||
|
||||
WSL 直接联网曾超时,Windows 下载可用。task-local CONNECT relay:
|
||||
|
||||
```text
|
||||
脚本: C:\Users\Swung0x48\repos\anland-legacy-mobilegl-unified\build\windows_build_proxy.py
|
||||
Windows listener: 127.0.0.1:18081
|
||||
Python PID at snapshot: 29096
|
||||
exec session originally: 75964
|
||||
```
|
||||
|
||||
Gradle/sdkmanager 配置 HTTP/HTTPS proxy `127.0.0.1:18081`,没有改变主机全局设置。复用前查进程;任务结束可停止这个明确的 helper。
|
||||
|
||||
### Android MobileGL
|
||||
|
||||
```text
|
||||
build: /root/anland-mgl-build/android
|
||||
configure log: /root/anland-mgl-configure.log
|
||||
build log: /root/anland-mgl-android-build.log
|
||||
arm64-v8a / android-26 / c++_static / Release / split ON
|
||||
targets: MobileGL MobileGLServer
|
||||
```
|
||||
|
||||
493 actions 构建成功。stripped `libMobileGL.so` 约17.6MB(unstripped约329MB)。8 个 embedded ABI exports 经 dynamic nm 验证。
|
||||
|
||||
anland 打包 dist:
|
||||
|
||||
```text
|
||||
C:\Users\Swung0x48\repos\FoldCraftLauncher\MobileGL\build\anland-dist
|
||||
/mnt/c/Users/Swung0x48/repos/FoldCraftLauncher/MobileGL/build/anland-dist
|
||||
```
|
||||
|
||||
当前 dist 含 libMobileGL.so、libMobileGLServer.so、EmbeddedServer.h;它是旧架构构建,**后续需重新构建统一 runtime**,不要盲用旧二进制。
|
||||
|
||||
最新读取 Android generated/MGGitHash.h:stamp `32c79f41350186274b6d545083656d564c0ea80f`;native client stamp `a5b463a5`。build 时曾包含未提交源码,stamp 不能证明实际源状态。最终两端使用相同确认 commit 显式 `-DMOBILEGL_BUILD_STAMP=<commit>` 重新构建,并验证 wireFingerprint,不要忽略 build drift。
|
||||
|
||||
一次 WSL shell quote 失误曾留下 `/libMobileGL.so`、`/libMobileGLServer.so`、`/EmbeddedServer.h` 任务残留,正确定向产物已复制到 dist。若清理只清这些明确文件,不广泛清理 `/`。
|
||||
|
||||
### Android anland APK
|
||||
|
||||
```text
|
||||
C:\Users\Swung0x48\repos\anland-legacy-mobilegl-unified\consumers\anland_v5\android_consumer
|
||||
artifact: app\build\outputs\apk\plain\debug\app-plain-debug.apk
|
||||
```
|
||||
|
||||
bundled APK 已构建成功,ZIP 验证包含 MobileGL 与 Anland JNI(APK压缩约7.38MB)。最新 session96573 已结束:BUILD SUCCESSFUL,28秒,42tasks。较新的 build artifact 包含生命周期修正,但**没有装到设备**;仍含被否定 AppsService。Android source没有比该APK更新的改动,AppsService removal补丁没有生效。
|
||||
|
||||
最新 APK:2026-10-01 13:07:18,7,381,976 bytes,SHA256 `CD15C203226AFB95D1464DDB0B52DD232FFFA22392794E3C086E8F09EB4D7772`。JVM测试11suites、98tests、0failure/error/skipped;这是现有逻辑测试,不能验证统一Service或GPU。
|
||||
|
||||
已有可复用构建脚本及日志:
|
||||
|
||||
```powershell
|
||||
wsl.exe -d archlinux -- bash /mnt/c/Users/Swung0x48/repos/anland-legacy-mobilegl-unified/build/build_bundled_apk.sh
|
||||
```
|
||||
|
||||
脚本固定JDK17/SDK/proxy/gitpaths,调用GradleWrapperMain。WSL日志 `/root/.gradle/daemon/8.11.1/daemon-256044.out.log`,HTML报告 `app/build/reports/tests/testPlainDebugUnitTest/index.html`。无activeGradle/Java build。
|
||||
|
||||
生命周期仍待复核:Worker.onDestroy没有join server thread;detach/uninstall 3秒超时返回值处理弱;load/install部分失败的清理未验证。随统一server设计处理,不能认为上述Surface修复已涵盖完整shutdown。
|
||||
|
||||
Gradle properties 是:`-PmobileglDist=...`、`-PanlandNdkVersion=27.2.12479018`、`-PmobileglApplicationId=com.anland.consumer.mobilegl`。**不是 `anlandApplicationId`**。
|
||||
|
||||
```sh
|
||||
MOBILEGL_DIST=/mnt/c/Users/Swung0x48/repos/FoldCraftLauncher/MobileGL/build/anland-dist \
|
||||
./gradlew :app:assemblePlainDebug :app:testPlainDebugUnitTest \
|
||||
-PanlandNdkVersion=27.2.12479018 \
|
||||
-PmobileglApplicationId=com.anland.consumer.mobilegl
|
||||
```
|
||||
|
||||
WSL 读 Windows worktree `.git` 文件的 `C:/...` path 有问题。Gradle版本追踪用明确 `GIT_DIR`/`GIT_WORK_TREE` 指向 `/mnt/c/...`,不要把运行成功但版本为 unknown 的结果当最终可追溯产物。
|
||||
|
||||
### 容器 client
|
||||
|
||||
```text
|
||||
/root/mobilegl-unified-src
|
||||
/root/mobilegl-unified-build
|
||||
/root/anland-build-client.sh
|
||||
/root/mobilegl-unified-client-build.log
|
||||
```
|
||||
|
||||
GCC Release split ON、LTO OFF、`ninja -j4` 构建完成并安装:
|
||||
|
||||
```text
|
||||
/opt/mobilegl/lib/libMobileGL.so # 约21MB
|
||||
/opt/mobilegl/lib/libEGL.so(.1) # aliases
|
||||
/opt/mobilegl/lib/libGL.so(.1) # aliases
|
||||
/opt/mobilegl/share/glvnd/egl_vendor.d/50_mobilegl.json
|
||||
```
|
||||
|
||||
JSON library_path 指向 `/opt/mobilegl/lib/libMobileGL.so`。当前 source tar 不是完整 git checkout,源码更新需要同步;此前 tar 过宽排除 `build`/`test` 曾漏 xxHash/build/cmake 与 spirv-tools/test,已经补齐。
|
||||
|
||||
client 曾在 ADB offline 时中止,之后 nohup 恢复;**当前构建完成,不要重复全量 build**。最终统一状态改动需要增量同步与重构建。
|
||||
|
||||
诊断程序 `/opt/mobilegl/bin/anland-egl-smoke` 已编译,source 在 clone `/root/anland-egl-smoke.c` 和 Windows MobileGL `build/anland-egl-smoke.c`。测试 EGL pbuffer、GL renderer、clear/readback RGBA预期64,128,191,255。**从未运行**,不能算通过。
|
||||
|
||||
### 容器 KWin
|
||||
|
||||
```text
|
||||
source/build: /root/mobilegl-build/kwin-6.7.4/build
|
||||
log: /root/mobilegl-build/kwin-build.log
|
||||
installed binary: /opt/mobilegl/kwin/bin/kwin_wayland
|
||||
installed library: /opt/mobilegl/kwin/lib/libkwin.so*
|
||||
helper: /opt/mobilegl/bin/mobilegl-startup.sh
|
||||
```
|
||||
|
||||
full build 1358 actions 通过;uid1000 `--version` 为6.7.4,ldd 验证加载 `/opt/mobilegl/kwin/lib/libkwin.so.6`。实际 build lib 在 **`build/bin`**,不是 `build/lib`。
|
||||
|
||||
执行位曾因 Windows re-tar 丢失:上游 `src/plugins/strip-effect-metadata.py` 已恢复755;不是 C++失败。
|
||||
|
||||
KWin 使用**系统 GLVND + vendor JSON**。只把 rebuilt libkwin目录放 LD_LIBRARY_PATH;不要把 `/opt/mobilegl/lib` 放入 KWin LD_LIBRARY_PATH,抢走 GLVND EGL库。glxinfo 的直接 libGL facade 可单独 scope `/opt/mobilegl/lib`。
|
||||
|
||||
### Host tests
|
||||
|
||||
```text
|
||||
/root/anland-mgl-build/host
|
||||
/root/anland-mgl-build/host-build.log
|
||||
/root/anland-mgl-build/host-server-tests.log
|
||||
/root/anland-mgl-build/test-embedding
|
||||
/root/anland-mgl-build/test-embedding.log
|
||||
```
|
||||
|
||||
20 项测试通过:14 display/ABI、2 Unix pool、3 inprocess、1 parent-death。验证真实 SHM connections/fork/lifetime,**不是实际 GPU 渲染测试**。
|
||||
|
||||
CMake test 子目录早于 server target,显式构建 `MobileGLServer`,不能依赖 test target自动构建它。host clang22构建已完成,无 active cmake/ninja/test/server任务。
|
||||
|
||||
Host configure 使用本地GoogleTest:`-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=/root/mobilegl-build/_deps/googletest-src`,避免网络clone。已经通过的suite复跑:
|
||||
|
||||
```sh
|
||||
ctest --test-dir /root/anland-mgl-build/host \
|
||||
-R '^(EmbeddedServerTest|ServerDisplayTest|UnixSupervisor|InProcessServer|SupervisorChildren)\.' \
|
||||
--output-on-failure
|
||||
```
|
||||
|
||||
协议测试复跑命令:
|
||||
|
||||
```powershell
|
||||
wsl -d archlinux -- bash /mnt/c/Users/Swung0x48/repos/anland-legacy-mobilegl-unified/tests/run_mobilegl_surface_exchange.sh
|
||||
```
|
||||
|
||||
## 命令与续接注意事项
|
||||
|
||||
Android/client env(以后统一 endpoint 名称需据新设计修改):
|
||||
|
||||
```sh
|
||||
MOBILEGL_TRANSPORT=spawn
|
||||
MOBILEGL_IPC_DATA=shm
|
||||
MOBILEGL_IPC_CONTROL=unix:@<embedded-endpoint>
|
||||
# compositor: MOBILEGL_IPC_SURFACE=server
|
||||
# applications: MOBILEGL_IPC_SURFACE=offscreen(或清除)
|
||||
```
|
||||
|
||||
`MOBILEGL_TRANSPORT=shm` **无效,会落回 monolith**;`MOBILEGL_IPC_SURFACE=client` 也无效。Listen/serve endpoint是 `@name`,client必须 `unix:@name`。
|
||||
|
||||
PowerShell 的 adb compound shell command 要保持 su quoting。以下错误写法只让第一条命令成为root:`adb shell su -c 'id; id -Z'`(adb flatten后分号跑到外层)。正确例子:
|
||||
|
||||
```powershell
|
||||
adb -s HA27Q3LQ shell "su -c 'id; id -Z'"
|
||||
```
|
||||
|
||||
更深的嵌套用 literal here-string或 push script,别使用 bash 的 `\"` 去转义 PowerShell字符串:
|
||||
|
||||
```powershell
|
||||
$mglCmd = @'
|
||||
su -c '/data/local/Droidspaces/bin/droidspaces --name=arch-kde-mgl run bash -lc "ls -l /run/display.sock; id"'
|
||||
'@
|
||||
adb -s HA27Q3LQ shell $mglCmd
|
||||
```
|
||||
|
||||
## 推荐续接顺序
|
||||
|
||||
1. 阅读本文、用户原话、kgsl-as-server与调研;检查两个本地 workspaces,保护用户原有dirtysubmodules。不要重复 clone或基线build。
|
||||
2. 首先完成 MobileGL 真正的 session/context/share-group/global-state设计,并移除 anland 应用离屏 Service/forkworker路径与对应旧文档。不要先把旧 APK再次部署来制造进展。
|
||||
3. 保留有用的 embedded ABI、Surface生命周期、无fd显示协议、KWinB路线改动;新增状态/资源生命周期测试要真实覆盖多session、多surface、多context及share-group。
|
||||
4. 增量构建统一 server与client,明确同一源码revision;构建APK并审查再安装。解决实验包 KernelSU rootgrant,待clone安全重启后使目录bind生效,保持原环境。
|
||||
5. Enforcing下采集真实 socket/SCM_RIGHTS/memfd AVC并精确处理;确认 renderer仍在anland自己的进程/UID。
|
||||
6. 先KWin单Surface真正上屏(renderer信息、GPU像素/截图、输入与帧节奏);然后Konsole、eglinfo、glxinfo、Plasma。**不能只用进程存在或版本字符串判成功。**
|
||||
7. 按实际失败修WSI、context共享、resize/Surface loss;记录截图与日志。阶段代码commit、推两个用户指定分支,最终写可复现步骤与真实限制。
|
||||
|
||||
目前没有合入/部署/最终验收请求被拒绝的自动审批。用户已授权实验clone、构建安装、修改、commit/push;除新的明确破坏性动作或确实缺失信息,不要重新索要相同授权。
|
||||
| `56b060c` | 恢复工具链入库 `producers/kde/Arch_v5/mobilegl-tools/`(KernelSU grant helper、源码同步与容器内 client 构建、EGL smoke 探针、设备侧部署/daemon 脚本) |
|
||||
| `1fb419a` | mobilegl-startup.sh:默认 socket 指向实验 daemon(/etc/environment 的 pam_env 会盖掉 systemd drop-in);plasma 模式改走 kwin_wayland_wrapper(BusName=org.kde.KWinWrapper 只在 wrapper 注册,直跑 kwin 90 秒被 systemd 杀);KWin 直写 surface 不加 FlipY(此前画面上下颠倒);sync-build-kwin.sh 容器侧 canonical 同步/增量构建/原子安装管线 |
|
||||
| `118ae52` | `MOBILEGL_BACKEND_TYPE=DirectGLES`(Espryt 只是别名,写错会被 pinned-backend 拒);eglChooseConfig 收 count≥1(MobileGL 默认有两份配置);compositor client 日志落文件 |
|
||||
| `da03d3b`/`35699f3` | consumer flap 时不再停 compositor;APK consumer 侧不再因 Surface 生命周期事件重启 native 管线 |
|
||||
| `33e496c` | 统一内嵌 server 宿主:`:mobilegl` Service 单 endpoint `@anland-mobilegl`;移除被否定的 MobileGLAppsService/按应用 fork 路径 |
|
||||
| `2ffa1f5` | KWin anland backend 的 `ANLAND_MOBILEGL=1` 路径(跳过 GPU/DRM probing,server-owned window) |
|
||||
| `6e1fa65` | 无 fd 的 MobileGL Surface 显示协议(DATA_MSG_MOBILEGL_SURFACE=201) |
|
||||
|
||||
## 真机已验证(TB321FU,HA27Q3LQ)
|
||||
|
||||
以实际画面/输出为准:
|
||||
|
||||
- **链路绿屏**:client clear → server(Adreno 750 厂商驱动)→ Android Surface → 屏幕,截图可见(win-smoke,60 帧 swap 无错误)。
|
||||
- **egl-smoke**:pbuffer + clear + readback RGBA 精确(64,128,191,255)。
|
||||
- **eglinfo**:GLVND vendor JSON 正常,EGL 1.5,两组配置。
|
||||
- **glxinfo / glmark2(X11)**:经 glvnd 的 MobileGL GLX vendor,不需 `LD_LIBRARY_PATH`;glxinfo 报 Espryt (Adreno 750) GL 4.6;glmark2(X11 窗口经 Xwayland)画面正确上屏,shading 场景约 280 fps;glmark2-wayland / glmark2-es2-wayland 正常且退出无报错。
|
||||
- **KWin 6.7.4**:合成器存活并呈现(黑桌面+光标可见)。
|
||||
- **Konsole**:窗口完整正确渲染(标题栏、工具栏、shell 提示符,方向正确)。
|
||||
- **多 session**:两个 win-smoke 连续运行同一窗口均 exit 0(stale surface 修复生效)。
|
||||
- **Chrome 跑在 MobileGL 上(2026-10-02)**:会话的 Chrome 启动项(`mobilegl-startup.sh chrome`,plasma 模式写入用户级 `google-chrome.desktop` 覆盖)用 `--use-gl=angle --use-angle=gles --in-process-gpu --render-node-override=<不存在的节点> --disable-features=WaylandFractionalScaleV1`:ANGLE 报 `ANGLE (MobileGL-Dev…, Espryt…, OpenGL 4.6.0 MobileGL…)`,GPU 合成开启,标签栏/工具栏/网页正确合成,缩放正确。为什么这样配:Chrome 的独立 GPU 进程在 Wayland 上只能经 GBM dma-buf 上屏(MobileGL 与本 KWin 都不收),放进浏览器进程后改走 wl_egl_window(MobileGL 的 wl_shm 呈现);该路径下 Chrome 不发 fractional-scale 的 viewport,整数缩放才会发 `set_buffer_scale`。此前镜像自带的 `/usr/local/bin/google-chrome` 是 `--use-angle=vulkan` + renderD128,走的是容器里的 Turnip。
|
||||
- **Plasma 桌面可用(2026-10-02,`ccf8eb65`:server 与容器 client 同源)**:壁纸、面板、托盘、时钟、桌面图标、Kickoff 开始菜单、通知窗口都正确渲染;鼠标/触摸输入可用(点击打开 Kickoff);KWin 过渡动画正常;开/关托盘弹窗不再花屏;按返回键收起快捷键栏时输出 resize 跟随。三线程/三 context/三 surface 并发回读探针(`anland-egl-mt-readback-probe.c`)与大纹理分块上传探针(`anland-egl-upload-probe.c`)全过。
|
||||
- **Plasma 会话(早期,`30fef23d` 的 server + `ff212061` 的容器 client)**:`desktop-session.service` 持续 active(>1 分钟,此前约 7 秒必拆);面板完整渲染(启动器、固定应用、托盘、时钟);光标尺寸正常;多个 session 并发、逐个 reap 而其余继续服务。截图里壁纸有横向条带错位(见下面第 1 条)。
|
||||
|
||||
## 未完成 / 已知问题(按优先级)
|
||||
|
||||
1. **Plasma:桌面已落地、基本可用,剩余问题**(按优先级):
|
||||
- ~~启动 Chrome 时 KWin 崩溃~~ 已修(anland `kwin.patch`):无 DRM 设备分支里 `waylandServer()->linuxDmabuf()` 会创建 linux-dmabuf global,而空 tranche 不建格式表,Chrome 请求 default feedback 时 KWin 解引用空表(`LinuxDmaBufV1FeedbackPrivate::send` → `FileDescriptor::get`)。现在该分支不碰 dmabuf,client 回落 wl_shm;Chrome 新标签页正常渲染。KWin shim 现在在 `/tmp/kwin-cores/<pid>/` 下运行,core 不会再被覆盖。
|
||||
- **某个 client 退出时 KWin 偶发 SEGV**(rc=139,core 被覆盖未取到);KWin 在 server 进程被杀时也会 SEGV(设备丢失路径),后者是预期外但可接受。
|
||||
- **ksplash 启动动画闪黑**:开机时 ksplash 帧间偶有整帧黑;单独 `ksplashqml --test` 在会话内不复现。约 13–15 fps(每帧 2560x1412 全尺寸回读 + wl_shm + KWin 重新上传),见第 3 条。
|
||||
- 合成成本:每个 Wayland 窗口每帧整幅 glReadPixels(2 MiB 一片)+ KWin 整幅 glTexSubImage,是当前帧率上限。
|
||||
- DirectGLES 里少量进程级「容器」对象(resolve FBO、scratch FBO、XFB helper、timer query 探测)不在 share group 里共享,多 session 交替使用时理论上会拿到别的 context 的名字——尚未观察到症状。
|
||||
- **Chrome 剩余渲染问题**:WebGL 画布不显示(get.webgl.org 的立方体区域空白、aquarium 只有底色,fps 计数正常),工具栏两个扩展图标是黑块;两边日志都无报错,待查(怀疑 shared image 的某种格式/swizzle 或画布合成路径)。
|
||||
- **锁屏界面花屏**:`kscreenlocker_greet`(空闲约 5 分钟自动锁屏)背景是噪点、时钟重复三份,疑似 1x1→2560x1412 resize 后读回尺寸/步长不对;锁屏后只能输密码,复现时用 `loginctl lock-session` / `unlock-session`。
|
||||
2. **光标巨大化**:2026-10-02 的 Plasma 会话截图里光标尺寸正常,未再复现;若再现,查 output scale 与 cursor layer 的 buffer scale。
|
||||
3. **CPU blit 禁令**:用户明确要求最终形态上屏路径无 CPU blit——当前 Wayland wl_shm client 走 readback(`32c79f41`),只是过渡。目标:应用窗口内容也由 server 在 GPU 侧直接给 KWin 合成(server 侧 GPU buffer → 同进程共享给 compositor 的 share group → 合成上屏),不经过 CPU 回读。设计要进 11-state-ownership.md 的后续切片。
|
||||
4. **GLX 上屏是 CPU 回读**:每帧整幅 glReadPixels + `xcb_put_image`,同第 3 条的过渡方案;只处理 24/32 位深窗口;直接拿 X 窗口(未经 glXCreateWindow)当 drawable 的 surface 不会随窗口销毁回收。
|
||||
5. **surface loss**:Wayland 窗口 resize 已跟随(`ccf8eb65`);surface loss 仍结束活动 session(无损挂起未实现);server 进程被杀后,新进程下 KWin 拿不到窗口 surface(KWin 不会重连,需重启会话)。
|
||||
6. **AVC 审计未做**:全程在 Enforcing 下跑通(容器侧有 droidspacesd 的既有 permissive 规则),SCM_RIGHTS/memfd 的精确 AVC 采集没做。
|
||||
7. **wire stamp 漂移**:容器构建的 `MGGitHash.h` 因 tar 无 .git 而陈旧(日志 WARN "compatible wire with different build");两端应同 commit + 显式 `-DMOBILEGL_BUILD_STAMP` 重建。
|
||||
|
||||
## 设备与环境要点(复现用)
|
||||
|
||||
- 设备 HA27Q3LQ(Y700 TB321FU),clone `arch-kde-mgl`(arch-kde 保持不动),容器内 `/opt/mobilegl/{lib,bin,kwin}`。
|
||||
- **KernelSU grant**:`ksud profile` 无直授命令;管理器专属 ioctl 的解法:root 下 setuid 到 manager UID(10255)→ `reboot(0xDEADBEEF,0xCAFEBABE)` 拿 `[ksu_driver]` fd → `SET_APP_PROFILE`。helper 源码在 anland `producers/kde/Arch_v5/mobilegl-tools/ksu_grant.c`。已持久化进 `/data/adb/ksu/.allowlist`。
|
||||
- 实验 daemon:独立实例 `display_daemon /data/local/tmp/anland-mobilegl/display.sock`(原 daemon 不动);socket 需 666、目录 777(容器内 uid1000 要连)。
|
||||
- clone config 的目录 bind:`/data/local/tmp/display_daemon.sock:/run/display.sock`、`/data/local/tmp/anland-mobilegl:/run/anland-mobilegl`。
|
||||
- KWin 启动:`desktop-session.service` + drop-in ExecStart=mobilegl-startup.sh compositor|plasma;Qt 日志默认只出 warning(info 要 QT_LOGGING_RULES)。
|
||||
- **当前设备上的 server 库是手工替换的**:`libMobileGL.so` 直接 root 覆盖到已装 APK 的 `/data/app/.../lib/arm64/`(保留 owner/SELinux context,原件备份在 `/data/local/tmp/anland-mobilegl/libMobileGL.so.orig`)。这样不用重签 APK(换签名要卸载重装,UID 会变,KernelSU grant 要重做)。本机构建:NDK 27.2 + `cmake -DCMAKE_TOOLCHAIN_FILE=.../android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-26 -DMOBILEGL_BUILD_DISAGGREGATED=ON -DMOBILEGL_BUILD_DISAGGREGATED_INPROC=ON -DMOBILEGL_BUILD_STAMP=<commit>`,`llvm-strip --strip-debug` 后推送。
|
||||
- **复现用探针**(anland `producers/kde/Arch_v5/mobilegl-tools/`):`anland-egl-upload-probe.c`(2560x1412 纹理整幅 + 跨分片的局部 TexSubImage 回读校验)、`anland-egl-mt-readback-probe.c`(三线程各自 context/pbuffer 并发绘制+整幅回读);在容器里以 swung0x48 身份、带 MobileGL 的 `__EGL_VENDOR_LIBRARY_FILENAMES`/`MOBILEGL_*` 环境运行。注入点击要用 `input mouse tap`(anland 抓了触摸屏 EVIOCGRAB,`input tap` 无效);不要对容器进程用 `debuggerd -b`(发 signal 35,glibc 进程直接被杀)。
|
||||
- **Chrome/ANGLE 排查手段**:`--gpu-launcher=<脚本>` 包 GPU 进程(strace 每进程 `-o file.$$`,Chrome 会多次重启 GPU 进程);ANGLE 只 `dlsym` 一个 `eglGetProcAddress`,其余入口全经它取,LD_PRELOAD 拦 `dlsym` 再包 `eglGetProcAddress` 才能看到 display 调用;headless Chrome + `--remote-debugging-port` + CDP `SystemInfo.getInfo` 能拿到 GL_RENDERER/扩展列表/featureStatus(`--dump-dom chrome://gpu` 在 headless 下拿到的是新标签页)。user manager 里 PAM 带进来的 Mesa/KGSL 变量 `systemctl --user unset-environment` 删不掉(返回 0 但无效),对 MobileGL 会话无害。
|
||||
- **诊断用的容器改动**:`/opt/mobilegl/kwin/bin/kwin_wayland` 现在是 shim(设 `MOBILEGL_LOG_FILE_PATH=/tmp/mgl-kwin-$$.log` 后 exec `/opt/mobilegl/kwin/real/kwin_wayland`;真二进制必须仍叫 `kwin_wayland`,否则 KWin 内置 QPA 插件拒绝加载);`~swung0x48/.config/systemd/user/plasma-plasmashell.service.d/mobilegl-log.conf` 给 plasmashell 单独日志 `/tmp/mgl-plasmashell.log`。MobileGL 打开日志是截断写,所以必须每进程一个文件。
|
||||
- 构建(之前那台机器的环境,本机没有 `/root/anland-mgl-build` 也没有 gitignored 的 `build_bundled_apk.sh`;APK 按 `consumers/anland_v5/android_consumer/MOBILEGL.md` 用 gradle + `MOBILEGL_DIST` 构建):Android dist 用 WSL(NDK r27c,stamp 显式指定);APK 用 anland worktree 的 `build/build_bundled_apk.sh`;容器 client 用 `producers/kde/Arch_v5/mobilegl-tools/anland-sync-source.sh build`(`MOBILEGL_REPO` 指向已 init 子模块的 MobileGL worktree;注意 `tools/trace_replay` 789MB 必须排除)。
|
||||
- 设备 30 秒无操作熄屏——熄屏可能 kill SurfaceView;长跑验证前 `svc power stayon true` 或调 screen_off_timeout。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"abort_sites": 78,
|
||||
"abort_sites": 77,
|
||||
"abort_sites_by_file": {
|
||||
"MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp": 14,
|
||||
"MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp": 13,
|
||||
"MobileGL/MG_Backend/DirectGLES/Managers.cpp": 12,
|
||||
"MobileGL/MG_Backend/DirectGLES/MultiDraw.cpp": 2,
|
||||
"MobileGL/MG_Backend/DirectGLES/Utils.cpp": 1,
|
||||
|
||||
Reference in New Issue
Block a user