org.lwjgl.vulkan.VkPhysicalDevice Java Examples

The following examples show how to use org.lwjgl.vulkan.VkPhysicalDevice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 6 votes vote down vote up
/**
 * This method will enumerate the physical devices (i.e. GPUs) the system has available for us, and will just return
 * the first one. 
 */
private static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance) {
    IntBuffer pPhysicalDeviceCount = memAllocInt(1);
    int err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, null);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get number of physical devices: " + translateVulkanResult(err));
    }
    PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    memFree(pPhysicalDeviceCount);
    memFree(pPhysicalDevices);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
 
Example #2
Source File: DeviceCapabilities.java    From oreon-engine with GNU General Public License v3.0 6 votes vote down vote up
public static List<String> getPhysicalDeviceExtensionNamesSupport(VkPhysicalDevice physicalDevice){

	IntBuffer extensionCount = memAllocInt(1);
	
	int err = vkEnumerateDeviceExtensionProperties(physicalDevice, "", extensionCount, null);
	if (err != VK_SUCCESS) {
           throw new AssertionError(VkUtil.translateVulkanResult(err));
       }
	
	VkExtensionProperties.Buffer extensions = VkExtensionProperties.calloc(extensionCount.get(0));
	
	err = vkEnumerateDeviceExtensionProperties(physicalDevice, "", extensionCount, extensions);
	if (err != VK_SUCCESS) {
           throw new AssertionError(VkUtil.translateVulkanResult(err));
       }
	
	List<String> extensionNames = new ArrayList<>();
	for (VkExtensionProperties extension : extensions){
		extensionNames.add(extension.extensionNameString());
	}
	
	return extensionNames;
}
 
Example #3
Source File: PhysicalDevice.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public PhysicalDevice(VkInstance vkInstance, long surface) {

		IntBuffer pPhysicalDeviceCount = memAllocInt(1);
        int err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, null);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get number of physical devices: " + VkUtil.translateVulkanResult(err));
        }
        
        log.info("Available Physical Devices: " + pPhysicalDeviceCount.get(0));
        
        PointerBuffer pPhysicalDevices = memAllocPointer(pPhysicalDeviceCount.get(0));
        err = vkEnumeratePhysicalDevices(vkInstance, pPhysicalDeviceCount, pPhysicalDevices);
        long physicalDevice = pPhysicalDevices.get(0);
       
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get physical devices: " + VkUtil.translateVulkanResult(err));
        }
        
        memFree(pPhysicalDeviceCount);
        memFree(pPhysicalDevices);
        
        handle =  new VkPhysicalDevice(physicalDevice, vkInstance);
        queueFamilies = new QueueFamilies(handle, surface);
        swapChainCapabilities = new SurfaceProperties(handle, surface);
        supportedExtensionNames = DeviceCapabilities.getPhysicalDeviceExtensionNamesSupport(handle);
        memoryProperties = VkPhysicalDeviceMemoryProperties.calloc();
        vkGetPhysicalDeviceMemoryProperties(handle, memoryProperties);
        
        properties = DeviceCapabilities.checkPhysicalDeviceProperties(handle);
        features = DeviceCapabilities.checkPhysicalDeviceFeatures(handle);
        
//        log.info(properties.apiVersion());
//        log.info(properties.driverVersion());
//        log.info(properties.vendorID());
//        log.info(properties.deviceID());
//        log.info(properties.deviceType());
//        log.info(properties.deviceNameString());
	}
 
Example #4
Source File: DeviceCapabilities.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public static VkFormatProperties getVkPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
		int format){
	
	VkFormatProperties formatProperties = VkFormatProperties.create();
	vkGetPhysicalDeviceFormatProperties(physicalDevice, format, formatProperties);
	
	return formatProperties;
}
 
Example #5
Source File: SurfaceProperties.java    From oreon-engine with GNU General Public License v3.0 5 votes vote down vote up
public SurfaceProperties(VkPhysicalDevice physicalDevice, long surface) {

		surfaceCapabilities = VkSurfaceCapabilitiesKHR.calloc();
        int err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, surfaceCapabilities);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get physical device surface capabilities: " + VkUtil.translateVulkanResult(err));
        }
        
        IntBuffer pFormatCount = memAllocInt(1);
        err = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pFormatCount, null);
        int formatCount = pFormatCount.get(0);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to query number of physical device surface formats: " + VkUtil.translateVulkanResult(err));
        }

        surfaceFormats = VkSurfaceFormatKHR.calloc(formatCount);
        err = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pFormatCount, surfaceFormats);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to query physical device surface formats: " + VkUtil.translateVulkanResult(err));
        }
        
        IntBuffer pPresentModeCount = memAllocInt(1);
        err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, null);
        int presentModeCount = pPresentModeCount.get(0);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get number of physical device surface presentation modes: " + VkUtil.translateVulkanResult(err));
        }

        presentModes = memAllocInt(presentModeCount);
        err = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount, presentModes);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to get physical device surface presentation modes: " + VkUtil.translateVulkanResult(err));
        }
        
        memFree(pPresentModeCount);
        memFree(pFormatCount);
	}
 
Example #6
Source File: PlatformX11VKCanvas.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
@Override
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return KHRXlibSurface.vkGetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, queueFamily, 0, 0);
}
 
Example #7
Source File: PlatformWin32VKCanvas.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamily);
}
 
Example #8
Source File: ClearScreenDemo.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) {
    IntBuffer pQueueFamilyPropertyCount = memAllocInt(1);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
    int queueCount = pQueueFamilyPropertyCount.get(0);
    VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.calloc(queueCount);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
    memFree(pQueueFamilyPropertyCount);
    int graphicsQueueFamilyIndex;
    for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) {
        if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0)
            break;
    }
    queueProps.free();
    FloatBuffer pQueuePriorities = memAllocFloat(1).put(0.0f);
    pQueuePriorities.flip();
    VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.calloc(1)
            .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
            .queueFamilyIndex(graphicsQueueFamilyIndex)
            .pQueuePriorities(pQueuePriorities);

    PointerBuffer extensions = memAllocPointer(1);
    ByteBuffer VK_KHR_SWAPCHAIN_EXTENSION = memUTF8(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
    extensions.put(VK_KHR_SWAPCHAIN_EXTENSION);
    extensions.flip();
    PointerBuffer ppEnabledLayerNames = memAllocPointer(layers.length);
    for (int i = 0; validation && i < layers.length; i++)
        ppEnabledLayerNames.put(layers[i]);
    ppEnabledLayerNames.flip();

    VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO)
            .pNext(NULL)
            .pQueueCreateInfos(queueCreateInfo)
            .ppEnabledExtensionNames(extensions)
            .ppEnabledLayerNames(ppEnabledLayerNames);

    PointerBuffer pDevice = memAllocPointer(1);
    int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice);
    long device = pDevice.get(0);
    memFree(pDevice);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to create device: " + translateVulkanResult(err));
    }

    DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily();
    ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo);
    ret.queueFamilyIndex = graphicsQueueFamilyIndex;

    deviceCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_KHR_SWAPCHAIN_EXTENSION);
    memFree(extensions);
    memFree(pQueuePriorities);
    return ret;
}
 
Example #9
Source File: PlatformWin32VKCanvas.java    From lwjgl3-swt with MIT License 4 votes vote down vote up
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamily);
}
 
Example #10
Source File: QueueFamilies.java    From oreon-engine with GNU General Public License v3.0 4 votes vote down vote up
public QueueFamilies(VkPhysicalDevice physicalDevice, long surface) {

	queueFamilies = new ArrayList<>();
	
	IntBuffer pQueueFamilyPropertyCount = memAllocInt(1);
       vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
       int queueCount = pQueueFamilyPropertyCount.get(0);
       
       VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.calloc(queueCount);
       vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
       
       log.info("Available Queues: " + queueCount);
       
       IntBuffer supportsPresent = memAllocInt(queueCount);

       for (int i = 0; i < queueCount; i++) {

       	supportsPresent.position(i);
       	supportsPresent.put(i, 0);
       	
       	int flags = queueProps.get(i).queueFlags();
       	int count = queueProps.get(i).queueCount();
       	
       	// check if surface exists
       	if (surface != -1){
        	int err = vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, 
					   i, 
					   surface, 
					   supportsPresent);
			if (err != VK_SUCCESS) {
			throw new AssertionError("Failed to physical device surface support: " + VkUtil.translateVulkanResult(err));
			}
       	}
       	
       	log.info("Index:" + i + " flags:" + flags + " count:" + count + " presentation:" + supportsPresent.get(i));
       	
       	QueueFamily queueFamily = new QueueFamily();
       	queueFamily.setIndex(i);
       	queueFamily.setFlags(flags);
       	queueFamily.setCount(count);
       	queueFamily.setPresentFlag(supportsPresent.get(i));
       	
       	queueFamilies.add(queueFamily);
       }
       
       memFree(pQueueFamilyPropertyCount);
       queueProps.free();
}
 
Example #11
Source File: DeviceCapabilities.java    From oreon-engine with GNU General Public License v3.0 3 votes vote down vote up
public static VkPhysicalDeviceProperties checkPhysicalDeviceProperties(VkPhysicalDevice physicalDevice){
	
	VkPhysicalDeviceProperties properties = VkPhysicalDeviceProperties.create();
	vkGetPhysicalDeviceProperties(physicalDevice, properties);
	
	log.info("Device: " + properties.deviceNameString());
	
	return properties;
}
 
Example #12
Source File: DeviceCapabilities.java    From oreon-engine with GNU General Public License v3.0 3 votes vote down vote up
public static VkPhysicalDeviceFeatures checkPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice){
	
	VkPhysicalDeviceFeatures features = VkPhysicalDeviceFeatures.create();
	vkGetPhysicalDeviceFeatures(physicalDevice, features);
	
	return features;
}
 
Example #13
Source File: AWTVKCanvas.java    From lwjgl3-awt with MIT License 2 votes vote down vote up
/**
 * Determine whether there is presentation support for the given {@link VkPhysicalDevice} in a command queue of the specified <code>queueFamiliy</code>.
 * 
 * @param physicalDevice
 *            the Vulkan {@link VkPhysicalDevice}
 * @param queueFamily
 *            the command queue family
 * @return <code>true</code> of <code>false</code>
 */
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return platformCanvas.getPhysicalDevicePresentationSupport(physicalDevice, queueFamily);
}
 
Example #14
Source File: VKCanvas.java    From lwjgl3-swt with MIT License 2 votes vote down vote up
/**
 * Determine whether there is presentation support for the given {@link VkPhysicalDevice} in a command queue of the specified
 * <code>queueFamiliy</code>.
 * 
 * @param physicalDevice
 *            the Vulkan {@link VkPhysicalDevice}
 * @param queueFamily
 *            the command queue family
 * @return <code>true</code> of <code>false</code>
 */
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return platformCanvas.getPhysicalDevicePresentationSupport(physicalDevice, queueFamily);
}
 
Example #15
Source File: PlatformVKCanvas.java    From lwjgl3-awt with MIT License votes vote down vote up
boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily); 
Example #16
Source File: PlatformVKCanvas.java    From lwjgl3-swt with MIT License votes vote down vote up
boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily);