mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 17:01:15 +01:00
Move error handling of create_shader_module into wgc
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
1 parent
31f1b0cd81
commit
bdea80afac
5 files changed
+27
-56
No files matched your search
@@ -474,7 +474,7 @@ impl GPUDevice {
|
||||
runtime_checks: wgpu_types::ShaderRuntimeChecks::default(),
|
||||
};
|
||||
|
||||
let (wgpu_shader_module, err) = self.wgpu_device.create_shader_module(
|
||||
let wgpu_shader_module = self.wgpu_device.create_shader_module(
|
||||
&wgpu_descriptor,
|
||||
wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::Borrowed(
|
||||
&descriptor.code,
|
||||
@@ -488,7 +488,6 @@ impl GPUDevice {
|
||||
);
|
||||
let compilation_info = make_cppgc_object(scope, compilation_info);
|
||||
let compilation_info = v8::Global::new(scope, compilation_info);
|
||||
self.error_handler.push_error(err);
|
||||
|
||||
GPUShaderModule {
|
||||
wgpu_shader_module,
|
||||
|
||||
+2
-8
@@ -255,10 +255,7 @@ impl Player {
|
||||
data.kind()
|
||||
);
|
||||
};
|
||||
let (shader, error) = device.create_shader_module(&desc, source);
|
||||
if let Some(e) = error {
|
||||
panic!("shader compilation error:\n---{code}\n---\n{e}");
|
||||
}
|
||||
let shader = device.create_shader_module(&desc, source);
|
||||
self.shader_modules.insert(id, shader);
|
||||
}
|
||||
Action::CreateShaderModulePassthrough {
|
||||
@@ -313,10 +310,7 @@ impl Player {
|
||||
glsl,
|
||||
wgsl,
|
||||
};
|
||||
let (shader, error) = unsafe { device.create_shader_module_passthrough(&desc) };
|
||||
if let Some(e) = error {
|
||||
panic!("shader compilation error:\n{e}");
|
||||
}
|
||||
let shader = unsafe { device.create_shader_module_passthrough(&desc) };
|
||||
self.shader_modules.insert(id, shader);
|
||||
}
|
||||
Action::DropShaderModule(id) => {
|
||||
|
||||
@@ -627,9 +627,6 @@ impl Global {
|
||||
device_id: DeviceId,
|
||||
desc: &ShaderModuleDescriptor,
|
||||
id_in: id::ShaderModuleId,
|
||||
) -> (
|
||||
id::ShaderModuleId,
|
||||
Option<pipeline::CreateShaderModuleError>,
|
||||
) {
|
||||
let mut hub = self.hub.borrow_mut();
|
||||
let Hub {
|
||||
@@ -647,11 +644,9 @@ impl Global {
|
||||
runtime_checks: wgt::ShaderRuntimeChecks::checked(),
|
||||
};
|
||||
|
||||
let (shader, error) = device.create_shader_module(&desc, code);
|
||||
let shader = device.create_shader_module(&desc, code);
|
||||
|
||||
let id = shader_modules.assign(id_in, shader);
|
||||
|
||||
(id, error)
|
||||
shader_modules.assign(id_in, shader);
|
||||
}
|
||||
|
||||
pub fn shader_module_compilation_info(
|
||||
|
||||
@@ -2410,10 +2410,7 @@ impl Device {
|
||||
self: &Arc<Self>,
|
||||
desc: &pipeline::ShaderModuleDescriptor<'a>,
|
||||
source: pipeline::ShaderModuleSource<'a>,
|
||||
) -> (
|
||||
Arc<pipeline::ShaderModule>,
|
||||
Option<pipeline::CreateShaderModuleError>,
|
||||
) {
|
||||
) -> Arc<pipeline::ShaderModule> {
|
||||
profiling::scope!("Device::create_shader_module");
|
||||
#[cfg(feature = "trace")]
|
||||
let data = self.trace.lock().as_mut().map(|trace| {
|
||||
@@ -2443,17 +2440,17 @@ impl Device {
|
||||
}
|
||||
}
|
||||
});
|
||||
let (shader, error) = match self.create_shader_module_inner(desc, source) {
|
||||
Ok(shader) => (shader, None),
|
||||
Err(e) => {
|
||||
let shader = self
|
||||
.create_shader_module_inner(desc, source)
|
||||
.unwrap_or_else(|e| {
|
||||
let shader = pipeline::ShaderModule::invalid(
|
||||
Arc::clone(self),
|
||||
desc.label.to_string(),
|
||||
shader_module_error_into_compilation_info(&e),
|
||||
);
|
||||
(shader, Some(e))
|
||||
}
|
||||
};
|
||||
self.handle_error(e, desc.label.as_deref(), "Device::create_shader_module");
|
||||
shader
|
||||
});
|
||||
api_log!("Device::create_shader_module -> {:?}", Arc::as_ptr(&shader));
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
@@ -2471,7 +2468,7 @@ impl Device {
|
||||
data,
|
||||
});
|
||||
};
|
||||
(shader, error)
|
||||
shader
|
||||
}
|
||||
|
||||
pub(crate) fn create_shader_module_inner<'a>(
|
||||
@@ -2619,23 +2616,24 @@ impl Device {
|
||||
pub unsafe fn create_shader_module_passthrough<'a>(
|
||||
self: &Arc<Self>,
|
||||
desc: &pipeline::ShaderModuleDescriptorPassthrough<'a>,
|
||||
) -> (
|
||||
Arc<pipeline::ShaderModule>,
|
||||
Option<pipeline::CreateShaderModuleError>,
|
||||
) {
|
||||
) -> Arc<pipeline::ShaderModule> {
|
||||
profiling::scope!("Device::create_shader_module_passthrough");
|
||||
|
||||
let (shader, error) = match unsafe { self.create_shader_module_passthrough_inner(desc) } {
|
||||
Ok(shader) => (shader, None),
|
||||
Err(e) => {
|
||||
let shader =
|
||||
unsafe { self.create_shader_module_passthrough_inner(desc) }.unwrap_or_else(|e| {
|
||||
let shader = pipeline::ShaderModule::invalid(
|
||||
Arc::clone(self),
|
||||
desc.label.to_string(),
|
||||
shader_module_error_into_compilation_info(&e),
|
||||
);
|
||||
(shader, Some(e))
|
||||
}
|
||||
};
|
||||
self.handle_error(
|
||||
e,
|
||||
desc.label.as_deref(),
|
||||
"Device::create_shader_module_passthrough",
|
||||
);
|
||||
shader
|
||||
});
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(ref mut trace) = *self.trace.lock() {
|
||||
use crate::device::trace::{DataKind, IntoTrace as _};
|
||||
@@ -2668,7 +2666,7 @@ impl Device {
|
||||
"Device::create_shader_module_spirv -> {:?}",
|
||||
Arc::as_ptr(&shader)
|
||||
);
|
||||
(shader, error)
|
||||
shader
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn create_shader_module_passthrough_inner<'a>(
|
||||
|
||||
@@ -795,15 +795,7 @@ impl dispatch::DeviceInterface for CoreDevice {
|
||||
ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module),
|
||||
ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"),
|
||||
};
|
||||
let (wgpu_shader_module, error) =
|
||||
self.wgpu_device.create_shader_module(&descriptor, source);
|
||||
if let Some(cause) = error {
|
||||
self.wgpu_device.handle_error(
|
||||
cause.clone(),
|
||||
desc.label,
|
||||
"Device::create_shader_module",
|
||||
);
|
||||
}
|
||||
let wgpu_shader_module = self.wgpu_device.create_shader_module(&descriptor, source);
|
||||
|
||||
CoreShaderModule { wgpu_shader_module }.into()
|
||||
}
|
||||
@@ -813,15 +805,8 @@ impl dispatch::DeviceInterface for CoreDevice {
|
||||
desc: &crate::ShaderModuleDescriptorPassthrough<'_>,
|
||||
) -> dispatch::DispatchShaderModule {
|
||||
let desc = desc.map_label(|l| l.map(Cow::from));
|
||||
let (wgpu_shader_module, error) =
|
||||
let wgpu_shader_module =
|
||||
unsafe { self.wgpu_device.create_shader_module_passthrough(&desc) };
|
||||
if let Some(cause) = error {
|
||||
self.wgpu_device.handle_error(
|
||||
cause.clone(),
|
||||
desc.label.as_deref(),
|
||||
"Device::create_shader_module_passthrough",
|
||||
);
|
||||
}
|
||||
|
||||
CoreShaderModule { wgpu_shader_module }.into()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user