adding base matrix management
Build / build (push) Successful in 1m33s
Test / build (push) Successful in 10m31s

This commit is contained in:
2026-05-11 01:48:13 +02:00
parent 9d20363ae8
commit 769009ad5e
8 changed files with 145 additions and 11 deletions
+3
View File
@@ -390,6 +390,7 @@ pub fn resolveLaneBitWidth(target_type: TypeData, rt: *const Runtime) RuntimeErr
.Float => |f| f.bit_length,
.Int => |i| i.bit_length,
.Vector => |v| continue :sw (try rt.results[v.components_type_word].getVariant()).Type,
.Matrix => |m| continue :sw (try rt.results[m.column_type_word].getVariant()).Type,
.Vector4f32,
.Vector3f32,
.Vector2f32,
@@ -408,6 +409,7 @@ pub fn resolveLaneCount(target_type: TypeData) RuntimeError!SpvWord {
return switch (target_type) {
.Bool, .Float, .Int => 1,
.Vector => |v| v.member_count,
.Matrix => |m| m.member_count,
.Vector4f32, .Vector4i32, .Vector4u32 => 4,
.Vector3f32, .Vector3i32, .Vector3u32 => 3,
.Vector2f32, .Vector2i32, .Vector2u32 => 2,
@@ -419,6 +421,7 @@ pub fn resolveSign(target_type: TypeData, rt: *const Runtime) RuntimeError!enum
return sw: switch (target_type) {
.Int => |i| if (i.is_signed) .signed else .unsigned,
.Vector => |v| continue :sw (try rt.results[v.components_type_word].getVariant()).Type,
.Matrix => |m| continue :sw (try rt.results[m.column_type_word].getVariant()).Type,
.Vector4i32 => .signed,
.Vector3i32 => .signed,
.Vector2i32 => .signed,
+1 -1
View File
@@ -136,7 +136,7 @@ pub const Value = union(Type) {
return switch (self.*) {
.Structure => |*s| s.values,
.Array => |*a| a.values,
.Vector, .Matrix => |v| v,
.Vector => |v| v,
else => null,
};
}
+31 -2
View File
@@ -289,7 +289,7 @@ pub fn initRuntimeDispatcher() void {
runtime_dispatcher[@intFromEnum(spv.SpvOp.LogicalNot)] = CondEngine(.Bool, .LogicalNot).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.LogicalNotEqual)] = CondEngine(.Bool, .LogicalNotEqual).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.LogicalOr)] = CondEngine(.Bool, .LogicalOr).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.MatrixTimesMatrix)] = MathEngine(.Float, .MatrixTimesMatrix, false).op; // TODO
runtime_dispatcher[@intFromEnum(spv.SpvOp.MatrixTimesMatrix)] = MathEngine(.Float, .MatrixTimesMatrix, false).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.MatrixTimesScalar)] = MathEngine(.Float, .MatrixTimesScalar, false).op; // TODO
runtime_dispatcher[@intFromEnum(spv.SpvOp.MatrixTimesVector)] = MathEngine(.Float, .MatrixTimesVector, false).op; // TODO
runtime_dispatcher[@intFromEnum(spv.SpvOp.Not)] = BitEngine(.UInt, .Not).op;
@@ -919,7 +919,9 @@ fn MathEngine(comptime T: PrimitiveType, comptime Op: MathOp, comptime IsAtomic:
return switch (Op) {
.Add => if (@typeInfo(TT) == .int) @addWithOverflow(op1, op2)[0] else op1 + op2,
.Sub => if (@typeInfo(TT) == .int) @subWithOverflow(op1, op2)[0] else op1 - op2,
.Mul => if (@typeInfo(TT) == .int) @mulWithOverflow(op1, op2)[0] else op1 * op2,
.Mul,
.MatrixTimesMatrix,
=> if (@typeInfo(TT) == .int) @mulWithOverflow(op1, op2)[0] else op1 * op2,
.Div => blk: {
if (op2 == 0) return RuntimeError.DivisionByZero;
break :blk if (@typeInfo(TT) == .int) @divTrunc(op1, op2) else op1 / op2;
@@ -1009,6 +1011,19 @@ fn MathEngine(comptime T: PrimitiveType, comptime Op: MathOp, comptime IsAtomic:
.Vector3u32 => |*d| try operator.applySIMDVector(u32, 3, d, &lhs.Vector3u32, &rhs.Vector3u32),
.Vector2u32 => |*d| try operator.applySIMDVector(u32, 2, d, &lhs.Vector2u32, &rhs.Vector2u32),
.Matrix => |dst_m| switch (Op) {
.MatrixTimesMatrix => {
for (dst_m, lhs.Matrix, rhs.Matrix) |*dst_vec, *lhs_vec, *rhs_vec| {
for (dst_vec.Vector, lhs_vec.Vector, rhs_vec.Vector) |*d_lane, *l_lane, *r_lane| {
try operator.applyScalar(lane_bits, d_lane, l_lane, r_lane);
}
}
},
// TODO : matrix times vector
// TODO : matrix times scalar
else => return RuntimeError.ToDo,
},
else => return RuntimeError.InvalidSpirV,
}
@@ -1600,6 +1615,20 @@ fn opCompositeConstruct(_: std.mem.Allocator, word_count: SpvWord, rt: *Runtime)
}
switch (value.*) {
.Matrix => |m| {
var index: SpvWord = 0;
for (m[0..]) |mat_elem| {
if (mat_elem.getCompositeDataOrNull()) |vec| {
for (vec[0..]) |*elem| {
const elem_value = (try rt.results[try rt.it.next()].getVariant()).Constant.value;
elem.* = elem_value;
index += 1;
if (index == index_count)
return;
}
}
}
},
.RuntimeArray => |arr| {
var offset: usize = 0;