mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Properly return native shader module errors to users
This commit is contained in:
@@ -154,6 +154,25 @@ pub fn map_shader_stage_flags(shader_stage_flags: wgt::ShaderStage) -> hal::pso:
|
||||
value
|
||||
}
|
||||
|
||||
pub fn map_hal_flags_to_shader_stage(
|
||||
shader_stage_flags: hal::pso::ShaderStageFlags,
|
||||
) -> wgt::ShaderStage {
|
||||
use hal::pso::ShaderStageFlags as H;
|
||||
use wgt::ShaderStage as Ss;
|
||||
|
||||
let mut value = Ss::empty();
|
||||
if shader_stage_flags.contains(H::VERTEX) {
|
||||
value |= Ss::VERTEX;
|
||||
}
|
||||
if shader_stage_flags.contains(H::FRAGMENT) {
|
||||
value |= Ss::FRAGMENT;
|
||||
}
|
||||
if shader_stage_flags.contains(H::COMPUTE) {
|
||||
value |= Ss::COMPUTE;
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
pub fn map_extent(extent: &wgt::Extent3d, dim: wgt::TextureDimension) -> hal::image::Extent {
|
||||
hal::image::Extent {
|
||||
width: extent.width,
|
||||
|
||||
@@ -1940,10 +1940,15 @@ impl<B: GfxBackend> Device<B> {
|
||||
let raw =
|
||||
unsafe { self.raw.create_compute_pipeline(&pipeline_desc, None) }.map_err(|err| {
|
||||
match err {
|
||||
hal::pso::CreationError::OutOfMemory(_) => DeviceError::OutOfMemory,
|
||||
hal::pso::CreationError::OutOfMemory(_) => {
|
||||
pipeline::CreateComputePipelineError::Device(DeviceError::OutOfMemory)
|
||||
}
|
||||
hal::pso::CreationError::ShaderCreationError(_, error) => {
|
||||
pipeline::CreateComputePipelineError::Internal(error)
|
||||
}
|
||||
_ => {
|
||||
log::error!("failed to create compute pipeline: {}", err);
|
||||
DeviceError::OutOfMemory
|
||||
pipeline::CreateComputePipelineError::Device(DeviceError::OutOfMemory)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
@@ -2391,10 +2396,18 @@ impl<B: GfxBackend> Device<B> {
|
||||
let raw =
|
||||
unsafe { self.raw.create_graphics_pipeline(&pipeline_desc, None) }.map_err(|err| {
|
||||
match err {
|
||||
hal::pso::CreationError::OutOfMemory(_) => DeviceError::OutOfMemory,
|
||||
hal::pso::CreationError::OutOfMemory(_) => {
|
||||
pipeline::CreateRenderPipelineError::Device(DeviceError::OutOfMemory)
|
||||
}
|
||||
hal::pso::CreationError::ShaderCreationError(stage, error) => {
|
||||
pipeline::CreateRenderPipelineError::Internal {
|
||||
stage: conv::map_hal_flags_to_shader_stage(stage),
|
||||
error,
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::error!("failed to create graphics pipeline: {}", err);
|
||||
DeviceError::OutOfMemory
|
||||
pipeline::CreateRenderPipelineError::Device(DeviceError::OutOfMemory)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
@@ -113,6 +113,8 @@ pub enum CreateComputePipelineError {
|
||||
Implicit(#[from] ImplicitLayoutError),
|
||||
#[error(transparent)]
|
||||
Stage(validation::StageError),
|
||||
#[error("Internal error: {0}")]
|
||||
Internal(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -234,6 +236,11 @@ pub enum CreateRenderPipelineError {
|
||||
#[source]
|
||||
error: validation::StageError,
|
||||
},
|
||||
#[error("Internal error in stage {stage:?}: {error}")]
|
||||
Internal {
|
||||
stage: wgt::ShaderStage,
|
||||
error: String,
|
||||
},
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
|
||||
Reference in New Issue
Block a user