From 52922a7a8ffded4c5e68493d5c483fb20835a5ea Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Wed, 15 Jul 2020 14:34:18 +0300 Subject: [PATCH] Detailed error messages for render bundle creation --- wgpu-core/src/command/bundle.rs | 18 ++++++++++++++---- wgpu-core/src/device/mod.rs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 82aef71da6..cb097ff86b 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -49,7 +49,7 @@ use crate::{ LifeGuard, RefCount, Stored, MAX_BIND_GROUPS, }; use arrayvec::ArrayVec; -use std::{borrow::Borrow, iter, marker::PhantomData, ops::Range}; +use std::{borrow::Borrow, fmt, iter, marker::PhantomData, ops::Range}; #[cfg_attr(feature = "serial-pass", derive(serde::Deserialize, serde::Serialize))] pub struct RenderBundleEncoder { @@ -63,7 +63,7 @@ impl RenderBundleEncoder { desc: &wgt::RenderBundleEncoderDescriptor, parent_id: id::DeviceId, base: Option>, - ) -> Result { + ) -> Result { span!(_guard, INFO, "RenderBundleEncoder::new"); Ok(RenderBundleEncoder { base: base.unwrap_or_else(BasePass::new), @@ -77,7 +77,7 @@ impl RenderBundleEncoder { sample_count: { let sc = desc.sample_count; if sc == 0 || sc > 32 || !conv::is_power_of_two(sc) { - return Err(InvalidSampleCountError); + return Err(CreateRenderBundleError::InvalidSampleCount(sc)); } sc as u8 }, @@ -92,7 +92,17 @@ impl RenderBundleEncoder { /// Error type returned from `RenderBundleEncoder::new` if the sample count is invalid. #[derive(Copy, Clone, Debug)] -pub struct InvalidSampleCountError; +pub enum CreateRenderBundleError { + InvalidSampleCount(u32), +} + +impl fmt::Display for CreateRenderBundleError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Self::InvalidSampleCount(count) => write!(f, "invalid number of samples {}", count), + } + } +} //Note: here, `RenderBundle` is just wrapping a raw stream of render commands. // The plan is to back it by an actual Vulkan secondary buffer, D3D12 Bundle, diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 3a6a6fb37e..2a80d5af59 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -2120,7 +2120,7 @@ impl Global { &self, device_id: id::DeviceId, desc: &wgt::RenderBundleEncoderDescriptor, - ) -> Result { + ) -> Result { span!(_guard, INFO, "Device::create_render_bundle_encoder"); let encoder = command::RenderBundleEncoder::new(desc, device_id, None); encoder.map(|encoder| Box::into_raw(Box::new(encoder)))