You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A certain pattern in SPIRV shaders seems to cause a crash in my AMD vulkan driver on windows. It seems to involve a variable defined using OpVariable with an initializer, loading a value from somewhere else via OpAccessChain and storing it to the variable, and then calling a function with a pointer to that variable.
I originally saw this with spriv from: glsl -> shaderc(unoptimized) -> spirv -> naga(create_shader_module_unchecked) -> spirv
I minimized the glsl shader and then made modifications to the spirv to narrow down the cause and found a combination of several aspects that seem to trigger the crash. Finally I found some wgsl that produces spirv with the same issue.
Not sure if there is anything to do other than reporting this to AMD, but I assume this is valuable to document here. I was actually planning to debug a different issue I saw previously with this combination of shader processing and platform... but was stopped by this crash.
Repro steps
Diff
diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs
index 7c82d49cf..3cb65f4f5 100644
--- a/examples/src/hello_triangle/mod.rs+++ b/examples/src/hello_triangle/mod.rs@@ -10,7 +10,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
size.width = size.width.max(1);
size.height = size.height.max(1);
- let instance = wgpu::Instance::default();+ let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {+ backends: wgpu::Backends::VULKAN,+ // Debugging OpLine(s) make the issue go away.+ flags: wgpu::InstanceFlags::empty(),+ ..Default::default()+ });
let surface = instance.create_surface(&window).unwrap();
let adapter = instance
diff --git a/examples/src/hello_triangle/shader.wgsl b/examples/src/hello_triangle/shader.wgsl
index f84ccfe94..2f68f3716 100644
--- a/examples/src/hello_triangle/shader.wgsl+++ b/examples/src/hello_triangle/shader.wgsl@@ -5,7 +5,14 @@ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) ve
return vec4<f32>(x, y, 0.0, 1.0);
}
+fn ptr_function(x: ptr<function, f32>) {}+
@fragment
-fn fs_main() -> @location(0) vec4<f32> {+fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> {+ var vector = vec2<f32>(1.0);+ var x: f32;+ // Combination of x with OpVariable initializer, loading via OpAccessChain and storing to x, and calling a function with a ptr to x.+ x = vector.x;+ ptr_function(&x);
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
Apply this diff or checkout amd-windows-vk-crash from my fork
Run cargo r --bin wgpu-examples hello_triangle
Expected vs observed behavior
no crash
Extra materials
No vulkan validation layer errors (made sure they were enabled)
Description
A certain pattern in SPIRV shaders seems to cause a crash in my AMD vulkan driver on windows. It seems to involve a variable defined using
OpVariable
with an initializer, loading a value from somewhere else viaOpAccessChain
and storing it to the variable, and then calling a function with a pointer to that variable.I originally saw this with spriv from: glsl -> shaderc(unoptimized) -> spirv -> naga(create_shader_module_unchecked) -> spirv
I minimized the glsl shader and then made modifications to the spirv to narrow down the cause and found a combination of several aspects that seem to trigger the crash. Finally I found some wgsl that produces spirv with the same issue.
Not sure if there is anything to do other than reporting this to AMD, but I assume this is valuable to document here. I was actually planning to debug a different issue I saw previously with this combination of shader processing and platform... but was stopped by this crash.
Repro steps
Diff
Apply this diff or checkout
amd-windows-vk-crash
from my forkRun
cargo r --bin wgpu-examples hello_triangle
Expected vs observed behavior
no crash
Extra materials
No vulkan validation layer errors (made sure they were enabled)
Output spirv
LLDB
Exception 0xc0000005 encountered at address 0x7ff8f85517c9: Access violation reading location 0x00000018
cppvsdbg
Unhandled exception at 0x00007FF8FD2017C9 (amdvlk64.dll) in wgpu-examples.exe: 0xC0000005: Access violation reading location 0x0000000000000018.
Platform
wgpu fb0cb1e
Windows
Vulkan
AMD Radeon RX 6650 XT
driver: "24.8.1 (AMD proprietary shader compiler)"
The text was updated successfully, but these errors were encountered: