Sync upstream changes#6
Open
github-actions[bot] wants to merge 42 commits into
Open
Conversation
Several glibc functions now return a const pointer if the input is a const pointer and a non-const pointer if the input is non-const, causing a build failure. Fix this by declaring the output pointers as const if they are never modified, and for the lone failure where the output is modified, instead make the input non-const. Signed-off-by: Maximilian Hofmann <maxi@maxiicodes.dev> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1599>
The UDMABUF option takes precedence over the GBM option. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1604>
Using SOCK_CLOEXEC and MSG_CMSG_CLOEXEC are good practice for socket communication, but venus client/server model doesn't involve any racy exec on parallel threads. Meanwhile, the ad-hoc server forked from the proxy client is after socket pair, and we manually close up corresponding fds on both client and server side. As for passing resource fds via socket, there's no requirement to set FD_CLOEXEC both internally and towards the virgl resource side. Just to ease MacOS adoption. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1603>
The same issue happened in Mesa https://gitlab.freedesktop.org/mesa/mesa/-/commit/9f1a4461074f117ed124b1d6086624ac4da0e6a1 Signed-off-by: Sergi Blanch Torne <sergi.blanch.torne@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1598>
We do not have signalfd() in macOS so we use kqueue() to listen for SIGCHLD. Also do not include <threads.h> when we do not have ENABLE_RENDER_SERVER_WORKER_THREAD. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
macOS does not have clock_nanosleep() Co-authored-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
macOS does not support SOCK_SEQPACKET so we have to make use of SOCK_STREAM. That means we have to take care of framing. Thankfully, the SCM_RIGHTS buffer will always be complete and ordered so we send that with a header indicating the number of bytes for the packet followed by the packet. Co-authored-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
When the peer closes the socket (e.g. QEMU dies abnormally), recvmsg() returns 0 on SOCK_STREAM. The existing loop only checked for s < 0, so a zero return caused want -= 0 (a no-op) and the loop spun at 100% CPU forever. Add s == 0 checks in both recvmsg and sendmsg paths of render_socket and proxy_socket, returning false to signal disconnection. This lets the render server exit cleanly when QEMU terminates without calling proxy_server_destroy(). Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
kqueue file descriptors do not support fcntl(F_SETFL, O_NONBLOCK)
on macOS. The kqueue code added in "server: add support for building
on macOS" attempted to set O_NONBLOCK this way, which failed silently.
Remove the broken fcntl call. Non-blocking behavior is already
achieved in render_worker_jail_drain_sigchld_fd() via kevent() with
a zero timeout, which is the correct approach for kqueue.
Fixes: eb2b98b4 ("server: add support for building on macOS")
Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
Rename proxy_socket_is_seqpacket and render_socket_is_seqpacket to proxy_socket_is_valid and render_socket_is_valid. The functions now validate the expected socket type per platform: SOCK_STREAM on macOS, SOCK_SEQPACKET elsewhere. This removes the #ifndef __APPLE__ guards at every call site. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1600>
This is to prepare for clean process spawn on non-Linux platforms e.g. MacOS and Windows. Also close the fds before ownership transfer. Inspired from https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1601 Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1607>
This helps skip: - render_worker_jail_create - render_server_run Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1607>
This ensures we don't unexpectedly unset VK_RING_STATUS_IDLE_BIT_MESA when the ring is still idle when spurious wakeups occur. The bug pattern would be driver side stuck in ring seqno progression. This change also properly handles cnd_wait errors. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1610>
The absolute wait target should be update only when real timeout occurs but not spurious wakeups. The bug pattern would be driver side unable to detect heartbeat, ending up with a false-positive ring alive status expiration. The chance to hit this is really low though. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1610>
On macOS, Metal shader compilation uses XPC (Mach port-based IPC). Pure fork() without exec() inherits stale XPC connections from the parent process, causing Metal to fail silently in worker subprocesses. Use posix_spawn() to create worker processes on macOS. posix_spawn() atomically creates a fresh process image without an intermediate forked state, ensuring valid XPC connections for Metal. POSIX_SPAWN_CLOEXEC_DEFAULT closes all file descriptors by default; only the context fd is explicitly inherited via addinherit_np(). The spawned worker receives its context via command-line arguments (--ctx-fd, --ctx-id, --init-flags, --ctx-name) and enters render_context_main() directly, bypassing the server socket loop. Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1601>
The same issue happened in Mesa https://gitlab.freedesktop.org/mesa/mesa/-/commit/0b51ed736d220be926b39bf76b3f4663cc68de78 Signed-off-by: Sergi Blanch Torne <sergi.blanch.torne@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1609>
If Y_0_TOP is not set, we should not flip the cursor data. Downstream consumers like QEMU expect the returned buffer to be the cursor in a format where y=0 is bottom. This fixes a bug where QEMU renders an inverted mouse cursor if using a gl-accelerated display with certain wayland compositors (for example wl-roots based) in the guest. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1611>
When vrend_renderer_init() hits cleanup_and_fail, it calls vrend_renderer_fini(), which in turn calls vrend_free_fences(). vrend_free_fences() asserts that the sync thread has already been freed: qemu-system-i386: ../src/vrend/vrend_renderer.c:7268: vrend_free_fences: Assertion `!vrend_state.sync_thread' failed. This tear sync thread down to avoid above misleading error log. Signed-off-by: Julia Zhang <Julia.Zhang@amd.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1613>
virgl_renderer_resource_map_fixed() was reading res->fd_type and res->fd into local variables before checking whether virgl_resource_lookup() had returned NULL, so a stale or invalid res_handle from a guest would crash the renderer before the -EINVAL early-return could fire. Move the initialisations below the NULL check so the lookup failure returns cleanly. Signed-off-by: Adam Ford <adam.ford@anodize.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1614>
Add macOS-specific dynamic library names for Vulkan loading. Try libvulkan.1.dylib and libvulkan.dylib first (Vulkan SDK loader), then fall back to libMoltenVK.dylib (direct MoltenVK usage). Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Enable Objective-C compilation and link Metal.framework and
Foundation.framework on macOS. These are required for the Metal
helper wrappers that implement cross-process GPU memory sharing
via MTLBuffer.
Add vkr_metal_helpers.h/.m with:
- vkr_metal_get_device(): retrieve the MTLDevice backing a VkDevice
via vkExportMetalObjectsEXT (correct for multi-GPU systems)
- vkr_mtl_shm_alloc()/free(): allocate and release Metal shared
memory (SHM file + mmap + MTLBuffer)
Move the with_host_darwin detection before compiler warning flags
so Objective-C arguments can be set alongside C arguments.
Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com>
Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Detect VK_EXT_external_memory_metal and VK_EXT_metal_objects from MoltenVK's physical device extension list. Skip opaque fd export probing when Metal external memory is available, since MoltenVK does not support opaque fd handles. Inject VK_KHR_external_memory_fd into the guest's view of the physical device extension list so the Mesa Venus driver accepts the device. MoltenVK does not natively support KHR_external_memory_fd; virglrenderer emulates it via Metal buffers backed by POSIX SHM. The injection sets the extension as advertised but does NOT mark physical_dev->KHR_external_memory_fd = true. That flag tracks native host support and is intentionally left false: it gates the host-side vkCreateDevice call, which must not forward KHR_external_memory_fd to MoltenVK (rejected with VK_ERROR_EXTENSION_NOT_PRESENT). Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
lseek() behavior is undefined on POSIX shared memory objects per POSIX.1. On platforms where os_create_anonymous_file() uses shm_open(), lseek() returns -1, breaking the existing size validation. Replace lseek(fd, 0, SEEK_END) with fstat(), which works on all fd types. Also page-align the expected size before comparing, since the server rounds up SHM allocations to page boundaries. Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
macOS lacks memfd_create and SHM_ANON. Add a shm_open() path with random name generation and immediate shm_unlink() to create anonymous shared memory files. Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
Implement cross-process GPU memory sharing via Metal buffers backed by POSIX shared memory. For HOST_VISIBLE allocations on macOS, allocate a page-aligned SHM file, mmap it, wrap as MTLBuffer using the cached vkr_device->mtl_device, and import into Vulkan via VK_EXT_external_memory_metal. The SHM fd is exported as VIRGL_RESOURCE_FD_SHM for the VMM to map into the guest address space. Cache the MTLDevice in struct vkr_device at vkCreateDevice time via vkExportMetalObjectsEXT, which returns the exact MTLDevice backing the VkPhysicalDevice (correct for multi-GPU systems). Page-align SHM allocation in vkr_context_create_resource_from_shm() for hv_vm_map alignment. Signed-off-by: Lucas Amaral <lucaaamaral@gmail.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1602>
When vkCreateInstance fails, the passed VkInstance handle might become non-NULL, which is allowed by the spec. Passing an invalid non-NULL handle to vkDestroyInstance violates the spec, whereas NULL is allowed. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1616>
The temp variables are all marked precise and assigning to the output is usually a indirect mopve in this case, so we should be good here and it avoids creating broken glsl. Closes: https://gitlab.freedesktop.org/virgl/virglrenderer/-/work_items/650 Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1619>
Remove fails that are fixed now. Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1619>
v2 (zzyiwei): roll the exact header used by venus-protocol Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
This also adds vkEnumerateInstanceExtensionProperties support to prepare for portability extension support. Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
MoltenVK requires loading with `VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR` which means that we will detect and load any library with portability enumeration extension. v2 (zzyiwei): - hide portability enumeration enablement behind __APPLE__ - misc refactors and clang-format Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
using raw string drops the dep on the header Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
This is required for MoltenVK to work. v2 (zzyiwei): - no extra guard needed since we have it at instance level - misc refactors Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1621>
…ons match for imported resources Part-of: <https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1615>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated sync from upstream repository