#require no-matrix
#zig build-exe {
--name test
-target spirv32-vulkan -mcpu vulkan_v1_2+runtime_descriptor_array+sampled_image_array_dynamic_indexing -fno-llvm
-Mroot=test.zig
#}

#write test.zig {
const spirv = @import("std").spirv;

pub const Image = @SpirvType(.{ .image = .{
    .usage = .{ .sampled = f32 },
    .format = .unknown,
    .dim = .@"2d",
    .depth = .not_depth,
    .arrayed = false,
    .multisampled = false,
    .access = .unknown,
} });
pub const SampledImage = @SpirvType(.{ .sampled_image = Image });

const image_in = @extern(*addrspace(.constant) const SampledImage, .{
    .name = "image_in",
    .decoration = .{ .descriptor = .{ .set = 2, .binding = 0 } },
});
const uv_in = @extern(*addrspace(.input) @Vector(2, f32), .{ .name = "uv", .decoration = .{ .location = 0 } });
const color_out = @extern(*addrspace(.output) @Vector(4, f32), .{ .name = "color", .decoration = .{ .location = 0 } });

export fn sampleImage() callconv(.{ .spirv_fragment = .{} }) void {
    color_out.* = spirv.image.sample(image_in, uv_in.*);
}

const ImageArray = @SpirvType(.{ .runtime_array = SampledImage });
const images = @extern(*addrspace(.constant) const ImageArray, .{
    .name = "images",
    .decoration = .{ .descriptor = .{ .set = 2, .binding = 1 } },
});
const image_index = @extern(*addrspace(.input) const u32, .{ .name = "image_index", .decoration = .{ .flat = 1 } });

export fn sampleImageArray() callconv(.{ .spirv_fragment = .{} }) void {
    color_out.* = spirv.image.sample(&images[image_index.*], uv_in.*);
}
#}
#update
#check errors
