From c71e165e7afe563b7a65d6b994314bb403df5f04 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 4 Aug 2024 01:15:45 +1000 Subject: more rust binding incremental changes --- bindgen/rust/examples/shaders.rs | 48 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'bindgen/rust/examples') 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::() as u32, - // data: ptr::null_mut(), - // }, - // }, - // }; - ShaderDataLayout { - bindings: todo!(), - binding_count: 1, - } + let mut bindings: heapless::Vec = heapless::Vec::new(); + let _ = bindings.push(ShaderBinding { + label: "MVP".to_string(), + kind: ShaderBindingKind::Bytes { + size: std::mem::size_of::(), + 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::(), + data: Some((self as *const MVP) as *mut u8), + }; + + unsafe { + GPU_EncodeBindShaderDataRaw(GPU_GetDefaultEncoder(), 0, layout.into_ffi_type()); } } } -- cgit v1.2.3-70-g09d2