Skip to content

Commit cd4b03c

Browse files
committed
spirv: define and use extended instruction set opcodes
1 parent 246e1de commit cd4b03c

File tree

7 files changed

+1504
-4206
lines changed

7 files changed

+1504
-4206
lines changed

src/codegen/spirv/Assembler.zig

Lines changed: 292 additions & 289 deletions
Large diffs are not rendered by default.

src/codegen/spirv/CodeGen.zig

Lines changed: 310 additions & 290 deletions
Large diffs are not rendered by default.

src/codegen/spirv/Module.zig

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ pub const Decl = struct {
125125
/// - For `invocation_global`, this is the result-id of the associated InvocationGlobal instruction.
126126
result_id: Id,
127127
/// The offset of the first dependency of this decl in the `decl_deps` array.
128-
begin_dep: u32,
128+
begin_dep: usize = 0,
129129
/// The past-end offset of the dependencies of this decl in the `decl_deps` array.
130-
end_dep: u32,
130+
end_dep: usize = 0,
131131
};
132132

133133
/// This models a kernel entry point.
@@ -258,7 +258,6 @@ pub fn resolveNav(module: *Module, ip: *InternPool, nav_index: InternPool.Nav.In
258258
.generic => .invocation_global,
259259
else => .global,
260260
};
261-
262261
entry.value_ptr.* = try module.allocDecl(kind);
263262
}
264263

@@ -782,15 +781,15 @@ pub fn builtin(
782781
const gop = try module.cache.builtins.getOrPut(module.gpa, .{ spirv_builtin, storage_class });
783782
if (!gop.found_existing) {
784783
const decl_index = try module.allocDecl(.global);
785-
const result_id = module.declPtr(decl_index).result_id;
784+
const decl = module.declPtr(decl_index);
785+
786786
gop.value_ptr.* = decl_index;
787787
try module.sections.globals.emit(module.gpa, .OpVariable, .{
788788
.id_result_type = result_ty_id,
789-
.id_result = result_id,
789+
.id_result = decl.result_id,
790790
.storage_class = storage_class,
791791
});
792-
try module.decorate(result_id, .{ .built_in = .{ .built_in = spirv_builtin } });
793-
try module.declareDeclDeps(decl_index, &.{});
792+
try module.decorate(decl.result_id, .{ .built_in = .{ .built_in = spirv_builtin } });
794793
}
795794
return gop.value_ptr.*;
796795
}
@@ -847,8 +846,6 @@ pub fn allocDecl(module: *Module, kind: Decl.Kind) !Decl.Index {
847846
try module.decls.append(module.gpa, .{
848847
.kind = kind,
849848
.result_id = module.allocId(),
850-
.begin_dep = undefined,
851-
.end_dep = undefined,
852849
});
853850

854851
return @as(Decl.Index, @enumFromInt(@as(u32, @intCast(module.decls.items.len - 1))));
@@ -858,17 +855,6 @@ pub fn declPtr(module: *Module, index: Decl.Index) *Decl {
858855
return &module.decls.items[@intFromEnum(index)];
859856
}
860857

861-
/// Declare ALL dependencies for a decl.
862-
pub fn declareDeclDeps(module: *Module, decl_index: Decl.Index, deps: []const Decl.Index) !void {
863-
const begin_dep: u32 = @intCast(module.decl_deps.items.len);
864-
try module.decl_deps.appendSlice(module.gpa, deps);
865-
const end_dep: u32 = @intCast(module.decl_deps.items.len);
866-
867-
const decl = module.declPtr(decl_index);
868-
decl.begin_dep = begin_dep;
869-
decl.end_dep = end_dep;
870-
}
871-
872858
/// Declare a SPIR-V function as an entry point. This causes an extra wrapper
873859
/// function to be generated, which is then exported as the real entry point. The purpose of this
874860
/// wrapper is to allocate and initialize the structure holding the instance globals.

src/codegen/spirv/Section.zig

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn deinit(section: *Section, allocator: Allocator) void {
2121
}
2222

2323
pub fn reset(section: *Section) void {
24-
section.instructions.items.len = 0;
24+
section.instructions.clearRetainingCapacity();
2525
}
2626

2727
pub fn toWords(section: Section) []Word {
@@ -86,16 +86,6 @@ pub fn emit(
8686
section.writeOperands(opcode.Operands(), operands);
8787
}
8888

89-
pub fn emitBranch(
90-
section: *Section,
91-
allocator: Allocator,
92-
target_label: spec.Id,
93-
) !void {
94-
try section.emit(allocator, .OpBranch, .{
95-
.target_label = target_label,
96-
});
97-
}
98-
9989
pub fn writeWord(section: *Section, word: Word) void {
10090
section.instructions.appendAssumeCapacity(word);
10191
}

0 commit comments

Comments
 (0)