diff --git a/Cargo.lock b/Cargo.lock index 86d7473..ca6a1a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,16 +4,17 @@ version = 4 [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "cc" -version = "1.2.29" +version = "1.2.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" +checksum = "e1354349954c6fc9cb0deab020f27f783cf0b604e8bb754dc4658ecf0d29c35f" dependencies = [ + "find-msvc-tools", "jobserver", "libc", "shlex", @@ -21,15 +22,15 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "errno" -version = "0.3.12" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", "windows-sys", @@ -41,6 +42,12 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ced73b1dacfc750a6db6c0a0c3a3853c8b41997e2e2c563dc90804ae6867959" + [[package]] name = "generate" version = "0.1.0" @@ -59,9 +66,9 @@ dependencies = [ [[package]] name = "jobserver" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" dependencies = [ "getrandom", "libc", @@ -69,21 +76,21 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.174" +version = "0.2.176" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" [[package]] name = "linux-raw-sys" -version = "0.9.4" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "memchr" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "once_cell" @@ -99,9 +106,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rustix" -version = "1.0.7" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ "bitflags", "errno", @@ -141,9 +148,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.20.0" +version = "3.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" +checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" dependencies = [ "fastrand", "getrandom", @@ -154,91 +161,39 @@ dependencies = [ [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" -dependencies = [ - "wit-bindgen-rt", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" +version = "0.14.7+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" dependencies = [ - "windows-targets", + "wasip2", ] [[package]] -name = "windows-targets" -version = "0.52.6" +name = "wasip2" +version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "wit-bindgen", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" +name = "windows-link" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" [[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "windows-sys" +version = "0.61.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "6f109e41dd4a3c848907eb83d5a42ea98b3769495597450cf6d153507b166f0f" +dependencies = [ + "windows-link", +] [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "wit-bindgen" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags", -] +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" diff --git a/Cargo.toml b/Cargo.toml index 021ea45..64dab28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ description = "Wrapper crate for SPIRV-Tools" repository = "https://github.com/rust-gpu/spirv-tools-rs" version = "0.12.2" authors = ["Embark "] -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" readme = "README.md" documentation = "https://docs.rs/spirv-tools" diff --git a/spirv-tools-sys/Cargo.toml b/spirv-tools-sys/Cargo.toml index 7438f55..40f4e2f 100644 --- a/spirv-tools-sys/Cargo.toml +++ b/spirv-tools-sys/Cargo.toml @@ -4,7 +4,7 @@ description = "Wrapper crate for SPIRV-Tools" repository = "https://github.com/rust-gpu/spirv-tools-rs" version = "0.12.2" authors = ["Embark "] -edition = "2021" +edition = "2024" # This is the same license for the underlying SPIRV-Tools code license = "Apache-2.0" documentation = "https://docs.rs/spirv-tools-sys" diff --git a/spirv-tools-sys/generated/build-version.inc b/spirv-tools-sys/generated/build-version.inc index 53db3fa..116c132 100644 --- a/spirv-tools-sys/generated/build-version.inc +++ b/spirv-tools-sys/generated/build-version.inc @@ -1 +1 @@ -"v2025.3", "SPIRV-Tools v2025.3 v2025.3.rc1-0-g33e02568" +"v2025.3", "SPIRV-Tools v2025.3 v2025.3-0-g33e02568" diff --git a/spirv-tools-sys/src/assembler.rs b/spirv-tools-sys/src/assembler.rs index 22f79b4..0fc144c 100644 --- a/spirv-tools-sys/src/assembler.rs +++ b/spirv-tools-sys/src/assembler.rs @@ -31,7 +31,7 @@ pub enum DisassembleOptions { Comment = 0x80, } -extern "C" { +unsafe extern "C" { /// Encodes the given SPIR-V assembly text to its binary representation. The /// length parameter specifies the number of bytes for text. Encoded binary will /// be stored into *binary. Any error will be written into *diagnostic if diff --git a/spirv-tools-sys/src/diagnostics.rs b/spirv-tools-sys/src/diagnostics.rs index 8b47bdf..e24ffe2 100644 --- a/spirv-tools-sys/src/diagnostics.rs +++ b/spirv-tools-sys/src/diagnostics.rs @@ -42,7 +42,7 @@ pub type MessageCallback = extern "C" fn( *mut std::ffi::c_void, // context we use for mapping ); -extern "C" { +unsafe extern "C" { /// Destroys a diagnostic object. This is a no-op if diagnostic is a null /// pointer. #[link_name = "spvDiagnosticDestroy"] diff --git a/spirv-tools-sys/src/lib.rs b/spirv-tools-sys/src/lib.rs index 32df4e3..8e68396 100644 --- a/spirv-tools-sys/src/lib.rs +++ b/spirv-tools-sys/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unsafe_code)] + #[cfg(not(any(feature = "use-installed-tools", feature = "use-compiled-tools")))] compile_error!("Enable at least one of `use-compiled-tools` or `use-installed-tools` features"); diff --git a/spirv-tools-sys/src/opt.rs b/spirv-tools-sys/src/opt.rs index 428b529..0fa008b 100644 --- a/spirv-tools-sys/src/opt.rs +++ b/spirv-tools-sys/src/opt.rs @@ -491,7 +491,7 @@ pub enum Passes { WrapOpKill, } -extern "C" { +unsafe extern "C" { pub fn optimizer_create(env: crate::shared::TargetEnv) -> *mut Optimizer; pub fn optimizer_destroy(opt: *mut Optimizer); diff --git a/spirv-tools-sys/src/shared.rs b/spirv-tools-sys/src/shared.rs index 54b6927..07c4a5e 100644 --- a/spirv-tools-sys/src/shared.rs +++ b/spirv-tools-sys/src/shared.rs @@ -4,18 +4,9 @@ use std::fmt; /// often necessary to specify which one applies. `Universal_*` implies an /// environment-agnostic SPIR-V. /// -/// When an API method needs to derive a SPIR-V version from a target environment -/// the method will choose the highest version of SPIR-V supported by the target -/// environment. Examples: -/// -/// ```text -/// SPV_ENV_VULKAN_1_0 -> SPIR-V 1.0 -/// SPV_ENV_VULKAN_1_1 -> SPIR-V 1.3 -/// SPV_ENV_VULKAN_1_1_SPIRV_1_4 -> SPIR-V 1.4 -/// SPV_ENV_VULKAN_1_2 -> SPIR-V 1.5 -/// ``` -/// -/// Consult the description of API entry points for specific rules. +/// This enum MUST be kept in sync with the `typedef enum spv_target_env` in +/// `spirv-tools-sys/spirv-tools/include/spirv-tools/libspirv.h`, it is being +/// sent across the ffi boundary. #[derive(Copy, Clone, Debug, PartialEq)] #[repr(C)] #[allow(non_camel_case_types, clippy::upper_case_acronyms)] @@ -58,8 +49,8 @@ pub enum TargetEnv { Universal_1_3, /// Vulkan 1.1 latest revision. Vulkan_1_1, - /// Work in progress WebGPU 1.0. - WebGPU_0, + /// DEPRECATED, may be removed in the future. + WebGPU_0_DEPRECATED, /// SPIR-V 1.4 latest revision, no other restrictions. Universal_1_4, /// Vulkan 1.1 with `VK_KHR_spirv_1_4`, i.e. SPIR-V 1.4 binary. @@ -109,11 +100,12 @@ impl TargetEnv { TargetEnv::Vulkan_1_0 => (1, 0), TargetEnv::Vulkan_1_1 => (1, 3), - TargetEnv::WebGPU_0 => (1, 3), TargetEnv::Vulkan_1_1_Spirv_1_4 => (1, 4), TargetEnv::Vulkan_1_2 => (1, 5), TargetEnv::Vulkan_1_3 => (1, 6), TargetEnv::Vulkan_1_4 => (1, 6), + + TargetEnv::WebGPU_0_DEPRECATED => (1, 3), } } } @@ -156,7 +148,7 @@ impl std::str::FromStr for TargetEnv { "opengl4.2" => Self::OpenGL_4_2, "opengl4.3" => Self::OpenGL_4_3, "opengl4.5" => Self::OpenGL_4_5, - "webgpu0" => Self::WebGPU_0, + "webgpu0_DEPRECATED" => Self::WebGPU_0_DEPRECATED, _ => return Err(SpirvResult::InvalidValue), }) } @@ -191,7 +183,7 @@ impl fmt::Display for TargetEnv { Self::OpenGL_4_2 => "opengl4.2", Self::OpenGL_4_3 => "opengl4.3", Self::OpenGL_4_5 => "opengl4.5", - Self::WebGPU_0 => "webgpu0", + Self::WebGPU_0_DEPRECATED => "webgpu0_DEPRECATED", }) } } @@ -271,7 +263,7 @@ pub struct ToolContext { _unused: [u8; 0], } -extern "C" { +unsafe extern "C" { /// Creates a context object for most of the SPIRV-Tools API. /// Returns null if env is invalid. /// diff --git a/spirv-tools-sys/src/val.rs b/spirv-tools-sys/src/val.rs index 1f637fd..fff4d6c 100644 --- a/spirv-tools-sys/src/val.rs +++ b/spirv-tools-sys/src/val.rs @@ -19,7 +19,7 @@ pub enum ValidatorLimits { IdBound, } -extern "C" { +unsafe extern "C" { /// 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. diff --git a/src/cmd.rs b/src/cmd.rs index f4535d2..dae9ef3 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -203,11 +203,11 @@ pub fn exec( let mut messages = Vec::new(); for line in split(&output.stdout, b'\n') { - if let Ok(s) = std::str::from_utf8(line) { - if let Some(msg) = crate::error::Message::parse(s) { - messages.push(msg); - continue; - } + if let Ok(s) = std::str::from_utf8(line) + && let Some(msg) = crate::error::Message::parse(s) + { + messages.push(msg); + continue; } break; diff --git a/src/error.rs b/src/error.rs index d5940d5..bf8703a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -52,23 +52,25 @@ impl Diagnostic { pub(crate) unsafe fn from_diag( diag: *mut diagnostics::Diagnostic, ) -> Result { - if diag.is_null() { - return Err(shared::SpirvResult::Success); - } + unsafe { + if diag.is_null() { + return Err(shared::SpirvResult::Success); + } - let (message, notes) = Message::message_and_notes_from_cstr((*diag).error); + let (message, notes) = Message::message_and_notes_from_cstr((*diag).error); - let res = Self { - line: (*diag).position.line, - column: (*diag).position.column, - index: (*diag).position.index, - message, - notes, - is_text: (*diag).is_text_source, - }; + let res = Self { + line: (*diag).position.line, + column: (*diag).position.column, + index: (*diag).position.index, + message, + notes, + is_text: (*diag).is_text_source, + }; - diagnostics::diagnostic_destroy(diag); - Ok(res) + diagnostics::diagnostic_destroy(diag); + Ok(res) + } } } @@ -126,15 +128,17 @@ impl Message { #[cfg(feature = "use-compiled-tools")] unsafe fn message_and_notes_from_cstr(msg: *const std::os::raw::c_char) -> (String, String) { - let full_message = std::ffi::CStr::from_ptr(msg).to_string_lossy(); - - if let Some(ind) = full_message.find('\n') { - ( - full_message[..ind].to_owned(), - full_message[ind + 1..].to_owned(), - ) - } else { - (full_message.into_owned(), String::new()) + unsafe { + let full_message = std::ffi::CStr::from_ptr(msg).to_string_lossy(); + + if let Some(ind) = full_message.find('\n') { + ( + full_message[..ind].to_owned(), + full_message[ind + 1..].to_owned(), + ) + } else { + (full_message.into_owned(), String::new()) + } } } diff --git a/src/opt/compiled.rs b/src/opt/compiled.rs index 19d879e..e2e3533 100644 --- a/src/opt/compiled.rs +++ b/src/opt/compiled.rs @@ -162,24 +162,6 @@ impl Optimizer for CompiledOptimizer { self } - // /// Registers passes that have been prescribed for converting from Vulkan to - // /// WebGPU. This sequence of passes is subject to constant review and will - // /// change from time to time. - // #[inline] - // pub fn register_vulkan_to_webgpu_passes(&mut self) -> &mut Self { - // unsafe { opt::optimizer_register_vulkan_to_webgpu_passes(self.inner) } - // self - // } - - // /// Registers passes that have been prescribed for converting from WebGPU to - // /// Vulkan. This sequence of passes is subject to constant review and will - // /// change from time to time. - // #[inline] - // pub fn register_webgpu_to_vulkan_passes(&mut self) -> &mut Self { - // unsafe { opt::optimizer_register_webgpu_to_vulkan_passes(self.inner) } - // self - // } - /// Registers passes that attempt to legalize the generated code. /// /// Note: this recipe is specially designed for legalizing SPIR-V. It should be diff --git a/src/opt/tool.rs b/src/opt/tool.rs index 08c3721..8df6a24 100644 --- a/src/opt/tool.rs +++ b/src/opt/tool.rs @@ -6,8 +6,6 @@ pub struct ToolOptimizer { passes: Vec, use_perf_passes: bool, use_size_passes: bool, - //use_vulkan_to_webgpu: bool, - //use_webgpu_to_vulkan: bool, legalize_hlsl: bool, } diff --git a/tests/val.rs b/tests/val.rs index b76ecde..0828526 100644 --- a/tests/val.rs +++ b/tests/val.rs @@ -5,7 +5,7 @@ const SPIRV_BIN: &[u8] = include_bytes!("wgpu_example_shader.spv"); fn validate_compiled(_input: &[u32]) -> Option> { #[cfg(feature = "use-compiled-tools")] { - use spirv_tools::val::{compiled::CompiledValidator, Validator}; + use spirv_tools::val::{Validator, compiled::CompiledValidator}; let cv = CompiledValidator::default(); Some(cv.validate(_input, None)) } @@ -16,7 +16,7 @@ fn validate_compiled(_input: &[u32]) -> Option> { fn validate_tool(_input: &[u32]) -> Option> { #[cfg(feature = "use-installed-tools")] { - use spirv_tools::val::{tool::ToolValidator, Validator}; + use spirv_tools::val::{Validator, tool::ToolValidator}; let cv = ToolValidator::default(); Some(cv.validate(_input, None)) } diff --git a/tools/generate/main.rs b/tools/generate/main.rs index c46cd8c..972ea54 100644 --- a/tools/generate/main.rs +++ b/tools/generate/main.rs @@ -8,9 +8,9 @@ use std::{fs, process::Command}; fn python>(args: impl IntoIterator) -> Result<(), i32> { Command::new("python") - .args(args.into_iter()) + .args(args) .status() - .map_err(|_| -1) + .map_err(|_e| -1) .and_then(|es| { if es.success() { Ok(()) @@ -22,10 +22,10 @@ fn python>(args: impl IntoIterator) -> Resul fn main() { let sys_root = PathBuf::from_iter([env!("CARGO_MANIFEST_DIR"), "..", "..", "spirv-tools-sys"]); - fs::create_dir_all(&sys_root.join("generated")).expect("unable to create 'generated'"); + fs::create_dir_all(sys_root.join("generated")).expect("unable to create 'generated'"); std::env::set_current_dir(&sys_root).unwrap(); - python(&[ + python([ "spirv-tools/utils/update_build_version.py", "spirv-tools/CHANGES", "generated/build-version.inc", @@ -66,7 +66,7 @@ fn grammar_tables() { } fn registry_table() { - python(&[ + python([ "spirv-tools/utils/generate_registry_tables.py", "--xml=spirv-headers/include/spirv/spir-v.xml", "--generator=generated/generators.inc", @@ -80,5 +80,5 @@ fn generate_header(header_name: &str, grammar: &str) { format!("--extinst-grammar={GRAMMAR_DIR}/extinst.{grammar}.grammar.json",), format!("--extinst-output-path=generated/{}.h", header_name), ]) - .expect("failed to generate C header") + .expect("failed to generate C header"); }