简体   繁体   English

在同一个子通道中将图像用作输入附件和颜色输出附件是否合法?

[英]Is it legal to use an image both as an input attachment and a color output attachment in the same subpass?

I'm trying to optimize my code with a move that I'm not confident with. 我正试图用我不自信的举动来优化我的代码。 I'm experimenting with deferred rendering, so I have built a render pass with two subpasses. 我正在尝试延迟渲染,所以我构建了一个带有两个子通道的渲染通道。 The first one output the albedo/normal/depth images, and second one uses them as input attachments to create the final image. 第一个输出反照率/正常/深度图像,第二个使用它们作为输入附件来创建最终图像。 Until now, I was using an image to write the albedo, and another one to ouput the final calculations using the G-buffer. 到目前为止,我正在使用图像来编写反照率,另一个使用G缓冲区输出最终计算结果。

I was wondering if it was possible to use the same image for the albedo and the final calculations. 我想知道是否可以使用相同的图像进行反照率和最终计算。 So I tried to use just one image, as color output attachment in the first subpass, and both as color output attachment and input attachment in the second subpass. 所以我试图只使用一个图像,作为第一个子通道中的颜色输出附件,以及第二个子通道中的颜色输出附件和输入附件。 Given that an input attachment can be either SHADER_READ_ONLY_OPTIMAL or GENERAL, I used the general layout since I need to write in the image. 鉴于输入附件可以是SHADER_READ_ONLY_OPTIMAL或GENERAL,我使用了一般布局,因为我需要在图像中写入。

It works almost perfectly, but first, I'm not sure not being lucky, and second, I get this message from the validation layers : 它的工作方式几乎完美,但首先,我不确定是不是很幸运,其次,我从验证层得到这条消息:

"Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL. “输入附件的布局是GENERAL,但应该是READ_ONLY_OPTIMAL。

Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL." 颜色附件的布局是GENERAL,但应该是COLOR_ATTACHMENT_OPTIMAL。“

Where the image refered by the input attachment and the color attachment is the image I used for reads and writes. 输入附件和颜色附件所指的图像是我用于读写的图像。 I don't know if this message is a driver bug or simply a way to tell me that I'm doing wrong. 我不知道这个消息是驱动程序错误还是只是告诉我我做错了。 Moreover, even if it's a legal move, I think that the use of GENERAL layout instead of COLOR_ATTACHMENT_OPTIMAL is likely to make performances worse than simply having two images. 此外,即使这是一个合法的举动,我认为使用GENERAL布局而不是COLOR_ATTACHMENT_OPTIMAL可能会使性能比简单地拥有两个图像更糟糕。

The answer to the question in your title is yes, you may use an attachment as both an input attachment and a color attachment in the same subpass. 标题中的问题答案是肯定的,您可以将附件用作同一子通道中的输入附件和颜色附件。 The validation layer should not be outputting a warning. 验证层不应该输出警告。 It is not a violation of the validation rules (and indeed, only the general layout allows the use of an attachment as both input and color). 它不违反验证规则(实际上, 只有一般布局允许使用附件作为输入和颜色)。 The validation layers can tell when you're using the same attachment for both in a subpass, so it shouldn't give a warning for using the general layout in this case. 验证层可以告诉您何时在子通道中使用相同的附件,因此在这种情况下不应该给出使用常规布局的警告。

Feel free to submit an issue to the validation layer project on GitHub . 随意向GitHub上的验证层项目提交问题

However, that's not entirely what your main text asks. 但是,这并不完全是您的主要文本所要求的。 The answer to this question: 这个问题的答案是:

if it was possible to use the same image for the albedo and the final calculations 如果可以使用相同的图像进行反照率和最终计算

Is "no". 没有”。

In the lighting pass of a deferred renderer, you will generally need to cover the same pixels several times. 在延迟渲染器的光照过程中,通常需要多次覆盖相同的像素。 You may have more lights than you could reasonably compute in a single pass, or you may need to do special shadows or other things that don't easily combine well, or various other things. 您可能拥有的光线数量超过了您在一次通过中合理计算的数量,或者您可能需要执行特殊阴影或其他不易组合的事物或其他各种事物。 So you will typically need to render the same area of the screen multiple times, using additive blending for each rendering with the output color. 因此,您通常需要多次渲染屏幕的相同区域,使用每种渲染的添加混合和输出颜色。

If you're writing to the same image that stored the albedo, then the later read (assuming you did the proper barrier gymnastics to allow reading from a value written to the attachment within the same subpass) will be reading the light intensity , not an albedo value. 如果您正在写入存储反照率的相同图像,那么后面的读取(假设您进行了适当的障碍体操以允许从写入相同子通道内的附件的值读取)将读取光强度 ,而不是反照率值。 Therefore, it's going to be doing the wrong math. 因此,它会做错误的数学运算。

So yes, you're going to need another image. 所以,是的,你需要另一张图片。

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

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