-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
666 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::{error::Error, fmt}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ShaderError<E> { | ||
/// The source code of the shader. | ||
pub source: String, | ||
pub label: Option<String>, | ||
pub inner: Box<E>, | ||
} | ||
|
||
#[cfg(feature = "wgsl-in")] | ||
impl fmt::Display for ShaderError<crate::front::wgsl::ParseError> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let label = self.label.as_deref().unwrap_or_default(); | ||
let string = self.inner.emit_to_string(&self.source); | ||
write!(f, "\nShader '{label}' parsing {string}") | ||
} | ||
} | ||
#[cfg(feature = "glsl-in")] | ||
impl fmt::Display for ShaderError<crate::front::glsl::ParseError> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let label = self.label.as_deref().unwrap_or_default(); | ||
let string = self.inner.emit_to_string(&self.source); | ||
write!(f, "\nShader '{label}' parsing {string}") | ||
} | ||
} | ||
#[cfg(feature = "spv-in")] | ||
impl fmt::Display for ShaderError<crate::front::spv::Error> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let label = self.label.as_deref().unwrap_or_default(); | ||
let string = self.inner.emit_to_string(&self.source); | ||
write!(f, "\nShader '{label}' parsing {string}") | ||
} | ||
} | ||
impl fmt::Display for ShaderError<crate::WithSpan<crate::valid::ValidationError>> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
use codespan_reporting::{ | ||
diagnostic::{Diagnostic, Label}, | ||
files::SimpleFile, | ||
term, | ||
}; | ||
|
||
let label = self.label.as_deref().unwrap_or_default(); | ||
let files = SimpleFile::new(label, &self.source); | ||
let config = term::Config::default(); | ||
let mut writer = term::termcolor::NoColor::new(Vec::new()); | ||
|
||
let diagnostic = Diagnostic::error().with_labels( | ||
self.inner | ||
.spans() | ||
.map(|&(span, ref desc)| { | ||
Label::primary((), span.to_range().unwrap()).with_message(desc.to_owned()) | ||
}) | ||
.collect(), | ||
); | ||
|
||
term::emit(&mut writer, &config, &files, &diagnostic).expect("cannot write error"); | ||
|
||
write!( | ||
f, | ||
"\nShader validation {}", | ||
String::from_utf8_lossy(&writer.into_inner()) | ||
) | ||
} | ||
} | ||
impl<E> Error for ShaderError<E> | ||
where | ||
ShaderError<E>: fmt::Display, | ||
E: Error + 'static, | ||
{ | ||
fn source(&self) -> Option<&(dyn Error + 'static)> { | ||
Some(&self.inner) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/*🐈🐈🐈🐈🐈🐈🐈*/? | ||
// Expected Error: invalid character found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use wgpu::include_wgsl; | ||
|
||
use wgpu_test::{gpu_test, GpuTestConfiguration, TestParameters}; | ||
|
||
#[gpu_test] | ||
static SHADER_COMPILE_SUCCESS: GpuTestConfiguration = GpuTestConfiguration::new() | ||
.parameters(TestParameters::default()) | ||
.run_async(|ctx| async move { | ||
let sm = ctx | ||
.device | ||
.create_shader_module(include_wgsl!("successful_shader.wgsl")); | ||
|
||
let compilation_info = sm.get_compilation_info().await; | ||
for message in compilation_info.messages.iter() { | ||
assert!(message.message_type != wgpu::CompilationMessageType::Error); | ||
} | ||
}); | ||
|
||
#[gpu_test] | ||
static SHADER_COMPILE_ERROR: GpuTestConfiguration = GpuTestConfiguration::new() | ||
.parameters(TestParameters::default()) | ||
.run_async(|ctx| async move { | ||
ctx.device.push_error_scope(wgpu::ErrorFilter::Validation); | ||
let sm = ctx | ||
.device | ||
.create_shader_module(include_wgsl!("error_shader.wgsl")); | ||
assert!(pollster::block_on(ctx.device.pop_error_scope()).is_some()); | ||
|
||
let compilation_info = sm.get_compilation_info().await; | ||
let error_message = compilation_info | ||
.messages | ||
.iter() | ||
.find(|message| message.message_type == wgpu::CompilationMessageType::Error) | ||
.expect("Expected error message not found"); | ||
let span = error_message.location.expect("Expected span not found"); | ||
assert_eq!( | ||
span.offset, 32, | ||
"Expected the offset to be 32, because we're counting UTF-8 bytes" | ||
); | ||
assert_eq!(span.length, 1, "Expected length to roughly be 1"); // Could be relaxed, depending on the parser requirements. | ||
assert_eq!( | ||
span.line_number, 1, | ||
"Expected the line number to be 1, because we're counting lines from 1" | ||
); | ||
assert_eq!( | ||
span.line_position, 33, | ||
"Expected the column number to be 33, because we're counting lines from 1" | ||
); | ||
}); |
31 changes: 31 additions & 0 deletions
31
tests/tests/shader/compilation_messages/successful_shader.wgsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const array_size = 512u; | ||
|
||
struct WStruct { | ||
arr: array<u32, array_size>, | ||
atom: atomic<u32> | ||
} | ||
|
||
var<workgroup> w_mem: WStruct; | ||
|
||
@group(0) @binding(0) | ||
var<storage, read_write> output: array<u32>; | ||
|
||
@compute @workgroup_size(1) | ||
fn read(@builtin(workgroup_id) wgid: vec3<u32>, @builtin(num_workgroups) num_workgroups: vec3<u32>) { | ||
var is_zero = true; | ||
for(var i = 0u; i < array_size; i++) { | ||
is_zero &= w_mem.arr[i] == 0u; | ||
} | ||
is_zero &= atomicLoad(&w_mem.atom) == 0u; | ||
|
||
let idx = wgid.x + (wgid.y * num_workgroups.x) + (wgid.z * num_workgroups.x * num_workgroups.y); | ||
output[idx] = u32(!is_zero); | ||
} | ||
|
||
@compute @workgroup_size(1) | ||
fn write() { | ||
for(var i = 0u; i < array_size; i++) { | ||
w_mem.arr[i] = i; | ||
} | ||
atomicStore(&w_mem.atom, 3u); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.