Remove VK_KHR_xlib_surface support XCB is a smaller and more direct interface to the client-side X11 protocol than Xlib, so VK_KHR_xcb_surface should be used instead of VK_KHR_xlib_surface. Bug: swiftshader:170 Change-Id: I9d707e3fd48ba79d6c4b4d5784d3b6a890982016 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61049 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: Nicolas Capens <nicolascapens@google.com> Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5771526..4600d3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -111,7 +111,6 @@ check_symbol_exists(mallinfo2 malloc.h HAVE_MALLINFO2) endif() -find_library(X11 X11) find_library(XCB xcb) if(SWIFTSHADER_BUILD_WSI_WAYLAND) find_library(WAYLAND wayland-client) @@ -771,9 +770,6 @@ if(WIN32) target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_WIN32_KHR") elseif(LINUX) - if(X11) - target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_XLIB_KHR") - endif() if(XCB) target_compile_definitions(vk_base INTERFACE "VK_USE_PLATFORM_XCB_KHR") endif()
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn index 58bc87c..dcf48a6 100644 --- a/src/Vulkan/BUILD.gn +++ b/src/Vulkan/BUILD.gn
@@ -20,7 +20,6 @@ config("swiftshader_libvulkan_private_config") { if (is_linux || is_chromeos) { defines = [ - "VK_USE_PLATFORM_XLIB_KHR", "VK_USE_PLATFORM_XCB_KHR", "VK_EXPORT=__attribute__((visibility(\"default\")))", ]
diff --git a/src/Vulkan/VkGetProcAddress.cpp b/src/Vulkan/VkGetProcAddress.cpp index 0290510..84d666e 100644 --- a/src/Vulkan/VkGetProcAddress.cpp +++ b/src/Vulkan/VkGetProcAddress.cpp
@@ -117,11 +117,6 @@ MAKE_VULKAN_INSTANCE_ENTRY(vkCreateXcbSurfaceKHR), MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceXcbPresentationSupportKHR), #endif -#ifdef VK_USE_PLATFORM_XLIB_KHR - // VK_KHR_xlib_surface - MAKE_VULKAN_INSTANCE_ENTRY(vkCreateXlibSurfaceKHR), - MAKE_VULKAN_INSTANCE_ENTRY(vkGetPhysicalDeviceXlibPresentationSupportKHR), -#endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR // VK_KHR_wayland_surface MAKE_VULKAN_INSTANCE_ENTRY(vkCreateWaylandSurfaceKHR),
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp index 2f8da98..33de5c9 100644 --- a/src/Vulkan/libVulkan.cpp +++ b/src/Vulkan/libVulkan.cpp
@@ -59,10 +59,6 @@ # include "WSI/XcbSurfaceKHR.hpp" #endif -#ifdef VK_USE_PLATFORM_XLIB_KHR -# include "WSI/XlibSurfaceKHR.hpp" -#endif - #ifdef VK_USE_PLATFORM_WAYLAND_KHR # include "WSI/WaylandSurfaceKHR.hpp" #endif @@ -315,9 +311,6 @@ #ifdef VK_USE_PLATFORM_XCB_KHR { { VK_KHR_XCB_SURFACE_EXTENSION_NAME, VK_KHR_XCB_SURFACE_SPEC_VERSION }, [] { return vk::XcbSurfaceKHR::isSupported(); } }, #endif -#ifdef VK_USE_PLATFORM_XLIB_KHR - { { VK_KHR_XLIB_SURFACE_EXTENSION_NAME, VK_KHR_XLIB_SURFACE_SPEC_VERSION }, [] { return vk::XlibSurfaceKHR::isSupported(); } }, -#endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR { { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, VK_KHR_WAYLAND_SURFACE_SPEC_VERSION } }, #endif @@ -3943,27 +3936,6 @@ } #endif -#ifdef VK_USE_PLATFORM_XLIB_KHR -VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) -{ - TRACE("(VkInstance instance = %p, VkXlibSurfaceCreateInfoKHR* pCreateInfo = %p, VkAllocationCallbacks* pAllocator = %p, VkSurface* pSurface = %p)", - instance, pCreateInfo, pAllocator, pSurface); - - // VUID-VkXlibSurfaceCreateInfoKHR-dpy-01313: dpy must point to a valid Xlib Display - ASSERT(pCreateInfo->dpy); - - return vk::XlibSurfaceKHR::Create(pAllocator, pCreateInfo, pSurface); -} - -VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display *dpy, VisualID visualID) -{ - TRACE("(VkPhysicalDevice physicalDevice = %p, uint32_t queueFamilyIndex = %d, Display* dpy = %p, VisualID visualID = %lu)", - physicalDevice, int(queueFamilyIndex), dpy, visualID); - - return VK_TRUE; -} -#endif - #ifdef VK_USE_PLATFORM_WAYLAND_KHR VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
diff --git a/src/WSI/BUILD.gn b/src/WSI/BUILD.gn index 22af89f..3357650 100644 --- a/src/WSI/BUILD.gn +++ b/src/WSI/BUILD.gn
@@ -37,10 +37,6 @@ sources += [ "XcbSurfaceKHR.cpp", "XcbSurfaceKHR.hpp", - "XlibSurfaceKHR.cpp", - "XlibSurfaceKHR.hpp", - "libX11.cpp", - "libX11.hpp", "libXCB.cpp", "libXCB.hpp", ]
diff --git a/src/WSI/CMakeLists.txt b/src/WSI/CMakeLists.txt index 844975d..0e14f95 100644 --- a/src/WSI/CMakeLists.txt +++ b/src/WSI/CMakeLists.txt
@@ -32,15 +32,6 @@ Win32SurfaceKHR.hpp ) elseif(LINUX) - if(X11) - list(APPEND WSI_SRC_FILES - XlibSurfaceKHR.cpp - XlibSurfaceKHR.hpp - libX11.cpp - libX11.hpp - ) - endif() - if(XCB) list(APPEND WSI_SRC_FILES XcbSurfaceKHR.cpp
diff --git a/src/WSI/XlibSurfaceKHR.cpp b/src/WSI/XlibSurfaceKHR.cpp deleted file mode 100644 index 881f436..0000000 --- a/src/WSI/XlibSurfaceKHR.cpp +++ /dev/null
@@ -1,118 +0,0 @@ -// Copyright 2019 The SwiftShader Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "XlibSurfaceKHR.hpp" - -#include "Vulkan/VkDeviceMemory.hpp" -#include "Vulkan/VkImage.hpp" - -namespace vk { - -bool XlibSurfaceKHR::isSupported() -{ - return libX11.isPresent(); -} - -XlibSurfaceKHR::XlibSurfaceKHR(const VkXlibSurfaceCreateInfoKHR *pCreateInfo, void *mem) - : pDisplay(pCreateInfo->dpy) - , window(pCreateInfo->window) -{ - ASSERT(isSupported()); - - int screen = DefaultScreen(pDisplay); - gc = libX11->XDefaultGC(pDisplay, screen); - - XVisualInfo xVisual; - Status status = libX11->XMatchVisualInfo(pDisplay, screen, 32, TrueColor, &xVisual); - bool match = (status != 0 && xVisual.blue_mask == 0xFF); - visual = match ? xVisual.visual : libX11->XDefaultVisual(pDisplay, screen); -} - -void XlibSurfaceKHR::destroySurface(const VkAllocationCallbacks *pAllocator) -{ -} - -size_t XlibSurfaceKHR::ComputeRequiredAllocationSize(const VkXlibSurfaceCreateInfoKHR *pCreateInfo) -{ - return 0; -} - -VkResult XlibSurfaceKHR::getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const -{ - setCommonSurfaceCapabilities(pSurfaceCapabilities); - - XWindowAttributes attr; - libX11->XGetWindowAttributes(pDisplay, window, &attr); - VkExtent2D extent = { static_cast<uint32_t>(attr.width), static_cast<uint32_t>(attr.height) }; - - pSurfaceCapabilities->currentExtent = extent; - pSurfaceCapabilities->minImageExtent = extent; - pSurfaceCapabilities->maxImageExtent = extent; - return VK_SUCCESS; -} - -void XlibSurfaceKHR::attachImage(PresentImage *image) -{ - XWindowAttributes attr; - libX11->XGetWindowAttributes(pDisplay, window, &attr); - - const VkExtent3D &extent = image->getImage()->getExtent(); - - int bytes_per_line = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0); - char *buffer = static_cast<char *>(image->getImageMemory()->getOffsetPointer(0)); - - XImage *xImage = libX11->XCreateImage(pDisplay, visual, attr.depth, ZPixmap, 0, buffer, extent.width, extent.height, 32, bytes_per_line); - - imageMap[image] = xImage; -} - -void XlibSurfaceKHR::detachImage(PresentImage *image) -{ - auto it = imageMap.find(image); - if(it != imageMap.end()) - { - XImage *xImage = it->second; - xImage->data = nullptr; // the XImage does not actually own the buffer - XDestroyImage(xImage); - imageMap.erase(it); - } -} - -VkResult XlibSurfaceKHR::present(PresentImage *image) -{ - auto it = imageMap.find(image); - if(it != imageMap.end()) - { - XImage *xImage = it->second; - - if(xImage->data) - { - XWindowAttributes attr; - libX11->XGetWindowAttributes(pDisplay, window, &attr); - VkExtent2D windowExtent = { static_cast<uint32_t>(attr.width), static_cast<uint32_t>(attr.height) }; - const VkExtent3D &extent = image->getImage()->getExtent(); - - if(windowExtent.width != extent.width || windowExtent.height != extent.height) - { - return VK_ERROR_OUT_OF_DATE_KHR; - } - - libX11->XPutImage(pDisplay, window, gc, xImage, 0, 0, 0, 0, extent.width, extent.height); - } - } - - return VK_SUCCESS; -} - -} // namespace vk \ No newline at end of file
diff --git a/src/WSI/XlibSurfaceKHR.hpp b/src/WSI/XlibSurfaceKHR.hpp deleted file mode 100644 index a0e6aba..0000000 --- a/src/WSI/XlibSurfaceKHR.hpp +++ /dev/null
@@ -1,53 +0,0 @@ -// Copyright 2018 The SwiftShader Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SWIFTSHADER_XLIBSURFACEKHR_HPP -#define SWIFTSHADER_XLIBSURFACEKHR_HPP - -#include "VkSurfaceKHR.hpp" -#include "libX11.hpp" -#include "Vulkan/VkObject.hpp" - -#include <vulkan/vulkan_xlib.h> - -#include <unordered_map> - -namespace vk { - -class XlibSurfaceKHR : public SurfaceKHR, public ObjectBase<XlibSurfaceKHR, VkSurfaceKHR> -{ -public: - static bool isSupported(); - XlibSurfaceKHR(const VkXlibSurfaceCreateInfoKHR *pCreateInfo, void *mem); - - void destroySurface(const VkAllocationCallbacks *pAllocator) override; - - static size_t ComputeRequiredAllocationSize(const VkXlibSurfaceCreateInfoKHR *pCreateInfo); - - VkResult getSurfaceCapabilities(VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) const override; - - virtual void attachImage(PresentImage *image) override; - virtual void detachImage(PresentImage *image) override; - VkResult present(PresentImage *image) override; - -private: - Display *const pDisplay; - const Window window; - GC gc; - Visual *visual = nullptr; - std::unordered_map<PresentImage *, XImage *> imageMap; -}; - -} // namespace vk -#endif // SWIFTSHADER_XLIBSURFACEKHR_HPP
diff --git a/src/WSI/libX11.cpp b/src/WSI/libX11.cpp deleted file mode 100644 index 42e2267..0000000 --- a/src/WSI/libX11.cpp +++ /dev/null
@@ -1,74 +0,0 @@ -// Copyright 2016 The SwiftShader Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "libX11.hpp" - -#include "System/SharedLibrary.hpp" - -#include <memory> - -LibX11exports::LibX11exports(void *libX11, void *libXext) -{ - getFuncAddress(libX11, "XOpenDisplay", &XOpenDisplay); - getFuncAddress(libX11, "XGetWindowAttributes", &XGetWindowAttributes); - getFuncAddress(libX11, "XDefaultScreenOfDisplay", &XDefaultScreenOfDisplay); - getFuncAddress(libX11, "XWidthOfScreen", &XWidthOfScreen); - getFuncAddress(libX11, "XHeightOfScreen", &XHeightOfScreen); - getFuncAddress(libX11, "XPlanesOfScreen", &XPlanesOfScreen); - getFuncAddress(libX11, "XDefaultGC", &XDefaultGC); - getFuncAddress(libX11, "XDefaultDepth", &XDefaultDepth); - getFuncAddress(libX11, "XMatchVisualInfo", &XMatchVisualInfo); - getFuncAddress(libX11, "XDefaultVisual", &XDefaultVisual); - getFuncAddress(libX11, "XSetErrorHandler", &XSetErrorHandler); - getFuncAddress(libX11, "XSync", &XSync); - getFuncAddress(libX11, "XCreateImage", &XCreateImage); - getFuncAddress(libX11, "XCloseDisplay", &XCloseDisplay); - getFuncAddress(libX11, "XPutImage", &XPutImage); - getFuncAddress(libX11, "XDrawString", &XDrawString); - - getFuncAddress(libXext, "XShmQueryExtension", &XShmQueryExtension); - getFuncAddress(libXext, "XShmCreateImage", &XShmCreateImage); - getFuncAddress(libXext, "XShmAttach", &XShmAttach); - getFuncAddress(libXext, "XShmDetach", &XShmDetach); - getFuncAddress(libXext, "XShmPutImage", &XShmPutImage); -} - -LibX11exports *LibX11::operator->() -{ - return loadExports(); -} - -LibX11exports *LibX11::loadExports() -{ - static LibX11exports exports = [] { - if(getProcAddress(RTLD_DEFAULT, "XOpenDisplay")) // Search the global scope for pre-loaded X11 library. - { - return LibX11exports(RTLD_DEFAULT, RTLD_DEFAULT); - } - - void *libX11 = loadLibrary("libX11.so"); - - if(libX11) - { - void *libXext = loadLibrary("libXext.so"); - return LibX11exports(libX11, libXext); - } - - return LibX11exports(); - }(); - - return exports.XOpenDisplay ? &exports : nullptr; -} - -LibX11 libX11;
diff --git a/src/WSI/libX11.hpp b/src/WSI/libX11.hpp deleted file mode 100644 index ef354c9..0000000 --- a/src/WSI/libX11.hpp +++ /dev/null
@@ -1,69 +0,0 @@ -// Copyright 2016 The SwiftShader Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef libX11_hpp -#define libX11_hpp - -#define Bool int -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/extensions/XShm.h> - -struct LibX11exports -{ - LibX11exports() {} - LibX11exports(void *libX11, void *libXext); - - Display *(*XOpenDisplay)(char *display_name) = nullptr; - Status (*XGetWindowAttributes)(Display *display, Window w, XWindowAttributes *window_attributes_return) = nullptr; - Screen *(*XDefaultScreenOfDisplay)(Display *display) = nullptr; - int (*XWidthOfScreen)(Screen *screen) = nullptr; - int (*XHeightOfScreen)(Screen *screen) = nullptr; - int (*XPlanesOfScreen)(Screen *screen) = nullptr; - GC(*XDefaultGC) - (Display *display, int screen_number) = nullptr; - int (*XDefaultDepth)(Display *display, int screen_number) = nullptr; - Status (*XMatchVisualInfo)(Display *display, int screen, int depth, int screen_class, XVisualInfo *vinfo_return) = nullptr; - Visual *(*XDefaultVisual)(Display *display, int screen_number) = nullptr; - int (*(*XSetErrorHandler)(int (*handler)(Display *, XErrorEvent *)))(Display *, XErrorEvent *) = nullptr; - int (*XSync)(Display *display, Bool discard) = nullptr; - XImage *(*XCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line) = nullptr; - int (*XCloseDisplay)(Display *display) = nullptr; - int (*XPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height) = nullptr; - int (*XDrawString)(Display *display, Drawable d, GC gc, int x, int y, char *string, int length) = nullptr; - - Bool (*XShmQueryExtension)(Display *display) = nullptr; - XImage *(*XShmCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, char *data, XShmSegmentInfo *shminfo, unsigned int width, unsigned int height) = nullptr; - Bool (*XShmAttach)(Display *display, XShmSegmentInfo *shminfo) = nullptr; - Bool (*XShmDetach)(Display *display, XShmSegmentInfo *shminfo) = nullptr; - int (*XShmPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height, bool send_event) = nullptr; -}; - -class LibX11 -{ -public: - bool isPresent() - { - return loadExports() != nullptr; - } - - LibX11exports *operator->(); - -private: - LibX11exports *loadExports(); -}; - -extern LibX11 libX11; - -#endif // libX11_hpp