Class VulkanModulePhysicalDevice

java.lang.Object
io.codetoil.curved_spacetime.vulkan.VulkanModulePhysicalDevice

public class VulkanModulePhysicalDevice extends Object
A Vulkan physical device — a GPU the driver has reported — together with everything queried about it.

Instances are created by createPhysicalDevice(VulkanModuleVulkanInstance, VulkanModuleEntrypoint, Logger), which enumerates every device, discards those that cannot present graphics or lack a required extension, and picks one. Discrete GPUs are preferred over integrated ones, and a device named in configuration wins outright.

The queried structures are allocated off-heap and are owned by this object, so every device that is enumerated must eventually be passed to cleanup() — including the ones that lose the selection.

  • Field Details

    • REQUIRED_EXTENSIONS

      protected static final Set<String> REQUIRED_EXTENSIONS
      Extensions a device must support to be considered usable, currently just the swap chain.
  • Method Details

    • createPhysicalDevice

      public static VulkanModulePhysicalDevice createPhysicalDevice(VulkanModuleVulkanInstance instance, VulkanModuleEntrypoint vulkanModuleEntrypoint, Logger logger)
      Enumerates the available devices and selects one to render with.

      A device named by preferredDeviceName in configuration is taken if it is present and otherwise suitable; failing that, a discrete GPU is preferred over an integrated one. Every device not selected is cleaned up before returning.

      Parameters:
      instance - the instance to enumerate devices from
      vulkanModuleEntrypoint - the entrypoint supplying the preferred device name
      logger - the logger to write selection diagnostics to
      Returns:
      the selected physical device, owned by the caller
      Throws:
      RuntimeException - if no device is present, or none meets the requirements
    • getPhysicalDevices

      protected static org.lwjgl.PointerBuffer getPhysicalDevices(VulkanModuleVulkanInstance instance, org.lwjgl.system.MemoryStack stack, Logger logger)
      Enumerates the handles of every physical device the instance can see.
      Parameters:
      instance - the instance to enumerate from
      stack - the stack to allocate the result buffer on
      logger - the logger to write the device count to
      Returns:
      a buffer of VkPhysicalDevice handles, valid for the stack frame
      Throws:
      AssertionError - if enumeration fails
    • getDeviceName

      public String getDeviceName()
      Returns the device's reported name.
      Returns:
      the device name as the driver reports it
    • cleanup

      public void cleanup()
      Frees the off-heap structures queried about this device.

      Must be called for every enumerated device, including those rejected during selection.

    • supportsExtensions

      public boolean supportsExtensions(Set<String> extensions)
      Returns whether this device supports every one of the given extensions.
      Parameters:
      extensions - the extension names required
      Returns:
      true if all of them are supported
    • getVkMemoryProperties

      public org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties getVkMemoryProperties()
      Returns the device's memory heaps and types.
      Returns:
      the memory properties, owned by this object
    • getVkPhysicalDevice

      public org.lwjgl.vulkan.VkPhysicalDevice getVkPhysicalDevice()
      Returns the underlying Vulkan physical device.
      Returns:
      the VkPhysicalDevice
    • getVkPhysicalDeviceFeatures

      public org.lwjgl.vulkan.VkPhysicalDeviceFeatures getVkPhysicalDeviceFeatures()
      Returns the optional features this device supports.
      Returns:
      the device features, owned by this object
    • getVkPhysicalDeviceProperties

      public org.lwjgl.vulkan.VkPhysicalDeviceProperties2 getVkPhysicalDeviceProperties()
      Returns the device's properties, including its name, type, and limits.
      Returns:
      the device properties, owned by this object
    • getVkQueueFamilyProps

      public org.lwjgl.vulkan.VkQueueFamilyProperties.Buffer getVkQueueFamilyProps()
      Returns the queue families this device offers.

      Callers scan this to find a family with the capability they need, such as graphics or presentation.

      Returns:
      the queue family properties, owned by this object