aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv/Module.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2024-06-03 00:44:08 +0200
committerRobin Voetter <robin@voetter.nl>2024-06-10 20:32:49 +0200
commita3b1ba82f57d5d8981a471850cbbb0db29c3a479 (patch)
tree848b20d5c8929a1198f331725865f1a08c07288d /src/codegen/spirv/Module.zig
parent4e7159ae1d08ce74548e0adc3b3936aacc23a06e (diff)
downloadzig-a3b1ba82f57d5d8981a471850cbbb0db29c3a479.tar.gz
zig-a3b1ba82f57d5d8981a471850cbbb0db29c3a479.zip
spirv: new vectorization helper
The old vectorization helper (WipElementWise) was clunky and a bit annoying to use, and it wasn't really flexible enough. This introduces a new vectorization helper, which uses Temporary and Operation types to deduce a Vectorization to perform the operation in a reasonably efficient manner. It removes the outer loop required by WipElementWise so that implementations of AIR instructions are cleaner. This helps with sanity when we start to introduce support for composite integers. airShift, convertToDirect, convertToIndirect, and normalize are initially implemented using this new method.
Diffstat (limited to 'src/codegen/spirv/Module.zig')
-rw-r--r--src/codegen/spirv/Module.zig22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/codegen/spirv/Module.zig b/src/codegen/spirv/Module.zig
index 88fe677345..d1b2171786 100644
--- a/src/codegen/spirv/Module.zig
+++ b/src/codegen/spirv/Module.zig
@@ -155,6 +155,9 @@ cache: struct {
void_type: ?IdRef = null,
int_types: std.AutoHashMapUnmanaged(std.builtin.Type.Int, IdRef) = .{},
float_types: std.AutoHashMapUnmanaged(std.builtin.Type.Float, IdRef) = .{},
+ // This cache is required so that @Vector(X, u1) in direct representation has the
+ // same ID as @Vector(X, bool) in indirect representation.
+ vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .{},
} = .{},
/// Set of Decls, referred to by Decl.Index.
@@ -194,6 +197,7 @@ pub fn deinit(self: *Module) void {
self.cache.int_types.deinit(self.gpa);
self.cache.float_types.deinit(self.gpa);
+ self.cache.vector_types.deinit(self.gpa);
self.decls.deinit(self.gpa);
self.decl_deps.deinit(self.gpa);
@@ -474,13 +478,17 @@ pub fn floatType(self: *Module, bits: u16) !IdRef {
}
pub fn vectorType(self: *Module, len: u32, child_id: IdRef) !IdRef {
- const result_id = self.allocId();
- try self.sections.types_globals_constants.emit(self.gpa, .OpTypeVector, .{
- .id_result = result_id,
- .component_type = child_id,
- .component_count = len,
- });
- return result_id;
+ const entry = try self.cache.vector_types.getOrPut(self.gpa, .{ child_id, len });
+ if (!entry.found_existing) {
+ const result_id = self.allocId();
+ entry.value_ptr.* = result_id;
+ try self.sections.types_globals_constants.emit(self.gpa, .OpTypeVector, .{
+ .id_result = result_id,
+ .component_type = child_id,
+ .component_count = len,
+ });
+ }
+ return entry.value_ptr.*;
}
pub fn constUndef(self: *Module, ty_id: IdRef) !IdRef {