Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 128 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mopro-msm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ rayon = "1.5.1"
itertools = "0.13.0"
rand = "0.8.5"

bytemuck = { version = "1.15", features = ["derive"] }

[build-dependencies]
enumset = "1.0.8"
toml = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
bindgen = "0.71"

[dev-dependencies]
serial_test = "3.0.0"
Expand Down
34 changes: 34 additions & 0 deletions mopro-msm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ fn compile_shaders() -> std::io::Result<()> {
let shader_out_dir = out_dir.join("shaders");
fs::create_dir_all(&shader_out_dir)?;

build_cpp_header(manifest_dir.clone());

// Check if we should compile all shaders for testing
// Check environment variable first, then check if this is a test build
let compile_all_shaders = env::var("MSM_COMPILE_ALL_SHADERS")
Expand Down Expand Up @@ -172,6 +174,38 @@ fn compile_shaders() -> std::io::Result<()> {
Ok(())
}

fn build_cpp_header(root_dir: PathBuf) {
println!("cargo:rerun-if-changed=src/msm/metal_msm/shader/cuzk/Common.h");

// macOS SDK root for clang
let sdk_root = String::from_utf8(
std::process::Command::new("xcrun")
.args(["--sdk", "macosx", "--show-sdk-path"])
.output()
.unwrap()
.stdout,
)
.unwrap()
.trim()
.to_owned();

let bindings = bindgen::Builder::default()
.header(format!(
"{}/src/msm/metal_msm/shader/cuzk/Common.h",
root_dir.to_str().unwrap()
))
.clang_arg(format!("-isysroot{}", sdk_root))
// .clang_arg("-x") // Objective-C dialect so #import works
// .clang_arg("objective-c")
.allowlist_type("Uniforms|Params")
.allowlist_type("BufferIndices|Attributes|TextureIndices")
.generate()
.expect("bindgen failed");

let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings.write_to_file(out_dir.join("common.rs")).unwrap();
}

fn detect_metal_version(sdk: &str) -> std::io::Result<(String, String, bool)> {
// Use OS version to determine Metal version support
let os_version = get_os_version();
Expand Down
1 change: 1 addition & 0 deletions mopro-msm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod msm;
pub mod types;
use thiserror::Error;

#[derive(Debug, Error)]
Expand Down
23 changes: 23 additions & 0 deletions mopro-msm/src/msm/metal_msm/shader/cuzk/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef Common_h
#define Common_h

#include <simd/simd.h>

typedef struct {
matrix_float4x4 trueMatrix;
matrix_float4x4 falseMatrix;
matrix_float4x4 otherMatrix;
} Uniforms;

typedef struct {
int width;
int height;
} Params;

typedef enum {
VertexBuffer = 0,
ParamsBuffer = 2
} BufferIndices;


#endif /* Common_h */
Loading
Loading