Fix crash when enabling optimizations
Due to generating rust style enums for slang enums that can contain more variants than explicitly defined, the generated optimized code probably trunkated the integer values of these additional variants. Fix by using constified enums for these cases.
This commit is contained in:
parent
85c4b2eb46
commit
3419fb03d9
@ -24,10 +24,16 @@ fn main() {
|
|||||||
.allowlist_type("slang.*")
|
.allowlist_type("slang.*")
|
||||||
.allowlist_var("SLANG_.*")
|
.allowlist_var("SLANG_.*")
|
||||||
.with_codegen_config(
|
.with_codegen_config(
|
||||||
bindgen::CodegenConfig::FUNCTIONS | bindgen::CodegenConfig::TYPES | bindgen::CodegenConfig::VARS,
|
bindgen::CodegenConfig::FUNCTIONS
|
||||||
|
| bindgen::CodegenConfig::TYPES
|
||||||
|
| bindgen::CodegenConfig::VARS,
|
||||||
)
|
)
|
||||||
.parse_callbacks(Box::new(ParseCallback {}))
|
.parse_callbacks(Box::new(ParseCallback {}))
|
||||||
.default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true })
|
.default_enum_style(bindgen::EnumVariation::Rust {
|
||||||
|
non_exhaustive: false,
|
||||||
|
})
|
||||||
|
.constified_enum("SlangProfileID")
|
||||||
|
.constified_enum("SlangCapabilityID")
|
||||||
.vtable_generation(true)
|
.vtable_generation(true)
|
||||||
.layout_tests(false)
|
.layout_tests(false)
|
||||||
.derive_copy(true)
|
.derive_copy(true)
|
||||||
@ -40,7 +46,8 @@ fn main() {
|
|||||||
fn link_libraries(slang_dir: &Path) {
|
fn link_libraries(slang_dir: &Path) {
|
||||||
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("Couldn't determine target OS.");
|
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("Couldn't determine target OS.");
|
||||||
|
|
||||||
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Couldn't determine target architecture.");
|
let target_arch =
|
||||||
|
env::var("CARGO_CFG_TARGET_ARCH").expect("Couldn't determine target architecture.");
|
||||||
|
|
||||||
let target = match (&*target_os, &*target_arch) {
|
let target = match (&*target_os, &*target_arch) {
|
||||||
("windows", "x86") => "windows-x86",
|
("windows", "x86") => "windows-x86",
|
||||||
|
42
src/lib.rs
42
src/lib.rs
@ -5,12 +5,11 @@ use slang_sys as sys;
|
|||||||
|
|
||||||
pub use sys::{
|
pub use sys::{
|
||||||
slang_CompilerOptionName as CompilerOptionName, slang_SessionDesc as SessionDesc,
|
slang_CompilerOptionName as CompilerOptionName, slang_SessionDesc as SessionDesc,
|
||||||
slang_TargetDesc as TargetDesc, SlangCapabilityID as CapabilityID,
|
slang_TargetDesc as TargetDesc, SlangCompileTarget as CompileTarget,
|
||||||
SlangCompileTarget as CompileTarget, SlangDebugInfoLevel as DebugInfoLevel,
|
SlangDebugInfoLevel as DebugInfoLevel, SlangFloatingPointMode as FloatingPointMode,
|
||||||
SlangFloatingPointMode as FloatingPointMode, SlangLineDirectiveMode as LineDirectiveMode,
|
SlangLineDirectiveMode as LineDirectiveMode, SlangMatrixLayoutMode as MatrixLayoutMode,
|
||||||
SlangMatrixLayoutMode as MatrixLayoutMode, SlangOptimizationLevel as OptimizationLevel,
|
SlangOptimizationLevel as OptimizationLevel, SlangSourceLanguage as SourceLanguage,
|
||||||
SlangProfileID as ProfileID, SlangSourceLanguage as SourceLanguage, SlangStage as Stage,
|
SlangStage as Stage, SlangUUID as UUID,
|
||||||
SlangUUID as UUID,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! vcall {
|
macro_rules! vcall {
|
||||||
@ -28,6 +27,18 @@ const fn uuid(data1: u32, data2: u16, data3: u16, data4: [u8; 8]) -> UUID {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ProfileID(sys::SlangProfileID);
|
||||||
|
|
||||||
|
impl ProfileID {
|
||||||
|
pub const UNKNOWN: ProfileID = ProfileID(sys::SlangProfileID_SlangProfileUnknown);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct CapabilityID(sys::SlangCapabilityID);
|
||||||
|
|
||||||
|
impl CapabilityID {
|
||||||
|
pub const UNKNOWN: CapabilityID = CapabilityID(sys::SlangCapabilityID_SlangCapabilityUnknown);
|
||||||
|
}
|
||||||
|
|
||||||
unsafe trait Interface: Sized {
|
unsafe trait Interface: Sized {
|
||||||
type Vtable;
|
type Vtable;
|
||||||
const IID: UUID;
|
const IID: UUID;
|
||||||
@ -146,12 +157,12 @@ impl GlobalSession {
|
|||||||
|
|
||||||
pub fn find_profile(&self, name: &str) -> ProfileID {
|
pub fn find_profile(&self, name: &str) -> ProfileID {
|
||||||
let name = CString::new(name).unwrap();
|
let name = CString::new(name).unwrap();
|
||||||
vcall!(self, findProfile(name.as_ptr()))
|
ProfileID(vcall!(self, findProfile(name.as_ptr())))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_capability(&self, name: &str) -> CapabilityID {
|
pub fn find_capability(&self, name: &str) -> CapabilityID {
|
||||||
let name = CString::new(name).unwrap();
|
let name = CString::new(name).unwrap();
|
||||||
vcall!(self, findCapability(name.as_ptr()))
|
CapabilityID(vcall!(self, findCapability(name.as_ptr())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +380,7 @@ impl TargetDescBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn profile(mut self, profile: ProfileID) -> Self {
|
pub fn profile(mut self, profile: ProfileID) -> Self {
|
||||||
self.inner.profile = profile;
|
self.inner.profile = profile.0;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +533,12 @@ impl OptionsBuilder {
|
|||||||
option!(Language, language(language: SourceLanguage));
|
option!(Language, language(language: SourceLanguage));
|
||||||
option!(MatrixLayoutColumn, matrix_layout_column(enable: bool));
|
option!(MatrixLayoutColumn, matrix_layout_column(enable: bool));
|
||||||
option!(MatrixLayoutRow, matrix_layout_row(enable: bool));
|
option!(MatrixLayoutRow, matrix_layout_row(enable: bool));
|
||||||
option!(Profile, profile(profile: ProfileID));
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn profile(self, profile: ProfileID) -> Self {
|
||||||
|
self.push_ints(CompilerOptionName::Profile, profile.0 as _, 0)
|
||||||
|
}
|
||||||
|
|
||||||
option!(Stage, stage(stage: Stage));
|
option!(Stage, stage(stage: Stage));
|
||||||
option!(Target, target(target: CompileTarget));
|
option!(Target, target(target: CompileTarget));
|
||||||
option!(WarningsAsErrors, warnings_as_errors(warning_codes: &str));
|
option!(WarningsAsErrors, warnings_as_errors(warning_codes: &str));
|
||||||
@ -534,7 +550,11 @@ impl OptionsBuilder {
|
|||||||
option!(SkipSPIRVValidation, skip_spirv_validation(enable: bool));
|
option!(SkipSPIRVValidation, skip_spirv_validation(enable: bool));
|
||||||
|
|
||||||
// Target
|
// Target
|
||||||
option!(Capability, capability(capability: CapabilityID));
|
#[inline(always)]
|
||||||
|
pub fn capability(self, capability: CapabilityID) -> Self {
|
||||||
|
self.push_ints(CompilerOptionName::Capability, capability.0 as _, 0)
|
||||||
|
}
|
||||||
|
|
||||||
option!(DefaultImageFormatUnknown, default_image_format_unknown(enable: bool));
|
option!(DefaultImageFormatUnknown, default_image_format_unknown(enable: bool));
|
||||||
option!(DisableDynamicDispatch, disable_dynamic_dispatch(enable: bool));
|
option!(DisableDynamicDispatch, disable_dynamic_dispatch(enable: bool));
|
||||||
option!(DisableSpecialization, disable_specialization(enable: bool));
|
option!(DisableSpecialization, disable_specialization(enable: bool));
|
||||||
|
Loading…
Reference in New Issue
Block a user