authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2026-09-13 20:37:15+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2026-09-18 16:36:24+03:30
log2d6970dd2c5f4fa7b1b141710d5d319668f0b46b
treeffec8f4223c8605277b4666cb356076e71e6cd68
parent65b95b0af42b3da0aaa86c9448e32e8aca388a17

spirv: accept all image type access qualifiers for vulkan


2 files changed, 28 insertions(+), 21 deletions(-)

src/codegen/spirv/CodeGen.zig+25-5
......@@ -308,6 +308,21 @@ pub fn generateNav(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) codegen.E
308308 else => {},
309309 }
310310
311 const image_ty = blk: {
312 if (ty.zigTypeTag(zcu) == .array or ty.isSpirvRuntimeArray(zcu)) {
313 break :blk ty.childType(zcu);
314 }
315 break :blk ty;
316 };
317 if (image_ty.zigTypeTag(zcu) == .spirv) {
318 const spirv_type = ip.loadSpirvType(image_ty.toIntern());
319 if (spirv_type.flags.tag == .image) switch (spirv_type.flags.access) {
320 .read_only => try cg.decorate(result_id, .non_writable),
321 .write_only => try cg.decorate(result_id, .non_readable),
322 .read_write, .unknown => {},
323 };
324 }
325
311326 if (ext.decoration) |decoration| switch (decoration) {
312327 .location => |location| {
313328 try cg.decorate(result_id, .{
......@@ -2237,11 +2252,16 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id {
22372252 .r32i => .r32i,
22382253 .r32u => .r32ui,
22392254 },
2240 .access_qualifier = switch (spirv_type.flags.access) {
2241 .unknown => null,
2242 .read_only => .read_only,
2243 .write_only => .write_only,
2244 .read_write => .read_write,
2255 .access_qualifier = blk: {
2256 if (target.os.tag == .opencl) {
2257 break :blk switch (spirv_type.flags.access) {
2258 .unknown => null,
2259 .read_only => .read_only,
2260 .write_only => .write_only,
2261 .read_write => .read_write,
2262 };
2263 }
2264 break :blk null;
22452265 },
22462266 });
22472267 },
test/cases/compile_errors/SpirvType_vulkan_target.zig+3-16
......@@ -1,15 +1,3 @@
1comptime {
2 _ = @SpirvType(.{ .image = .{
3 .usage = .{ .storage = u32 },
4 .format = .unknown,
5 .dim = .@"2d",
6 .depth = .unknown,
7 .arrayed = false,
8 .multisampled = false,
9 .access = .read_only,
10 } });
11}
12
131comptime {
142 _ = @SpirvType(.{ .image = .{
153 .usage = .{ .sampled = bool },
......@@ -50,7 +38,6 @@ comptime {
5038// backend=selfhosted
5139// target=spirv32-vulkan
5240//
53// :2:21: error: access qualifier '.read_only' is only valid under the 'opencl' OS
54// :14:21: error: invalid 'sampled' field value 'bool'
55// :26:21: error: 'void' type for 'sampled' field is only valid under the 'opencl' OS
56// :38:21: error: 'sampled' field value must be a 32-bit int, 64-bit int or 32-bit float under the 'vulkan' OS
41// :2:21: error: invalid 'sampled' field value 'bool'
42// :14:21: error: 'void' type for 'sampled' field is only valid under the 'opencl' OS
43// :26:21: error: 'sampled' field value must be a 32-bit int, 64-bit int or 32-bit float under the 'vulkan' OS