c++ - Vulkan,单渲染通道,2 个着色器,不同数量的输出
问题描述
这是我目前的设置:
- 开始渲染通道
- 着色器 1 将颜色输出到 5 个附件。
- 着色器 2 将颜色输出到相同的 5 个附件
- 完成记录命令
然而,第二个并不真正需要输出任何到 5 个附件,只需要输出到第一个。
是否可以即时更改附件数量?就像是:
- 开始渲染通道
- 着色器 1 将颜色输出到 5 个附件。
- 修改渲染过程中的活动帧缓冲区
- 着色器 2 仅将颜色输出到第一个附件中的一个。
- 完成记录命令
或者如果这不能做到。是否可以关闭渲染通道之间的附件清除?
编辑有问题的片段着色器如下所示:
#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 即可防止写入该附件。
或者,您可以在单独的子通道中执行“着色器 2”,该子通道仅使用感兴趣的附件。
使用哪个取决于您的渲染操作的性质。
推荐阅读
- android - Android:subscriptionManager.getActiveSubscriptionInfoList() 给出 null,尽管 SIM 存在
- excel - 如何在 VBA 中移动特定值的单元格?
- ios - 如何在不知道方法名称的情况下添加断点来捕获按钮的触摸事件?
- react-native - 在与 expo 反应原生项目中显示视频
- django - 如何从 Django AdminLTE iFrame 注销?
- python - 在 pandas 的数据帧上使用contracts.fix时显示IndexError:字符串索引超出范围
- sql - CTE中变量值的PostgreSQL限制
- python - 如何根据其他列值动态填充列值?
- android - 打开嵌入式 Unity 片段后,父 Android 应用程序中的分辨率发生变化
- asp.net - 将对象列表添加到 SQL Server - ASP.NET Web API