summaryrefslogtreecommitdiff
path: root/bindgen/rust/examples/shaders.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bindgen/rust/examples/shaders.rs')
-rw-r--r--bindgen/rust/examples/shaders.rs48
1 files changed, 25 insertions, 23 deletions
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());
}
}
}