working on runtime API; ci skip
All checks were successful
Test / build (push) Has been skipped
Build / build (push) Has been skipped

This commit is contained in:
2026-02-02 17:25:31 +01:00
parent 1974afd6d7
commit 61513f20d5
2 changed files with 51 additions and 43 deletions

View File

@@ -519,6 +519,20 @@ pub fn resolveLaneBitWidth(target_type: TypeData, rt: *const Runtime) RuntimeErr
}; };
} }
pub fn resolveSign(target_type: TypeData, rt: *const Runtime) RuntimeError!enum { signed, unsigned } {
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,
.Vector4i32 => .signed,
.Vector3i32 => .signed,
.Vector2i32 => .signed,
.Vector4u32 => .unsigned,
.Vector3u32 => .unsigned,
.Vector2u32 => .unsigned,
else => .unsinged,
};
}
pub fn resolveType(self: *const Self, results: []const Self) *const Self { pub fn resolveType(self: *const Self, results: []const Self) *const Self {
return if (self.variant) |variant| return if (self.variant) |variant|
switch (variant) { switch (variant) {

View File

@@ -150,9 +150,9 @@ pub fn callEntryPoint(self: *Self, allocator: std.mem.Allocator, entry_point_ind
//}) catch return RuntimeError.OutOfMemory; //}) catch return RuntimeError.OutOfMemory;
} }
pub fn readOutput(self: *const Self, comptime T: type, output: []T, result: SpvWord) RuntimeError!void { pub fn readOutput(self: *const Self, output: []u8, result: SpvWord) RuntimeError!void {
if (std.mem.indexOfScalar(SpvWord, &self.mod.output_locations, result)) |_| { if (std.mem.indexOfScalar(SpvWord, &self.mod.output_locations, result)) |_| {
try self.readValue(T, output, &self.results[result].variant.?.Variable.value); try self.readValue(output, &self.results[result]);
} else { } else {
return RuntimeError.NotFound; return RuntimeError.NotFound;
} }
@@ -183,7 +183,7 @@ pub fn writeDescriptorSet(self: *const Self, comptime T: type, allocator: std.me
variable.value = try Result.initValue(allocator, input.len, self.results, resolved); variable.value = try Result.initValue(allocator, input.len, self.results, resolved);
}, },
.Vector, .Matrix, .Array, .Structure => |v| { .Vector, .Matrix, .Array, .Structure => |v| {
_ = v;
}, },
} }
try self.writeValue(T, input, &variable.value); try self.writeValue(T, input, &variable.value);
@@ -197,70 +197,64 @@ fn reset(self: *Self) void {
self.current_function = null; self.current_function = null;
} }
fn readValue(self: *const Self, comptime T: type, output: []T, value: *const Result.Value) RuntimeError!void { fn readValue(self: *const Self, output: []u8, value: *const Result.Value) RuntimeError!void {
const type_word = try result.getValueTypeWord();
const value = try result.getValue();
const lane_bits = try Result.resolveLaneBitWidth((try self.results[type_word].getVariant()).Type, self);
switch (value.*) { switch (value.*) {
.Bool => |b| { .Bool => |b| output[0] = if (b == true) 1 else 0,
if (T == bool) {
output[0] = b;
} else {
return RuntimeError.InvalidValueType;
}
},
.Int => |i| { .Int => |i| {
switch (T) { switch (lane_bits) {
i8 => output[0] = i.sint8, 8 => output[0] = @bitCast(i.uint8),
i16 => output[0] = i.sint16, 16 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(i.uint16)),
i32 => output[0] = i.sint32, 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(i.uint32)),
i64 => output[0] = i.sint64, 64 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(i.uint64)),
u8 => output[0] = i.uint8,
u16 => output[0] = i.uint16,
u32 => output[0] = i.uint32,
u64 => output[0] = i.uint64,
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
} }
}, },
.Float => |f| { .Float => |f| {
switch (T) { switch (lane_bits) {
f16 => output[0] = f.float16, 16 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(f.float16)),
f32 => output[0] = f.float32, 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(f.float32)),
f64 => output[0] = f.float64, 64 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(f.float64)),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
} }
}, },
.Vector4f32 => |vec| inline for (0..4) |i| switch (T) { .Vector4f32 => |vec| inline for (0..4) |i| switch (lane_bits) {
f32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector3f32 => |vec| inline for (0..3) |i| switch (T) { .Vector3f32 => |vec| inline for (0..3) |i| switch (lane_bits) {
f32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector2f32 => |vec| inline for (0..2) |i| switch (T) { .Vector2f32 => |vec| inline for (0..2) |i| switch (lane_bits) {
f32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector4i32 => |vec| inline for (0..4) |i| switch (T) { .Vector4i32 => |vec| inline for (0..4) |i| switch (lane_bits) {
i32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector3i32 => |vec| inline for (0..3) |i| switch (T) { .Vector3i32 => |vec| inline for (0..3) |i| switch (lane_bits) {
i32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector2i32 => |vec| inline for (0..2) |i| switch (T) { .Vector2i32 => |vec| inline for (0..2) |i| switch (lane_bits) {
i32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector4u32 => |vec| inline for (0..4) |i| switch (T) { .Vector4u32 => |vec| inline for (0..4) |i| switch (lane_bits) {
u32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector3u32 => |vec| inline for (0..3) |i| switch (T) { .Vector3u32 => |vec| inline for (0..3) |i| switch (lane_bits) {
u32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Vector2u32 => |vec| inline for (0..2) |i| switch (T) { .Vector2u32 => |vec| inline for (0..2) |i| switch (lane_bits) {
u32 => output[i] = vec[i], 32 => std.mem.copyForward(u8, output[0..], std.mem.asBytes(vec[i])),
inline else => return RuntimeError.InvalidValueType, inline else => return RuntimeError.InvalidValueType,
}, },
.Array, .Array,
@@ -270,7 +264,7 @@ fn readValue(self: *const Self, comptime T: type, output: []T, value: *const Res
=> |values| for (values, 0..) |v, i| try self.readValue(T, output[i..], &v), => |values| for (values, 0..) |v, i| try self.readValue(T, output[i..], &v),
.RuntimeArray => |opt_values| if (opt_values) |values| { .RuntimeArray => |opt_values| if (opt_values) |values| {
for (values, 0..) |v, i| for (values, 0..) |v, i|
try self.readValue(T, output[i..], &v); try self.readValue(output[i..], result);
}, },
else => return RuntimeError.InvalidValueType, else => return RuntimeError.InvalidValueType,
} }