Java 类org.lwjgl.vulkan.VkPhysicalDevice 实例源码

项目:Vulkan-Tests    文件:VkUtils.java   
/**
 * Returns the handle to the first physical device connected to the system.
 *
 * @param instance The instance of the vulkan
 *
 * @return The handle to the first physical device.
 */
public static VkPhysicalDevice getFirstPhysicalDevice(VkInstance instance)
{
    IntBuffer gpuCount = memAllocInt(1);

    vkEnumeratePhysicalDevices(instance, gpuCount, null);
    PointerBuffer devices = memAllocPointer(gpuCount.get(0));
    vkEnumeratePhysicalDevices(instance, gpuCount, devices);

    VkPhysicalDevice firstPhysicalDevice = new VkPhysicalDevice(devices.get(0), instance);

    memFree(gpuCount);
    memFree(devices);

    return firstPhysicalDevice;
}
项目:oreon-engine    文件:VKRenderEngine.java   
private 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: " + VKUtil.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: " + VKUtil.translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
/**
 * 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);
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
/**
 * 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 = stackMallocInt(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 = stackMallocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
/**
 * 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 = stackMallocInt(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 = stackMallocPointer(pPhysicalDeviceCount.get(0));
    err = vkEnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
    long physicalDevice = pPhysicalDevices.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to get physical devices: " + translateVulkanResult(err));
    }
    return new VkPhysicalDevice(physicalDevice, instance);
}
项目:lwjgl3-awt    文件:PlatformWin32VKCanvas.java   
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamily);
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) {
    IntBuffer pQueueFamilyPropertyCount = stackMallocInt(1);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
    int queueCount = pQueueFamilyPropertyCount.get(0);
    VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.callocStack(queueCount);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
    int graphicsQueueFamilyIndex;
    for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) {
        if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0)
            break;
    }
    VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.callocStack(1)
            .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
            .queueFamilyIndex(graphicsQueueFamilyIndex)
            .pQueuePriorities(stackFloats(0.0f));

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

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

    PointerBuffer pDevice = stackMallocPointer(1);
    int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice);
    long device = pDevice.get(0);
    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;
    return ret;
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
private static DeviceAndGraphicsQueueFamily createDeviceAndGetGraphicsQueueFamily(VkPhysicalDevice physicalDevice) {
    IntBuffer pQueueFamilyPropertyCount = stackMallocInt(1);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, null);
    int queueCount = pQueueFamilyPropertyCount.get(0);
    VkQueueFamilyProperties.Buffer queueProps = VkQueueFamilyProperties.callocStack(queueCount);
    vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, pQueueFamilyPropertyCount, queueProps);
    int graphicsQueueFamilyIndex;
    for (graphicsQueueFamilyIndex = 0; graphicsQueueFamilyIndex < queueCount; graphicsQueueFamilyIndex++) {
        if ((queueProps.get(graphicsQueueFamilyIndex).queueFlags() & VK_QUEUE_GRAPHICS_BIT) != 0)
            break;
    }
    VkDeviceQueueCreateInfo.Buffer queueCreateInfo = VkDeviceQueueCreateInfo.callocStack(1)
            .sType(VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO)
            .queueFamilyIndex(graphicsQueueFamilyIndex)
            .pQueuePriorities(stackFloats(0.0f));

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

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

    PointerBuffer pDevice = stackMallocPointer(1);
    int err = vkCreateDevice(physicalDevice, deviceCreateInfo, null, pDevice);
    long device = pDevice.get(0);
    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;
    return ret;
}
项目:oreon-engine    文件:VKRenderEngine.java   
void recreate(VkCommandBuffer setupCommandBuffer,
              VkDevice device,
              VkPhysicalDevice physicalDevice,
              long surface,
              ColorFormatAndSpace colorFormatAndSpace,
              VkQueue queue,
              long renderPass,
              long renderCommandPool,
              long pipeline,
              Vertices vertices) {
    // Begin the setup command buffer (the one we will use for swapchain/framebuffer creation)
    VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO)
            .pNext(0);
    int err = vkBeginCommandBuffer(setupCommandBuffer, cmdBufInfo);
    cmdBufInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to begin setup command buffer: " + VKUtil.translateVulkanResult(err));
    }
    long oldChain = swapchain != null ? swapchain.swapchainHandle : VK_NULL_HANDLE;
    // Create the swapchain (this will also add a memory barrier to initialize the framebuffer images)
    swapchain = createSwapChain(device, physicalDevice, surface, oldChain, setupCommandBuffer,
            width, height, colorFormatAndSpace.colorFormat, colorFormatAndSpace.colorSpace);
    err = vkEndCommandBuffer(setupCommandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to end setup command buffer: " + VKUtil.translateVulkanResult(err));
    }
    submitCommandBuffer(queue, setupCommandBuffer);
    vkQueueWaitIdle(queue);

    if (framebuffers != null) {
        for (int i = 0; i < framebuffers.length; i++)
            vkDestroyFramebuffer(device, framebuffers[i], null);
    }
    framebuffers = createFramebuffers(device, swapchain, renderPass, width, height);
    // Create render command buffers
    if (renderCommandBuffers != null) {
        vkResetCommandPool(device, renderCommandPool, 0);
    }
    renderCommandBuffers = createRenderCommandBuffers(device, renderCommandPool, framebuffers, renderPass, width, height, pipeline,
            vertices.verticesBuf);

    mustRecreate = false;
}
项目:oreon-engine    文件:VKRenderEngine.java   
private 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(0)
            .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: " + VKUtil.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;
}
项目:lwjgl3-swt    文件:PlatformWin32VKCanvas.java   
public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
    return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, queueFamily);
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
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;
}
项目:lwjgl3-awt    文件:AWTVKCanvas.java   
/**
 * 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);
}
项目:lwjgl3-swt    文件:VKCanvas.java   
/**
 * 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);
}
项目:lwjgl3-awt    文件:PlatformVKCanvas.java   
boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily);
项目:lwjgl3-swt    文件:PlatformVKCanvas.java   
boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily);