summaryrefslogtreecommitdiffstats
path: root/third_party/rust/spirv-cross-internal/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/spirv-cross-internal/src/lib.rs
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/spirv-cross-internal/src/lib.rs')
-rw-r--r--third_party/rust/spirv-cross-internal/src/lib.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/third_party/rust/spirv-cross-internal/src/lib.rs b/third_party/rust/spirv-cross-internal/src/lib.rs
new file mode 100644
index 0000000000..5e95a1ae86
--- /dev/null
+++ b/third_party/rust/spirv-cross-internal/src/lib.rs
@@ -0,0 +1,95 @@
+#[cfg(target_arch = "wasm32")]
+macro_rules! check {
+ ($check:expr) => {{
+ $check
+ }};
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+macro_rules! check {
+ ($check:expr) => {{
+ let result = $check;
+ if br::ScInternalResult::Success != result {
+ if br::ScInternalResult::CompilationError == result {
+ let mut message_ptr = ptr::null();
+
+ if br::ScInternalResult::Success
+ != br::sc_internal_get_latest_exception_message(&mut message_ptr)
+ {
+ return Err(ErrorCode::Unhandled);
+ }
+
+ let message = match std::ffi::CStr::from_ptr(message_ptr)
+ .to_owned()
+ .into_string()
+ {
+ Err(_) => return Err(ErrorCode::Unhandled),
+ Ok(v) => v,
+ };
+
+ if br::ScInternalResult::Success
+ != br::sc_internal_free_pointer(message_ptr as *mut std::os::raw::c_void)
+ {
+ return Err(ErrorCode::Unhandled);
+ }
+
+ return Err(ErrorCode::CompilationError(message));
+ }
+
+ return Err(ErrorCode::Unhandled);
+ }
+ }};
+}
+
+mod compiler;
+
+#[cfg(feature = "glsl")]
+pub mod glsl;
+#[cfg(all(feature = "hlsl", not(target_arch = "wasm32")))]
+pub mod hlsl;
+#[cfg(all(feature = "msl", not(target_arch = "wasm32")))]
+pub mod msl;
+
+pub mod spirv;
+
+#[cfg(target_arch = "wasm32")]
+pub(crate) mod emscripten;
+pub(crate) mod ptr_util;
+
+#[cfg(target_arch = "wasm32")]
+mod bindings_wasm_functions;
+
+#[cfg(target_arch = "wasm32")]
+mod bindings {
+ #![allow(dead_code)]
+ #![allow(non_upper_case_globals)]
+ #![allow(non_camel_case_types)]
+ #![allow(non_snake_case)]
+ include!(concat!("bindings_wasm.rs"));
+ pub use crate::bindings_wasm_functions::*;
+ pub use root::*;
+}
+
+#[cfg(not(target_arch = "wasm32"))]
+mod bindings {
+ #![allow(dead_code)]
+ #![allow(non_upper_case_globals)]
+ #![allow(non_camel_case_types)]
+ #![allow(non_snake_case)]
+ include!(concat!("bindings_native.rs"));
+ pub use root::*;
+}
+
+#[derive(Clone, Debug, Hash, Eq, PartialEq)]
+pub enum ErrorCode {
+ Unhandled,
+ CompilationError(String),
+}
+
+impl std::fmt::Display for ErrorCode {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(f, "{:?}", self)
+ }
+}
+
+impl std::error::Error for ErrorCode {}