From dbd6081a8e221e5b4218d996d415ae752af095de Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Wed, 26 Aug 2020 10:03:44 +0300 Subject: [PATCH] Improve diagnostics of incompatible attachments --- wgpu-core/src/command/bundle.rs | 8 ++++--- wgpu-core/src/command/draw.rs | 4 ++-- wgpu-core/src/command/render.rs | 21 +++++++++-------- wgpu-core/src/device/mod.rs | 41 +++++++++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 4947cdc49..2272322c6 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -719,9 +719,11 @@ impl Global { .use_extend(&*pipeline_guard, pipeline_id, (), ()) .unwrap(); - if !bundle_encoder.context.compatible(&pipeline.pass_context) { - Err(RenderCommandError::IncompatiblePipeline)? - } + bundle_encoder + .context + .check_compatible(&pipeline.pass_context) + .map_err(|e| RenderCommandError::IncompatiblePipeline(e))?; + //TODO: check read-only depth let layout = &pipeline_layout_guard[pipeline.layout_id.value]; diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index d5f13a2ff..2efcef469 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -59,8 +59,8 @@ pub enum RenderCommandError { InvalidDynamicOffsetCount { actual: usize, expected: usize }, #[error("render pipeline {0:?} is invalid")] InvalidPipeline(id::RenderPipelineId), - #[error("render pipeline output formats and sample counts do not match render pass attachment formats")] - IncompatiblePipeline, + #[error("render pipeline is incompatible, {0}")] + IncompatiblePipeline(#[from] crate::device::RenderPassCompatibilityError), #[error("pipeline is not compatible with the depth-stencil read-only render pass")] IncompatibleReadOnlyDepthStencil, #[error("buffer {0:?} is in error {1:?}")] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 957737238..a2cb016f7 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -11,8 +11,8 @@ use crate::{ }, conv, device::{ - AttachmentData, AttachmentDataVec, FramebufferKey, RenderPassContext, RenderPassKey, - MAX_COLOR_TARGETS, MAX_VERTEX_BUFFERS, + AttachmentData, AttachmentDataVec, FramebufferKey, RenderPassCompatibilityError, + RenderPassContext, RenderPassKey, MAX_COLOR_TARGETS, MAX_VERTEX_BUFFERS, }, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Token}, id, @@ -361,8 +361,8 @@ pub enum RenderPassError { }, #[error("cannot pop debug group, because number of pushed debug groups is zero")] InvalidPopDebugGroup, - #[error("render bundle output formats do not match render pass attachment formats")] - IncompatibleRenderBundle, + #[error("render bundle is incompatible, {0}")] + IncompatibleRenderBundle(#[from] RenderPassCompatibilityError), #[error(transparent)] RenderCommand(#[from] RenderCommandError), #[error(transparent)] @@ -1016,9 +1016,10 @@ impl Global { .use_extend(&*pipeline_guard, pipeline_id, (), ()) .unwrap(); - if !context.compatible(&pipeline.pass_context) { - return Err(RenderCommandError::IncompatiblePipeline.into()); - } + context + .check_compatible(&pipeline.pass_context) + .map_err(|e| RenderCommandError::IncompatiblePipeline(e))?; + if pipeline.flags.contains(PipelineFlags::WRITES_DEPTH_STENCIL) && is_ds_read_only { @@ -1512,9 +1513,9 @@ impl Global { .use_extend(&*bundle_guard, bundle_id, (), ()) .unwrap(); - if !context.compatible(&bundle.context) { - return Err(RenderPassError::IncompatibleRenderBundle); - } + context + .check_compatible(&bundle.context) + .map_err(|e| RenderPassError::IncompatibleRenderBundle(e))?; unsafe { bundle.execute( diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index d7f142d20..ff81df1ba 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -106,13 +106,46 @@ pub(crate) struct RenderPassContext { pub attachments: AttachmentData, pub sample_count: u8, } +#[derive(Clone, Debug, Error)] +pub enum RenderPassCompatibilityError { + #[error("incompatible color attachment: {0:?} != {1:?}")] + IncompatibleColorAttachment( + ArrayVec<[TextureFormat; MAX_COLOR_TARGETS]>, + ArrayVec<[TextureFormat; MAX_COLOR_TARGETS]>, + ), + #[error("incompatible depth-stencil attachment: {0:?} != {1:?}")] + IncompatibleDepthStencilAttachment(Option, Option), + #[error("incompatible sample count: {0:?} != {1:?}")] + IncompatibleSampleCount(u8, u8), +} impl RenderPassContext { // Assumed the renderpass only contains one subpass - pub(crate) fn compatible(&self, other: &RenderPassContext) -> bool { - self.attachments.colors == other.attachments.colors - && self.attachments.depth_stencil == other.attachments.depth_stencil - && self.sample_count == other.sample_count + pub(crate) fn check_compatible( + &self, + other: &RenderPassContext, + ) -> Result<(), RenderPassCompatibilityError> { + if self.attachments.colors != other.attachments.colors { + return Err(RenderPassCompatibilityError::IncompatibleColorAttachment( + self.attachments.colors.clone(), + other.attachments.colors.clone(), + )); + } + if self.attachments.depth_stencil != other.attachments.depth_stencil { + return Err( + RenderPassCompatibilityError::IncompatibleDepthStencilAttachment( + self.attachments.depth_stencil.clone(), + other.attachments.depth_stencil.clone(), + ), + ); + } + if self.sample_count != other.sample_count { + return Err(RenderPassCompatibilityError::IncompatibleSampleCount( + self.sample_count, + other.sample_count, + )); + } + Ok(()) } }