Write a texel to an image without a sampler.
The type of image must be a pointer to a SPIR-V image.
pub fn imageWrite(
image: anytype,
T: type,
coordinate: ImageCoordinate(std.meta.Child(@TypeOf(image)), T),
texel: @Vector(4, ImageSampledType(std.meta.Child(@TypeOf(image)))),
) void
pub fn imageWrite(
image: anytype,
T: type,
coordinate: ImageCoordinate(std.meta.Child(@TypeOf(image)), T),
texel: @Vector(4, ImageSampledType(std.meta.Child(@TypeOf(image)))),
) void {
switch (T) {
u32, i32 => {},
f32 => if (builtin.target.os.tag != .opencl) {
@compileError("Floating point image coordinates only supported by OpenCL");
},
else => @compileError("Expected one of u32, i32 and f32 types. Found '" ++ @typeName(T) ++ "'"),
}
const Image = switch (@typeInfo(@TypeOf(image))) {
.pointer => |pointer| pointer.child,
else => @compileError("Expected a pointer to SPIR-V image type, found '" ++ @typeName(@TypeOf(image)) ++ "'"),
};
const image_info = switch (@typeInfo(Image)) {
.spirv => |spirv| switch (spirv) {
.image => |info| info,
else => @compileError("Expected SPIR-V image type, found '" ++ @typeName(Image) ++ "'"),
},
else => @compileError("Expected SPIR-V image type, found '" ++ @typeName(Image) ++ "'"),
};
switch (image_info.usage) {
.unknown, .storage => {},
else => @compileError("SPIR-V image must have unknown or storage usage"),
}
// TODO: If SubpassData dim is added, throw a compiler error if the image is arrayed and has the SubpassData dim.
return asm volatile (
\\%loaded_image = OpLoad %Image %image
\\ OpImageWrite %loaded_image %coordinate %texel
:
: [Image] "t" (Image),
[image] "" (image),
[coordinate] "" (coordinate),
[texel] "" (texel),
);
}