working on restuls
This commit is contained in:
@@ -17,7 +17,7 @@ const Result = @import("Result.zig");
|
||||
const Runtime = @import("Runtime.zig");
|
||||
const WordIterator = @import("WordIterator.zig");
|
||||
|
||||
const SpvValue = Result.SpvValue;
|
||||
const Value = Result.Value;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
@@ -74,10 +74,10 @@ geometry_output_count: SpvWord,
|
||||
geometry_input: SpvWord,
|
||||
geometry_output: SpvWord,
|
||||
|
||||
input_locations: std.AutoHashMap(SpvWord, *SpvValue),
|
||||
output_locations: std.AutoHashMap(SpvWord, *SpvValue),
|
||||
bindings: std.AutoHashMap(SpvBinding, *SpvValue),
|
||||
push_constants: []SpvValue,
|
||||
input_locations: std.AutoHashMap(SpvWord, *Value),
|
||||
output_locations: std.AutoHashMap(SpvWord, *Value),
|
||||
bindings: std.AutoHashMap(SpvBinding, *Value),
|
||||
push_constants: []Value,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord) ModuleError!Self {
|
||||
var self: Self = std.mem.zeroInit(Self, .{
|
||||
@@ -90,9 +90,9 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord) ModuleError!S
|
||||
.local_size_x = 1,
|
||||
.local_size_y = 1,
|
||||
.local_size_z = 1,
|
||||
.input_locations = std.AutoHashMap(SpvWord, *SpvValue).init(allocator),
|
||||
.output_locations = std.AutoHashMap(SpvWord, *SpvValue).init(allocator),
|
||||
.bindings = std.AutoHashMap(SpvBinding, *SpvValue).init(allocator),
|
||||
.input_locations = std.AutoHashMap(SpvWord, *Value).init(allocator),
|
||||
.output_locations = std.AutoHashMap(SpvWord, *Value).init(allocator),
|
||||
.bindings = std.AutoHashMap(SpvBinding, *Value).init(allocator),
|
||||
});
|
||||
errdefer self.deinit(allocator);
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
const std = @import("std");
|
||||
const spv = @import("spv.zig");
|
||||
|
||||
const RuntimeError = @import("Runtime.zig").RuntimeError;
|
||||
|
||||
const SpvVoid = spv.SpvVoid;
|
||||
const SpvByte = spv.SpvByte;
|
||||
const SpvWord = spv.SpvWord;
|
||||
@@ -52,7 +54,7 @@ const Decoration = struct {
|
||||
index: SpvWord,
|
||||
};
|
||||
|
||||
pub const SpvValue = union(Type) {
|
||||
pub const Value = union(Type) {
|
||||
Void: noreturn,
|
||||
Bool: bool,
|
||||
Int: union {
|
||||
@@ -70,8 +72,8 @@ pub const SpvValue = union(Type) {
|
||||
float32: f32,
|
||||
float64: f64,
|
||||
},
|
||||
Vector: noreturn,
|
||||
Matrix: noreturn,
|
||||
Vector: []Value,
|
||||
Matrix: []Value,
|
||||
Array: struct {},
|
||||
RuntimeArray: struct {},
|
||||
Structure: struct {},
|
||||
@@ -134,10 +136,15 @@ variant: ?union(Variant) {
|
||||
},
|
||||
Variable: struct {
|
||||
storage_class: spv.SpvStorageClass,
|
||||
value: SpvValue,
|
||||
value: Value,
|
||||
},
|
||||
Constant: Value,
|
||||
Function: struct {
|
||||
return_type: SpvWord,
|
||||
function_type: SpvWord,
|
||||
/// Allocated array
|
||||
params: []const SpvWord,
|
||||
},
|
||||
Constant: SpvValue,
|
||||
Function: struct {},
|
||||
AccessChain: struct {},
|
||||
FunctionParameter: struct {},
|
||||
Label: struct {},
|
||||
@@ -188,3 +195,18 @@ pub fn resolveType(self: *const Self, results: []const Self) *const Self {
|
||||
else
|
||||
self;
|
||||
}
|
||||
|
||||
pub fn initConstantValue(self: *Self, results: []const Self, target: SpvWord) RuntimeError!void {
|
||||
_ = self;
|
||||
const resolved = results[target].resolveType(results);
|
||||
if (resolved.variant) |variant| {
|
||||
switch (variant) {
|
||||
.Type => |t| switch (t) {
|
||||
.Structure => |s|
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
},
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
}
|
||||
}
|
||||
return RuntimeError.InvalidSpirV;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@ const SpvBool = spv.SpvBool;
|
||||
|
||||
// DUMB INDEV OPCODES TODO :
|
||||
// OpVariable X
|
||||
// OpFunction X
|
||||
// OpLabel X
|
||||
// OpCompositeConstruct X
|
||||
// OpAccessChain X
|
||||
// OpStore X
|
||||
// OpLoad X
|
||||
@@ -51,6 +48,9 @@ pub const SetupDispatcher = block: {
|
||||
.TypeVector = opTypeVector,
|
||||
.TypeVoid = opTypeVoid,
|
||||
.Variable = opVariable,
|
||||
.Function = opFunction,
|
||||
.Label = opLabel,
|
||||
.CompositeConstruct = opCompositeConstruct,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -334,7 +334,7 @@ fn opConstant(_: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeEr
|
||||
.Int => {
|
||||
break :value if (word_count - 2 != 1) .{
|
||||
.Int = .{
|
||||
.uint64 = try rt.it.next() | (@as(u64, try rt.it.next()) >> 32),
|
||||
.uint64 = @as(u64, try rt.it.next()) | (@as(u64, try rt.it.next()) >> 32),
|
||||
},
|
||||
} else .{
|
||||
.Int = .{
|
||||
@@ -382,6 +382,46 @@ fn opVariable(_: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeEr
|
||||
};
|
||||
}
|
||||
|
||||
fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||
const return_type = try rt.it.next();
|
||||
const id = try rt.it.next();
|
||||
_ = rt.it.skip(); // Skip function control
|
||||
const function_type_id = try rt.it.next();
|
||||
|
||||
rt.mod.results.items[id].variant = .{
|
||||
.Function = .{
|
||||
.return_type = return_type,
|
||||
.function_type = function_type_id,
|
||||
.params = params: {
|
||||
if (rt.mod.results.items[function_type_id].variant) |variant| {
|
||||
const params_count = switch (variant) {
|
||||
.Type => |t| switch (t) {
|
||||
.Function => |f| f.params.len,
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
},
|
||||
else => return RuntimeError.InvalidSpirV,
|
||||
};
|
||||
break :params allocator.alloc(SpvWord, params_count) catch return RuntimeError.OutOfMemory;
|
||||
}
|
||||
return RuntimeError.InvalidSpirV;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
rt.current_function = &rt.mod.results.items[id];
|
||||
}
|
||||
|
||||
fn opLabel(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||
const id = try rt.it.next();
|
||||
rt.mod.results.items[id].variant = .{
|
||||
.Label = .{},
|
||||
};
|
||||
}
|
||||
|
||||
fn opCompositeConstruct(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||
_ = rt;
|
||||
}
|
||||
|
||||
fn readString(allocator: std.mem.Allocator, it: *WordIterator) RuntimeError![]const u8 {
|
||||
var str: std.ArrayList(u8) = .empty;
|
||||
while (it.nextOrNull()) |word| {
|
||||
|
||||
Reference in New Issue
Block a user