Ver código fonte

make Vulkan module compile on Linux

rdb 9 anos atrás
pai
commit
a8405a74fb

+ 8 - 3
makepanda/makepanda.py

@@ -775,6 +775,7 @@ if (COMPILER=="GCC"):
         SmartPkgEnable("VORBIS",    "vorbisfile",("vorbisfile", "vorbis", "ogg"), ("ogg/ogg.h", "vorbis/vorbisfile.h"))
         SmartPkgEnable("JPEG",      "",          ("jpeg"), "jpeglib.h")
         SmartPkgEnable("PNG",       "libpng",    ("png"), "png.h", tool = "libpng-config")
+        SmartPkgEnable("VULKAN",    "",          ("vulkan"), "vulkan/vulkan.h")
 
         if GetTarget() == "darwin" and not PkgSkip("FFMPEG"):
             LibName("FFMPEG", "-Wl,-read_only_relocs,suppress")
@@ -4577,13 +4578,17 @@ if (PkgSkip("EGL")==0 and PkgSkip("GLES2")==0 and PkgSkip("X11")==0 and not RUNT
 # DIRECTORY: panda/src/vulkandisplay/
 #
 
-if (GetTarget() == 'windows' and PkgSkip("GL")==0 and not RUNTIME):
+if not PkgSkip("VULKAN") and not RUNTIME:
   OPTS=['DIR:panda/src/vulkandisplay', 'DIR:panda/src/vulkandisplay', 'BUILDING:VULKANDISPLAY', 'VULKAN']
   TargetAdd('p3vulkandisplay_composite1.obj', opts=OPTS, input='p3vulkandisplay_composite1.cxx')
   TargetAdd('libp3vulkandisplay.dll', input='p3vulkandisplay_composite1.obj')
-  TargetAdd('libp3vulkandisplay.dll', input='libp3windisplay.dll')
+  if GetTarget() == 'windows':
+    TargetAdd('libp3vulkandisplay.dll', input='libp3windisplay.dll')
+    TargetAdd('libp3vulkandisplay.dll', opts=['MODULE', 'VULKAN'])
+  else:
+    TargetAdd('libp3vulkandisplay.dll', input='p3x11display_composite1.obj')
+    TargetAdd('libp3vulkandisplay.dll', opts=['MODULE', 'VULKAN', 'X11', 'XRANDR', 'XF86DGA', 'XCURSOR'])
   TargetAdd('libp3vulkandisplay.dll', input=COMMON_PANDA_LIBS)
-  TargetAdd('libp3vulkandisplay.dll', opts=['MODULE', 'VULKAN'])
 
 #
 # DIRECTORY: panda/src/ode/

+ 1 - 1
panda/src/vulkandisplay/config_vulkandisplay.cxx

@@ -82,7 +82,7 @@ get_pipe_type_p3vulkandisplay() {
 /**
  * Returns a string describing a VkResult code, or NULL if it is unrecognized.
  */
-static const char *const string_result(VkResult result) {
+static const char *string_result(VkResult result) {
   switch (result) {
   case VK_SUCCESS:
     return "Success.";

+ 13 - 0
panda/src/vulkandisplay/config_vulkandisplay.h

@@ -25,9 +25,22 @@ extern ConfigVariableInt vulkan_color_palette_size;
 extern EXPCL_VULKANDISPLAY void init_libvulkandisplay();
 extern "C" EXPCL_VULKANDISPLAY int get_pipe_type_p3vulkandisplay();
 
+#ifdef _WIN32
 #define VK_USE_PLATFORM_WIN32_KHR
+
+#elif defined(HAVE_X11)
+// Make sure Eigen is included first to avoid conflict
+#include "lsimpleMatrix.h"
+#include "pre_x11_include.h"
+#define VK_USE_PLATFORM_XLIB_KHR
+#endif
+
 #include <vulkan/vulkan.h>
 
+#ifdef HAVE_X11
+#include "post_x11_include.h"
+#endif
+
 void vulkan_error(VkResult result, const char *message);
 
 #endif

+ 6 - 0
panda/src/vulkandisplay/vulkanGraphicsPipe.cxx

@@ -62,7 +62,13 @@ VulkanGraphicsPipe() {
   const char *extensions[] = {
     "VK_EXT_debug_report",
     "VK_KHR_surface",
+#ifdef _WIN32
     "VK_KHR_win32_surface"
+#elif defined(HAVE_X11)
+    "VK_KHR_xlib_surface"
+#else
+    ""
+#endif
   };
 
   VkApplicationInfo app_info;

+ 3 - 0
panda/src/vulkandisplay/vulkanGraphicsPipe.h

@@ -20,6 +20,9 @@
 #ifdef _WIN32
 #include "winGraphicsPipe.h"
 typedef WinGraphicsPipe BaseGraphicsPipe;
+#elif defined(HAVE_X11)
+#include "x11GraphicsPipe.h"
+typedef x11GraphicsPipe BaseGraphicsPipe;
 #else
 #include "graphicsPipe.h"
 typedef GraphicsPipe BaseGraphicsPipe;

+ 13 - 7
panda/src/vulkandisplay/vulkanGraphicsStateGuardian.cxx

@@ -198,7 +198,7 @@ VulkanGraphicsStateGuardian(GraphicsEngine *engine, VulkanGraphicsPipe *pipe,
   // flat color assigned via ColorAttrib.
   VkBuffer buffer;
   VkDeviceMemory memory;
-  uint32_t palette_size = (uint32_t)min(2, vulkan_color_palette_size) * 16;
+  uint32_t palette_size = (uint32_t)min(2, vulkan_color_palette_size.get_value()) * 16;
   if (!create_buffer(palette_size, _color_vertex_buffer, memory,
                      VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
                      VK_BUFFER_USAGE_TRANSFER_DST_BIT,
@@ -453,9 +453,9 @@ prepare_texture(Texture *texture, int view) {
          image_info.extent.height > img_props.maxExtent.height ||
          image_info.extent.depth > img_props.maxExtent.depth) {
     // Reduce the size by bumping the first mipmap level uploaded.
-    image_info.extent.width = max(1, image_info.extent.width >> 1);
-    image_info.extent.height = max(1, image_info.extent.height >> 1);
-    image_info.extent.depth = max(1, image_info.extent.depth >> 1);
+    image_info.extent.width = max(1U, image_info.extent.width >> 1);
+    image_info.extent.height = max(1U, image_info.extent.height >> 1);
+    image_info.extent.depth = max(1U, image_info.extent.depth >> 1);
     ++mipmap_begin;
   }
 
@@ -872,9 +872,9 @@ upload_texture(VulkanTextureContext *tc) {
       blit.srcOffsets[1].z = region.imageExtent.depth;
     }
 
-    region.imageExtent.width = max(1, region.imageExtent.width >> 1);
-    region.imageExtent.height = max(1, region.imageExtent.height >> 1);
-    region.imageExtent.depth = max(1, region.imageExtent.depth >> 1);
+    region.imageExtent.width = max(1U, region.imageExtent.width >> 1);
+    region.imageExtent.height = max(1U, region.imageExtent.height >> 1);
+    region.imageExtent.depth = max(1U, region.imageExtent.depth >> 1);
     ++region.imageSubresource.mipLevel;
   }
 
@@ -1973,6 +1973,8 @@ make_pipeline(const RenderState *state, const GeomVertexFormat *format,
     case GeomEnums::NT_packed_dabc:
       attrib_desc[i].format = VK_FORMAT_A8B8G8R8_UINT_PACK32;
       break;
+    case GeomEnums::NT_stdfloat:
+      assert(false);
     case GeomEnums::NT_float32:
       attrib_desc[i].format = (VkFormat)(VK_FORMAT_R32_SFLOAT + 3 * fmt_jump);
       break;
@@ -2392,6 +2394,10 @@ get_image_format(const Texture *texture) const {
     } else {
       return (VkFormat)(VK_FORMAT_BC5_UNORM_BLOCK + is_signed);
     }
+
+  default:
+    // Compression mode not supported.
+    break;
   }
 
   switch (format) {

+ 17 - 2
panda/src/vulkandisplay/vulkanGraphicsWindow.cxx

@@ -373,7 +373,10 @@ open_window() {
     return false;
   }
 
+  VkResult err;
+
   // Create a surface using the WSI extension.
+#ifdef _WIN32
   VkWin32SurfaceCreateInfoKHR surface_info;
   surface_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
   surface_info.pNext = NULL;
@@ -381,9 +384,21 @@ open_window() {
   surface_info.hinstance = GetModuleHandle(NULL);
   surface_info.hwnd = _hWnd;
 
-  VkResult err = vkCreateWin32SurfaceKHR(vkpipe->_instance, &surface_info, NULL, &_surface);
+  err = vkCreateWin32SurfaceKHR(vkpipe->_instance, &surface_info, NULL, &_surface);
+
+#elif defined(HAVE_X11)
+  VkXlibSurfaceCreateInfoKHR surface_info;
+  surface_info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
+  surface_info.pNext = NULL;
+  surface_info.flags = 0;
+  surface_info.dpy = _display;
+  surface_info.window = _xwindow;
+
+  err = vkCreateXlibSurfaceKHR(vkpipe->_instance, &surface_info, NULL, &_surface);
+#endif
+
   if (err) {
-    vulkan_error(err, "Failed to create Win32 surface");
+    vulkan_error(err, "Failed to create surface");
     return false;
   }
 

+ 3 - 0
panda/src/vulkandisplay/vulkanGraphicsWindow.h

@@ -19,6 +19,9 @@
 #ifdef _WIN32
 #include "winGraphicsWindow.h"
 typedef WinGraphicsWindow BaseGraphicsWindow;
+#elif defined(HAVE_X11)
+#include "x11GraphicsWindow.h"
+typedef x11GraphicsWindow BaseGraphicsWindow;
 #else
 #include "graphicsWindow.h"
 typedef GraphicsWindow BaseGraphicsWindow;