Query the dimensions of image, with no level of detail.
pub fn imageQuerySize(
image: anytype,
) ImageCoordinate(std.meta.Child(@TypeOf(image)), u32)
pub fn imageQuerySize(
image: anytype,
) ImageCoordinate(std.meta.Child(@TypeOf(image)), u32) {
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) ++ "'"),
};
// TODO: Remove this check if dimension is not 1d, 2d, 3d, or cube (in case buffer is added).
if (!image_info.multisampled and image_info.usage != .unknown and image_info.usage != .storage)
@compileError("SPIR-V image must be either be multisampled or have an unknown or storage usage");
const Result = ImageCoordinate(std.meta.Child(@TypeOf(image)), u32);
return asm volatile (
\\%loaded_image = OpLoad %Image %image
\\%ret = OpImageQuerySize %Result %loaded_image
: [ret] "" (-> Result),
: [Image] "t" (Image),
[image] "" (image),
[Result] "t" (Result),
);
}