Skip to content

Commit d9bd34f

Browse files
authored
Merge pull request #20247 from Snektron/spirv-vectors-v3
spirv: vectors v3
2 parents d4bc640 + a567f38 commit d9bd34f

22 files changed

+1958
-1077
lines changed

lib/std/Build.zig

+17-3
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,24 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
972972
// Consider that this is declarative; the run step may not be run unless a user
973973
// option is supplied.
974974
const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name}));
975-
run_step.addArtifactArg(exe);
975+
if (exe.kind == .@"test") {
976+
if (exe.exec_cmd_args) |exec_cmd_args| {
977+
for (exec_cmd_args) |cmd_arg| {
978+
if (cmd_arg) |arg| {
979+
run_step.addArg(arg);
980+
} else {
981+
run_step.addArtifactArg(exe);
982+
}
983+
}
984+
} else {
985+
run_step.addArtifactArg(exe);
986+
}
976987

977-
if (exe.kind == .@"test" and exe.test_server_mode) {
978-
run_step.enableTestRunnerMode();
988+
if (exe.test_server_mode) {
989+
run_step.enableTestRunnerMode();
990+
}
991+
} else {
992+
run_step.addArtifactArg(exe);
979993
}
980994

981995
return run_step;

src/codegen/spirv.zig

+1,761-1,026
Large diffs are not rendered by default.

src/codegen/spirv/Module.zig

+15-7
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ cache: struct {
155155
void_type: ?IdRef = null,
156156
int_types: std.AutoHashMapUnmanaged(std.builtin.Type.Int, IdRef) = .{},
157157
float_types: std.AutoHashMapUnmanaged(std.builtin.Type.Float, IdRef) = .{},
158+
// This cache is required so that @Vector(X, u1) in direct representation has the
159+
// same ID as @Vector(X, bool) in indirect representation.
160+
vector_types: std.AutoHashMapUnmanaged(struct { IdRef, u32 }, IdRef) = .{},
158161
} = .{},
159162

160163
/// Set of Decls, referred to by Decl.Index.
@@ -194,6 +197,7 @@ pub fn deinit(self: *Module) void {
194197

195198
self.cache.int_types.deinit(self.gpa);
196199
self.cache.float_types.deinit(self.gpa);
200+
self.cache.vector_types.deinit(self.gpa);
197201

198202
self.decls.deinit(self.gpa);
199203
self.decl_deps.deinit(self.gpa);
@@ -474,13 +478,17 @@ pub fn floatType(self: *Module, bits: u16) !IdRef {
474478
}
475479

476480
pub fn vectorType(self: *Module, len: u32, child_id: IdRef) !IdRef {
477-
const result_id = self.allocId();
478-
try self.sections.types_globals_constants.emit(self.gpa, .OpTypeVector, .{
479-
.id_result = result_id,
480-
.component_type = child_id,
481-
.component_count = len,
482-
});
483-
return result_id;
481+
const entry = try self.cache.vector_types.getOrPut(self.gpa, .{ child_id, len });
482+
if (!entry.found_existing) {
483+
const result_id = self.allocId();
484+
entry.value_ptr.* = result_id;
485+
try self.sections.types_globals_constants.emit(self.gpa, .OpTypeVector, .{
486+
.id_result = result_id,
487+
.component_type = child_id,
488+
.component_count = len,
489+
});
490+
}
491+
return entry.value_ptr.*;
484492
}
485493

486494
pub fn constUndef(self: *Module, ty_id: IdRef) !IdRef {

src/link/SpirV.zig

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, prog_node: std.Progress.Node)
232232
// name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
233233
// We're using : as separator, which is a reserved character.
234234

235+
try error_info.append(':');
235236
try std.Uri.Component.percentEncode(
236237
error_info.writer(),
237238
name.toSlice(&mod.intern_pool),

test/behavior/array.zig

+1
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ test "slicing array of zero-sized values" {
768768
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
769769
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
770770
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
771+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
771772

772773
var arr: [32]u0 = undefined;
773774
for (arr[0..]) |*zero|

test/behavior/byval_arg_var.zig

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var result: []const u8 = "wrong";
66
test "pass string literal byvalue to a generic var param" {
77
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
88
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
9+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
910

1011
start();
1112
blowUpStack(10);

test/behavior/cast.zig

+1
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ test "assignment to optional pointer result loc" {
13781378

13791379
test "cast between *[N]void and []void" {
13801380
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1381+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
13811382

13821383
var a: [4]void = undefined;
13831384
const b: []void = &a;

test/behavior/enum.zig

+1
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ test "matching captures causes enum equivalence" {
12861286
test "large enum field values" {
12871287
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
12881288
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1289+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
12891290

12901291
{
12911292
const E = enum(u64) { min = std.math.minInt(u64), max = std.math.maxInt(u64) };

test/behavior/error.zig

+3
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ test "try used in recursive function with inferred error set" {
997997
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
998998
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
999999
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1000+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10001001

10011002
const Value = union(enum) {
10021003
values: []const @This(),
@@ -1103,6 +1104,7 @@ test "result location initialization of error union with OPV payload" {
11031104
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
11041105
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
11051106
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1107+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
11061108

11071109
const S = struct {
11081110
x: u0,
@@ -1125,6 +1127,7 @@ test "result location initialization of error union with OPV payload" {
11251127
test "return error union with i65" {
11261128
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
11271129
if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1130+
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
11281131

11291132
try expect(try add(1000, 234) == 1234);
11301133
}

0 commit comments

Comments
 (0)