首页 > 解决方案 > Vulkan,单渲染通道,2 个着色器,不同数量的输出

问题描述

这是我目前的设置:

然而,第二个并不真正需要输出任何到 5 个附件,只需要输出到第一个。

是否可以即时更改附件数量?就像是:

或者如果这不能做到。是否可以关闭渲染通道之间的附件清除?

编辑有问题的片段着色器如下所示:

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) out vec4 color_out;
layout(location = 1) out vec4 color_out1;
layout(location = 2) out vec4 color_out2;
layout(location = 3) out vec4 color_out3;
layout(location = 4) out vec4 color_out4;

void main()
{
    color_out = vec4(1,1,1,1);
    color_out1 = vec4(0,0,0,0);
    color_out2 = vec4(0,0,0,0);
    color_out3 = vec4(0,0,0,0);
    color_out4 = vec4(0,0,0,0);
}

我正试图摆脱它。

我目前的渲染方式是:

// Initialize the FB with 5 image attachemnts + the clear values, etc...
vk::RenderPassBeginInfo render_pass_info;
render_pass_info.renderPass = *render_pass;
render_pass_info.framebuffer = *framebuffer;
render_pass_info.renderArea = vk::Rect2D({0,0}, extent);
render_pass_info.clearValueCount = clears.size();
render_pass_info.pClearValues = clears.data();

cmd.beginRenderPass(&render_pass_info, vk::SubpassContents::eInline);

/* setup pipeline 1 info, like it's descriptor sets, samplers etc*/
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *graphics_pipeline);
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline_layout, 0, 1, descriptor_set_ptr, 0, nullptr);

/* Do the same for the second pipeline */
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *graphics_pipeline);
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline_layout, 0, 1, descriptor_set_ptr, 0, nullptr);

目标是不在着色器中输出额外的 5 个附件。当前终止我的程序并出现以下错误:

Message ID name: UNASSIGNED-CoreValidation-Shader-InputNotProduced
Message: Attachment 1 not written by fragment shader; undefined values will be written to attachment
Severity: VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT

标签: c++graphicsrenderingvulkan

解决方案


你有很多选择。

“Shader 2”可以使用写入掩码来关闭对其他附件的写入。这些位于 中VkPipelineColorBlendAttachmentState::colorWriteMask,因此您只需将此值设置为 0 即可防止写入该附件。

或者,您可以在单独的子通道中执行“着色器 2”,该子通道仅使用感兴趣的附件。

使用哪个取决于您的渲染操作的性质。


推荐阅读