Skip to content

Commit

Permalink
tune mtl::FnConstValues api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 11, 2024
1 parent d70f248 commit 217a185
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cidre/src/mtl/function_constant_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ use std::ffi::c_void;

use crate::{arc, define_mtl, define_obj_type, mtl, ns, objc};

define_obj_type!(pub FnConstValues(ns::Id), MTL_FUNCTION_CONSTANT_VALUES);
define_obj_type!(
#[doc(alias = "MTLFunctionConstantValues")]
pub FnConstValues(ns::Id),
MTL_FUNCTION_CONSTANT_VALUES
);

impl FnConstValues {
define_mtl!(reset);

#[objc::msg_send(setConstantValue:type:atIndex:)]
pub fn set_value_at(&mut self, val: *const c_void, type_: mtl::DType, at_index: ns::UInteger);

pub fn set_bool_at(&mut self, val: bool, at_index: usize) {
debug_assert!(at_index < u16::MAX as _);
self.set_value_at(&val as *const bool as *const _, mtl::DType::Bool, at_index);
}

pub fn set_u8_at(&mut self, val: u8, at_index: usize) {
debug_assert!(at_index < u16::MAX as _);
self.set_value_at(&val as *const u8 as *const _, mtl::DType::U8, at_index);
}

#[objc::msg_send(setConstantValues:type:withRange:)]
pub fn set_values(&mut self, values: *const c_void, type_: mtl::DType, with_range: ns::Range);

Expand All @@ -34,5 +48,8 @@ mod tests {
fcv.reset();
let name = ns::str!(c"name");
fcv.set_value_with_name(&v as *const bool as _, mtl::DType::Bool, name);

fcv.set_bool_at(true, 0);
fcv.set_u8_at(10, 1);
}
}

0 comments on commit 217a185

Please sign in to comment.