diff --git a/src/codegen/spirv/CodeGen.zig b/src/codegen/spirv/CodeGen.zig index df127e949b55dcc7401d3dbb7ad53179c7f7d3ef..7c2595beec3d7322284ac8b111d9c71e0be53911 100644 --- a/src/codegen/spirv/CodeGen.zig +++ b/src/codegen/spirv/CodeGen.zig @@ -308,6 +308,21 @@ pub fn generateNav(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) codegen.E else => {}, } + const image_ty = blk: { + if (ty.zigTypeTag(zcu) == .array or ty.isSpirvRuntimeArray(zcu)) { + break :blk ty.childType(zcu); + } + break :blk ty; + }; + if (image_ty.zigTypeTag(zcu) == .spirv) { + const spirv_type = ip.loadSpirvType(image_ty.toIntern()); + if (spirv_type.flags.tag == .image) switch (spirv_type.flags.access) { + .read_only => try cg.decorate(result_id, .non_writable), + .write_only => try cg.decorate(result_id, .non_readable), + .read_write, .unknown => {}, + }; + } + if (ext.decoration) |decoration| switch (decoration) { .location => |location| { try cg.decorate(result_id, .{ @@ -2237,11 +2252,16 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { .r32i => .r32i, .r32u => .r32ui, }, - .access_qualifier = switch (spirv_type.flags.access) { - .unknown => null, - .read_only => .read_only, - .write_only => .write_only, - .read_write => .read_write, + .access_qualifier = blk: { + if (target.os.tag == .opencl) { + break :blk switch (spirv_type.flags.access) { + .unknown => null, + .read_only => .read_only, + .write_only => .write_only, + .read_write => .read_write, + }; + } + break :blk null; }, }); }, diff --git a/test/cases/compile_errors/SpirvType_vulkan_target.zig b/test/cases/compile_errors/SpirvType_vulkan_target.zig index 7871365f4ed83ecbda72abff178b24704b6496b8..855eaad9c1ddbc6dc1fcb3f07a7b2bf7b3574fbe 100644 --- a/test/cases/compile_errors/SpirvType_vulkan_target.zig +++ b/test/cases/compile_errors/SpirvType_vulkan_target.zig @@ -1,15 +1,3 @@ -comptime { - _ = @SpirvType(.{ .image = .{ - .usage = .{ .storage = u32 }, - .format = .unknown, - .dim = .@"2d", - .depth = .unknown, - .arrayed = false, - .multisampled = false, - .access = .read_only, - } }); -} - comptime { _ = @SpirvType(.{ .image = .{ .usage = .{ .sampled = bool }, @@ -50,7 +38,6 @@ comptime { // backend=selfhosted // 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' -// :26:21: error: 'void' type for 'sampled' field is only valid under the 'opencl' OS -// :38:21: error: 'sampled' field value must be a 32-bit int, 64-bit int or 32-bit float under the 'vulkan' OS +// :2:21: error: invalid 'sampled' field value 'bool' +// :14:21: error: 'void' type for 'sampled' field is only valid under the 'opencl' OS +// :26:21: error: 'sampled' field value must be a 32-bit int, 64-bit int or 32-bit float under the 'vulkan' OS