use of org.lwjgl.vulkan.VkCommandBufferAllocateInfo in project lwjgl3-demos by LWJGL.
the class ClearScreenDemo method createRenderCommandBuffers.
private static VkCommandBuffer[] createRenderCommandBuffers(VkDevice device, long commandPool, long[] framebuffers, long renderPass, int width, int height) {
// Create the render command buffers (one command buffer per framebuffer image)
VkCommandBufferAllocateInfo cmdBufAllocateInfo = VkCommandBufferAllocateInfo.calloc().sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO).commandPool(commandPool).level(VK_COMMAND_BUFFER_LEVEL_PRIMARY).commandBufferCount(framebuffers.length);
PointerBuffer pCommandBuffer = memAllocPointer(framebuffers.length);
int err = vkAllocateCommandBuffers(device, cmdBufAllocateInfo, pCommandBuffer);
if (err != VK_SUCCESS) {
throw new AssertionError("Failed to allocate render command buffer: " + translateVulkanResult(err));
}
VkCommandBuffer[] renderCommandBuffers = new VkCommandBuffer[framebuffers.length];
for (int i = 0; i < framebuffers.length; i++) {
renderCommandBuffers[i] = new VkCommandBuffer(pCommandBuffer.get(i), device);
}
memFree(pCommandBuffer);
cmdBufAllocateInfo.free();
// Create the command buffer begin structure
VkCommandBufferBeginInfo cmdBufInfo = VkCommandBufferBeginInfo.calloc().sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO).pNext(NULL);
// Specify clear color (cornflower blue)
VkClearValue.Buffer clearValues = VkClearValue.calloc(1);
clearValues.color().float32(0, 100 / 255.0f).float32(1, 149 / 255.0f).float32(2, 237 / 255.0f).float32(3, 1.0f);
// Specify everything to begin a render pass
VkRenderPassBeginInfo renderPassBeginInfo = VkRenderPassBeginInfo.calloc().sType(VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO).pNext(NULL).renderPass(renderPass).pClearValues(clearValues);
VkRect2D renderArea = renderPassBeginInfo.renderArea();
renderArea.offset().x(0).y(0);
renderArea.extent().width(width).height(height);
for (int i = 0; i < renderCommandBuffers.length; ++i) {
// Set target frame buffer
renderPassBeginInfo.framebuffer(framebuffers[i]);
err = vkBeginCommandBuffer(renderCommandBuffers[i], cmdBufInfo);
if (err != VK_SUCCESS) {
throw new AssertionError("Failed to begin render command buffer: " + translateVulkanResult(err));
}
vkCmdBeginRenderPass(renderCommandBuffers[i], renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
// Update dynamic viewport state
VkViewport.Buffer viewport = VkViewport.calloc(1).height(height).width(width).minDepth(0.0f).maxDepth(1.0f);
vkCmdSetViewport(renderCommandBuffers[i], 0, viewport);
viewport.free();
// Update dynamic scissor state
VkRect2D.Buffer scissor = VkRect2D.calloc(1);
scissor.extent().width(width).height(height);
scissor.offset().x(0).y(0);
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
scissor.free();
vkCmdEndRenderPass(renderCommandBuffers[i]);
// Add a present memory barrier to the end of the command buffer
// This will transform the frame buffer color attachment to a
// new layout for presenting it to the windowing system integration
VkImageMemoryBarrier.Buffer prePresentBarrier = createPrePresentBarrier(swapchain.images[i]);
vkCmdPipelineBarrier(renderCommandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_FLAGS_NONE, // No memory barriers
null, // No buffer memory barriers
null, // One image memory barrier
prePresentBarrier);
prePresentBarrier.free();
err = vkEndCommandBuffer(renderCommandBuffers[i]);
if (err != VK_SUCCESS) {
throw new AssertionError("Failed to begin render command buffer: " + translateVulkanResult(err));
}
}
renderPassBeginInfo.free();
clearValues.free();
cmdBufInfo.free();
return renderCommandBuffers;
}
use of org.lwjgl.vulkan.VkCommandBufferAllocateInfo in project lwjgl3-demos by LWJGL.
the class ClearScreenDemo method createCommandBuffer.
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);
}
use of org.lwjgl.vulkan.VkCommandBufferAllocateInfo in project lwjgl3-demos by LWJGL.
the class ColoredRotatingQuadDemo method createCommandBuffer.
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);
}
use of org.lwjgl.vulkan.VkCommandBufferAllocateInfo in project lwjgl3-demos by LWJGL.
the class ColoredTriangleDemo method createCommandBuffer.
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);
}
Aggregations