Hi, I'm using V-EZ for a simple example: clearing screen to a specific color.
Here is my command buffer generation.
I only create and bind 1 color attachment for the framebuffer.
void CVulkanDriver::createCommandBuffer()
{
// Get the graphics queue handle.
vezGetDeviceGraphicsQueue(VKDevice, 0, &GraphicsQueue);
// Create a command buffer handle.
VezCommandBufferAllocateInfo allocInfo = {};
allocInfo.queue = GraphicsQueue;
allocInfo.commandBufferCount = 1;
if (vezAllocateCommandBuffers(VKDevice, &allocInfo, &CommandBuffer) != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vezAllocateCommandBuffers failed");
exit(1);
}
// Begin command buffer recording.
if (vezBeginCommandBuffer(CommandBuffer, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vezBeginCommandBuffer failed");
exit(1);
}
// Set the viewport state and dimensions.
auto width = Device.getWidth();
auto height = Device.getHeight();
VkViewport viewport = { 0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f, 1.0f };
VkRect2D scissor = { { 0, 0 },{ static_cast<uint32_t>(width), static_cast<uint32_t>(height) } };
vezCmdSetViewport(0, 1, &viewport);
vezCmdSetScissor(0, 1, &scissor);
vezCmdSetViewportState(1);
VkClearColorValue clearColor = {
{ 0.4f, 0.6f, 0.9f, 1.0f } // R, G, B, A
};
// Define clear values for the swapchain's color and depth attachments.
// std::array<VezAttachmentReference, 2> attachmentReferences = {};
std::array<VezAttachmentReference, 1> attachmentReferences = {};
attachmentReferences[0].clearValue.color = clearColor;
attachmentReferences[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
attachmentReferences[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
// attachmentReferences[1].clearValue.depthStencil.depth = 1.0f;
// attachmentReferences[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
// attachmentReferences[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
// Begin a render pass.
VezRenderPassBeginInfo beginInfo = {};
beginInfo.framebuffer = Framebuffer.handle;
beginInfo.attachmentCount = static_cast<uint32_t>(attachmentReferences.size());
beginInfo.pAttachments = attachmentReferences.data();
vezCmdBeginRenderPass(&beginInfo);
// Bind the pipeline and associated resources.
vezCmdBindPipeline(BasicPipeline.pipeline);
// vezCmdBindBuffer(m_uniformBuffer, 0, VK_WHOLE_SIZE, 0, 0, 0);
// vezCmdBindImageView(ImageView, Sampler, 0, 1, 0);
// Set depth stencil state.
// VezPipelineDepthStencilState depthStencilState = {};
// depthStencilState.depthTestEnable = VK_TRUE;
// depthStencilState.depthWriteEnable = VK_TRUE;
// depthStencilState.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
// vezCmdSetDepthStencilState(&depthStencilState);
// Bind the vertex buffer and index buffers.
// VkDeviceSize offset = 0;
// vezCmdBindVertexBuffers(0, 1, &m_vertexBuffer, &offset);
// vezCmdBindIndexBuffer(m_indexBuffer, 0, VK_INDEX_TYPE_UINT32);
// Draw the quad.
// vezCmdDrawIndexed(6, 1, 0, 0, 0);
// End the render pass.
vezCmdEndRenderPass();
// End command buffer recording.
if (vezEndCommandBuffer() != VK_SUCCESS)
{
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vezEndCommandBuffer failed");
exit(1);
}
}