我正在尝试执行以下操作:使用渲染通道 1,渲染到附件集 S。
进行渲染通道 2,再次渲染到附件集 S。
在官方的Khronos github中有一对一的解释如何做到这一点:
在图形到图形依赖项下。但是,尝试实现与示例中相同的代码是行不通的。
这就是我所看到的:
这是我应该看到的:
我认为目前正在发生的是深度缓冲区没有正确同步,因此深度测试无法正常工作。我创建了两个渲染通道,如下所示:
// Create a render pass from the information of a render target
vk::UniqueRenderPass CreateRenderPass(HardwareInterface& hi,
const std::vector<vk::AttachmentDescription>& attachment_descriptions)
{
auto instance = hi.GetInstance();
auto phys_device = hi.GetPhysicalDevice();
auto device = hi.GetDevice();
// Create a reference for each image target the renderpass will render to
std::vector<vk::AttachmentReference> attachment_references(
attachment_descriptions.size());
for(uint i = 0; i < attachment_descriptions.size() - 1; i++)
{
vk::AttachmentReference color_attachment_ref(
i, vk::ImageLayout::eColorAttachmentOptimal);
attachment_references[i] = color_attachment_ref;
}
// Last attachment is depth
vk::AttachmentReference depth_attachment_ref(
attachment_descriptions.size() - 1,
vk::ImageLayout::eDepthStencilAttachmentOptimal);
attachment_references[attachment_references.size() - 1] = depth_attachment_ref;
const uint subpass_num = 1;
vector<vk::SubpassDescription> subpasses(subpass_num);
for(auto& sub_pass: subpasses)
{
// No input attachment (3rd and 4th parameters)
sub_pass = vk::SubpassDescription();
sub_pass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
sub_pass.inputAttachmentCount = 0;
sub_pass.pInputAttachments = nullptr;
sub_pass.colorAttachmentCount = attachment_references.size() - 1;
sub_pass.pColorAttachments = attachment_references.data();
sub_pass.pResolveAttachments = nullptr;
sub_pass.pDepthStencilAttachment = &attachment_references.back();
}
vector<vk::SubpassDependency> dependencies(subpass_num);
uint current_dependency = 0;
for(auto& dependency: dependencies)
{
// Set the dependency of this subpass
uint32_t prev = current_dependency == 0 ? (uint32_t)VK_SUBPASS_EXTERNAL
: current_dependency - 1;
uint32_t next = current_dependency;
current_dependency++;
// Execution and memory dependencies between subpasses
dependency = vk::SubpassDependency();
dependency.srcSubpass = prev;
dependency.dstSubpass = next;
dependency.srcStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput
| vk::PipelineStageFlagBits::eEarlyFragmentTests
| vk::PipelineStageFlagBits::eLateFragmentTests;
dependency.dstStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput
| vk::PipelineStageFlagBits::eEarlyFragmentTests
| vk::PipelineStageFlagBits::eLateFragmentTests;
dependency.srcAccessMask =
vk::AccessFlagBits::eDepthStencilAttachmentWrite |
vk::AccessFlagBits::eDepthStencilAttachmentRead;
dependency.dstAccessMask =
vk::AccessFlagBits::eColorAttachmentRead |
vk::AccessFlagBits::eColorAttachmentWrite |
vk::AccessFlagBits::eDepthStencilAttachmentRead |
vk::AccessFlagBits::eDepthStencilAttachmentWrite;
}
vk::RenderPassCreateInfo render_pass_info(
{},
attachment_descriptions.size(),
attachment_descriptions.data(),
subpasses.size(),
subpasses.data(),
dependencies.size(),
dependencies.data());
auto [result, render_pass] = device.createRenderPassUnique(render_pass_info);
if(result != vk::Result::eSuccess)
Log::RecordLogError("Failed to create render pass!");
return move(render_pass);
}
我已经阅读并重新阅读了该示例,并尝试使我的代码尽可能与它相同,但是唉,问题仍然存在。我创建工作图像的方式是让两个渲染发生在同一个渲染通道下,但我不想那样做。