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

项目:oreon-engine    文件:VKRenderEngine.java   
private VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = memAllocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    cmdBufAllocateInfo.free();
    long commandBuffer = pCommandBuffer.get(0);
    memFree(pCommandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + VKUtil.translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
项目:oreon-engine    文件:VKRenderEngine.java   
private static void submitCommandBuffer(VkQueue queue, VkCommandBuffer commandBuffer) {
    if (commandBuffer == null || commandBuffer.address() == 0)
        return;
    VkSubmitInfo submitInfo = VkSubmitInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_SUBMIT_INFO);
    PointerBuffer pCommandBuffers = memAllocPointer(1)
            .put(commandBuffer)
            .flip();
    submitInfo.pCommandBuffers(pCommandBuffers);
    int err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
    memFree(pCommandBuffers);
    submitInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to submit command buffer: " + VKUtil.translateVulkanResult(err));
    }
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = memAllocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    cmdBufAllocateInfo.free();
    long commandBuffer = pCommandBuffer.get(0);
    memFree(pCommandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
private static void submitCommandBuffer(VkQueue queue, VkCommandBuffer commandBuffer) {
    if (commandBuffer == null || commandBuffer.address() == NULL)
        return;
    VkSubmitInfo submitInfo = VkSubmitInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_SUBMIT_INFO);
    PointerBuffer pCommandBuffers = memAllocPointer(1)
            .put(commandBuffer)
            .flip();
    submitInfo.pCommandBuffers(pCommandBuffers);
    int err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
    memFree(pCommandBuffers);
    submitInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to submit command buffer: " + translateVulkanResult(err));
    }
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = stackMallocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    long commandBuffer = pCommandBuffer.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
private static void imageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) {
    // Create an image barrier object
    VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(NULL)
            .oldLayout(oldImageLayout)
            .srcAccessMask(srcAccess)
            .newLayout(newImageLayout)
            .dstAccessMask(dstAccess)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    imageMemoryBarrier.subresourceRange()
            .aspectMask(aspectMask)
            .baseMipLevel(0)
            .levelCount(1)
            .layerCount(1);

    // Put barrier on top
    int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;

    // Put barrier inside setup command buffer
    vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, VK_FLAGS_NONE,
            null, // no memory barriers
            null, // no buffer memory barriers
            imageMemoryBarrier); // one image memory barrier
    imageMemoryBarrier.free();
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
private static void submitCommandBuffer(VkQueue queue, VkCommandBuffer commandBuffer) {
    if (commandBuffer == null || commandBuffer.address() == NULL)
        return;
    VkSubmitInfo submitInfo = VkSubmitInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_SUBMIT_INFO);
    PointerBuffer pCommandBuffers = stackMallocPointer(1)
            .put(commandBuffer)
            .flip();
    submitInfo.pCommandBuffers(pCommandBuffers);
    int err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to submit command buffer: " + translateVulkanResult(err));
    }
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
private static VkCommandBuffer createCommandBuffer(VkDevice device, long commandPool) {
    VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO)
            .commandPool(commandPool)
            .level(VK_COMMAND_BUFFER_LEVEL_PRIMARY)
            .commandBufferCount(1);
    PointerBuffer pCommandBuffer = stackMallocPointer(1);
    int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
    long commandBuffer = pCommandBuffer.get(0);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to allocate command buffer: " + translateVulkanResult(err));
    }
    return new VkCommandBuffer(commandBuffer, device);
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
private static void imageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) {
    // Create an image barrier object
    VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(NULL)
            .oldLayout(oldImageLayout)
            .srcAccessMask(srcAccess)
            .newLayout(newImageLayout)
            .dstAccessMask(dstAccess)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    imageMemoryBarrier.subresourceRange()
            .aspectMask(aspectMask)
            .baseMipLevel(0)
            .levelCount(1)
            .layerCount(1);

    // Put barrier on top
    int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;

    // Put barrier inside setup command buffer
    vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, VK_FLAGS_NONE,
            null, // no memory barriers
            null, // no buffer memory barriers
            imageMemoryBarrier); // one image memory barrier
    imageMemoryBarrier.free();
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
private static void submitCommandBuffer(VkQueue queue, VkCommandBuffer commandBuffer) {
    if (commandBuffer == null || commandBuffer.address() == NULL)
        return;
    VkSubmitInfo submitInfo = VkSubmitInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_SUBMIT_INFO);
    PointerBuffer pCommandBuffers = stackMallocPointer(1)
            .put(commandBuffer)
            .flip();
    submitInfo.pCommandBuffers(pCommandBuffers);
    int err = vkQueueSubmit(queue, submitInfo, VK_NULL_HANDLE);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to submit command buffer: " + translateVulkanResult(err));
    }
}
项目:oreon-engine    文件:VKRenderEngine.java   
private void createImageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) {
    // Create an image barrier object
    VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(0)
            .oldLayout(oldImageLayout)
            .srcAccessMask(srcAccess)
            .newLayout(newImageLayout)
            .dstAccessMask(dstAccess)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    imageMemoryBarrier.subresourceRange()
            .aspectMask(aspectMask)
            .baseMipLevel(0)
            .levelCount(1)
            .layerCount(1);

    // Put barrier on top
    int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;

    // Put barrier inside setup command buffer
    vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, 0,
            null, // no memory barriers
            null, // no buffer memory barriers
            imageMemoryBarrier); // one image memory barrier
        imageMemoryBarrier.free();
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
private static void imageBarrier(VkCommandBuffer cmdbuffer, long image, int aspectMask, int oldImageLayout, int srcAccess, int newImageLayout, int dstAccess) {
    // Create an image barrier object
    VkImageMemoryBarrier.Buffer imageMemoryBarrier = VkImageMemoryBarrier.calloc(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(NULL)
            .oldLayout(oldImageLayout)
            .srcAccessMask(srcAccess)
            .newLayout(newImageLayout)
            .dstAccessMask(dstAccess)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    imageMemoryBarrier.subresourceRange()
            .aspectMask(aspectMask)
            .baseMipLevel(0)
            .levelCount(1)
            .layerCount(1);

    // Put barrier on top
    int srcStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    int destStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;

    // Put barrier inside setup command buffer
    vkCmdPipelineBarrier(cmdbuffer, srcStageFlags, destStageFlags, VK_FLAGS_NONE,
            null, // no memory barriers
            null, // no buffer memory barriers
            imageMemoryBarrier); // one image memory barrier
    imageMemoryBarrier.free();
}
项目:lwjgl3-swt    文件:ClearScreenDemo.java   
private static void submitPostPresentBarrier(long image, VkCommandBuffer commandBuffer, VkQueue queue) {
    VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO)
            .pNext(NULL);
    int err = vkBeginCommandBuffer(commandBuffer, cmdBufInfo);
    cmdBufInfo.free();
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to begin command buffer: " + translateVulkanResult(err));
    }

    VkImageMemoryBarrier.Buffer postPresentBarrier = createPostPresentBarrier(image);
    vkCmdPipelineBarrier(
        commandBuffer,
        VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
        VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
        VK_FLAGS_NONE,
        null, // No memory barriers,
        null, // No buffer barriers,
        postPresentBarrier); // one image barrier
    postPresentBarrier.free();

    err = vkEndCommandBuffer(commandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to wait for idle queue: " + translateVulkanResult(err));
    }

    // Submit the command buffer
    submitCommandBuffer(queue, commandBuffer);
}
项目:autostack    文件:ClearScreenDemoUseNewStack.java   
@UseNewStack
private static void submitPostPresentBarrier(long image, VkCommandBuffer commandBuffer, VkQueue queue) {
    VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO)
            .pNext(NULL);
    int err = vkBeginCommandBuffer(commandBuffer, cmdBufInfo);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to begin command buffer: " + translateVulkanResult(err));
    }

    VkImageMemoryBarrier.Buffer postPresentBarrier = VkImageMemoryBarrier.callocStack(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(NULL)
            .srcAccessMask(0)
            .dstAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT)
            .oldLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
            .newLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    postPresentBarrier.subresourceRange()
            .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT)
            .baseMipLevel(0)
            .levelCount(1)
            .baseArrayLayer(0)
            .layerCount(1);
    vkCmdPipelineBarrier(
        commandBuffer,
        VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
        VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
        VK_FLAGS_NONE,
        null, // No memory barriers,
        null, // No buffer barriers,
        postPresentBarrier); // one image barrier

    err = vkEndCommandBuffer(commandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to wait for idle queue: " + translateVulkanResult(err));
    }

    // Submit the command buffer
    submitCommandBuffer(queue, commandBuffer);
}
项目:autostack    文件:ClearScreenDemoUseCallerStack.java   
@UseNewStack
private static void submitPostPresentBarrier(long image, VkCommandBuffer commandBuffer, VkQueue queue) {
    VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.callocStack()
            .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO)
            .pNext(NULL);
    int err = vkBeginCommandBuffer(commandBuffer, cmdBufInfo);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to begin command buffer: " + translateVulkanResult(err));
    }

    VkImageMemoryBarrier.Buffer postPresentBarrier = VkImageMemoryBarrier.callocStack(1)
            .sType(VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER)
            .pNext(NULL)
            .srcAccessMask(0)
            .dstAccessMask(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT)
            .oldLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
            .newLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
            .srcQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .dstQueueFamilyIndex(VK_QUEUE_FAMILY_IGNORED)
            .image(image);
    postPresentBarrier.subresourceRange()
            .aspectMask(VK_IMAGE_ASPECT_COLOR_BIT)
            .baseMipLevel(0)
            .levelCount(1)
            .baseArrayLayer(0)
            .layerCount(1);
    vkCmdPipelineBarrier(
        commandBuffer,
        VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
        VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
        VK_FLAGS_NONE,
        null, // No memory barriers,
        null, // No buffer barriers,
        postPresentBarrier); // one image barrier

    err = vkEndCommandBuffer(commandBuffer);
    if (err != VK_SUCCESS) {
        throw new AssertionError("Failed to wait for idle queue: " + translateVulkanResult(err));
    }

    // Submit the command buffer
    submitCommandBuffer(queue, commandBuffer);
}
项目: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;
}