adding spec constant management
All checks were successful
Build / build (push) Successful in 2m11s
Test / build (push) Successful in 8m24s

This commit is contained in:
2026-03-30 04:45:52 +02:00
parent 6c8b364c7d
commit 8072d671af
2 changed files with 65 additions and 13 deletions

View File

@@ -187,8 +187,6 @@ pub const SetupDispatcher = block: {
.Variable = opVariable,
.VectorTimesMatrix = autoSetupConstant,
.VectorTimesScalar = autoSetupConstant,
.SpecConstant = opConstant,
.SpecConstantOp = opSpecConstantOp,
.SpecConstantTrue = opSpecConstantTrue,
.SpecConstantFalse = opSpecConstantFalse,
.SpecConstantComposite = opConstantComposite,
@@ -287,6 +285,8 @@ pub fn initRuntimeDispatcher() void {
runtime_dispatcher[@intFromEnum(spv.SpvOp.UMod)] = MathEngine(.UInt, .Mod).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.VectorTimesMatrix)] = MathEngine(.Float, .VectorTimesMatrix).op; // TODO
runtime_dispatcher[@intFromEnum(spv.SpvOp.VectorTimesScalar)] = MathEngine(.Float, .VectorTimesScalar).op;
runtime_dispatcher[@intFromEnum(spv.SpvOp.SpecConstant)] = opSpecConstant;
runtime_dispatcher[@intFromEnum(spv.SpvOp.SpecConstantOp)] = opSpecConstantOp;
// zig fmt: on
// Extensions init
@@ -574,10 +574,7 @@ fn CondOperator(comptime T: PrimitiveType, comptime Op: CondOp) type {
}
return switch (Op) {
.IsFinite => std.math.isFinite(a),
.IsInf => blk: {
//std.debug.print("test {s} - {d} - {s}\n", .{ @typeName(TT), a, if (std.math.isInf(a)) "true" else "false" });
break :blk std.math.isInf(a);
},
.IsInf => std.math.isInf(a),
.IsNan => std.math.isNan(a),
.IsNormal => std.math.isNormal(a),
else => RuntimeError.InvalidSpirV,
@@ -1644,6 +1641,25 @@ fn opConstantComposite(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) R
}
}
fn opSpecConstant(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
const location = rt.it.emitSourceLocation();
_ = rt.it.skip();
const result_id = try rt.it.next();
_ = rt.it.goToSourceLocation(location);
try opConstant(allocator, word_count, rt);
const result = &rt.results[result_id];
for (result.decorations.items) |decoration| {
if (decoration.rtype == .SpecId) {
if (rt.specialization_constants.get(decoration.literal_1)) |data| {
_ = try (try result.getValue()).writeConst(data);
}
}
}
}
fn opSpecConstantTrue(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
const target = try setupConstant(allocator, rt);
switch (target.variant.?.Constant.value) {