Vulkan,单渲染通道,2 个着色器,不同数量的输出

Vulkan, single render pass, 2 shaders, different number of outputs

这是我当前的设置:

然而,第二个并不真正需要向 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

你有很多选择。

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

或者,您可以在单独的子通道中执行 "Shader 2",该子通道仅使用感兴趣的附件。

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