1402: Check render target aspects r=kvark a=kvark

**Connections**
Reported on Matrix by "m4b"

**Description**
Passing a depth texture as a color attachment results in:
> Validation Error: [ VUID-vkCmdBeginRenderPass-initialLayout-00895 ] Object 0: handle = 0x280000000028, name = ShadowTexture, type = VK_OBJECT_TYPE_IMAGE; Object 1: handle = 0x3020000000302, type = VK_OBJECT_TYPE_RENDER_PASS; Object 2: handle = 0x3030000000303, type = VK_OBJECT_TYPE_FRAMEBUFFER; Object 3: handle = 0x2b000000002b, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0x34f84ef4 | vkCmdBeginRenderPass(): Layout/usage mismatch for attachment 0 in VkRenderPass 0x3020000000302[] - the color attachment layout is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image attached to VkFramebuffer 0x3030000000303[] via VkImageView 0x2b000000002b[] was not created with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT The Vulkan spec states: If any of the initialLayout or finalLayout member of the VkAttachmentDescription structures or the layout member of the VkAttachmentReference structures specified when creating the render pass specified in the renderPass member of pRenderPassBegin is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL then the corresponding attachment image view of the framebuffer specified in the framebuffer member of pRenderPassBegin must have been created with a usage value including VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-vkCmdBeginRenderPass-initialLayout-00895)

**Testing**
Just ran wgpu-rs examples

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
bors[bot] 2021-05-19 04:53:42 +00:00 committed by GitHub
commit 7ce535cc97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -391,6 +391,10 @@ pub enum RenderPassErrorInner {
Encoder(#[from] CommandEncoderError),
#[error("attachment texture view {0:?} is invalid")]
InvalidAttachment(id::TextureViewId),
#[error("attachment format {0:?} is not a color format")]
InvalidColorAttachmentFormat(wgt::TextureFormat),
#[error("attachment format {0:?} is not a depth-stencil format")]
InvalidDepthStencilAttachmentFormat(wgt::TextureFormat),
#[error("necessary attachments are missing")]
MissingAttachments,
#[error("attachments have differing sizes: {previous:?} is followed by {mismatch:?}")]
@ -567,6 +571,11 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
add_view(view, "depth")?;
depth_stencil_aspects = view.aspects;
if view.aspects.contains(hal::format::Aspects::COLOR) {
return Err(RenderPassErrorInner::InvalidDepthStencilAttachmentFormat(
view.format,
));
}
let source_id = match view.inner {
TextureViewInner::Native { ref source_id, .. } => source_id,
@ -624,6 +633,12 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
.map_err(|_| RenderPassErrorInner::InvalidAttachment(at.view))?;
add_view(view, "color")?;
if !view.aspects.contains(hal::format::Aspects::COLOR) {
return Err(RenderPassErrorInner::InvalidColorAttachmentFormat(
view.format,
));
}
let layouts = match view.inner {
TextureViewInner::Native { ref source_id, .. } => {
let previous_use = cmd_buf