hal/vulkan: With internal_error_panic, panic on Vulkan validation errors (#9879)

This commit is contained in:
Andy Leiserson authored and GitHub committed 2026-07-17 12:41:57 -07:00
1 parent 59209f2761
commit ef79a923cf
5 files changed
+82 -4

No files matched your search

Generated
+1
View File
@@ -815,6 +815,7 @@ dependencies = [
"tempfile",
"termcolor",
"tokio",
"wgpu-hal",
]
[[package]]
+1
View File
@@ -24,6 +24,7 @@ log.workspace = true
pico-args.workspace = true
tokio = { workspace = true, features = ["full"] }
termcolor.workspace = true
wgpu-hal = { workspace = true, features = ["internal_error_panic"] }
[dev-dependencies]
tempfile.workspace = true
+5 -4
View File
@@ -186,10 +186,11 @@ portable-atomic = ["dep:portable-atomic", "dep:portable-atomic-util"]
# Panic when running into a device lost error (for debugging purposes).
# Only affects the d3d12 and vulkan backends.
device_lost_panic = []
# Panic when running into an internal error other than out-of-memory and device lost
# (for debugging purposes).
#
# Only affects the d3d12 and vulkan backends.
# Panic on unexpected errors (does _not_ include out-of-memory errors or device
# loss) from platform APIs, for debugging purposes. Such errors likely indicate
# bug(s) in wgpu, platform components, or drivers. Despite the name, this is not
# related to the spec's `GPUInternalError`. Only affects the d3d12 and vulkan
# backends.
internal_error_panic = []
# Tracks validation errors in a `VALIDATION_CANARY` static.
validation_canary = ["dep:parking_lot"]
+71
View File
@@ -158,9 +158,80 @@ unsafe extern "system" fn debug_utils_messenger_callback(
crate::VALIDATION_CANARY.add(message.to_string());
}
#[cfg(all(debug_assertions, feature = "internal_error_panic"))]
if level == log::Level::Error
&& message_type.contains(vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION)
&& !error_is_waived(cd.message_id_number)
&& !cts_error_is_waived(cd.message_id_number)
{
use alloc::string::ToString as _;
panic!("{}", message.to_string());
}
vk::FALSE
}
/// Validation errors known to fire, not just in the CTS.
///
/// These never panic.
#[cfg(feature = "internal_error_panic")]
fn error_is_waived(message_id_number: i32) -> bool {
const WAIVED_MESSAGE_IDS: &[i32] = &[
// SYNC-HAZARD-WRITE-AFTER-WRITE
// e.g. webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:*
// https://github.com/gfx-rs/wgpu/issues/5231
// https://github.com/gfx-rs/wgpu/issues/8705
0x5c0ec5d6_u32 as i32,
];
WAIVED_MESSAGE_IDS.contains(&message_id_number)
}
/// Validation errors known to fire when running the CTS.
///
/// These waivers are keyed off the `WGPU_CTS_XTASK` environment variable, which
/// is set in `xtask/src/cts.rs`.
#[cfg(feature = "internal_error_panic")]
fn cts_error_is_waived(message_id_number: i32) -> bool {
use std::sync::LazyLock;
static WGPU_CTS_XTASK: LazyLock<bool> =
LazyLock::new(|| std::env::var_os("WGPU_CTS_XTASK").is_some());
if !*WGPU_CTS_XTASK {
return false;
}
const WAIVED_MESSAGE_IDS: &[i32] = &[
// VUID-vkCmdPushConstants-offset-01795
// e.g. webgpu:api,operation,command_buffer,programmable,immediate:*
0x27bc88c6_u32 as i32,
// VUID-SampleMask-SampleMask-04359
// e.g. webgpu:api,validation,render_pipeline,inter_stage:max_variables_count,*
0x34d444b2_u32 as i32,
// VUID-vkCmdCopyImage-srcImage-01728
// e.g. webgpu:api,validation,encoding,cmds,copyTextureToTexture:*
0x6b654496_u32 as i32,
// VUID-StandaloneSpirv-OpImageQuerySizeLod-04659
// e.g. webgpu:shader,execution,expression,call,builtin,textureNumLayers:*
0x82396078_u32 as i32,
// VUID-RuntimeSpirv-Location-06272
// e.g. webgpu:api,validation,render_pipeline,inter_stage:max_variables_count,*
0xa3614f8b_u32 as i32,
// VUID-VkViewport-width-01770
// e.g. webgpu:api,validation,encoding,cmds,render,dynamic_state:*
0xa4164ba5_u32 as i32,
// VUID-VkImageViewCreateInfo-image-04441
// e.g. webgpu:api,validation,createView:texture_view_usage:*
0xb75da543_u32 as i32,
// VUID-VkBufferCreateInfo-None-09500
// e.g. webgpu:api,validation,buffer,create:usage,*
0xf6d454db_u32 as i32,
];
WAIVED_MESSAGE_IDS.contains(&message_id_number)
}
impl super::DebugUtilsCreateInfo {
fn to_vk_create_info(&self) -> vk::DebugUtilsMessengerCreateInfoEXT<'_> {
let user_data_ptr: *const super::DebugUtilsMessengerUserData = &*self.callback_data;
+4
View File
@@ -72,6 +72,10 @@ pub fn run_cts(
let llvm_cov = args.contains("--llvm-cov");
let release = args.contains("--release");
// This is used in the Vulkan hal to waive pre-existing validation
// errors in the CTS, until they can be fixed.
shell.set_var("WGPU_CTS_XTASK", "1");
let output_filter = args
.opt_value_from_str::<_, String>("--print-output-when")?
.map(|f| {