Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ By @cwfitzgerald in [#8388](https://github.com/gfx-rs/wgpu/pull/8388).
- `Device::poll` now always returns `PollError::CantWait` if called with `PollType::Wait` on the WebGPU backend. By @teoxoy in [#10218](https://github.com/gfx-rs/wgpu/pull/10218).
- `DownlevelFlags::SHADER_F16_IN_F32` has been removed. It previously blocked broken `quantizeToF16`, `pack2x16float`, and `unpack2x16float` on older llvmpipe / lavapipe. Using wgpu with an up-to-date Mesa version is always recommended. By @szymros in [#10957](https://github.com/gfx-rs/wgpu/pull/10957)
- Texture copy extents are now correctly validated for subsampled chroma planes. Copying is now supported between a plane of a multi-planar texture and other textures or buffers, in either direction. By @andyleiserson in [#10776](https://github.com/gfx-rs/wgpu/pull/10776).
- When a device is lost because of a backend error, wgpu-core now logs an error with the location in wgpu-core that reported it, the adapter name and the driver name and version. The Vulkan backend also logs the `VkResult` of an error it did not expect. The message passed to the device-lost callback is unchanged. By @matthargett in [#XXXXX](https://github.com/gfx-rs/wgpu/pull/XXXXX).

#### naga

Expand Down Expand Up @@ -407,6 +408,7 @@ By @cwfitzgerald in [#8388](https://github.com/gfx-rs/wgpu/pull/8388).
- Polyfill workgroup zero init in mesh and task shaders on AMD's proprietary driver, which fails with `VK_ERROR_INITIALIZATION_FAILED` when they use `OpVariable` initializers. By @apollo-2006 in [#10692](https://github.com/gfx-rs/wgpu/pull/10692).
- Fix a fence data race between submitting and polling on devices without timeline semaphores. By @JasperDeSutter in [#10960](https://github.com/gfx-rs/wgpu/pull/10960).
- Fix pass timestamp queries on Vulkan sometimes reporting a duration of almost zero for a render or compute pass, when the GPU was busy with other work. By @kikijiki in [#10837](https://github.com/gfx-rs/wgpu/pull/10837).
- A `vkCreateGraphicsPipelines`, `vkCreateComputePipelines` or `vkCreateRayTracingPipelinesKHR` call that fails with a result other than out-of-memory or device-lost (drivers return `VK_ERROR_INITIALIZATION_FAILED` or `VK_ERROR_UNKNOWN` for shaders they cannot compile) now fails that pipeline with an internal error naming the command and the result. It used to lose the device. By @matthargett in [#XXXXX](https://github.com/gfx-rs/wgpu/pull/XXXXX).

#### Metal

Expand Down Expand Up @@ -442,6 +444,10 @@ By @cwfitzgerald in [#8388](https://github.com/gfx-rs/wgpu/pull/8388).
- Fix `Device::on_uncaptured_error` never firing in browsers that do not implement `GPUDevice.onuncapturederror`, such as Safari, by listening for the `uncapturederror` event instead of assigning to that attribute. By @zemse in [#10270](https://github.com/gfx-rs/wgpu/pull/10270).
- Pass `RenderPassColorAttachment::depth_slice` to the browser, so a render pass into a 3D texture no longer fails validation with "depthSlice is required for a 3D attachment". By @jheising in [#10693](https://github.com/gfx-rs/wgpu/pull/10693).

#### deno_webgpu

- `GPUInternalError` now has the message of the error; it used to be `undefined`. `createComputePipelineAsync()` and `createRenderPipelineAsync()` now reject with reason `"internal"` instead of `"validation"` when the failure is an internal error. By @matthargett in [#XXXXX](https://github.com/gfx-rs/wgpu/pull/XXXXX).

### Performance

- GLES: `Queue::submit` no longer resets GL state for command buffers that record no commands (e.g. the internal transit and pre-pass encoders), removing two full reset sequences (about 20 GL calls) per frame for a typical single-pass WebGL2 renderer. By @chinqan in [#10913](https://github.com/gfx-rs/wgpu/pull/10913).
Expand Down
7 changes: 6 additions & 1 deletion deno_webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,14 @@ class GPUOutOfMemoryError extends GPUError {
core.registerErrorClass("GPUOutOfMemoryError", GPUOutOfMemoryError);

class GPUInternalError extends GPUError {
constructor() {
/** @param {string} message */
constructor(message) {
const prefix = "Failed to construct 'GPUInternalError'";
webidl.requiredArguments(arguments.length, 1, prefix);
message = webidl.converters.DOMString(message, prefix, "Argument 1");
super(illegalConstructorKey);
this[webidl.brand] = webidl.brand;
this[_message] = message;
}
}
core.registerErrorClass("GPUInternalError", GPUInternalError);
Expand Down
4 changes: 2 additions & 2 deletions deno_webgpu/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl GPUDevice {
Err(err) => {
let err = make_pipeline_error(
scope,
GPUPipelineErrorReason::Validation,
GPUPipelineErrorReason::of(&err),
&fmt_err(&err),
);
resolver.reject(scope, err.into());
Expand Down Expand Up @@ -608,7 +608,7 @@ impl GPUDevice {
Err(err) => {
let err = make_pipeline_error(
scope,
GPUPipelineErrorReason::Validation,
GPUPipelineErrorReason::of(&err),
&fmt_err(&err),
);
resolver.reject(scope, err.into());
Expand Down
30 changes: 24 additions & 6 deletions deno_webgpu/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub enum GPUError {
#[class("GPUOutOfMemoryError")]
OutOfMemory,
#[class("GPUInternalError")]
Internal,
Internal(String),
}

impl Display for GPUError {
Expand All @@ -95,7 +95,7 @@ impl Display for GPUError {
GPUError::Lost => Ok(()),
GPUError::Validation(s) => f.write_str(s),
GPUError::OutOfMemory => f.write_str("not enough memory left"),
GPUError::Internal => Ok(()),
GPUError::Internal(s) => f.write_str(s),
}
}
}
Expand All @@ -105,7 +105,7 @@ impl std::error::Error for GPUError {}
impl GPUError {
pub(crate) fn from_webgpu(e: impl WebGpuError) -> Self {
match e.webgpu_error_type() {
ErrorType::Internal => GPUError::Internal,
ErrorType::Internal => GPUError::Internal(fmt_err(&e)),
ErrorType::DeviceLost => GPUError::Lost, // this will be ignored by handle_error in wgpu-core
ErrorType::OutOfMemory => GPUError::OutOfMemory,
ErrorType::Validation => GPUError::Validation(fmt_err(&e)),
Expand All @@ -127,7 +127,16 @@ impl From<wgpu_types::error::Error> for GPUError {
}
}
wgpu_types::error::Error::OutOfMemory { .. } => GPUError::OutOfMemory,
wgpu_types::error::Error::Internal { .. } => GPUError::Internal,
wgpu_types::error::Error::Internal {
description,
source,
} => {
if let Some(e) = source.source() {
GPUError::Internal(fmt_err(e))
} else {
GPUError::Internal(description)
}
}
}
}
}
Expand All @@ -138,7 +147,7 @@ impl WebGpuError for GPUError {
GPUError::Lost => ErrorType::DeviceLost,
GPUError::Validation(_) => ErrorType::Validation,
GPUError::OutOfMemory => ErrorType::OutOfMemory,
GPUError::Internal => ErrorType::Internal,
GPUError::Internal(_) => ErrorType::Internal,
}
}
}
Expand Down Expand Up @@ -318,10 +327,19 @@ pub enum GPUGenericError {

pub enum GPUPipelineErrorReason {
Validation,
#[expect(dead_code)]
Internal,
}

impl GPUPipelineErrorReason {
/// The reason a pipeline creation that failed with `err` is rejected with.
pub(crate) fn of(err: &impl WebGpuError) -> Self {
match err.webgpu_error_type() {
ErrorType::Internal => Self::Internal,
_ => Self::Validation,
}
}
}

impl Display for GPUPipelineErrorReason {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/wgpu-gpu/clip_distances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static CLIP_DISTANCES: GpuTestConfiguration = GpuTestConfiguration::new()
wgpu_test::FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateGraphicsPipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(clip_distances);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/wgpu-gpu/draw_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static DRAW_INDEX: GpuTestConfiguration = GpuTestConfiguration::new()
wgpu_test::FailureCase::molten_vk()
.validation_error("could not be compiled into pipeline")
.validation_error("vkDestroyDevice")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateGraphicsPipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(test);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/wgpu-gpu/oob_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static RESTRICT_WORKGROUP_PRIVATE_FUNCTION_LET: GpuTestConfiguration = GpuTestCo
FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateComputePipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(|ctx| async move {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/wgpu-gpu/per_vertex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static PER_VERTEX: GpuTestConfiguration = GpuTestConfiguration::new()
.expect_fail(
wgpu_test::FailureCase::molten_vk()
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateGraphicsPipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(per_vertex);
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/wgpu-gpu/shader/array_size_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static ARRAY_SIZE_OVERRIDES: GpuTestConfiguration = GpuTestConfiguration::new()
wgpu_test::FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateComputePipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(move |ctx| async move {
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/wgpu-gpu/shader/zero_init_workgroup_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static ZERO_INIT_WORKGROUP_MEMORY_PARALLEL: GpuTestConfiguration = GpuTestConfig
wgpu_test::FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateComputePipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(parallel_zero_init);
Expand All @@ -42,7 +42,7 @@ static ZERO_INIT_WORKGROUP_MEMORY_PARALLEL_F16: GpuTestConfiguration = GpuTestCo
wgpu_test::FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateComputePipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(parallel_zero_init);
Expand Down Expand Up @@ -137,7 +137,7 @@ static ZERO_INIT_WORKGROUP_MEMORY: GpuTestConfiguration = GpuTestConfiguration::
wgpu_test::FailureCase::molten_vk()
.validation_error("Shader library compile failed")
.validation_error("could not be compiled into pipeline")
.unexpected_error("Unexpected Vulkan error: ERROR_INITIALIZATION_FAILED"),
.panic("vkCreateComputePipelines failed: ERROR_INITIALIZATION_FAILED"),
),
)
.run_async(|ctx| async move {
Expand Down
22 changes: 21 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ impl Device {
.map_err(|e| self.handle_hal_error(e));
}

#[track_caller]
pub fn handle_hal_error(&self, error: hal::DeviceError) -> DeviceError {
match error {
hal::DeviceError::OutOfMemory
Expand All @@ -905,6 +906,7 @@ impl Device {
DeviceError::from_hal(error)
}

#[track_caller]
pub fn handle_hal_error_with_nonfatal_oom(&self, error: hal::DeviceError) -> DeviceError {
match error {
hal::DeviceError::OutOfMemory => DeviceError::from_hal(error),
Expand Down Expand Up @@ -5446,6 +5448,7 @@ impl Device {
/// so that `self` is marked as lost when appropriate.
///
/// [`CreatePipelineError`]: pipeline::CreatePipelineError
#[track_caller]
pub(crate) fn handle_hal_pipeline_error(
&self,
error: hal::PipelineError,
Expand Down Expand Up @@ -5672,12 +5675,29 @@ impl Device {
Ok(query_set)
}

#[track_caller]
pub(crate) fn lose(&self, message: &str) {
// Follow the steps at https://gpuweb.github.io/gpuweb/#lose-the-device.

// Mark the device explicitly as invalid. This is checked in various
// places to prevent new work from being submitted.
self.valid.store(false, Ordering::Release);
let was_valid = self.valid.swap(false, Ordering::AcqRel);

if was_valid {
// `message` rarely identifies the cause on its own ("Device is
// lost"), so say which operation failed and on which driver.
// This is only logged: the message below may reach web content.
let info = &self.adapter.raw.info;
log::error!(
"{} lost at {}: {message}. Adapter: {:?} ({:?}), driver: {:?} {:?}",
self.error_ident(),
core::panic::Location::caller(),
info.name,
info.backend,
info.driver,
info.driver_info,
);
}

// 1) Resolve the GPUDevice device.lost promise.
if let Some(device_lost_closure) = self.device_lost_closure.lock().take() {
Expand Down
Loading
Loading