The type of sampled_image must be a pointer to a SPIR-V sampled image.
pub fn imageSampleImplicitLod(
sampled_image: anytype,
coordinate: ImageCoordinate(std.meta.Child(@TypeOf(sampled_image)), f32),
) @Vector(4, ImageSampledType(std.meta.Child(@TypeOf(sampled_image))))
pub fn imageSampleImplicitLod(
sampled_image: anytype,
coordinate: ImageCoordinate(std.meta.Child(@TypeOf(sampled_image)), f32),
) @Vector(4, ImageSampledType(std.meta.Child(@TypeOf(sampled_image)))) {
const SampledImage = switch (@typeInfo(@TypeOf(sampled_image))) {
.pointer => |pointer| pointer.child,
else => @compileError("Expected a pointer to SPIR-V sampled image type, found '" ++ @typeName(@TypeOf(sampled_image)) ++ "'"),
};
const Result = @Vector(4, ImageSampledType(SampledImage));
const image_info = switch (@typeInfo(SampledImage)) {
.spirv => |spirv| switch (spirv) {
.sampled_image => |sampled_image_info| @typeInfo(sampled_image_info).spirv.image,
else => @compileError("Expected SPIR-V sampled image type, found '" ++ @typeName(SampledImage) ++ "'"),
},
else => @compileError("Expected SPIR-V sampled image type, found '" ++ @typeName(SampledImage) ++ "'"),
};
if (image_info.multisampled)
@compileError("Can not implicitly sample a sampled image that was multisampled");
// TOOD: If buffer dim is added, throw a compile error if the dimension is a buffer.
return asm volatile (
\\%loaded_sampler = OpLoad %SampledImage %sampled_image
\\%ret = OpImageSampleImplicitLod %Result %loaded_sampler %coordinate
: [ret] "" (-> Result),
: [SampledImage] "t" (SampledImage),
[sampled_image] "" (sampled_image),
[Result] "t" (Result),
[coordinate] "" (coordinate),
);
}