Search in sources :

Example 6 with VkDeviceCreateInfo

use of org.lwjgl.vulkan.VkDeviceCreateInfo in project lwjgl3-demos by LWJGL.

the class TriangleDemo method createDeviceAndGetGraphicsQueueFamily.

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));
    }
    VkPhysicalDeviceMemoryProperties memoryProperties = VkPhysicalDeviceMemoryProperties.calloc();
    vkGetPhysicalDeviceMemoryProperties(physicalDevice, memoryProperties);
    DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily();
    ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo);
    ret.queueFamilyIndex = graphicsQueueFamilyIndex;
    ret.memoryProperties = memoryProperties;
    deviceCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_KHR_SWAPCHAIN_EXTENSION);
    memFree(extensions);
    memFree(pQueuePriorities);
    return ret;
}
Also used : VkQueueFamilyProperties(org.lwjgl.vulkan.VkQueueFamilyProperties) VkDevice(org.lwjgl.vulkan.VkDevice) VkDeviceQueueCreateInfo(org.lwjgl.vulkan.VkDeviceQueueCreateInfo) PointerBuffer(org.lwjgl.PointerBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) VkDeviceCreateInfo(org.lwjgl.vulkan.VkDeviceCreateInfo) VkPhysicalDeviceMemoryProperties(org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties) IntBuffer(java.nio.IntBuffer)

Example 7 with VkDeviceCreateInfo

use of org.lwjgl.vulkan.VkDeviceCreateInfo in project lwjgl3-demos by LWJGL.

the class ColoredRotatingQuadDemo method createDeviceAndGetGraphicsQueueFamily.

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));
    }
    VkPhysicalDeviceMemoryProperties memoryProperties = VkPhysicalDeviceMemoryProperties.calloc();
    vkGetPhysicalDeviceMemoryProperties(physicalDevice, memoryProperties);
    DeviceAndGraphicsQueueFamily ret = new DeviceAndGraphicsQueueFamily();
    ret.device = new VkDevice(device, physicalDevice, deviceCreateInfo);
    ret.queueFamilyIndex = graphicsQueueFamilyIndex;
    ret.memoryProperties = memoryProperties;
    deviceCreateInfo.free();
    memFree(ppEnabledLayerNames);
    memFree(VK_KHR_SWAPCHAIN_EXTENSION);
    memFree(extensions);
    memFree(pQueuePriorities);
    return ret;
}
Also used : VkQueueFamilyProperties(org.lwjgl.vulkan.VkQueueFamilyProperties) VkDevice(org.lwjgl.vulkan.VkDevice) VkDeviceQueueCreateInfo(org.lwjgl.vulkan.VkDeviceQueueCreateInfo) PointerBuffer(org.lwjgl.PointerBuffer) FloatBuffer(java.nio.FloatBuffer) ByteBuffer(java.nio.ByteBuffer) VkDeviceCreateInfo(org.lwjgl.vulkan.VkDeviceCreateInfo) VkPhysicalDeviceMemoryProperties(org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties) IntBuffer(java.nio.IntBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)7 FloatBuffer (java.nio.FloatBuffer)7 IntBuffer (java.nio.IntBuffer)7 PointerBuffer (org.lwjgl.PointerBuffer)7 VkDevice (org.lwjgl.vulkan.VkDevice)7 VkDeviceCreateInfo (org.lwjgl.vulkan.VkDeviceCreateInfo)7 VkDeviceQueueCreateInfo (org.lwjgl.vulkan.VkDeviceQueueCreateInfo)7 VkQueueFamilyProperties (org.lwjgl.vulkan.VkQueueFamilyProperties)7 VkPhysicalDeviceMemoryProperties (org.lwjgl.vulkan.VkPhysicalDeviceMemoryProperties)6