繁体   English   中英

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

[英]Vulkan, single render pass, 2 shaders, different number of outputs

这是我目前的设置:

  • 开始渲染通道
  • 着色器 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”,该子通道仅使用感兴趣的附件。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM