From 8686ef4bcb9d9d243ffa51263fed4e17280536f1 Mon Sep 17 00:00:00 2001 From: Garvit Surana <251430630+garvitsurana271@users.noreply.github.com> Date: Mon, 23 Nov 2026 00:00:12 +0000 Subject: [PATCH] fix(gpu): ask only NVK for a pipeline's internal representations in a lost device's fault dump, as Stela's pipelines are made without the capture flag, where RADV answered the query with strlen(NULL) and stopped the PC on an AMD device loss (review X1) --- crates/stela-driver-gpu/src/metal/native.rs | 22 +++++++++++++++++-- .../src/metal/native/tests.rs | 11 ++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/stela-driver-gpu/src/metal/native.rs b/crates/stela-driver-gpu/src/metal/native.rs index e5030a056f..787804df21 100644 --- a/crates/stela-driver-gpu/src/metal/native.rs +++ b/crates/stela-driver-gpu/src/metal/native.rs @@ -36,7 +36,7 @@ use super::{ error::{Error, Result, ensure}, fault_dump::{self, ShaderImage}, vulkan::{ - SampleCounts, + DriverId, SampleCounts, backend::{ Backend, BufferAllocation, Descriptor, HeapUse, IdleStep, MemoryBlocks, Object, Outside, PreparedImport, Requirements, requirements, @@ -548,6 +548,19 @@ struct ExtensionFns { struct Executables { fns: khr::pipeline_executable_properties::Device, log: fn(&str), + /// The driver answers internal representations of a pipeline made + /// without `CAPTURE_INTERNAL_REPRESENTATIONS` ([`reads_representations`]). + representations: bool, +} + +/// Whether the fault dump may ask `driver` for a pipeline's internal +/// representations, which Stela's pipelines are created without asking to +/// capture: NVK answers them (Mesa patch 0043), while the Vulkan spec makes +/// the query invalid without the capture flag and RADV then runs +/// `strlen(NULL)` (radv_pipeline.c `radv_copy_representation`), stopping the +/// PC on the device loss the dump reports. +fn reads_representations(driver: DriverId) -> bool { + driver == DriverId::MesaNvk } /// A statistic's value as an unsigned count; 0 for a format that is none. @@ -625,7 +638,11 @@ impl Executables { /// The executable's internal representations, by name, with their /// bytes: the driver says each one's size, then fills buffers of them. + /// None from a driver that cannot be asked ([`reads_representations`]). fn representations(&self, info: &vk::PipelineExecutableInfoKHR<'_>) -> Vec<(String, Vec)> { + if !self.representations { + return Vec::new(); + } // SAFETY: the executable is one the pipeline listed; with no data // pointers the driver writes each representation's size alone. let Ok(sized) = (unsafe { @@ -925,6 +942,7 @@ impl NativeBackend { executables: has(khr::pipeline_executable_properties::NAME).then(|| Executables { fns: khr::pipeline_executable_properties::Device::new(&instance, &device), log: loader.log, + representations: reads_representations(snapshot.identity.driver_id), }), }; let kernels = kernels(physical); @@ -1973,7 +1991,7 @@ impl NativeBackend { fn report_executables(&self, pipeline: vk::Pipeline) { /// Instructions past which a shader is reported. const LARGE_SHADER: u64 = 16384; - let Some(Executables { fns, log }) = &self.fns.executables else { + let Some(Executables { fns, log, .. }) = &self.fns.executables else { return; }; let info = vk::PipelineInfoKHR::default().pipeline(pipeline); diff --git a/crates/stela-driver-gpu/src/metal/native/tests.rs b/crates/stela-driver-gpu/src/metal/native/tests.rs index e31f96acaf..ca9498533e 100644 --- a/crates/stela-driver-gpu/src/metal/native/tests.rs +++ b/crates/stela-driver-gpu/src/metal/native/tests.rs @@ -19,6 +19,17 @@ use ash::vk::{self, Handle}; mod lifecycle; mod submission; +#[test] +fn only_nvk_is_asked_for_internal_representations() { + use crate::metal::vulkan::DriverId; + assert!(super::reads_representations(DriverId::MesaNvk)); + // RADV dereferences the representation it never kept without the + // capture flag; ANV and Venus are not asked either. + assert!(!super::reads_representations(DriverId::MesaRadv)); + assert!(!super::reads_representations(DriverId::IntelOpenSourceMesa)); + assert!(!super::reads_representations(DriverId::MesaVenus)); +} + #[test] fn in_flight_retirement_observes_a_timeline_once_per_ready_run() { let main = vk::Semaphore::from_raw(1);