mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2025-02-16 17:04:16 +00:00
Fix val error output (#188)
* Add test for validation output * Fix validation to use correct functions * Clippy y so strict
This commit is contained in:
parent
98eb8d369c
commit
aef85ea5d8
@ -20,15 +20,36 @@ pub enum ValidatorLimits {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
/// Validates a raw SPIR-V binary for correctness. Any errors will be written
|
||||
/// into *diagnostic if diagnostic is non-null, otherwise the context's message
|
||||
/// Validates a SPIR-V binary for correctness. Any errors will be written into
|
||||
/// *diagnostic if diagnostic is non-null, otherwise the context's message
|
||||
/// consumer will be used.
|
||||
#[link_name = "spvValidateBinary"]
|
||||
///
|
||||
/// Validate for SPIR-V spec rules for the SPIR-V version named in the
|
||||
/// binary's header (at word offset 1). Additionally, if the context target
|
||||
/// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
/// client API version, to the extent that it is verifiable from data in the
|
||||
/// binary itself.
|
||||
#[link_name = "spvValidate"]
|
||||
pub fn validate(
|
||||
tool: *const shared::ToolContext,
|
||||
binary: *const u32,
|
||||
size: usize,
|
||||
binary: *const shared::Binary,
|
||||
diagnostic: *mut *mut crate::diagnostics::Diagnostic,
|
||||
) -> crate::shared::SpirvResult;
|
||||
|
||||
/// Validates a SPIR-V binary for correctness. Uses the provided Validator
|
||||
/// options. Any errors will be written into *diagnostic if diagnostic is
|
||||
/// non-null, otherwise the context's message consumer will be used.
|
||||
///
|
||||
/// Validate for SPIR-V spec rules for the SPIR-V version named in the
|
||||
/// binary's header (at word offset 1). Additionally, if the context target
|
||||
/// environment is a client API (such as Vulkan 1.1), then validate for that
|
||||
/// client API version, to the extent that it is verifiable from data in the
|
||||
/// binary itself, or in the validator options.
|
||||
#[link_name = "spvValidateWithOptions"]
|
||||
pub fn validate_with_options(
|
||||
tool: *const shared::ToolContext,
|
||||
options: *const ValidatorOptions,
|
||||
binary: *const shared::Binary,
|
||||
diagnostic: *mut *mut crate::diagnostics::Diagnostic,
|
||||
) -> crate::shared::SpirvResult;
|
||||
|
||||
|
@ -77,18 +77,17 @@ impl Validator for CompiledValidator {
|
||||
|
||||
let options = options.map(Options::from);
|
||||
|
||||
let options = match options {
|
||||
Some(opts) => opts.inner,
|
||||
None => std::ptr::null(),
|
||||
let input = shared::Binary {
|
||||
code: binary.as_ptr(),
|
||||
size: binary.len(),
|
||||
};
|
||||
|
||||
let res = val::validate(
|
||||
self.inner,
|
||||
binary.as_ptr(),
|
||||
binary.len(),
|
||||
options,
|
||||
&mut diagnostic,
|
||||
);
|
||||
let res = match options {
|
||||
Some(opts) => {
|
||||
val::validate_with_options(self.inner, opts.inner, &input, &mut diagnostic)
|
||||
}
|
||||
None => val::validate(self.inner, &input, &mut diagnostic),
|
||||
};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
let diagnostic = crate::error::Diagnostic::try_from(diagnostic).ok();
|
||||
|
44
spirv-tools/tests/val.rs
Normal file
44
spirv-tools/tests/val.rs
Normal file
@ -0,0 +1,44 @@
|
||||
const SPIRV_BIN: &[u8] = include_bytes!("wgpu_example_shader.spv");
|
||||
|
||||
fn validate_compiled(_input: &[u8]) -> Option<Result<(), spirv_tools::Error>> {
|
||||
#[cfg(feature = "use-compiled-tools")]
|
||||
{
|
||||
use spirv_tools::val::{compiled::CompiledValidator, Validator};
|
||||
let cv = CompiledValidator::default();
|
||||
Some(cv.validate(spirv_tools::util::to_binary(_input).unwrap(), None))
|
||||
}
|
||||
#[cfg(not(feature = "use-compiled-tools"))]
|
||||
None
|
||||
}
|
||||
|
||||
fn validate_tool(_input: &[u8]) -> Option<Result<(), spirv_tools::Error>> {
|
||||
#[cfg(feature = "use-installed-tools")]
|
||||
{
|
||||
use spirv_tools::val::{tool::ToolValidator, Validator};
|
||||
let cv = ToolValidator::default();
|
||||
Some(cv.validate(spirv_tools::util::to_binary(_input).unwrap(), None))
|
||||
}
|
||||
#[cfg(not(feature = "use-installed-tools"))]
|
||||
None
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gets_error_message() {
|
||||
let cexpected_msg = "invalid cfg:0:0 - Loop header 6[%loop_header] is targeted by 2 back-edge blocks but the standard requires exactly one\n %loop_header = OpLabel\n";
|
||||
let texpected_msg = "internal error:0:0 - Loop header 6[%loop_header] is targeted by 2 back-edge blocks but the standard requires exactly one";
|
||||
match (validate_compiled(SPIRV_BIN), validate_tool(SPIRV_BIN)) {
|
||||
(Some(resc), Some(rest)) => {
|
||||
// assert_eq!(resc, rest);
|
||||
|
||||
assert_eq!(resc.unwrap_err().to_string(), cexpected_msg);
|
||||
assert_eq!(rest.unwrap_err().to_string(), texpected_msg);
|
||||
}
|
||||
(Some(resc), None) => {
|
||||
assert_eq!(resc.unwrap_err().to_string(), cexpected_msg);
|
||||
}
|
||||
(None, Some(rest)) => {
|
||||
assert_eq!(rest.unwrap_err().to_string(), texpected_msg);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
BIN
spirv-tools/tests/wgpu_example_shader.spv
Normal file
BIN
spirv-tools/tests/wgpu_example_shader.spv
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user