summaryrefslogtreecommitdiff
path: root/bindgen
diff options
context:
space:
mode:
Diffstat (limited to 'bindgen')
-rw-r--r--bindgen/rust/Cargo.lock32
-rw-r--r--bindgen/rust/Cargo.toml1
-rw-r--r--bindgen/rust/examples/shaders.rs48
-rw-r--r--bindgen/rust/src/ral.rs60
4 files changed, 105 insertions, 36 deletions
diff --git a/bindgen/rust/Cargo.lock b/bindgen/rust/Cargo.lock
index 29e8e92..3d17b7a 100644
--- a/bindgen/rust/Cargo.lock
+++ b/bindgen/rust/Cargo.lock
@@ -87,6 +87,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
+
+[[package]]
name = "cc"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -101,6 +107,7 @@ dependencies = [
"egui",
"egui_glfw",
"gl",
+ "heapless",
"serde",
"serde_json",
"thiserror",
@@ -349,12 +356,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
+name = "hash32"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
+dependencies = [
+ "byteorder",
+]
+
+[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
+name = "heapless"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
+dependencies = [
+ "hash32",
+ "stable_deref_trait",
+]
+
+[[package]]
name = "home"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -748,6 +774,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
+name = "stable_deref_trait"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
+
+[[package]]
name = "str-buf"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/bindgen/rust/Cargo.toml b/bindgen/rust/Cargo.toml
index e6656ca..001a815 100644
--- a/bindgen/rust/Cargo.toml
+++ b/bindgen/rust/Cargo.toml
@@ -13,3 +13,4 @@ egui_glfw = { git = "https://github.com/omnisci3nce/egui_glfw.git", rev = "67b43
gl = "0.14.0"
thiserror = "1.0.63"
bitflags = "2.6.0"
+heapless = "0.8.0"
diff --git a/bindgen/rust/examples/shaders.rs b/bindgen/rust/examples/shaders.rs
index 842a8d2..09f13b4 100644
--- a/bindgen/rust/examples/shaders.rs
+++ b/bindgen/rust/examples/shaders.rs
@@ -1,9 +1,12 @@
-use celeritas::ral::{ShaderData, ShaderDataLayout};
+use celeritas::ral::{
+ ShaderBinding, ShaderBindingKind, ShaderData, ShaderDataLayout, ShaderVisibility,
+};
use celeritas_sys::{
- Mat4, ShaderVisibility_VISIBILITY_COMPUTE, ShaderVisibility_VISIBILITY_FRAGMENT,
- ShaderVisibility_VISIBILITY_VERTEX,
+ GPU_EncodeBindShaderDataRaw, GPU_GetDefaultEncoder, Mat4, ShaderVisibility_VISIBILITY_COMPUTE,
+ ShaderVisibility_VISIBILITY_FRAGMENT, ShaderVisibility_VISIBILITY_VERTEX,
};
+#[repr(C)]
struct MVP {
model: Mat4,
view: Mat4,
@@ -18,29 +21,28 @@ fn shader_vis_all() -> u32 {
impl ShaderData for MVP {
fn layout() -> ShaderDataLayout {
- let mut bindings = [ShaderBinding::default(); 8];
- // bindings[0] = ShaderBinding {
- // label: unsafe { CStr::from_bytes_with_nul_unchecked(b"MVP\0").as_ptr() },
- // kind: ShaderBindingKind_BINDING_BYTES,
- // vis: shader_vis_all(),
- // data: ShaderBinding__bindgen_ty_1 {
- // bytes: ShaderBinding__bindgen_ty_1__bindgen_ty_1 {
- // size: std::mem::size_of::<MVP>() as u32,
- // data: ptr::null_mut(),
- // },
- // },
- // };
- ShaderDataLayout {
- bindings: todo!(),
- binding_count: 1,
- }
+ let mut bindings: heapless::Vec<ShaderBinding, 8> = heapless::Vec::new();
+ let _ = bindings.push(ShaderBinding {
+ label: "MVP".to_string(),
+ kind: ShaderBindingKind::Bytes {
+ size: std::mem::size_of::<MVP>(),
+ data: None,
+ },
+ vis: ShaderVisibility::all(),
+ });
+ ShaderDataLayout { bindings }
}
fn bind(&self) {
- let layout = Self::layout();
- for i in 0..layout.binding_count {
- let binding = &layout.bindings[i];
- // match binding.kind {}
+ let mut layout = Self::layout();
+ let b0 = &mut layout.bindings[0];
+ b0.kind = ShaderBindingKind::Bytes {
+ size: std::mem::size_of::<MVP>(),
+ data: Some((self as *const MVP) as *mut u8),
+ };
+
+ unsafe {
+ GPU_EncodeBindShaderDataRaw(GPU_GetDefaultEncoder(), 0, layout.into_ffi_type());
}
}
}
diff --git a/bindgen/rust/src/ral.rs b/bindgen/rust/src/ral.rs
index 4132885..5f1ca00 100644
--- a/bindgen/rust/src/ral.rs
+++ b/bindgen/rust/src/ral.rs
@@ -5,9 +5,10 @@ use std::{ffi::c_void, ptr::addr_of_mut};
use celeritas_sys::{
BufferHandle, GPU_CmdEncoder, GPU_CmdEncoder_BeginRender, GPU_CmdEncoder_EndRender,
GPU_EncodeBindShaderData, GPU_GetDefaultEncoder, GPU_GetDefaultRenderpass,
- GPU_GraphicsPipeline_Create, GraphicsPipelineDesc, ShaderVisibility_VISIBILITY_COMPUTE,
- ShaderVisibility_VISIBILITY_FRAGMENT, ShaderVisibility_VISIBILITY_VERTEX, TextureHandle,
- MAX_SHADER_DATA_LAYOUTS,
+ GPU_GraphicsPipeline_Create, GraphicsPipelineDesc, ShaderBindingKind_BINDING_BYTES,
+ ShaderBinding__bindgen_ty_1, ShaderBinding__bindgen_ty_1__bindgen_ty_1,
+ ShaderVisibility_VISIBILITY_COMPUTE, ShaderVisibility_VISIBILITY_FRAGMENT,
+ ShaderVisibility_VISIBILITY_VERTEX, TextureHandle, MAX_SHADER_DATA_LAYOUTS,
};
use thiserror::Error;
@@ -72,12 +73,12 @@ pub enum RALError {
impl PipelineBuilder {
pub fn build(self) -> Result<Pipeline, RALError> {
- let mut layouts = [celeritas_sys::ShaderDataLayout::default(); 8];
+ let layouts = [celeritas_sys::ShaderDataLayout::default(); 8];
if self.data_layouts.len() > MAX_SHADER_DATA_LAYOUTS as usize {
return Err(RALError::TooManyShaderDataLayouts);
}
for (i, layout) in self.data_layouts.iter().enumerate().take(8) {
- layouts[i] = celeritas_sys::ShaderDataLayout::from(layout);
+ // layouts[i] = celeritas_sys::ShaderDataLayout::from(layout);
}
let mut desc = GraphicsPipelineDesc {
@@ -108,11 +109,18 @@ impl PipelineBuilder {
}
}
+///
pub trait ShaderData {
+ ///
fn layout() -> ShaderDataLayout;
+ ///
fn bind(&self);
+
+ // fn bind_texture(&self, binding_name: &str, handle: TextureHandle);
+ // fn bind_buffer(&self, binding_name: &str, handle: BufferHandle);
}
+#[derive(Clone)]
pub struct ShaderBinding {
pub label: String,
// pub label: *const ::std::os::raw::c_char,
@@ -121,10 +129,11 @@ pub struct ShaderBinding {
// pub data: ShaderBinding__bindgen_ty_1,
}
+#[derive(Clone)]
pub enum ShaderBindingKind {
- Bytes(u32),
- Buffer(BufferHandle),
- Texture(TextureHandle),
+ Bytes { size: usize, data: Option<*mut u8> },
+ Buffer(Option<BufferHandle>),
+ Texture(Option<TextureHandle>),
}
bitflags::bitflags! {
@@ -143,14 +152,39 @@ impl Default for ShaderVisibility {
#[derive(Default)]
pub struct ShaderDataLayout {
- pub bindings: [Option<ShaderBinding>; 8],
- pub binding_count: usize,
+ pub bindings: heapless::Vec<ShaderBinding, 8>,
}
-impl From<&ShaderDataLayout> for celeritas_sys::ShaderDataLayout {
- fn from(value: &ShaderDataLayout) -> Self {
- todo!()
+impl ShaderDataLayout {
+ pub fn into_ffi_type(self) -> celeritas_sys::ShaderDataLayout {
+ let mut bindings = [celeritas_sys::ShaderBinding::default(); 8];
+ for (i, b) in self.bindings.iter().enumerate().take(8) {
+ bindings[i] = match b.kind {
+ ShaderBindingKind::Bytes { size, data } => celeritas_sys::ShaderBinding {
+ label: b.label.as_ptr() as *const i8,
+ kind: ShaderBindingKind_BINDING_BYTES,
+ vis: ShaderVisibility_VISIBILITY_VERTEX,
+ data: ShaderBinding__bindgen_ty_1 {
+ bytes: ShaderBinding__bindgen_ty_1__bindgen_ty_1 {
+ size: size as u32,
+ data: data.unwrap() as *mut c_void,
+ },
+ },
+ },
+ ShaderBindingKind::Buffer(_) => todo!(),
+ ShaderBindingKind::Texture(_) => todo!(),
+ };
+ }
+ celeritas_sys::ShaderDataLayout {
+ bindings,
+ binding_count: bindings.len(),
+ }
}
}
+// impl<'a> From<&ShaderDataLayout<'a>> for celeritas_sys::ShaderDataLayout {
+// fn from(value: &ShaderDataLayout) -> Self {
+// todo!()
+// }
+// }
// --- types