Exemple #1
0
def setupDebugging(instance, flags, callback):
    CreateDebugReportCallback = vk.vkGetInstanceProcAddr(
        instance, "vkCreateDebugReportCallbackEXT")
    DestroyDebugReportCallback = vk.vkGetInstanceProcAddr(
        instance, "vkDestroyDebugReportCallbackEXT")
    dbgBreakCallback = vk.vkGetInstanceProcAddr(instance,
                                                "vkDebugReportMessageEXT")
    dbgCreateInfo = vk.VkDebugReportCallbackCreateInfoEXT(
        sType=vk.VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
        #flags=VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT,
        flags=flags,
        pfnCallback=messageCallback)
    msgCallback = CreateDebugReportCallback(instance, dbgCreateInfo, None)
Exemple #2
0
 def add_pfn(name):
     try:
         self.pfn[name] = vk.vkGetInstanceProcAddr(self.instance, name)
     except ImportError:
         msg = "Can't get address of %s extension function" % name
         logger.critical(msg)
         raise VulkError(msg)
Exemple #3
0
 def add_pfn(name):
     try:
         self.pfn[name] = vk.vkGetInstanceProcAddr(self.instance, name)
     except ImportError:
         msg = "Can't get address of %s extension function" % name
         logger.critical(msg)
         raise VulkError(msg)
Exemple #4
0
 def __call__(self, *args, **kwargs):
     func_name = self.__func.__name__
     func = vk.vkGetInstanceProcAddr(args[0], func_name)
     if func:
         return func(*args, **kwargs)
     else:
         return vk.VK_ERROR_EXTENSION_NOT_PRESENT
Exemple #5
0
 def connect(self, instance, physicalDevice, device):
     self.instance = instance
     self.device = device
     self.physicalDevice = physicalDevice
     self.fpGetPhysicalDeviceSurfaceSupportKHR = vk.vkGetInstanceProcAddr(
         self.instance, "vkGetPhysicalDeviceSurfaceSupportKHR")
     self.fpGetPhysicalDeviceSurfaceCapabilitiesKHR = vk.vkGetInstanceProcAddr(
         self.instance, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR")
     self.fpGetPhysicalDeviceSurfaceFormatsKHR = vk.vkGetInstanceProcAddr(
         self.instance, "vkGetPhysicalDeviceSurfaceFormatsKHR")
     self.fpGetPhysicalDeviceSurfacePresentModesKHR = vk.vkGetInstanceProcAddr(
         self.instance, "vkGetPhysicalDeviceSurfacePresentModesKHR")
     self.fpCreateSwapchainKHR = vk.vkGetDeviceProcAddr(
         self.device, "vkCreateSwapchainKHR")
     self.fpDestroySwapchainKHR = vk.vkGetDeviceProcAddr(
         self.device, "vkDestroySwapchainKHR")
     self.fpGetSwapchainImagesKHR = vk.vkGetDeviceProcAddr(
         self.device, "vkGetSwapchainImagesKHR")
     self.fpAcquireNextImageKHR = vk.vkGetDeviceProcAddr(
         self.device, "vkAcquireNextImageKHR")
     self.fpQueuePresentKHR = vk.vkGetDeviceProcAddr(
         self.device, "vkQueuePresentKHR")
Exemple #6
0
    def cleanup(self):
        """
Destroy and free Vulkan resources used for the swapchain
        """
        if self.swapChain != vk.VK_NULL_HANDLE:
            for imageView in self.imageViews:
                vk.vkDestroyImageView(self.device, imageView, None)
        if self.surface != vk.VK_NULL_HANDLE:
            self.fpDestroySwapchainKHR(self.device, self.swapChain, None)
            fpDestroySurfaceKHR = vk.vkGetInstanceProcAddr(
                self.instance, "vkDestroySurfaceKHR")
            fpDestroySurfaceKHR(self.instance, self.surface, None)
        self.swapChain = vk.VK_NULL_HANDLE
        self.surface = vk.VK_NULL_HANDLE
Exemple #7
0
    def __getattr__(self, fn):

        if fn in vulkan._vulkan._instance_ext_funcs:
            return vulkan.vkGetInstanceProcAddr(self._instance, fn)
        else:
            super().__getattribute__(fn)
Exemple #8
0
 def call_platform(name, surface_create):
     f = vk.vkGetInstanceProcAddr(self.instance, name)
     return f(self.instance, surface_create, None)
Exemple #9
0
 def call_platform(name, surface_create):
     f = vk.vkGetInstanceProcAddr(self.instance, name)
     return f(instance=self.instance, pCreateInfo=surface_create)
Exemple #10
0
 def call_platform(name, surface_create):
     f = vk.vkGetInstanceProcAddr(self.instance, name)
     return f(self.instance, surface_create, None)
Exemple #11
0
    def initSurface(self, **kwargs):
        """
Create the os-specific surface
see also https://github.com/gabdube/python-vulkan-triangle for surface management with xcb/wayland/xlib
        """
        if VK_USE_PLATFORM_XCB_KHR:
            connection = kwargs['connection']
            window = kwargs['window']
            pCreateXcbSurfaceKHR = vk.vkGetInstanceProcAddr(
                self.instance, "vkCreateXcbSurfaceKHR")
            surfaceCreateInfo = vk.VkXcbSurfaceCreateInfoKHR(
                sType=vk.VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR,
                #connection = connection,
                connection=vk.ffi.cast('void*', connection._conn),
                window=window)
            self.surface = pCreateXcbSurfaceKHR(instance=self.instance,
                                                pCreateInfo=surfaceCreateInfo,
                                                pAllocator=None)
        if VK_USE_PLATFORM_WIN32_KHR:
            platformHandle = kwargs['platformHandle']
            platformWindow = kwargs['platformWindow']
            pCreateWin32SurfaceKHR = vk.vkGetInstanceProcAddr(
                self.instance, "vkCreateWin32SurfaceKHR")
            surfaceCreateInfo = vk.VkWin32SurfaceCreateInfoKHR(
                sType=vk.VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR,
                hinstance=platformHandle,
                hwnd=platformWindow)
            self.surface = pCreateWin32SurfaceKHR(
                instance=self.instance,
                pCreateInfo=surfaceCreateInfo,
                pAllocator=None)

        if self.surface is None:
            vks.vulkantools.exitFatal("Could not create surface", -1)

        # Get available queue family properties
        queueProps = vk.vkGetPhysicalDeviceQueueFamilyProperties(
            self.physicalDevice)
        # Iterate over each queue to learn whether it supports presenting:
        # Find a queue with present support
        # Will be used to present the swap chain images to the windowing system

        supportsPresent = []
        for i in range(len(queueProps)):
            supportsPresent.append(
                self.fpGetPhysicalDeviceSurfaceSupportKHR(
                    physicalDevice=self.physicalDevice,
                    queueFamilyIndex=i,
                    surface=self.surface))
        # Search for a graphics and a present queue in the array of queue
        # families, try to find one that supports both
        graphicsQueueNodeIndex = None
        presentQueueNodeIndex = None

        for i in range(len(queueProps)):
            #            print('properties for queue family ' + str(i) + ': ', end='')
            #            if (queueProps[i].queueFlags & vk.VK_QUEUE_GRAPHICS_BIT) != 0:
            #                print('GRAPHICS', end='')
            #            if (queueProps[i].queueFlags & vk.VK_QUEUE_COMPUTE_BIT) != 0:
            #                print(', COMPUTE', end='')
            #            if (queueProps[i].queueFlags & vk.VK_QUEUE_TRANSFER_BIT) != 0:
            #                print(', TRANSFER', end='')
            #            if (queueProps[i].queueFlags & vk.VK_QUEUE_SPARSE_BINDING_BIT) != 0:
            #                print(', SPARSE_BINDING', end='')
            #            if supportsPresent[i] == vk.VK_TRUE:
            #                 print(', SUPPORTS PRESENTATION', end='')
            #            print(', supportsPresent='+str(supportsPresent[i]))
            if (queueProps[i].queueFlags & vk.VK_QUEUE_GRAPHICS_BIT) != 0:
                if graphicsQueueNodeIndex is None:
                    graphicsQueueNodeIndex = i
                if supportsPresent[i] == vk.VK_TRUE:
                    graphicsQueueNodeIndex = i
                    presentQueueNodeIndex = i
                    break
        if presentQueueNodeIndex is None:
            # If there's no queue that supports both present and graphics
            # try to find a separate present queue
            for i in range(len(queueProps)):
                if supportsPresent[i] == vk.VK_TRUE:
                    presentQueueNodeIndex = i
                    break
#        if VK_USE_PLATFORM_WIN32_KHR and presentQueueNodeIndex is None:   # is this a bug in Win32? look at the python code in sdl2_exmaple
#            presentQueueNodeIndex = graphicsQueueNodeIndex
# Exit if either a graphics or a presenting queue hasn't been found
        if graphicsQueueNodeIndex is None or presentQueueNodeIndex is None:
            vks.vulkantools.exitFatal(
                "Could not find a graphics and/or presenting queue!", -1)
        # todo : Add support for separate graphics and presenting queue
        if graphicsQueueNodeIndex != presentQueueNodeIndex:
            vks.vulkantools.exitFatal(
                "Separate graphics and presenting queues are not supported yet!",
                -1)

        self.queueNodeIndex = graphicsQueueNodeIndex

        # Get list of supported surface formats
        surfaceFormats = self.fpGetPhysicalDeviceSurfaceFormatsKHR(
            physicalDevice=self.physicalDevice, surface=self.surface)
        if (len(surfaceFormats) == 1) and (surfaceFormats[0].format
                                           == vk.VK_FORMAT_UNDEFINED):
            self.colorFormat = vk.VK_FORMAT_B8G8R8A8_UNORM
            self.colorSpace = surfaceFormats[0].colorSpace
        else:
            # iterate over the list of available surface format and
            # check for the presence of VK_FORMAT_B8G8R8A8_UNORM
            found_B8G8R8A8_UNORM = False
            for surfaceFormat in surfaceFormats:
                if surfaceFormat.format == vk.VK_FORMAT_B8G8R8A8_UNORM:
                    self.colorFormat = surfaceFormat.format
                    self.colorSpace = surfaceFormat.colorSpace
                    found_B8G8R8A8_UNORM = True
                    break
            # in case VK_FORMAT_B8G8R8A8_UNORM is not available
            # select the first available color format
            if not found_B8G8R8A8_UNORM:
                self.colorFormat = surfaceFormats[0].format
                self.colorSpace = surfaceFormats[0].colorSpace