[英]Clear screen only on first command buffer at vulkan api
I try to realize multithreaded rendering with vulkan api.I build a multiple command buffers from other threads.我尝试使用 vulkan api 实现多线程渲染。我从其他线程构建了多个命令缓冲区。 Then execute them.But since there is have a clear screen in every command buffer, I don't get picture.
然后执行它们。但是由于每个命令缓冲区中都有一个清晰的屏幕,所以我没有得到图片。
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassInfo.renderPass = m_pRenderPass;
renderPassInfo.framebuffer = m_swapChainFrameBufferPtrs[m_nImageIndex];
renderPassInfo.renderArea.offset = { 0, 0 };
renderPassInfo.renderArea.extent = { m_nWidth, m_nHeight };
std::array<VkClearValue, 2> clearValues{};
clearValues[0].color = { {0.0f, 0.0f, 0.0f, 1.0f} };
clearValues[1].depthStencil = { 1.0f, 0 };
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
renderPassInfo.pClearValues = clearValues.data();
VkViewport viewport{...};
VkRect2D scissor{...};
CFrameCommandBuffer& currentFrame = m_frames[m_nCurrentFrame];
for (std::uint32_t n = 0; n < currentFrame.m_commandBufferPtrs.size(); ++n)
{
auto& pCmdBuffer = currentFrame.m_commandBufferPtrs[n];
vkResetCommandBuffer(pCmdBuffer, 0);
vkBeginCommandBuffer(pCmdBuffer, &beginInfo);
vkCmdBeginRenderPass(pCmdBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
vkCmdSetViewport(pCmdBuffer, 0, 1, &viewport);
vkCmdSetScissor(pCmdBuffer, 0, 1, &scissor);
}
If I don't use screen clearing for the second and subsequent buffers.如果我不对第二个和后续缓冲区使用屏幕清除。
renderPassInfo.clearValueCount = 0;
renderPassInfo.pClearValues = nullptr;
I get an error:我收到一个错误:
In vkCmdBeginRenderPass the VkRenderPassBeginInfo struct has a clearValueCount of 0 but there must be at least 2 entries in pClearValues array to account for the highest index attachment in VkRenderPass 0x1ebe0f000000012a[] that uses VK_ATTACHMENT_LOAD_OP_CLEAR is 2. Note that the pClearValues array is indexed by attachment number so even if some pClearValues entries between 0 and 1 correspond to attachments that aren't cleared they will be ignored.
How can I clear screen correctly only at first command buffer ?如何仅在第一个命令缓冲区正确清除屏幕?
When calling vkCmdBeginRenderPass
you are required a set of values to clear the render pass attachments.调用
vkCmdBeginRenderPass
时,您需要一组值来清除渲染通道附件。
pClearValues
is a pointer to an array ofclearValueCount
VkClearValue
structures containing clear values for each attachment, if the attachment uses aloadOp
value ofVK_ATTACHMENT_LOAD_OP_CLEAR
or if the attachment has a depth/stencil format and uses astencilLoadOp
value ofVK_ATTACHMENT_LOAD_OP_CLEAR
.pClearValues
是指向clearValueCount
结构数组的指针,VkClearValue
包含每个附件的清除值,如果附件使用VK_ATTACHMENT_LOAD_OP_CLEAR
的loadOp
值,或者附件具有深度/模板格式并使用VK_ATTACHMENT_LOAD_OP_CLEAR
的stencilLoadOp
值。 The array is indexed by attachment number.该数组由附件编号索引。 Only elements corresponding to cleared attachments are used.
仅使用与已清除附件相对应的元素。 Other elements of
pClearValues
are ignored.pClearValues
的其他元素被忽略。 1 archive1 个存档
When creating the VkRenderPass
object you specified whether you wanted each attachment cleared in the VkRenderPassCreateInfo
stucture.创建
VkRenderPass
对象时,您指定是否希望在VkRenderPassCreateInfo
结构中清除每个附件。 If you don't want to clear the attachment at the beginning of a render pass then you need to set the loadOp
of each of the VkAttachmentDescription
to VK_ATTACHMENT_LOAD_OP_LOAD
.如果您不想在渲染通道开始时清除附件,则需要将每个
loadOp
的VkAttachmentDescription
设置为VK_ATTACHMENT_LOAD_OP_LOAD
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.