Skip to content

[hal vulkan] Fail the pipeline, not the device, when the driver rejects it - #14

Open
matthargett wants to merge 3 commits into
review-base/trunk-60cef2be8from
fix/vulkan-pipeline-creation-error-20261126
Open

matthargett wants to merge 3 commits into
review-base/trunk-60cef2be8from
fix/vulkan-pipeline-creation-error-20261126

Conversation

@matthargett

Copy link
Copy Markdown
Member

Connections

Upstream issue 10027 in gfx-rs/wgpu describes the first problem for Mesa ANV and NVIDIA's driver. It was closed by its author without a linked change, and the code it describes is the same on trunk 60cef2be8.

Found running the WebGPU CTS with cts_runner on a Mali-G52 MC2 (Arm proprietary Vulkan 1.1 driver v1.r20p0-01rel0, Android 10). #7 fixes the shader that triggers it on that device; this PR is about what happens when a driver rejects a pipeline for any reason. Other fixes for the device: #8, #9, #10.

Description

Three commits.

  1. [hal vulkan] A rejected pipeline fails the pipeline. vkCreate*Pipelines results other than out-of-memory became DeviceError::Unexpected, which drops the result code, and wgpu-core loses the device on that. They are now PipelineError::Linkage with the command name and the result, as on DX12 and Metal: an internal error on the pipeline, and the device stays usable. VK_ERROR_DEVICE_LOST maps to a lost device.
  2. [core] Log where and on which driver a device was lost. The first time a backend error loses a device, wgpu-core logs the place in wgpu-core that reported it (#[track_caller] on handle_hal_error), the adapter, the backend and the driver name and version. The Vulkan backend logs the VkResult of an unexpected error. The message passed to the device-lost callback is unchanged.
  3. [deno] Keep the message of internal errors. GPUInternalError.message was undefined. The async pipeline creation methods now reject with reason "internal" for an internal error instead of "validation".

To check when reviewing:

  • With internal_error_panic (which cts_runner enables) these results no longer panic. Eight GPU tests expect this failure from MoltenVK and matched the panic text; their expectations now match the new error. I have no MoltenVK install, so only CI checks them.
  • The temporary shader modules are now destroyed before the result is checked; they used to leak on failure.
  • The stage in these messages is printed with {:?}, which is long now that ShaderStages has two parts. Not changed here.

Testing

  • macOS: cargo fmt --check and clippy for wgpu-hal, wgpu-core and deno_webgpu are clean; the wgpu-hal unit tests pass, including a new one for the result mapping. Not run locally: the GPU tests and cts_runner's own tests.
  • Mali-G52, cts_runner built from trunk 60cef2be8 and from this branch.

A compute pipeline whose shader declares a texture_depth_multisampled_2d, which this driver rejects with VK_ERROR_INITIALIZATION_FAILED, then more work on the same device. The second "before" run is trunk built without internal_error_panic, which is what an application gets:

A pipeline the driver rejects, then more work on the same device, before and after

A render pass that loses the device on this driver (the layout bug #9 works around). Both runs end in the deno_webgpu panic and hang that #10 fixes; the difference is the ERROR line, which points at the fence wait in Device::maintain:

A lost device, before and after: the new log line

  • CTS textureNumSamples and the two resource_compatibility groups, 199 cases: on trunk four of the nine processes abort and 139 cases report a result. With this branch all 199 report one: 195 pass and 4 fail. The four declare a multisampled depth texture, and each failure message names the Vulkan command and the result.
  • Not tested on desktop Vulkan or with ray tracing pipelines.

Squash or Rebase?

Rebase. The three commits are independent.

LLM Use?

Claude Code (Claude Mythos 5.2) found this on the device, wrote the code and the probe, ran the tests and drafted this description.

…ts it

`vkCreateGraphicsPipelines`, `vkCreateComputePipelines` and
`vkCreateRayTracingPipelinesKHR` results other than out-of-memory were
mapped to `DeviceError::Unexpected`, which dropped the result code. wgpu-core
loses the device on that error, so one shader a driver could not compile made
every later operation on the device fail, and nothing said which pipeline or
which result was the cause. With the `internal_error_panic` feature, which
`cts_runner` enables, the process panicked.

Drivers return such results for shaders they cannot compile, and only the
pipeline is affected. Arm's proprietary Mali driver (seen with r20p0 on a
Mali-G52 MC2) returns `VK_ERROR_INITIALIZATION_FAILED` for a shader that
declares a multisampled depth image. The GPU tests expect the same result
from MoltenVK in eight tests, and gfx-rs#10027 reports it for Mesa ANV and NVIDIA's
driver with compute shaders that need too much private memory.

Report these as `PipelineError::Linkage` with the command name and the result,
as the DX12 and Metal backends do when pipeline creation fails. wgpu-core
turns that into an internal error on the pipeline, with the pipeline's label,
and the device stays usable. `VK_ERROR_DEVICE_LOST` is now reported as a lost
device instead of an unexpected error.

Since the device now outlives a failed creation, destroy the temporary shader
modules before checking the result instead of leaking them.

The MoltenVK expectations of those eight GPU tests matched the old panic text
and are updated to the new error.
When a backend error makes wgpu-core lose a device, the device-lost callback
gets "Device is lost" or "Unexpected error variant (driver implementation is
at fault)" and nothing is logged. Neither says which operation failed, which
driver was in use, or what the driver returned, so a report from the field
cannot be matched to a cause.

Log an error the first time a device is lost, with the caller of
`handle_hal_error` (`#[track_caller]`, so the location in wgpu-core of the
operation that failed), the adapter name, the backend, and the driver name and
version. In the Vulkan backend, log the `VkResult` of an unexpected error,
which `DeviceError::Unexpected` cannot carry.

The message passed to the device-lost callback is unchanged: embedders may
hand it to web content, and the driver strings are already available to the
application from `AdapterInfo`.
`GPUError::Internal` had no payload, and the JS `GPUInternalError`
constructor took no message, so `message` was `undefined` on an internal
error popped from an error scope or passed to `uncapturederror`. A script
could tell that pipeline creation failed in the backend but not why.

Carry the message, as `GPUValidationError` does. WebGPU declares the
constructor of all three error classes with a `message` argument.

`createComputePipelineAsync()` and `createRenderPipelineAsync()` rejected
with reason "validation" for every failure. Use "internal" when the error
is an internal one.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:53:57.841218Z 9655925 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant