chore(ext): update webgpu (#15059)

This commit is contained in:
Dante Issaias 2022-07-20 01:22:26 +01:00 committed by GitHub
parent 649536e266
commit 2b1f145c3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 1605 additions and 1867 deletions

View file

@ -3,7 +3,9 @@ use deno_core::error::AnyError;
use deno_core::ResourceId;
use serde::Serialize;
use std::convert::From;
use std::error::Error;
use std::fmt;
use std::fmt::Write;
use wgpu_core::binding_model::CreateBindGroupError;
use wgpu_core::binding_model::CreateBindGroupLayoutError;
use wgpu_core::binding_model::CreatePipelineLayoutError;
@ -29,6 +31,20 @@ use wgpu_core::resource::CreateSamplerError;
use wgpu_core::resource::CreateTextureError;
use wgpu_core::resource::CreateTextureViewError;
fn fmt_err(err: &(dyn Error + 'static)) -> String {
let mut output = err.to_string();
let mut e = err.source();
while let Some(source) = e {
// No error possible, unwrap is fine here.
// https://github.com/rust-lang/rust/blob/1.47.0/library/alloc/src/string.rs#L2414-L2427
write!(output, ": {source}").unwrap();
e = source.source();
}
output
}
#[derive(Serialize)]
pub struct WebGpuResult {
pub rid: Option<ResourceId>,
@ -49,14 +65,14 @@ impl WebGpuResult {
) -> Self {
Self {
rid: Some(rid),
err: err.map(|e| e.into()),
err: err.map(Into::into),
}
}
pub fn maybe_err<T: Into<WebGpuError>>(err: Option<T>) -> Self {
Self {
rid: None,
err: err.map(|e| e.into()),
err: err.map(Into::into),
}
}
@ -82,7 +98,7 @@ impl From<CreateBufferError> for WebGpuError {
match err {
CreateBufferError::Device(err) => err.into(),
CreateBufferError::AccessError(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -92,7 +108,7 @@ impl From<DeviceError> for WebGpuError {
match err {
DeviceError::Lost => WebGpuError::Lost,
DeviceError::OutOfMemory => WebGpuError::OutOfMemory,
DeviceError::Invalid => WebGpuError::Validation(err.to_string()),
DeviceError::Invalid => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -101,7 +117,7 @@ impl From<BufferAccessError> for WebGpuError {
fn from(err: BufferAccessError) -> Self {
match err {
BufferAccessError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -110,7 +126,7 @@ impl From<CreateBindGroupLayoutError> for WebGpuError {
fn from(err: CreateBindGroupLayoutError) -> Self {
match err {
CreateBindGroupLayoutError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -119,7 +135,7 @@ impl From<CreatePipelineLayoutError> for WebGpuError {
fn from(err: CreatePipelineLayoutError) -> Self {
match err {
CreatePipelineLayoutError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -128,44 +144,44 @@ impl From<CreateBindGroupError> for WebGpuError {
fn from(err: CreateBindGroupError) -> Self {
match err {
CreateBindGroupError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
impl From<RenderBundleError> for WebGpuError {
fn from(err: RenderBundleError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CreateRenderBundleError> for WebGpuError {
fn from(err: CreateRenderBundleError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CopyError> for WebGpuError {
fn from(err: CopyError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<CommandEncoderError> for WebGpuError {
fn from(err: CommandEncoderError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<QueryError> for WebGpuError {
fn from(err: QueryError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
impl From<ComputePassError> for WebGpuError {
fn from(err: ComputePassError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@ -173,14 +189,14 @@ impl From<CreateComputePipelineError> for WebGpuError {
fn from(err: CreateComputePipelineError) -> Self {
match err {
CreateComputePipelineError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
impl From<GetBindGroupLayoutError> for WebGpuError {
fn from(err: GetBindGroupLayoutError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@ -188,14 +204,14 @@ impl From<CreateRenderPipelineError> for WebGpuError {
fn from(err: CreateRenderPipelineError) -> Self {
match err {
CreateRenderPipelineError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
impl From<RenderPassError> for WebGpuError {
fn from(err: RenderPassError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@ -203,7 +219,7 @@ impl From<CreateSamplerError> for WebGpuError {
fn from(err: CreateSamplerError) -> Self {
match err {
CreateSamplerError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -212,7 +228,7 @@ impl From<CreateShaderModuleError> for WebGpuError {
fn from(err: CreateShaderModuleError) -> Self {
match err {
CreateShaderModuleError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -221,14 +237,14 @@ impl From<CreateTextureError> for WebGpuError {
fn from(err: CreateTextureError) -> Self {
match err {
CreateTextureError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
impl From<CreateTextureViewError> for WebGpuError {
fn from(err: CreateTextureViewError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}
@ -236,7 +252,7 @@ impl From<CreateQuerySetError> for WebGpuError {
fn from(err: CreateQuerySetError) -> Self {
match err {
CreateQuerySetError::Device(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -245,7 +261,7 @@ impl From<QueueSubmitError> for WebGpuError {
fn from(err: QueueSubmitError) -> Self {
match err {
QueueSubmitError::Queue(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
@ -254,14 +270,14 @@ impl From<QueueWriteError> for WebGpuError {
fn from(err: QueueWriteError) -> Self {
match err {
QueueWriteError::Queue(err) => err.into(),
err => WebGpuError::Validation(err.to_string()),
err => WebGpuError::Validation(fmt_err(&err)),
}
}
}
impl From<ClearError> for WebGpuError {
fn from(err: ClearError) -> Self {
WebGpuError::Validation(err.to_string())
WebGpuError::Validation(fmt_err(&err))
}
}