use of org.lwjgl.vulkan.VkCommandBufferAllocateInfo in project lwjgl3-demos by LWJGL.
the class ColoredRotatingQuadDemo method createRenderCommandBuffers.
private static VkCommandBuffer[] createRenderCommandBuffers(VkDevice device, long commandPool, long[] framebuffers, long renderPass, int width, int height, Pipeline pipeline, long descriptorSet, long verticesBuf) {
// 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().set(0, 0);
renderArea.extent().set(width, 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().set(width, height);
scissor.offset().set(0, 0);
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
scissor.free();
// Bind descriptor sets describing shader binding points
LongBuffer descriptorSets = memAllocLong(1).put(0, descriptorSet);
vkCmdBindDescriptorSets(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, descriptorSets, null);
memFree(descriptorSets);
// Bind the rendering pipeline (including the shaders)
vkCmdBindPipeline(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline);
// Bind triangle vertices
LongBuffer offsets = memAllocLong(1);
offsets.put(0, 0L);
LongBuffer pBuffers = memAllocLong(1);
pBuffers.put(0, verticesBuf);
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
memFree(pBuffers);
memFree(offsets);
// Draw triangle
vkCmdDraw(renderCommandBuffers[i], 6, 1, 0, 0);
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 ColoredTriangleDemo method createRenderCommandBuffers.
private static VkCommandBuffer[] createRenderCommandBuffers(VkDevice device, long commandPool, long[] framebuffers, long renderPass, int width, int height, long pipeline, long verticesBuf) {
// 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().set(0, 0);
renderArea.extent().set(width, 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().set(width, height);
scissor.offset().set(0, 0);
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
scissor.free();
// Bind the rendering pipeline (including the shaders)
vkCmdBindPipeline(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
// Bind triangle vertices
LongBuffer offsets = memAllocLong(1);
offsets.put(0, 0L);
LongBuffer pBuffers = memAllocLong(1);
pBuffers.put(0, verticesBuf);
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
memFree(pBuffers);
memFree(offsets);
// Draw triangle
vkCmdDraw(renderCommandBuffers[i], 3, 1, 0, 0);
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 TriangleDemo method createRenderCommandBuffers.
private static VkCommandBuffer[] createRenderCommandBuffers(VkDevice device, long commandPool, long[] framebuffers, long renderPass, int width, int height, long pipeline, long verticesBuf) {
// 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().set(0, 0);
renderArea.extent().set(width, 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().set(width, height);
scissor.offset().set(0, 0);
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
scissor.free();
// Bind the rendering pipeline (including the shaders)
vkCmdBindPipeline(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
// Bind triangle vertices
LongBuffer offsets = memAllocLong(1);
offsets.put(0, 0L);
LongBuffer pBuffers = memAllocLong(1);
pBuffers.put(0, verticesBuf);
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
memFree(pBuffers);
memFree(offsets);
// Draw triangle
vkCmdDraw(renderCommandBuffers[i], 3, 1, 0, 0);
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 TwoRotatingTrianglesDemo method createRenderCommandBuffers.
private static VkCommandBuffer[] createRenderCommandBuffers(VkDevice device, long commandPool, long[] framebuffers, long renderPass, int width, int height, Pipeline pipeline, long descriptorSet, long verticesBuf) {
// 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(2);
clearValues.get(0).color().float32(0, 100 / 255.0f).float32(1, 149 / 255.0f).float32(2, 237 / 255.0f).float32(3, 1.0f);
// Specify clear depth-stencil
clearValues.get(1).depthStencil().depth(1.0f).stencil(0);
// 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().set(0, 0);
renderArea.extent().set(width, 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().set(width, height);
scissor.offset().set(0, 0);
vkCmdSetScissor(renderCommandBuffers[i], 0, scissor);
scissor.free();
// Bind descriptor sets describing shader binding points
LongBuffer descriptorSets = memAllocLong(1).put(0, descriptorSet);
vkCmdBindDescriptorSets(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, descriptorSets, null);
memFree(descriptorSets);
// Bind the rendering pipeline (including the shaders)
vkCmdBindPipeline(renderCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline);
// Bind triangle vertices
LongBuffer offsets = memAllocLong(1);
offsets.put(0, 0L);
LongBuffer pBuffers = memAllocLong(1);
pBuffers.put(0, verticesBuf);
vkCmdBindVertexBuffers(renderCommandBuffers[i], 0, pBuffers, offsets);
memFree(pBuffers);
memFree(offsets);
// Draw triangle
vkCmdDraw(renderCommandBuffers[i], 6, 1, 0, 0);
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 TwoRotatingTrianglesInvDepthDemo 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