working on descriptor sets; 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-01 22:19:36 +01:00
parent 57de432d0b
commit 1974afd6d7
9 changed files with 430 additions and 726 deletions

View File

@@ -30,13 +30,6 @@ const SpvEntryPoint = struct {
globals: []SpvWord,
};
const SpvSource = struct {
file_name: []const u8,
lang: spv.SpvSourceLanguage,
lang_version: SpvWord,
source: []const u8,
};
pub const ModuleError = error{
InvalidSpirV,
InvalidMagic,
@@ -62,7 +55,6 @@ code: []const SpvWord,
addressing: spv.SpvAddressingModel,
memory_model: spv.SpvMemoryModel,
files: std.ArrayList(SpvSource),
extensions: std.ArrayList([]const u8),
results: []Result,
@@ -79,25 +71,21 @@ geometry_output_count: SpvWord,
geometry_input: SpvWord,
geometry_output: SpvWord,
input_locations: std.ArrayList(SpvWord),
output_locations: std.ArrayList(SpvWord),
bindings: std.AutoHashMap(SpvBinding, Value),
input_locations: [lib.SPIRV_MAX_INPUT_LOCATIONS]SpvWord,
output_locations: [lib.SPIRV_MAX_OUTPUT_LOCATIONS]SpvWord,
bindings: [lib.SPIRV_MAX_SET][lib.SPIRV_MAX_SET_BINDINGS]SpvWord,
push_constants: []Value,
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: ModuleOptions) ModuleError!Self {
var self: Self = std.mem.zeroInit(Self, .{
.options = options,
.code = allocator.dupe(SpvWord, source) catch return ModuleError.OutOfMemory,
.files = std.ArrayList(SpvSource).empty,
.extensions = std.ArrayList([]const u8).empty,
.entry_points = std.ArrayList(SpvEntryPoint).empty,
.capabilities = std.EnumSet(spv.SpvCapability).initEmpty(),
.local_size_x = 1,
.local_size_y = 1,
.local_size_z = 1,
.input_locations = std.ArrayList(SpvWord).empty,
.output_locations = std.ArrayList(SpvWord).empty,
.bindings = std.AutoHashMap(SpvBinding, Value).init(allocator),
});
errdefer allocator.free(self.code);
@@ -137,7 +125,7 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
_ = self.it.skip(); // Skip schema
try self.pass(allocator); // Setup pass
try self.populateMaps(allocator);
try self.populateMaps();
if (std.process.hasEnvVarConstant("SPIRV_INTERPRETER_DEBUG_LOGS")) {
var capability_set_names: std.ArrayList([]const u8) = .empty;
@@ -218,34 +206,46 @@ fn pass(self: *Self, allocator: std.mem.Allocator) ModuleError!void {
}
}
fn populateMaps(self: *Self, allocator: std.mem.Allocator) ModuleError!void {
fn populateMaps(self: *Self) ModuleError!void {
for (self.results, 0..) |result, id| {
if (result.variant == null or std.meta.activeTag(result.variant.?) != .Variable) continue;
switch (result.variant.?.Variable.storage_class) {
.Input => for (result.decorations.items) |decoration| switch (decoration.rtype) {
.Location => self.input_locations.append(allocator, @intCast(id)) catch return ModuleError.OutOfMemory,
if (result.variant == null or std.meta.activeTag(result.variant.?) != .Variable)
continue;
var current_set: usize = 0;
for (result.decorations.items) |decoration| {
switch (result.variant.?.Variable.storage_class) {
.Input => {
if (decoration.rtype == .Location)
self.input_locations[decoration.literal_1] = @intCast(id);
},
.Output => {
if (decoration.rtype == .Location)
self.output_locations[decoration.literal_1] = @intCast(id);
},
.StorageBuffer,
.Uniform,
.UniformConstant,
=> {
switch (decoration.rtype) {
.Binding => self.bindings[current_set][decoration.literal_1] = @intCast(id),
.DescriptorSet => current_set = decoration.literal_1,
else => {},
}
},
else => {},
},
.Output => for (result.decorations.items) |decoration| switch (decoration.rtype) {
.Location => self.output_locations.append(allocator, @intCast(id)) catch return ModuleError.OutOfMemory,
else => {},
},
else => {},
}
}
}
}
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
allocator.free(self.code);
self.input_locations.deinit(allocator);
self.output_locations.deinit(allocator);
self.bindings.deinit();
for (self.entry_points.items) |entry| {
allocator.free(entry.name);
allocator.free(entry.globals);
}
self.entry_points.deinit(allocator);
self.files.deinit(allocator);
for (self.extensions.items) |ext| {
allocator.free(ext);

View File

@@ -107,17 +107,23 @@ pub const Value = union(Type) {
Vector2u32: Vec2u32,
Matrix: []Value,
Array: []Value,
RuntimeArray: struct {},
RuntimeArray: ?[]Value,
Structure: []Value,
Function: noreturn,
Image: struct {},
Sampler: struct {},
SampledImage: struct {},
Pointer: noreturn,
Pointer: union(enum) {
common: *Value,
f32_ptr: *f32,
i32_ptr: *i32, //< For vectors specializations
u32_ptr: *u32,
},
pub inline fn getCompositeDataOrNull(self: *const Value) ?[]Value {
return switch (self.*) {
.Vector, .Matrix, .Array, .Structure => |v| v,
.RuntimeArray => |v| v,
else => null,
};
}
@@ -176,7 +182,7 @@ pub const Value = union(Type) {
}
break :blk self;
},
.RuntimeArray => .{ .RuntimeArray = .{} },
.RuntimeArray => .{ .RuntimeArray = null },
else => unreachable,
},
else => unreachable,
@@ -207,6 +213,17 @@ pub const Value = union(Type) {
break :blk values;
},
},
.RuntimeArray => |opt_a| .{
.RuntimeArray = blk: {
if (opt_a) |a| {
const values = allocator.dupe(Value, a) catch return RuntimeError.OutOfMemory;
for (values, a) |*new_value, value| new_value.* = try value.dupe(allocator);
break :blk values;
} else {
break :blk null;
}
},
},
.Structure => |s| .{
.Structure = blk: {
const values = allocator.dupe(Value, s) catch return RuntimeError.OutOfMemory;
@@ -224,6 +241,10 @@ pub const Value = union(Type) {
for (values) |*value| value.deinit(allocator);
allocator.free(values);
},
.RuntimeArray => |opt_values| if (opt_values) |values| {
for (values) |*value| value.deinit(allocator);
allocator.free(values);
},
else => {},
}
}
@@ -263,7 +284,10 @@ pub const TypeData = union(Type) {
components_type: Type,
member_count: SpvWord,
},
RuntimeArray: struct {},
RuntimeArray: struct {
components_type_word: SpvWord,
components_type: Type,
},
Structure: struct {
members_type_word: []const SpvWord,
member_names: std.ArrayList([]const u8),
@@ -308,7 +332,7 @@ pub const VariantData = union(Variant) {
},
AccessChain: struct {
target: SpvWord,
value: *Value,
value: Value,
},
FunctionParameter: struct {
type_word: SpvWord,
@@ -353,7 +377,6 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
},
.Constant => |*c| c.value.deinit(allocator),
.Variable => |*v| v.value.deinit(allocator),
//.AccessChain => |*a| a.value.deinit(allocator),
.Function => |f| allocator.free(f.params),
else => {},
}
@@ -365,7 +388,7 @@ pub inline fn getValueTypeWord(self: *Self) RuntimeError!SpvWord {
return switch ((try self.getVariant()).*) {
.Variable => |v| v.type_word,
.Constant => |c| c.type_word,
.AccessChain => |*a| a.target,
.AccessChain => |a| a.target,
.FunctionParameter => |p| p.type_word,
else => RuntimeError.InvalidSpirV,
};
@@ -384,12 +407,22 @@ pub inline fn getValue(self: *Self) RuntimeError!*Value {
return switch ((try self.getVariant()).*) {
.Variable => |*v| &v.value,
.Constant => |*c| &c.value,
.AccessChain => |a| a.value,
.AccessChain => |*a| &a.value,
.FunctionParameter => |*p| p.value_ptr orelse return RuntimeError.InvalidSpirV,
else => RuntimeError.InvalidSpirV,
};
}
pub inline fn getConstValue(self: *Self) RuntimeError!*const Value {
return switch ((try self.getVariant()).*) {
.Variable => |v| &v.value,
.Constant => |c| &c.value,
.AccessChain => |a| &a.value,
.FunctionParameter => |p| p.value_ptr orelse return RuntimeError.InvalidSpirV,
else => RuntimeError.InvalidSpirV,
};
}
pub inline fn getVariant(self: *Self) RuntimeError!*VariantData {
return &(self.variant orelse return RuntimeError.InvalidSpirV);
}
@@ -561,6 +594,18 @@ pub fn initValue(allocator: std.mem.Allocator, member_count: usize, results: []c
}
break :blk value;
},
.RuntimeArray => |a| blk: {
std.debug.print("test {d}\n", .{member_count});
if (member_count == 0) {
break :blk Value{ .RuntimeArray = null };
}
const value: Value = .{ .RuntimeArray = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
errdefer allocator.free(value.RuntimeArray.?);
for (value.RuntimeArray.?) |*val| {
val.* = try Value.init(allocator, results, a.components_type_word);
}
break :blk value;
},
.Structure => |s| blk: {
const value: Value = .{ .Structure = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
errdefer allocator.free(value.Structure);

View File

@@ -3,6 +3,7 @@
const std = @import("std");
const spv = @import("spv.zig");
const op = @import("opcodes.zig");
const lib = @import("lib.zig");
const SpvVoid = spv.SpvVoid;
const SpvByte = spv.SpvByte;
@@ -150,7 +151,7 @@ pub fn callEntryPoint(self: *Self, allocator: std.mem.Allocator, entry_point_ind
}
pub fn readOutput(self: *const Self, comptime T: type, output: []T, result: SpvWord) RuntimeError!void {
if (std.mem.indexOf(SpvWord, self.mod.output_locations.items, &.{result})) |_| {
if (std.mem.indexOfScalar(SpvWord, &self.mod.output_locations, result)) |_| {
try self.readValue(T, output, &self.results[result].variant.?.Variable.value);
} else {
return RuntimeError.NotFound;
@@ -158,13 +159,39 @@ pub fn readOutput(self: *const Self, comptime T: type, output: []T, result: SpvW
}
pub fn writeInput(self: *const Self, comptime T: type, input: []const T, result: SpvWord) RuntimeError!void {
if (std.mem.indexOf(SpvWord, self.mod.input_locations.items, &.{result})) |_| {
if (std.mem.indexOfScalar(SpvWord, &self.mod.input_locations, result)) |_| {
try self.writeValue(T, input, &self.results[result].variant.?.Variable.value);
} else {
return RuntimeError.NotFound;
}
}
pub fn readDescriptorSet(self: *const Self, comptime T: type, output: *T, set: SpvWord, binding: SpvWord) RuntimeError!void {
if (set < lib.SPIRV_MAX_SET and binding < lib.SPIRV_MAX_SET_BINDINGS) {
try self.readValue(T, output, &self.results[self.mod.bindings[set][binding]].variant.?.Variable.value);
} else {
return RuntimeError.NotFound;
}
}
pub fn writeDescriptorSet(self: *const Self, comptime T: type, allocator: std.mem.Allocator, input: *const T, set: SpvWord, binding: SpvWord) RuntimeError!void {
if (set < lib.SPIRV_MAX_SET and binding < lib.SPIRV_MAX_SET_BINDINGS) {
const variable = &self.results[self.mod.bindings[set][binding]].variant.?.Variable;
switch (variable.value) {
.RuntimeArray => {
const resolved = self.results[variable.type_word].resolveType(self.results);
variable.value = try Result.initValue(allocator, input.len, self.results, resolved);
},
.Vector, .Matrix, .Array, .Structure => |v| {
},
}
try self.writeValue(T, input, &variable.value);
} else {
return RuntimeError.NotFound;
}
}
fn reset(self: *Self) void {
self.function_stack.clearRetainingCapacity();
self.current_function = null;
@@ -236,7 +263,15 @@ fn readValue(self: *const Self, comptime T: type, output: []T, value: *const Res
u32 => output[i] = vec[i],
inline else => return RuntimeError.InvalidValueType,
},
.Vector, .Matrix, .Array, .Structure => |values| for (values, 0..) |v, i| try self.readValue(T, output[i..], &v),
.Array,
.Matrix,
.Structure,
.Vector,
=> |values| for (values, 0..) |v, i| try self.readValue(T, output[i..], &v),
.RuntimeArray => |opt_values| if (opt_values) |values| {
for (values, 0..) |v, i|
try self.readValue(T, output[i..], &v);
},
else => return RuntimeError.InvalidValueType,
}
}
@@ -307,7 +342,15 @@ fn writeValue(self: *const Self, comptime T: type, input: []const T, value: *Res
u32 => vec[i] = input[i],
inline else => return RuntimeError.InvalidValueType,
},
.Vector, .Matrix, .Array, .Structure => |*values| for (values.*, 0..) |*v, i| try self.writeValue(T, input[i..], v),
.Array,
.Matrix,
.Structure,
.Vector,
=> |*values| for (values.*, 0..) |*v, i| try self.writeValue(T, input[i..], v),
.RuntimeArray => |opt_values| if (opt_values) |*values| {
for (values.*, 0..) |*v, i|
try self.writeValue(T, input[i..], v);
},
else => return RuntimeError.InvalidValueType,
}
}

View File

@@ -43,3 +43,15 @@ pub const SpvWord = spv.SpvWord;
pub const SpvBool = spv.SpvBool;
pub const GLSL_std_450 = @import("GLSL_std_450/opcodes.zig");
/// Maximum number of input locations per module
pub const SPIRV_MAX_INPUT_LOCATIONS: usize = 32;
/// Maximum number of output locations per module
pub const SPIRV_MAX_OUTPUT_LOCATIONS: usize = 32;
/// Maximum number of descriptor set per module
pub const SPIRV_MAX_SET: usize = 32;
/// Maximum number of bindings per descriptor set
pub const SPIRV_MAX_SET_BINDINGS: usize = 32;

View File

@@ -149,7 +149,6 @@ pub const SetupDispatcher = block: {
.ShiftLeftLogical = autoSetupConstant,
.ShiftRightArithmetic = autoSetupConstant,
.ShiftRightLogical = autoSetupConstant,
.Source = opSource,
.SourceExtension = opSourceExtension,
.TypeArray = opTypeArray,
.TypeBool = opTypeBool,
@@ -377,7 +376,6 @@ fn BitOperator(comptime T: ValueType, comptime Op: BitOp) type {
4 => &op2.*.Vector4u32,
else => unreachable,
};
// NOTE: the above dummy mapping isnt type-correct for i32; call sites below pass correct rhs pointer.
_ = b;
return RuntimeError.InvalidSpirV;
}
@@ -796,32 +794,32 @@ fn addDecoration(allocator: std.mem.Allocator, rt: *Runtime, target: SpvWord, de
decoration.index = if (member) |memb| memb else 0;
switch (decoration_type) {
.SpecId,
.ArrayStride,
.MatrixStride,
.BuiltIn,
.UniformId,
.Stream,
.Location,
.Component,
.Index,
.Binding,
.DescriptorSet,
.Offset,
.XfbBuffer,
.XfbStride,
.FuncParamAttr,
.FPRoundingMode,
.FPFastMathMode,
.InputAttachmentIndex,
.Alignment,
.MaxByteOffset,
.AlignmentId,
.MaxByteOffsetId,
.SecondaryViewportRelativeNV,
.ArrayStride,
.Binding,
.BuiltIn,
.Component,
.CounterBuffer,
.DescriptorSet,
.FPFastMathMode,
.FPRoundingMode,
.FuncParamAttr,
.Index,
.InputAttachmentIndex,
.Location,
.MatrixStride,
.MaxByteOffset,
.MaxByteOffsetId,
.Offset,
.SecondaryViewportRelativeNV,
.SpecId,
.Stream,
.UniformId,
.UserSemantic,
.UserTypeGOOGLE,
.XfbBuffer,
.XfbStride,
=> {
decoration.literal_1 = try rt.it.next();
decoration.literal_2 = null;
@@ -869,21 +867,123 @@ fn opBitcast(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
}
fn copyValue(dst: *Result.Value, src: *const Result.Value) void {
switch (src.*) {
.Vector, .Matrix, .Array, .Structure => |src_slice| {
const dst_slice = switch (dst.*) {
.Vector, .Matrix, .Array, .Structure => |d| d,
else => unreachable,
};
const helpers = struct {
fn copySlice(dst_slice: []Result.Value, src_slice: []const Result.Value) void {
for (0..@min(dst_slice.len, src_slice.len)) |i| {
copyValue(&dst_slice[i], &src_slice[i]);
}
}
fn getDstSlice(v: *Result.Value) ?[]Result.Value {
return switch (v.*) {
.Vector, .Matrix, .Array, .Structure => |s| s,
.RuntimeArray => |s| s,
else => null,
};
}
fn writeF32(dst_f32_ptr: *f32, src_v: *const Result.Value) void {
switch (src_v.*) {
.Pointer => |src_ptr| switch (src_ptr) {
.f32_ptr => |src_f32_ptr| dst_f32_ptr.* = src_f32_ptr.*,
.common => |src_val_ptr| switch (src_val_ptr.*) {
.Float => |f| dst_f32_ptr.* = f.float32,
else => unreachable,
},
else => unreachable,
},
.Float => |f| dst_f32_ptr.* = f.float32,
else => unreachable,
}
}
fn writeI32(dst_i32_ptr: *i32, src_v: *const Result.Value) void {
switch (src_v.*) {
.Pointer => |src_ptr| switch (src_ptr) {
.i32_ptr => |src_i32_ptr| dst_i32_ptr.* = src_i32_ptr.*,
.common => |src_val_ptr| switch (src_val_ptr.*) {
.Int => |i| dst_i32_ptr.* = i.sint32,
else => unreachable,
},
else => unreachable,
},
.Int => |i| dst_i32_ptr.* = i.sint32,
else => unreachable,
}
}
fn writeU32(dst_u32_ptr: *u32, src_v: *const Result.Value) void {
switch (src_v.*) {
.Pointer => |src_ptr| switch (src_ptr) {
.u32_ptr => |src_u32_ptr| dst_u32_ptr.* = src_u32_ptr.*,
.common => |src_val_ptr| switch (src_val_ptr.*) {
.Int => |i| dst_u32_ptr.* = i.uint32,
else => unreachable,
},
else => unreachable,
},
.Int => |i| dst_u32_ptr.* = i.uint32,
else => unreachable,
}
}
};
if (std.meta.activeTag(dst.*) == .Pointer) {
switch (dst.Pointer) {
.common => |dst_val_ptr| return switch (src.*) {
.Pointer => |src_ptr| switch (src_ptr) {
.common => |src_val_ptr| copyValue(dst_val_ptr, src_val_ptr),
else => dst_val_ptr.* = src.*,
},
else => copyValue(dst_val_ptr, src),
},
.f32_ptr => |dst_f32_ptr| {
helpers.writeF32(dst_f32_ptr, src);
return;
},
.i32_ptr => |dst_i32_ptr| {
helpers.writeI32(dst_i32_ptr, src);
return;
},
.u32_ptr => |dst_u32_ptr| {
helpers.writeU32(dst_u32_ptr, src);
return;
},
}
}
if (std.meta.activeTag(src.*) == .Pointer) {
switch (src.Pointer) {
.common => |src_val_ptr| {
copyValue(dst, src_val_ptr);
return;
},
else => {},
}
}
const dst_slice = helpers.getDstSlice(dst);
switch (src.*) {
.Vector, .Matrix, .Array, .Structure => |src_slice| {
helpers.copySlice(dst_slice.?, src_slice);
},
.RuntimeArray => |opt_src_slice| if (opt_src_slice) |src_slice| {
helpers.copySlice(dst_slice.?, src_slice);
} else unreachable,
else => dst.* = src.*,
}
}
pub fn getValuePrimitiveField(comptime T: ValueType, comptime BitCount: SpvWord, v: *Result.Value) RuntimeError!*getValuePrimitiveFieldType(T, BitCount) {
if (std.meta.activeTag(v.*) == .Pointer) {
return switch (v.Pointer) {
.common => |value| getValuePrimitiveField(T, BitCount, value),
.f32_ptr => |ptr| @ptrCast(@alignCast(ptr)),
.u32_ptr => |ptr| @ptrCast(@alignCast(ptr)),
.i32_ptr => |ptr| @ptrCast(@alignCast(ptr)),
};
}
return switch (T) {
.Bool => &v.Bool,
.Float => switch (BitCount) {
@@ -937,25 +1037,53 @@ fn opAccessChain(_: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) Runtim
if (i.uint32 > v.len) return RuntimeError.InvalidSpirV;
value_ptr = &v[i.uint32];
},
//.Vector4f32 => |v| {
// if (i.uint32 > 4) return RuntimeError.InvalidSpirV;
// break :blk .{
// .Float = .{ .float32 = v[i.uint32] },
// };
//},
//.Vector2f32 => |v| {
// if (i.uint32 > 2) return RuntimeError.InvalidSpirV;
// break :blk .{
// .Float = .{ .float32 = v[i.uint32] },
// };
//},
.RuntimeArray => |opt_v| if (opt_v) |v| {
if (i.uint32 > v.len) return RuntimeError.InvalidSpirV;
value_ptr = &v[i.uint32];
} else return RuntimeError.InvalidSpirV,
.Vector4f32 => |*v| {
if (i.uint32 > 4) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .f32_ptr = &v[i.uint32] } };
},
.Vector3f32 => |*v| {
if (i.uint32 > 3) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .f32_ptr = &v[i.uint32] } };
},
.Vector2f32 => |*v| {
if (i.uint32 > 2) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .f32_ptr = &v[i.uint32] } };
},
.Vector4i32 => |*v| {
if (i.uint32 > 4) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .i32_ptr = &v[i.uint32] } };
},
.Vector3i32 => |*v| {
if (i.uint32 > 3) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .i32_ptr = &v[i.uint32] } };
},
.Vector2i32 => |*v| {
if (i.uint32 > 2) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .i32_ptr = &v[i.uint32] } };
},
.Vector4u32 => |*v| {
if (i.uint32 > 4) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .u32_ptr = &v[i.uint32] } };
},
.Vector3u32 => |*v| {
if (i.uint32 > 3) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .u32_ptr = &v[i.uint32] } };
},
.Vector2u32 => |*v| {
if (i.uint32 > 2) return RuntimeError.InvalidSpirV;
break :blk .{ .Pointer = .{ .u32_ptr = &v[i.uint32] } };
},
else => return RuntimeError.InvalidSpirV,
}
},
else => return RuntimeError.InvalidSpirV,
}
}
break :blk value_ptr;
break :blk .{ .Pointer = .{ .common = value_ptr } };
},
},
};
@@ -1186,8 +1314,16 @@ fn opExecutionMode(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!
},
.Invocations => rt.mod.geometry_invocations = try rt.it.next(),
.OutputVertices => rt.mod.geometry_output_count = try rt.it.next(),
.InputPoints, .InputLines, .Triangles, .InputLinesAdjacency, .InputTrianglesAdjacency => rt.mod.geometry_input = @intFromEnum(mode),
.OutputPoints, .OutputLineStrip, .OutputTriangleStrip => rt.mod.geometry_output = @intFromEnum(mode),
.InputPoints,
.InputLines,
.Triangles,
.InputLinesAdjacency,
.InputTrianglesAdjacency,
=> rt.mod.geometry_input = @intFromEnum(mode),
.OutputPoints,
.OutputLineStrip,
.OutputTriangleStrip,
=> rt.mod.geometry_output = @intFromEnum(mode),
else => {},
}
}
@@ -1393,26 +1529,6 @@ fn opReturnValue(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!vo
}
}
fn opSource(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
var file = rt.mod.files.addOne(allocator) catch return RuntimeError.OutOfMemory;
file.lang = try rt.it.nextAs(spv.SpvSourceLanguage);
file.lang_version = try rt.it.next();
if (word_count > 2) {
const id = try rt.it.next();
if (id >= rt.mod.results.len) return RuntimeError.InvalidSpirV;
if (rt.mod.results[id].name) |name| {
file.file_name = name;
}
}
if (word_count > 3) {
const id = try rt.it.next();
if (id >= rt.mod.results.len) return RuntimeError.InvalidSpirV;
if (rt.mod.results[id].name) |name| {
file.source = name;
}
}
}
fn opSourceExtension(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
rt.mod.extensions.append(allocator, try readStringN(allocator, &rt.it, word_count)) catch return RuntimeError.OutOfMemory;
}
@@ -1523,9 +1639,16 @@ fn opTypePointer(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!vo
fn opTypeRuntimeArray(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next();
const components_type_word = try rt.it.next();
rt.mod.results[id].variant = .{
.Type = .{
.RuntimeArray = .{},
.RuntimeArray = .{
.components_type_word = components_type_word,
.components_type = switch ((try rt.mod.results[components_type_word].getVariant()).*) {
.Type => |t| @as(Result.Type, t),
else => return RuntimeError.InvalidSpirV,
},
},
},
};
}
@@ -1631,9 +1754,6 @@ fn opVariable(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) R
const resolved = rt.mod.results[var_type].resolveType(rt.mod.results);
const member_count = resolved.getMemberCounts();
if (member_count == 0) {
return RuntimeError.InvalidSpirV;
}
target.variant = .{
.Variable = .{
.storage_class = storage_class,