Skip to content

Commit

Permalink
Improve lib.rs error handling and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
FlannyH committed May 6, 2024
1 parent 437c372 commit 62eca61
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ members = [

[dependencies]
libloading = "0.8"
thiserror = "1.0.59"
32 changes: 16 additions & 16 deletions examples/convert-dxil.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::ffi::CStr;

use saxaboom::{
IRComparisonFunction, IRCompilerFactory, IRFilter, IRMetalLibBinary, IRObject,
IRReflectionVersion, IRRootConstants, IRRootParameter1, IRRootParameter1_u,
IRRootParameterType, IRRootSignature, IRRootSignatureDescriptor1, IRRootSignatureFlags,
IRRootSignatureVersion, IRShaderReflection, IRShaderStage, IRShaderVisibility,
IRStaticBorderColor, IRStaticSamplerDescriptor, IRTextureAddressMode,
IRComparisonFunction, IRCompilerFactory, IRFilter, IRObject, IRReflectionVersion,
IRRootConstants, IRRootParameter1, IRRootParameter1_u, IRRootParameterType, IRRootSignature,
IRRootSignatureDescriptor1, IRRootSignatureFlags, IRRootSignatureVersion, IRShaderStage,
IRShaderVisibility, IRStaticBorderColor, IRStaticSamplerDescriptor, IRTextureAddressMode,
IRVersionedRootSignatureDescriptor, IRVersionedRootSignatureDescriptor_u,
};

Expand Down Expand Up @@ -62,13 +61,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

// Load DXIL
let dxil = include_bytes!("assets/memcpy.cs.dxil");
let obj = IRObject::create_from_dxil(&compiler, dxil)?;
let obj = IRObject::create_from_dxil(&compiler, dxil);

// Convert to Metal
let mut mtl_binary = IRMetalLibBinary::new(&compiler)?;
let mtllib = compiler
.alloc_compile_and_link(CStr::from_bytes_with_nul_unchecked(b"main\0"), &obj)?;
mtllib.get_metal_lib_binary(IRShaderStage::IRShaderStageCompute, &mut mtl_binary);
let mtl_binary =
mtllib.get_metal_lib_binary(&compiler, IRShaderStage::IRShaderStageCompute)?;

// Get Metal bytecode
let metal_bytecode = mtl_binary.get_byte_code();
Expand All @@ -77,14 +76,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
dbg!(mtllib.get_metal_ir_shader_stage());

// Get reflection from the shader
let mut mtl_reflection = IRShaderReflection::new(&compiler)?;
mtllib.get_reflection(IRShaderStage::IRShaderStageCompute, &mut mtl_reflection);

let compute_info = mtl_reflection
.get_compute_info(IRReflectionVersion::IRReflectionVersion_1_0)
.unwrap()
.u_1
.info_1_0;
let mtl_reflection = mtllib.get_reflection(&compiler, IRShaderStage::IRShaderStageCompute);

let compute_info = mtl_reflection.map(|mtl_reflection| {
mtl_reflection
.get_compute_info(IRReflectionVersion::IRReflectionVersion_1_0)
.unwrap()
.u_1
.info_1_0
});
dbg!(compute_info);
}
Ok(())
Expand Down
Loading

0 comments on commit 62eca61

Please sign in to comment.