zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit dccc724179d984ac5785b6a20bd187bb9c8f749d (tree)
parent 6754fc8af277e65827ae531ca4d114df0576398c
Author: Ali Cheraghi <alichraghi@proton.me>
Date:   Sun, 21 Jun 2026 09:51:04 +0330

spirv: require `mesh_shading_ext` for `spirv_task` and `spirv_mesh`

Also adds a `cpu_features` key to the test manifest.

Diffstat:
Msrc/Sema.zig | 15+++++++++++++--
Mtest/behavior/array.zig | 2++
Mtest/cases/callconv_spirv.zig | 5+++--
Mtest/cases/compile_errors/SpirvType_vulkan_target.zig | 2+-
Mtest/cases/compile_errors/callconv_spirv_invalid_options.zig | 2+-
Dtest/cases/compile_errors/callconv_spirv_mesh_task_require_vulkan.zig | 17-----------------
Mtest/cases/compile_errors/callconv_spirv_on_unsupported_platform.zig | 1+
Mtest/cases/compile_errors/directly_embedding_spirv_type_in_struct_and_union.zig | 2+-
Mtest/cases/compile_errors/extern_spirv_decoration_validation.zig | 2+-
Mtest/cases/compile_errors/spirv_merge_logical_pointers.zig | 4++--
Mtest/cases/spirv_mergable_pointers.zig | 2+-
Mtest/src/Cases.zig | 13++++++++++++-
12 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -8694,15 +8694,26 @@ fn checkReturnTypeAndCallConv( return sema.fail(block, callconv_src, "'pixel_centered_integer' is not supported on this target", .{}); } }, - .spirv_kernel, .spirv_task => |kernel| { + .spirv_kernel => |kernel| { if (kernel.x == 0 or kernel.y == 0 or kernel.z == 0) { return sema.fail(block, callconv_src, "kernel workgroup dimensions must be at least 1", .{}); } }, + .spirv_task => |task| { + if (task.x == 0 or task.y == 0 or task.z == 0) { + return sema.fail(block, callconv_src, "kernel workgroup dimensions must be at least 1", .{}); + } + if (!target.cpu.has(.spirv, .mesh_shading_ext)) { + return sema.fail(block, callconv_src, "calling convention '{t}' requires the 'mesh_shading_ext' feature", .{@"callconv"}); + } + }, .spirv_mesh => |mesh| { if (mesh.max_vertices == 0 or mesh.max_primitives == 0) { return sema.fail(block, callconv_src, "mesh shader 'max_vertices' and 'max_primitives' must be at least 1", .{}); } + if (!target.cpu.has(.spirv, .mesh_shading_ext)) { + return sema.fail(block, callconv_src, "calling convention '{t}' requires the 'mesh_shading_ext' feature", .{@"callconv"}); + } }, else => {}, } @@ -8844,7 +8855,7 @@ fn checkMergeAllowed(sema: *Sema, block: *Block, src: LazySrcLoc, peer_ty: Type) try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); const backend = target_util.zigBackend(target, zcu.comp.config.use_llvm); - try sema.errNote(src, msg, "pointers with address space '{s}' cannot be returned from a branch on target {s}-{s} by compiler backend {s}", .{ + try sema.errNote(src, msg, "pointers with address space '{s}' cannot be returned from a branch on target '{s}-{s}' by compiler backend '{s}'", .{ @tagName(as), @tagName(target.cpu.arch.family()), @tagName(target.os.tag), diff --git a/test/behavior/array.zig b/test/behavior/array.zig @@ -1150,6 +1150,8 @@ test "resist alias of explicit copy of array passed as arg" { } test "access element through reference" { + if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; + const S = struct { fn doTheTest(x: u8) !void { { diff --git a/test/cases/callconv_spirv.zig b/test/cases/callconv_spirv.zig @@ -7,5 +7,6 @@ export fn mesh() callconv(.{ .spirv_mesh = .{ .stage_output = .output_lines, .ma // compile // output_mode=Obj // backend=selfhosted -// target=spirv64-vulkan -// emit_bin=false +// target=spirv32-vulkan +// cpu_features=vulkan_v1_2+mesh_shading_ext +// emit_bin=true diff --git a/test/cases/compile_errors/SpirvType_vulkan_target.zig b/test/cases/compile_errors/SpirvType_vulkan_target.zig @@ -48,7 +48,7 @@ comptime { // error // backend=selfhosted -// target=spirv64-vulkan +// target=spirv32-vulkan // // :2:21: error: access qualifier '.read_only' is only valid under the 'opencl' os // :14:21: error: invalid 'sampled' field value 'bool' diff --git a/test/cases/compile_errors/callconv_spirv_invalid_options.zig b/test/cases/compile_errors/callconv_spirv_invalid_options.zig @@ -21,7 +21,7 @@ export fn entry4() void { // error // backend=selfhosted -// target=spirv64-vulkan +// target=spirv32-vulkan // // :1:28: error: kernel workgroup dimensions must be at least 1 // :2:28: error: kernel workgroup dimensions must be at least 1 diff --git a/test/cases/compile_errors/callconv_spirv_mesh_task_require_vulkan.zig b/test/cases/compile_errors/callconv_spirv_mesh_task_require_vulkan.zig @@ -1,17 +0,0 @@ -const F1 = fn () callconv(.{ .spirv_task = .{ .x = 1, .y = 1, .z = 1 } }) void; -const F2 = fn () callconv(.{ .spirv_mesh = .{} }) void; -export fn entry1() void { - const a: F1 = undefined; - _ = a; -} -export fn entry2() void { - const a: F2 = undefined; - _ = a; -} - -// error -// backend=selfhosted -// target=spirv64-opengl -// -// :1:28: error: calling convention 'spirv_task' not supported by compiler backend 'stage2_spirv' -// :2:28: error: calling convention 'spirv_mesh' not supported by compiler backend 'stage2_spirv' diff --git a/test/cases/compile_errors/callconv_spirv_on_unsupported_platform.zig b/test/cases/compile_errors/callconv_spirv_on_unsupported_platform.zig @@ -22,6 +22,7 @@ export fn entry4() void { // error // backend=selfhosted // target=spirv64-opencl +// cpu_features=opencl_v2+mesh_shading_ext // // :1:28: error: calling convention 'spirv_fragment' not supported by compiler backend 'stage2_spirv' // :2:28: error: calling convention 'spirv_vertex' not supported by compiler backend 'stage2_spirv' diff --git a/test/cases/compile_errors/directly_embedding_spirv_type_in_struct_and_union.zig b/test/cases/compile_errors/directly_embedding_spirv_type_in_struct_and_union.zig @@ -25,7 +25,7 @@ export fn d() void { // error // backend=selfhosted -// target=spirv64-vulkan +// target=spirv32-vulkan // // :4:8: error: cannot directly embed SPIR-V type 'tmp.Sampler__SpirvType_4' in struct // :4:8: note: opaque types have unknown size diff --git a/test/cases/compile_errors/extern_spirv_decoration_validation.zig b/test/cases/compile_errors/extern_spirv_decoration_validation.zig @@ -8,6 +8,6 @@ comptime { // error // backend=selfhosted -// target=spirv64-vulkan +// target=spirv32-vulkan // // :1:45: error: 'flat' decoration requires 'input' address space diff --git a/test/cases/compile_errors/spirv_merge_logical_pointers.zig b/test/cases/compile_errors/spirv_merge_logical_pointers.zig @@ -11,8 +11,8 @@ export fn a() void { } // error -// target=spirv64-vulkan +// target=spirv32-vulkan // // :9:13: error: value with non-mergable pointer type '*i32' depends on runtime control flow // :9:17: note: runtime control flow here -// :9:13: note: pointers with address space 'generic' cannot be returned from a branch on target spirv-vulkan by compiler backend stage2_spirv +// :9:13: note: pointers with address space 'generic' cannot be returned from a branch on target 'spirv-vulkan' by compiler backend 'stage2_spirv' diff --git a/test/cases/spirv_mergable_pointers.zig b/test/cases/spirv_mergable_pointers.zig @@ -13,5 +13,5 @@ export fn a() void { // compile // output_mode=Obj // backend=selfhosted -// target=spirv64-vulkan +// target=spirv32-vulkan // emit_bin=true diff --git a/test/src/Cases.zig b/test/src/Cases.zig @@ -357,7 +357,15 @@ fn addFromDirInner( var manifest = try TestManifest.parse(ctx.arena, src); const backends = try manifest.getConfigForKeyAlloc(ctx.arena, "backend", Backend); - const targets = try manifest.getConfigForKeyAlloc(ctx.arena, "target", std.Target.Query); + const target_strs = try manifest.getConfigForKeyAlloc(ctx.arena, "target", []const u8); + const cpu_features_str = manifest.config_map.get("cpu_features") orelse ""; + const targets = try ctx.arena.alloc(std.Target.Query, target_strs.len); + for (targets, target_strs) |*query, target_str| { + query.* = try std.Target.Query.parse(.{ + .arch_os_abi = target_str, + .cpu_features = if (cpu_features_str.len == 0) null else cpu_features_str, + }); + } const is_test = try manifest.getConfigForKeyAssertSingle("is_test", bool); const link_libc = try manifest.getConfigForKeyAssertSingle("link_libc", bool); const output_mode = try manifest.getConfigForKeyAssertSingle("output_mode", std.builtin.OutputMode); @@ -707,6 +715,8 @@ const TestManifestConfigDefaults = struct { return "null"; } else if (std.mem.eql(u8, key, "imports")) { return ""; + } else if (std.mem.eql(u8, key, "cpu_features")) { + return ""; } else unreachable; } }; @@ -739,6 +749,7 @@ const TestManifest = struct { .{ "is_test", {} }, .{ "output_mode", {} }, .{ "target", {} }, + .{ "cpu_features", {} }, .{ "c_frontend", {} }, .{ "link_libc", {} }, .{ "backend", {} },