Compare commits
	
		
			3 Commits
		
	
	
		
			4b4f1a93b7
			...
			1816118c7a
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 1816118c7a | |||
| dd22d7a164 | |||
| 9edd9fb7b6 | 
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,6 +1,4 @@ | ||||
| debug/ | ||||
| target/ | ||||
| Cargo.lock | ||||
|  | ||||
| .cargo/ | ||||
| .idea/ | ||||
| .vscode/ | ||||
| target/ | ||||
|  | ||||
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| [submodule "slang-sys/slang"] | ||||
| 	path = slang-sys/slang | ||||
| 	url = https://github.com/shader-slang/slang.git | ||||
							
								
								
									
										333
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										333
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @ -0,0 +1,333 @@ | ||||
| # This file is automatically @generated by Cargo. | ||||
| # It is not intended for manual editing. | ||||
| version = 4 | ||||
|  | ||||
| [[package]] | ||||
| name = "aho-corasick" | ||||
| version = "1.1.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" | ||||
| dependencies = [ | ||||
|  "memchr", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "bindgen" | ||||
| version = "0.71.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3" | ||||
| dependencies = [ | ||||
|  "bitflags", | ||||
|  "cexpr", | ||||
|  "clang-sys", | ||||
|  "itertools", | ||||
|  "log", | ||||
|  "prettyplease", | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
|  "regex", | ||||
|  "rustc-hash", | ||||
|  "shlex", | ||||
|  "syn", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "bitflags" | ||||
| version = "2.6.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" | ||||
|  | ||||
| [[package]] | ||||
| name = "cc" | ||||
| version = "1.2.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" | ||||
| dependencies = [ | ||||
|  "shlex", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "cexpr" | ||||
| version = "0.6.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" | ||||
| dependencies = [ | ||||
|  "nom", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "cfg-if" | ||||
| version = "1.0.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | ||||
|  | ||||
| [[package]] | ||||
| name = "clang-sys" | ||||
| version = "1.8.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" | ||||
| dependencies = [ | ||||
|  "glob", | ||||
|  "libc", | ||||
|  "libloading", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "cmake" | ||||
| version = "0.1.52" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" | ||||
| dependencies = [ | ||||
|  "cc", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "either" | ||||
| version = "1.13.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" | ||||
|  | ||||
| [[package]] | ||||
| name = "glob" | ||||
| version = "0.3.2" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" | ||||
|  | ||||
| [[package]] | ||||
| name = "itertools" | ||||
| version = "0.12.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" | ||||
| dependencies = [ | ||||
|  "either", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "libc" | ||||
| version = "0.2.169" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" | ||||
|  | ||||
| [[package]] | ||||
| name = "libloading" | ||||
| version = "0.8.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" | ||||
| dependencies = [ | ||||
|  "cfg-if", | ||||
|  "windows-targets", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "log" | ||||
| version = "0.4.22" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" | ||||
|  | ||||
| [[package]] | ||||
| name = "memchr" | ||||
| version = "2.7.4" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" | ||||
|  | ||||
| [[package]] | ||||
| name = "minimal-lexical" | ||||
| version = "0.2.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" | ||||
|  | ||||
| [[package]] | ||||
| name = "nom" | ||||
| version = "7.1.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" | ||||
| dependencies = [ | ||||
|  "memchr", | ||||
|  "minimal-lexical", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "prettyplease" | ||||
| version = "0.2.25" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "syn", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "proc-macro2" | ||||
| version = "1.0.92" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" | ||||
| dependencies = [ | ||||
|  "unicode-ident", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "quote" | ||||
| version = "1.0.38" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "regex" | ||||
| version = "1.11.1" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" | ||||
| dependencies = [ | ||||
|  "aho-corasick", | ||||
|  "memchr", | ||||
|  "regex-automata", | ||||
|  "regex-syntax", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "regex-automata" | ||||
| version = "0.4.9" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" | ||||
| dependencies = [ | ||||
|  "aho-corasick", | ||||
|  "memchr", | ||||
|  "regex-syntax", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "regex-syntax" | ||||
| version = "0.8.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" | ||||
|  | ||||
| [[package]] | ||||
| name = "rustc-hash" | ||||
| version = "2.1.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" | ||||
|  | ||||
| [[package]] | ||||
| name = "shlex" | ||||
| version = "1.3.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" | ||||
|  | ||||
| [[package]] | ||||
| name = "slang" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "slang-sys", | ||||
|  "thiserror", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "slang-sys" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "bindgen", | ||||
|  "cmake", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "syn" | ||||
| version = "2.0.93" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
|  "unicode-ident", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "thiserror" | ||||
| version = "2.0.9" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" | ||||
| dependencies = [ | ||||
|  "thiserror-impl", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "thiserror-impl" | ||||
| version = "2.0.9" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" | ||||
| dependencies = [ | ||||
|  "proc-macro2", | ||||
|  "quote", | ||||
|  "syn", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "unicode-ident" | ||||
| version = "1.0.14" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" | ||||
|  | ||||
| [[package]] | ||||
| name = "windows-targets" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" | ||||
| 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", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "windows_aarch64_gnullvm" | ||||
| version = "0.52.6" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" | ||||
|  | ||||
| [[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" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" | ||||
| @ -7,6 +7,7 @@ publish = false | ||||
|  | ||||
| [dependencies] | ||||
| slang-sys = { path = "slang-sys" } | ||||
| thiserror = "2.0" | ||||
|  | ||||
| [workspace] | ||||
| members = [ | ||||
|  | ||||
| @ -4,7 +4,7 @@ version = "0.1.0" | ||||
| edition = "2021" | ||||
| license = "MIT OR Apache-2.0" | ||||
| publish = false | ||||
| build = "build.rs" | ||||
|  | ||||
| [build-dependencies] | ||||
| bindgen = "0.69.4" | ||||
| bindgen = "0.71" | ||||
| cmake = "0.1" | ||||
|  | ||||
| @ -1,19 +1,38 @@ | ||||
| extern crate bindgen; | ||||
|  | ||||
| use std::env; | ||||
| use std::path::{Path, PathBuf}; | ||||
| use std::path::PathBuf; | ||||
|  | ||||
| fn do_link_env() -> Option<PathBuf> { | ||||
| 	println!("cargo:rerun-if-env-changed=SLANG_DIR"); | ||||
| 	Some(env::var("SLANG_DIR").ok()?.into()) | ||||
| } | ||||
|  | ||||
| fn do_link_cmake() -> Option<PathBuf> { | ||||
| 	let cmake_output = cmake::Config::new("./slang") | ||||
| 		// https://github.com/shader-slang/slang/issues/5832#issuecomment-2533324982 | ||||
| 		.define("CMAKE_SKIP_INSTALL_RULES", "ON") | ||||
| 		.build_target("slang") | ||||
| 		.build(); | ||||
|  | ||||
| 	for build_type in ["Debug", "Release"] { | ||||
| 		let slang_dir = cmake_output.join("build").join(build_type); | ||||
| 		if slang_dir.exists() { | ||||
| 			return Some(slang_dir); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	None | ||||
| } | ||||
|  | ||||
| fn main() { | ||||
| 	println!("cargo:rerun-if-env-changed=SLANG_DIR"); | ||||
| 	let slang_dir = env::var("SLANG_DIR").map(PathBuf::from).expect( | ||||
| 		"Environment variable `SLANG_DIR` should be set to the directory of a Slang installation.", | ||||
| 	); | ||||
| 	println!("cargo:rerun-if-changed=build.rs"); | ||||
|  | ||||
| 	let out_dir = env::var("OUT_DIR") | ||||
| 		.map(PathBuf::from) | ||||
| 		.expect("Couldn't determine output directory."); | ||||
|  | ||||
| 	link_libraries(&slang_dir); | ||||
| 	let slang_dir = do_link_env() | ||||
| 		.or_else(do_link_cmake) | ||||
| 		.expect("Unable to locate slang"); | ||||
| 	println!("cargo:rustc-link-lib=dylib=slang"); | ||||
| 	println!("cargo:rustc-link-search=native={}", slang_dir.join("lib").display()); | ||||
|  | ||||
| 	bindgen::builder() | ||||
| 		.header(slang_dir.join("include/slang.h").to_str().unwrap()) | ||||
| @ -35,26 +54,16 @@ fn main() { | ||||
| 		}) | ||||
| 		.constified_enum("SlangProfileID") | ||||
| 		.constified_enum("SlangCapabilityID") | ||||
| 		.new_type_alias("SlangResult") | ||||
| 		.vtable_generation(true) | ||||
| 		.layout_tests(false) | ||||
| 		.derive_copy(true) | ||||
| 		.generate() | ||||
| 		.expect("Couldn't generate bindings.") | ||||
| 		.write_to_file(out_dir.join("bindings.rs")) | ||||
| 		.write_to_file(format!("{}/bindings.rs", env::var("OUT_DIR").unwrap())) | ||||
| 		.expect("Couldn't write bindings."); | ||||
| } | ||||
|  | ||||
| fn link_libraries(slang_dir: &Path) { | ||||
| 	let lib_dir = slang_dir.join("lib"); | ||||
|  | ||||
| 	if !lib_dir.is_dir() { | ||||
| 		panic!("Couldn't find the `lib` subdirectory in the Slang installation directory.") | ||||
| 	} | ||||
|  | ||||
| 	println!("cargo:rustc-link-search=native={}", lib_dir.display()); | ||||
| 	println!("cargo:rustc-link-lib=dylib=slang"); | ||||
| } | ||||
|  | ||||
| #[derive(Debug)] | ||||
| struct ParseCallback {} | ||||
|  | ||||
|  | ||||
							
								
								
									
										1
									
								
								slang-sys/slang
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								slang-sys/slang
									
									
									
									
									
										Submodule
									
								
							 Submodule slang-sys/slang added at 4003d337a7
									
								
							| @ -3,7 +3,7 @@ | ||||
| include!(concat!(env!("OUT_DIR"), "/bindings.rs")); | ||||
|  | ||||
| use std::ffi::{c_char, c_int, c_void}; | ||||
|  | ||||
| use std::fmt::{Display, Formatter}; | ||||
| // Based on Slang version 2024.14.5 | ||||
|  | ||||
| #[repr(C)] | ||||
| @ -135,3 +135,13 @@ pub struct IModuleVtable { | ||||
| 	pub getDependencyFilePath: unsafe extern "C" fn(*mut c_void, index: SlangInt32) -> *const c_char, | ||||
| 	pub getModuleReflection: unsafe extern "C" fn(*mut c_void) -> *mut slang_DeclReflection, | ||||
| } | ||||
|  | ||||
| impl Display for SlangResult { | ||||
| 	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||||
| 		if self.0 > 0 { | ||||
| 			write!(f, "success") | ||||
| 		} else { | ||||
| 			write!(f, "failure") | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										56
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								src/lib.rs
									
									
									
									
									
								
							| @ -1,6 +1,7 @@ | ||||
| pub mod reflection; | ||||
|  | ||||
| use std::ffi::{CStr, CString}; | ||||
| use std::fmt::{Debug, Display, Formatter}; | ||||
| use std::ptr::{null, null_mut}; | ||||
|  | ||||
| use slang_sys as sys; | ||||
| @ -29,33 +30,26 @@ const fn uuid(data1: u32, data2: u16, data3: u16, data4: [u8; 8]) -> UUID { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #[derive(thiserror::Error, Debug)] | ||||
| pub enum Error { | ||||
| 	Code(sys::SlangResult), | ||||
| 	Blob(Blob), | ||||
| } | ||||
| 	#[error("underlying library error: `{0}`")] | ||||
| 	Slang(sys::SlangResult), | ||||
|  | ||||
| impl std::fmt::Debug for Error { | ||||
| 	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
| 		match self { | ||||
| 			Error::Code(code) => write!(f, "{}", code), | ||||
| 			Error::Blob(blob) => write!(f, "{}", blob.as_str().unwrap()), | ||||
| 		} | ||||
| 	} | ||||
| 	#[error("blob")] | ||||
| 	Blob, | ||||
| } | ||||
|  | ||||
| pub type Result<T> = std::result::Result<T, Error>; | ||||
|  | ||||
| pub(crate) fn succeeded(result: sys::SlangResult) -> bool { | ||||
| 	result >= 0 | ||||
| 	result.0 >= 0 | ||||
| } | ||||
|  | ||||
| fn result_from_blob(code: sys::SlangResult, blob: *mut sys::slang_IBlob) -> Result<()> { | ||||
| 	if code < 0 { | ||||
| 		Err(Error::Blob(Blob(IUnknown( | ||||
| 			std::ptr::NonNull::new(blob as *mut _).unwrap(), | ||||
| 		)))) | ||||
| 	} else { | ||||
| fn result_from_blob(code: sys::SlangResult, _blob: *mut sys::slang_IBlob) -> Result<()> { | ||||
| 	if succeeded(code) { | ||||
| 		Ok(()) | ||||
| 	} else { | ||||
| 		Err(Error::Blob) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -125,6 +119,18 @@ impl Drop for IUnknown { | ||||
| #[derive(Clone)] | ||||
| pub struct Blob(IUnknown); | ||||
|  | ||||
| impl Debug for Blob { | ||||
| 	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||||
| 		write!(f, "ptr={:p}", self.0.0) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| impl Display for Blob { | ||||
| 	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||||
| 		Debug::fmt(&self, f) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| unsafe impl Interface for Blob { | ||||
| 	type Vtable = sys::IBlobVtable; | ||||
| 	const IID: UUID = uuid( | ||||
| @ -224,10 +230,10 @@ impl Session { | ||||
| 		let module = vcall!(self, loadModule(name.as_ptr(), &mut diagnostics)); | ||||
|  | ||||
| 		if module.is_null() { | ||||
| 			let blob = Blob(IUnknown( | ||||
| 			let _blob = Blob(IUnknown( | ||||
| 				std::ptr::NonNull::new(diagnostics as *mut _).unwrap(), | ||||
| 			)); | ||||
| 			Err(Error::Blob(blob)) | ||||
| 			Err(Error::Blob) | ||||
| 		} else { | ||||
| 			let module = Module(IUnknown(std::ptr::NonNull::new(module as *mut _).unwrap())); | ||||
| 			unsafe { (module.as_unknown().vtable().ISlangUnknown_addRef)(module.as_raw()) }; | ||||
| @ -311,9 +317,7 @@ impl ComponentType { | ||||
| 		let ptr = vcall!(self, getLayout(target, &mut diagnostics)); | ||||
|  | ||||
| 		if ptr.is_null() { | ||||
| 			Err(Error::Blob(Blob(IUnknown( | ||||
| 				std::ptr::NonNull::new(diagnostics as *mut _).unwrap(), | ||||
| 			)))) | ||||
| 			Err(Error::Blob) | ||||
| 		} else { | ||||
| 			Ok(unsafe { &*(ptr as *const _) }) | ||||
| 		} | ||||
| @ -706,6 +710,14 @@ impl OptionsBuilder { | ||||
|  | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
| 	use crate::Error; | ||||
|  | ||||
| 	#[test] | ||||
| 	fn compiles() {} | ||||
|  | ||||
| 	#[test] | ||||
| 	fn can_send_error() { | ||||
| 		let lambda = |e: &(dyn std::error::Error + Send + Sync)| {}; | ||||
| 		lambda(&Error::Blob); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -90,7 +90,7 @@ impl Shader { | ||||
| 		) | ||||
| 	} | ||||
|  | ||||
| 	fn type_layout(&self, ty: &Type, rules: sys::SlangLayoutRules) -> Option<&TypeLayout> { | ||||
| 	pub fn type_layout(&self, ty: &Type, rules: sys::SlangLayoutRules) -> Option<&TypeLayout> { | ||||
| 		rcall!( | ||||
| 			spReflection_GetTypeLayout(self, ty as *const _ as *mut _, rules) | ||||
| 				as Option<&TypeLayout> | ||||
|  | ||||
		Reference in New Issue
	
	Block a user