[Duplicate] glDeleteSemaphoresEXT stalls ~45 ms on every 512th delete of an imported semaphore (EGL/GLES, Linux)

Summary

With the NVIDIA EGL/GLES driver, deleting GL semaphores that were imported from Vulkan with
GL_EXT_semaphore_fd is deferred. On every 512th glDeleteSemaphoresEXT, the driver frees all
512 pending semaphores synchronously inside that one call. The call takes 42–66 ms; every other
delete takes ~0 ms.

Creating, importing, waiting on and deleting one semaphore per frame is a common interop pattern.
For example, Chromium does it to hand a WebGPU (Vulkan) canvas to its GL compositor. The result
is a periodic dropped-frame hitch: in Chrome and Brave on Wayland, a WebGPU page that draws a
single triangle freezes for ~45 ms every ~256 frames (about once a second at 240 Hz).

The same work done in Vulkan (import into a VkSemaphore, wait, destroy) costs about the same
per semaphore (~0.09 ms), but it is paid at destroy time, so it never stalls.

System

  • GPU: GeForce RTX 3080 (GA102), VBIOS 94.02.26.40.95
  • Driver: 595.99.02, open kernel module, GSP firmware 595.99.02
  • OS: Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic
  • Session: GNOME on Wayland (mutter 50.1). The repro below uses the EGL device platform and needs no
    window system.

Repro

gcc -O2 -o semrepro semrepro.c -lEGL -lGLESv2 -lvulkan
./semrepro 2100 0 full

Each iteration does the following:

  1. create an exportable VkSemaphore (OPAQUE_FD)
  2. signal it with a vkQueueSubmit
  3. vkGetSemaphoreFdKHR
  4. in a GLES 3.2 context: glGenSemaphoresEXT, glImportSemaphoreFdEXT(GL_HANDLE_TYPE_OPAQUE_FD_EXT),
    glWaitSemaphoreEXT, glFlush, glDeleteSemaphoresEXT
  5. vkQueueWaitIdle, vkDestroySemaphore

Output:

Vulkan device: NVIDIA GeForce RTX 3080
EGL 1.5 vendor=NVIDIA
GL_RENDERER=NVIDIA GeForce RTX 3080/PCIe/SSE2
slow frame   511: total  58.84 ms  (vk  0.55, import+wait  0.27, delete  58.03)
slow frame  1023: total  46.02 ms  (vk  0.83, import+wait  0.14, delete  45.05)
slow frame  1535: total  46.29 ms  (vk  0.36, import+wait  0.13, delete  45.81)
slow frame  2047: total  46.10 ms  (vk  0.41, import+wait  0.15, delete  45.54)

Variants (2100 iterations each)

mode what changes deletes ≥ 10 ms avg delete
full as above 4 (iterations 511, 1023, 1535, 2047; max 58 ms) 0.10 ms
leak never delete the GL semaphore 0 –
genonly gen + delete, no import 0 0.00 ms
glonly one VkSemaphore for the whole run; a new fd exported and imported each frame 0 0.00 ms
vkimport import the fd into another VkSemaphore, wait, vkDestroySemaphore (no GL) 0 0.09 ms
full, keep=16 delete each GL semaphore 16 frames later 2 (every 512) 0.08 ms
full, 4 ms sleep per frame paced like a 240 Hz app 2 (every 512) 0.09 ms

The stall depends only on the number of deleted imported semaphores. Frame pacing and delete
latency don’t change it.

What happens during the stall

Under strace, the stalling glDeleteSemaphoresEXT makes hundreds of RM calls on /dev/nvidiactl.
Per freed semaphore there are about:

  • 2 × _IOC(0x46, 0x29)
  • 1 × _IOC(0x46, 0x4f)
  • 1 × _IOC(0x46, 0x58)
  • 1 × munmap

Nearly all of the time is spent in these ioctls. Each import opens /dev/nvidiactl, mmaps and
allocates RM objects; these are released only in the batch.

In Chromium (Chrome 145–156, Brave 156; Ozone Wayland, ANGLE on GL, WebGPU on Vulkan) we see the
same signature: the batch runs inside ANGLE’s SemaphoreGL::onDestroy → glDeleteSemaphoresEXT
on the GPU main thread. It blocks SkiaOutputSurfaceImplOnGpu::SwapBuffers for 40–60 ms every
~256 presented frames. WebGL2 content, which uses no semaphore interop, has no hitches.

Expected

Deleting an imported semaphore should not periodically block for tens of milliseconds. The
cleanup could be done per semaphore (as the Vulkan driver effectively does), incrementally, or off
the calling thread.

Questions

  • Is the batch size (512) or the deferral configurable?
  • Is there a recommended way to reuse imported GL semaphores across frames?

Attachments

semrepro.c (uploaded as .txt because .c files are not allowed here):

semrepro.c.txt (10.0 KB)

Closing as a duplicate of 615.71.09: glDeleteSemaphoresEXT blocks for ~16 ms on every 512th call (GL_EXT_semaphore_fd) (tracked internally as bug 6931032), which reports the same behaviour on 615.71.09. I have added the details from this thread there: it also happens on 595.99.02, and Chromium’s WebGPU on Wayland runs into it every ~256 frames.