//! Drops memory-access operands (`Aligned 4`) from OpLoad/OpStore: Zig //! emits them, Vulkan accepts them, naga's SPIR-V reader does not. const std = @import("std"); pub fn main(init: std.process.Init) !void { var args = init.minimal.args.iterate(); _ = args.skip(); const in_path = args.next().?; const out_path = args.next().?; const cwd = std.Io.Dir.cwd(); const arena = init.arena.allocator(); const bytes = try cwd.readFileAlloc(init.io, in_path, arena, .limited(16 << 20)); const words: []const u32 = @alignCast(std.mem.bytesAsSlice(u32, bytes)); if (words.len < 5 or words[0] != 0x07230203) return error.NotSpirv; var out: std.ArrayList(u32) = .empty; try out.appendSlice(arena, words[0..5]); var i: usize = 5; while (i < words.len) { const count = words[i] >> 16; const opcode = words[i] & 0xffff; if (count == 0 or i + count > words.len) return error.Malformed; // OpLoad: op, type, id, pointer; OpStore: op, pointer, object. const keep: u32 = switch (opcode) { 61 => @min(count, 4), 62 => @min(count, 3), else => count, }; try out.append(arena, (keep << 16) | opcode); try out.appendSlice(arena, words[i + 1 .. i + keep]); i += count; } try cwd.writeFile(init.io, .{ .sub_path = out_path, .data = std.mem.sliceAsBytes(out.items) }); }