Skip to content

Commit 8323475

Browse files
spirv: add test for SPIR-V string constants with c constraint
1 parent 7dafd68 commit 8323475

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/codegen/spirv/Module.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,15 @@ pub fn resolveString(self: *Module, string: []const u8) !Id {
506506
return id;
507507
}
508508

509-
pub fn constStringGlobal(self: *Module, str: []const u8) !IdRef {
509+
pub fn constStringGlobal(self: *Module, str: []const u8) !Id {
510510
if (self.cache.const_strings.get(str)) |id| return id;
511511

512512
const u8_ty = try self.intType(.unsigned, 8);
513513
const len = str.len + 1;
514514
const len_id = try self.constant(try self.intType(.unsigned, 32), .{ .uint32 = @intCast(len) });
515515
const arr_ty = try self.arrayType(len_id, u8_ty);
516516

517-
const char_ids = try self.gpa.alloc(IdRef, len);
517+
const char_ids = try self.gpa.alloc(Id, len);
518518
defer self.gpa.free(char_ids);
519519
for (str, 0..) |c, i| {
520520
char_ids[i] = try self.constant(u8_ty, .{ .uint32 = c });
@@ -531,15 +531,15 @@ pub fn constStringGlobal(self: *Module, str: []const u8) !IdRef {
531531
const ptr_ty = self.allocId();
532532
try self.sections.types_globals_constants.emit(self.gpa, .OpTypePointer, .{
533533
.id_result = ptr_ty,
534-
.storage_class = .UniformConstant,
534+
.storage_class = .uniform_constant,
535535
.type = arr_ty,
536536
});
537537

538538
const var_id = self.allocId();
539539
try self.sections.types_globals_constants.emit(self.gpa, .OpVariable, .{
540540
.id_result_type = ptr_ty,
541541
.id_result = var_id,
542-
.storage_class = .UniformConstant,
542+
.storage_class = .uniform_constant,
543543
.initializer = const_arr_id,
544544
});
545545

test/behavior/asm.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,13 @@ test "asm modifiers (AArch64)" {
179179
);
180180
try expectEqual(2 * x, double);
181181
}
182+
183+
test "SPIR-V string constants with c constraint" {
184+
if (builtin.zig_backend != .stage2_spirv) return error.SkipZigTest;
185+
if (builtin.target.os.tag != .opencl) return error.SkipZigTest;
186+
187+
_ = std.gpu.printf("testing printf\n", .{});
188+
var a: i32 = -10;
189+
_ = &a;
190+
_ = std.gpu.printf("a: %d, a + 10: %d\n", .{ a, a + 10 });
191+
}

0 commit comments

Comments
 (0)