feat(vm): add deterministic gameplay math and domain coverage gates
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
Intrepid/Prometeu/Runtime/pipeline/pr-master There was a failure building this commit
This commit is contained in:
@@ -206,6 +206,7 @@ pub enum IntrinsicExecutionError {
|
||||
ArityMismatch { expected: usize, got: usize },
|
||||
TypeMismatch { index: usize, expected: AbiType },
|
||||
HardwareUnavailable,
|
||||
Numeric(crate::numeric::NumericError),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -226,6 +227,9 @@ pub struct IntrinsicMeta {
|
||||
pub version: u16,
|
||||
pub arg_layout: &'static [AbiType],
|
||||
pub ret_layout: &'static [AbiType],
|
||||
pub parameter_names: &'static [&'static str],
|
||||
/// Total virtual call cost; math attempts are charged before checks.
|
||||
pub cost_cycles: u64,
|
||||
pub deterministic: bool,
|
||||
pub may_allocate: bool,
|
||||
pub implementation: IntrinsicImplementation,
|
||||
@@ -424,7 +428,23 @@ const COLOR_MAGENTA_SLOTS: [BuiltinConstSlotValue; 1] =
|
||||
const COLOR_TRANSPARENT_SLOTS: [BuiltinConstSlotValue; 1] =
|
||||
[BuiltinConstSlotValue::Int64(Color::TRANSPARENT.raw() as i64)];
|
||||
|
||||
const BUILTIN_CONSTS: [BuiltinConstMeta; 13] = [
|
||||
const BUILTIN_CONSTS: [BuiltinConstMeta; 15] = [
|
||||
BuiltinConstMeta {
|
||||
key: BuiltinConstKey::new("mathf", "pi", 1),
|
||||
flat_slot_layout: &SINGLE_FLOAT_RET,
|
||||
flat_slot_width: 1,
|
||||
materializer: BuiltinConstMaterializer::Direct(&[BuiltinConstSlotValue::Float(
|
||||
f64::from_bits(crate::numeric::PI_BITS),
|
||||
)]),
|
||||
},
|
||||
BuiltinConstMeta {
|
||||
key: BuiltinConstKey::new("mathf", "tau", 1),
|
||||
flat_slot_layout: &SINGLE_FLOAT_RET,
|
||||
flat_slot_width: 1,
|
||||
materializer: BuiltinConstMaterializer::Direct(&[BuiltinConstSlotValue::Float(
|
||||
f64::from_bits(crate::numeric::TAU_BITS),
|
||||
)]),
|
||||
},
|
||||
BuiltinConstMeta {
|
||||
key: BuiltinConstKey::new("vec2", "zero", 1),
|
||||
flat_slot_layout: &VEC2_ZERO_LAYOUT,
|
||||
@@ -491,6 +511,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &VEC2_DOT_ARGS,
|
||||
ret_layout: &SINGLE_FLOAT_RET,
|
||||
parameter_names: &["ax", "ay", "bx", "by"],
|
||||
cost_cycles: 10,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: vec2_dot,
|
||||
@@ -502,6 +524,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &VEC2_LENGTH_ARGS,
|
||||
ret_layout: &SINGLE_FLOAT_RET,
|
||||
parameter_names: &["x", "y"],
|
||||
cost_cycles: 40,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: vec2_length,
|
||||
@@ -513,6 +537,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &INT_RET,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &["raw"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_from_raw,
|
||||
@@ -524,6 +550,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &COLOR_RGB_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &["r", "g", "b"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_rgb,
|
||||
@@ -535,6 +563,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &COLOR_RGBA_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &["r", "g", "b", "a"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_rgba,
|
||||
@@ -546,6 +576,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &COLOR_HTML_RGBA_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &["value"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_html_rgba,
|
||||
@@ -557,6 +589,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &INT_RET,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &["value"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_gray_scale,
|
||||
@@ -568,6 +602,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &COLOR_ARGS,
|
||||
ret_layout: &INT_RET,
|
||||
parameter_names: &["color"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_hex,
|
||||
@@ -579,6 +615,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &COLOR_ARGS,
|
||||
ret_layout: &INT_RET,
|
||||
parameter_names: &["color"],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_alpha,
|
||||
@@ -590,6 +628,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_black,
|
||||
@@ -601,6 +641,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_white,
|
||||
@@ -612,6 +654,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_red,
|
||||
@@ -623,6 +667,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_green,
|
||||
@@ -634,6 +680,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_blue,
|
||||
@@ -645,6 +693,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_yellow,
|
||||
@@ -656,6 +706,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_orange,
|
||||
@@ -667,6 +719,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_indigo,
|
||||
@@ -678,6 +732,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_gray,
|
||||
@@ -689,6 +745,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_cyan,
|
||||
@@ -700,6 +758,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_magenta,
|
||||
@@ -711,6 +771,8 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
|
||||
version: 1,
|
||||
arg_layout: &NO_ARGS,
|
||||
ret_layout: &COLOR_RET,
|
||||
parameter_names: &[],
|
||||
cost_cycles: 1,
|
||||
deterministic: true,
|
||||
may_allocate: false,
|
||||
implementation: color_transparent,
|
||||
@@ -743,6 +805,7 @@ pub fn lookup_intrinsic(owner: &str, name: &str, version: u16) -> Option<&'stati
|
||||
INTRINSICS
|
||||
.iter()
|
||||
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
|
||||
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
|
||||
.find(|meta| meta.owner == owner && meta.name == name && meta.version == version)
|
||||
}
|
||||
|
||||
@@ -750,6 +813,7 @@ pub fn lookup_intrinsic_by_id(id: u32) -> Option<&'static IntrinsicMeta> {
|
||||
INTRINSICS
|
||||
.iter()
|
||||
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
|
||||
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
|
||||
.find(|meta| meta.id == id)
|
||||
}
|
||||
|
||||
@@ -841,6 +905,7 @@ fn vec2_dot(
|
||||
args: &[Value],
|
||||
_ctx: &mut HostContext<'_>,
|
||||
) -> Result<Vec<Value>, IntrinsicExecutionError> {
|
||||
lookup_intrinsic_by_id(0x1000).unwrap().validate_argument_values(args)?;
|
||||
if args.len() != 4 {
|
||||
return Err(IntrinsicExecutionError::ArityMismatch { expected: 4, got: args.len() });
|
||||
}
|
||||
@@ -848,7 +913,7 @@ fn vec2_dot(
|
||||
let ay = expect_float_arg(args, 1)?;
|
||||
let bx = expect_float_arg(args, 2)?;
|
||||
let by = expect_float_arg(args, 3)?;
|
||||
Ok(vec![Value::Float((ax * bx) + (ay * by))])
|
||||
Ok(vec![Value::Float(crate::numeric::dot([ax, ay, bx, by])?)])
|
||||
}
|
||||
|
||||
fn vec2_length(
|
||||
@@ -858,9 +923,10 @@ fn vec2_length(
|
||||
if args.len() != 2 {
|
||||
return Err(IntrinsicExecutionError::ArityMismatch { expected: 2, got: args.len() });
|
||||
}
|
||||
lookup_intrinsic_by_id(0x1001).unwrap().validate_argument_values(args)?;
|
||||
let x = expect_float_arg(args, 0)?;
|
||||
let y = expect_float_arg(args, 1)?;
|
||||
Ok(vec![Value::Float((x * x + y * y).sqrt())])
|
||||
Ok(vec![Value::Float(crate::numeric::length(x, y)?)])
|
||||
}
|
||||
|
||||
fn color_value(color: Color) -> Vec<Value> {
|
||||
@@ -1041,7 +1107,11 @@ pub(crate) fn metered_lookup_intrinsic(
|
||||
id: u32,
|
||||
budget: &mut prometeu_bytecode::load_limits::LoadBudget,
|
||||
) -> Result<Option<&'static IntrinsicMeta>, prometeu_bytecode::load_limits::LoadFailure> {
|
||||
for meta in INTRINSICS.iter().chain(crate::input_intrinsics::INPUT_INTRINSICS.iter()) {
|
||||
for meta in INTRINSICS
|
||||
.iter()
|
||||
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
|
||||
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
|
||||
{
|
||||
budget.work(1)?;
|
||||
if meta.id == id {
|
||||
return Ok(Some(meta));
|
||||
@@ -1210,3 +1280,14 @@ mod tests {
|
||||
assert_eq!(pixel.field("color").map(|field| field.start_slot), Some(2));
|
||||
}
|
||||
}
|
||||
|
||||
/// Runtime-owned catalogue, including input and scalar math.
|
||||
pub fn intrinsic_catalog() -> impl Iterator<Item = &'static IntrinsicMeta> {
|
||||
INTRINSICS
|
||||
.iter()
|
||||
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
|
||||
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
|
||||
}
|
||||
pub fn builtin_constant_catalog() -> impl Iterator<Item = &'static BuiltinConstMeta> {
|
||||
BUILTIN_CONSTS.iter()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user