adding util to runtime api
Test / build (push) Failing after 31s
Build / build (push) Successful in 48s

This commit is contained in:
2026-06-05 17:48:21 +02:00
parent ee5a400010
commit ad87703ea8
4 changed files with 166 additions and 1 deletions
+16 -1
View File
@@ -12,7 +12,9 @@ const SpvWord = spv.SpvWord;
const SpvBool = spv.SpvBool;
const Module = @import("Module.zig");
const PrimitiveType = @import("Value.zig").PrimitiveType;
const Result = @import("Result.zig");
const Value = @import("Value.zig").Value;
const WordIterator = @import("WordIterator.zig");
const Self = @This();
@@ -195,6 +197,19 @@ pub fn getResultByLocationComponent(self: *const Self, location: SpvWord, compon
return RuntimeError.NotFound;
}
pub fn getResultPrimitiveType(self: *const Self, result: SpvWord) RuntimeError!PrimitiveType {
if (result >= self.results.len)
return RuntimeError.OutOfBounds;
return (try self.results[result].getConstValue()).resolvePrimitiveType();
}
pub fn resultIsInteger(self: *const Self, result: SpvWord) bool {
return switch (self.getResultPrimitiveType(result) catch return false) {
.SInt, .UInt => true,
else => false,
};
}
pub fn dumpResultsTable(self: *Self, allocator: std.mem.Allocator, writer: *std.Io.Writer) RuntimeError!void {
const dump = pretty.dump(allocator, self.results, .{
.tab_size = 4,
@@ -414,7 +429,7 @@ fn resolveInputLocationTarget(self: *const Self, location: SpvWord) RuntimeError
return RuntimeError.NotFound;
}
fn getInputLocationTargetValue(self: *const Self, target: InputLocationTarget) RuntimeError!*@import("Value.zig").Value {
fn getInputLocationTargetValue(self: *const Self, target: InputLocationTarget) RuntimeError!*Value {
const value = switch ((try self.results[target.result].getVariant()).*) {
.Variable => |*v| &v.value,
.AccessChain => |*a| &a.value,
+33
View File
@@ -169,6 +169,39 @@ pub const Value = union(Type) {
};
}
pub fn resolvePrimitiveType(self: *const Self) RuntimeError!PrimitiveType {
return switch (self.*) {
.Bool => .Bool,
.Float,
.Vector2f32,
.Vector3f32,
.Vector4f32,
=> .Float,
.Int => |int| if (int.is_signed) .SInt else .UInt,
.Vector2i32,
.Vector3i32,
.Vector4i32,
=> .SInt,
.Vector2u32,
.Vector3u32,
.Vector4u32,
=> .UInt,
.Vector => |lanes| {
if (lanes.len == 0)
return RuntimeError.InvalidValueType;
return lanes[0].resolvePrimitiveType();
},
else => RuntimeError.InvalidValueType,
};
}
pub fn isInteger(self: *const Self) bool {
return switch (self.resolvePrimitiveType() catch return false) {
.SInt, .UInt => true,
else => false,
};
}
pub fn init(allocator: std.mem.Allocator, results: []const Result, target_type: SpvWord, is_externally_visible: bool) RuntimeError!Self {
const resolved = results[target_type].resolveTypeWordOrNull() orelse target_type;
return initUnresolved(allocator, results, resolved, is_externally_visible);