| 1 | pub const Image = @SpirvType(.{ .image = .{ |
| 2 | .usage = .{ .sampled = f32 }, |
| 3 | .format = .unknown, |
| 4 | .dim = .@"2d", |
| 5 | .depth = .not_depth, |
| 6 | .arrayed = false, |
| 7 | .multisampled = false, |
| 8 | .access = .unknown, |
| 9 | } }); |
| 10 | pub const SampledImage = @SpirvType(.{ .sampled_image = Image }); |
| 11 | |
| 12 | const image_in = @extern(*addrspace(.constant) const SampledImage, .{ |
| 13 | .name = "image_in", |
| 14 | .decoration = .{ .descriptor = .{ .set = 2, .binding = 0 } }, |
| 15 | }); |
| 16 | const uv_in = @extern(*addrspace(.input) @Vector(2, f32), .{ .name = "uv", .decoration = .{ .location = 0 } }); |
| 17 | const color_out = @extern(*addrspace(.output) @Vector(4, f32), .{ .name = "color", .decoration = .{ .location = 0 } }); |
| 18 | |
| 19 | export fn main() callconv(.{ .spirv_fragment = .{} }) void { |
| 20 | color_out.* = imageSample(image_in, uv_in.*); |
| 21 | } |
| 22 | |
| 23 | fn imageSample( |
| 24 | sampled_image: *addrspace(.constant) const SampledImage, |
| 25 | uv: @Vector(2, f32), |
| 26 | ) @Vector(4, f32) { |
| 27 | return asm volatile ( |
| 28 | \\%loaded_sampler = OpLoad %SampledImage %sampled_image |
| 29 | \\%ret = OpImageSampleImplicitLod %Result %loaded_sampler %uv |
| 30 | : [ret] "" (-> @Vector(4, f32)), |
| 31 | : [SampledImage] "t" (SampledImage), |
| 32 | [sampled_image] "" (sampled_image), |
| 33 | [Result] "t" (@Vector(4, f32)), |
| 34 | [uv] "" (uv), |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | // compile |
| 39 | // output_mode=Exe |
| 40 | // backend=selfhosted |
| 41 | // target=spirv32-vulkan |
| 42 | // emit_bin=true |