1const std = @import("std");
2const expect = std.testing.expect;
3
4const Sampler = @SpirvType(.sampler);
5const Image = @SpirvType(.{ .image = .{
6 .usage = .{ .sampled = u32 },
7 .format = .unknown,
8 .dim = .@"2d",
9 .depth = .unknown,
10 .arrayed = false,
11 .multisampled = false,
12 .access = .unknown,
13} });
14const SampledImage = @SpirvType(.{ .sampled_image = Image });
15const StorageImage = @SpirvType(.{ .image = .{
16 .usage = .{ .storage = u32 },
17 .format = .unknown,
18 .dim = .@"2d",
19 .depth = .unknown,
20 .arrayed = false,
21 .multisampled = false,
22 .access = .unknown,
23} });
24const RuntimeArray = @SpirvType(.{ .runtime_array = u32 });
25
26const RuntimeArrayBuf = extern struct { e: RuntimeArray };
27
28const sampler = @extern(*addrspace(.constant) const Sampler, .{
29 .name = "sampler",
30 .decoration = .{ .descriptor = .{ .set = 0, .binding = 0 } },
31});
32const sampled_image = @extern(*addrspace(.constant) const SampledImage, .{
33 .name = "sampled_image",
34 .decoration = .{ .descriptor = .{ .set = 0, .binding = 1 } },
35});
36const storage_image = @extern(*addrspace(.constant) const StorageImage, .{
37 .name = "storage_image",
38 .decoration = .{ .descriptor = .{ .set = 0, .binding = 2 } },
39});
40const runtime_array = @extern(*addrspace(.storage_buffer) const RuntimeArrayBuf, .{
41 .name = "runtime_array",
42 .decoration = .{ .descriptor = .{ .set = 0, .binding = 3 } },
43});
44
45test "@SpirvType" {
46 _ = sampler;
47 _ = sampled_image;
48 _ = storage_image;
49 _ = runtime_array;
50}
51
52test "@ptrCast to first field type" {
53 const Inner = extern struct { a: u32 };
54 const Outer = extern struct { a: Inner, b: u32 };
55 var outer: Outer = undefined;
56 var inner: *Inner = @ptrCast(&outer);
57 _ = &inner;
58}
59
60test "@SpirvType equality" {
61 try expect(@SpirvType(.sampler) == Sampler);
62 try expect(@SpirvType(.{ .runtime_array = u32 }) == RuntimeArray);
63 try expect(@SpirvType(.{ .sampled_image = Image }) == SampledImage);
64 try expect(@SpirvType(.{ .image = .{
65 .usage = .{ .sampled = u32 },
66 .format = .unknown,
67 .dim = .@"2d",
68 .depth = .unknown,
69 .arrayed = false,
70 .multisampled = false,
71 .access = .unknown,
72 } }) == Image);
73 try expect(@SpirvType(.{ .image = .{
74 .usage = .{ .sampled = u32 },
75 .format = .unknown,
76 .dim = .@"3d",
77 .depth = .unknown,
78 .arrayed = false,
79 .multisampled = false,
80 .access = .unknown,
81 } }) != Image);
82 try expect(@SpirvType(.{ .runtime_array = u32 }) != @SpirvType(.{ .runtime_array = u8 }));
83 try expect(@SpirvType(.sampler) != @SpirvType(.{ .runtime_array = u32 }));
84}