wgsl_to_wgpu 0.15.2

Generate typesafe Rust bindings from WGSL shaders to wgpu
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
---
source: wgsl_to_wgpu/src/structs.rs
---
pub const ENTRY_MAIN: &str = "main";
#[derive(Debug)]
pub struct FragmentEntry<const N: usize> {
    pub entry_point: &'static str,
    pub targets: [Option<wgpu::ColorTargetState>; N],
    pub constants: Vec<(&'static str, f64)>,
}
pub fn fragment_state<'a, const N: usize>(
    module: &'a wgpu::ShaderModule,
    entry: &'a FragmentEntry<N>,
) -> wgpu::FragmentState<'a> {
    wgpu::FragmentState {
        module,
        entry_point: Some(entry.entry_point),
        targets: &entry.targets,
        compilation_options: wgpu::PipelineCompilationOptions {
            constants: &entry.constants,
            ..Default::default()
        },
    }
}
pub fn main_entry(targets: [Option<wgpu::ColorTargetState>; 0]) -> FragmentEntry<0> {
    FragmentEntry {
        entry_point: ENTRY_MAIN,
        targets,
        constants: Default::default(),
    }
}
pub const SOURCE: &str = include_str!("types.wgsl");
pub fn create_shader_module(device: &wgpu::Device) -> wgpu::ShaderModule {
    let source = std::borrow::Cow::Borrowed(SOURCE);
    device.create_shader_module(wgpu::ShaderModuleDescriptor {
        label: None,
        source: wgpu::ShaderSource::Wgsl(source),
    })
}
pub fn create_pipeline_layout(device: &wgpu::Device) -> wgpu::PipelineLayout {
    device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
        label: None,
        bind_group_layouts: &[],
        push_constant_ranges: &[],
    })
}
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct Atomics {
    pub num: u32,
    pub numi: i32,
}
const _: () = assert!(
    std::mem::size_of::<Atomics>() == 8,
    "size of Atomics does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Atomics, num) == 0,
    "offset of Atomics.num does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Atomics, numi) == 4,
    "offset of Atomics.numi does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct MatricesF16 {
    pub a: [[half::f16; 4]; 4],
    pub b: [[half::f16; 4]; 3],
    pub c: [[half::f16; 4]; 2],
    pub d: [[half::f16; 3]; 4],
    pub e: [[half::f16; 3]; 3],
    pub f: [[half::f16; 3]; 2],
    pub g: [[half::f16; 2]; 4],
    pub h: [[half::f16; 2]; 3],
    pub i: [[half::f16; 2]; 2],
}
const _: () = assert!(
    std::mem::size_of::<MatricesF16>() == 184,
    "size of MatricesF16 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, a) == 0,
    "offset of MatricesF16.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, b) == 32,
    "offset of MatricesF16.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, c) == 64,
    "offset of MatricesF16.c does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, d) == 80,
    "offset of MatricesF16.d does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, e) == 104,
    "offset of MatricesF16.e does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, f) == 128,
    "offset of MatricesF16.f does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, g) == 144,
    "offset of MatricesF16.g does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, h) == 160,
    "offset of MatricesF16.h does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF16, i) == 176,
    "offset of MatricesF16.i does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct MatricesF32 {
    pub a: [[f32; 4]; 4],
    pub b: [[f32; 4]; 3],
    pub c: [[f32; 4]; 2],
    pub d: [[f32; 3]; 4],
    pub e: [[f32; 3]; 3],
    pub f: [[f32; 3]; 2],
    pub g: [[f32; 2]; 4],
    pub h: [[f32; 2]; 3],
    pub i: [[f32; 2]; 2],
}
const _: () = assert!(
    std::mem::size_of::<MatricesF32>() == 368,
    "size of MatricesF32 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, a) == 0,
    "offset of MatricesF32.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, b) == 64,
    "offset of MatricesF32.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, c) == 128,
    "offset of MatricesF32.c does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, d) == 160,
    "offset of MatricesF32.d does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, e) == 208,
    "offset of MatricesF32.e does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, f) == 256,
    "offset of MatricesF32.f does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, g) == 288,
    "offset of MatricesF32.g does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, h) == 320,
    "offset of MatricesF32.h does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF32, i) == 352,
    "offset of MatricesF32.i does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct MatricesF64 {
    pub a: [[f64; 4]; 4],
    pub b: [[f64; 4]; 3],
    pub c: [[f64; 4]; 2],
    pub d: [[f64; 3]; 4],
    pub e: [[f64; 3]; 3],
    pub f: [[f64; 3]; 2],
    pub g: [[f64; 2]; 4],
    pub h: [[f64; 2]; 3],
    pub i: [[f64; 2]; 2],
}
const _: () = assert!(
    std::mem::size_of::<MatricesF64>() == 736,
    "size of MatricesF64 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, a) == 0,
    "offset of MatricesF64.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, b) == 128,
    "offset of MatricesF64.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, c) == 256,
    "offset of MatricesF64.c does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, d) == 320,
    "offset of MatricesF64.d does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, e) == 416,
    "offset of MatricesF64.e does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, f) == 512,
    "offset of MatricesF64.f does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, g) == 576,
    "offset of MatricesF64.g does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, h) == 640,
    "offset of MatricesF64.h does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(MatricesF64, i) == 704,
    "offset of MatricesF64.i does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct Nested {
    pub a: MatricesF32,
    pub b: MatricesF64,
}
const _: () = assert!(
    std::mem::size_of::<Nested>() == 1120,
    "size of Nested does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Nested, a) == 0,
    "offset of Nested.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Nested, b) == 384,
    "offset of Nested.b does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct Scalars {
    pub a: u32,
    pub b: i32,
    pub c: f32,
    pub d: half::f16,
}
const _: () = assert!(
    std::mem::size_of::<Scalars>() == 16,
    "size of Scalars does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Scalars, a) == 0,
    "offset of Scalars.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Scalars, b) == 4,
    "offset of Scalars.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Scalars, c) == 8,
    "offset of Scalars.c does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(Scalars, d) == 12,
    "offset of Scalars.d does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct StaticArrays {
    pub a: [u32; 5],
    pub b: [f32; 3],
    pub c: [[[f32; 4]; 4]; 512],
}
const _: () = assert!(
    std::mem::size_of::<StaticArrays>() == 32800,
    "size of StaticArrays does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(StaticArrays, a) == 0,
    "offset of StaticArrays.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(StaticArrays, b) == 20,
    "offset of StaticArrays.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(StaticArrays, c) == 32,
    "offset of StaticArrays.c does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct VectorsF16 {
    pub a: [half::f16; 2],
    pub b: [half::f16; 4],
}
const _: () = assert!(
    std::mem::size_of::<VectorsF16>() == 16,
    "size of VectorsF16 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF16, a) == 0,
    "offset of VectorsF16.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF16, b) == 8,
    "offset of VectorsF16.b does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct VectorsF32 {
    pub a: [f32; 2],
    pub b: [f32; 3],
    pub c: [f32; 4],
}
const _: () = assert!(
    std::mem::size_of::<VectorsF32>() == 48,
    "size of VectorsF32 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF32, a) == 0,
    "offset of VectorsF32.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF32, b) == 16,
    "offset of VectorsF32.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF32, c) == 32,
    "offset of VectorsF32.c does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct VectorsF64 {
    pub a: [f64; 2],
    pub b: [f64; 3],
    pub c: [f64; 4],
}
const _: () = assert!(
    std::mem::size_of::<VectorsF64>() == 96,
    "size of VectorsF64 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF64, a) == 0,
    "offset of VectorsF64.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF64, b) == 32,
    "offset of VectorsF64.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsF64, c) == 64,
    "offset of VectorsF64.c does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct VectorsI32 {
    pub a: [i32; 2],
    pub b: [i32; 3],
    pub c: [i32; 4],
}
const _: () = assert!(
    std::mem::size_of::<VectorsI32>() == 48,
    "size of VectorsI32 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsI32, a) == 0,
    "offset of VectorsI32.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsI32, b) == 16,
    "offset of VectorsI32.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsI32, c) == 32,
    "offset of VectorsI32.c does not match WGSL"
);
#[repr(C)]
#[derive(
    Debug, Copy, Clone, PartialEq, bytemuck :: Pod, bytemuck :: Zeroable, encase :: ShaderType,
)]
pub struct VectorsU32 {
    pub a: [u32; 2],
    pub b: [u32; 3],
    pub c: [u32; 4],
}
const _: () = assert!(
    std::mem::size_of::<VectorsU32>() == 48,
    "size of VectorsU32 does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsU32, a) == 0,
    "offset of VectorsU32.a does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsU32, b) == 16,
    "offset of VectorsU32.b does not match WGSL"
);
const _: () = assert!(
    std::mem::offset_of!(VectorsU32, c) == 32,
    "offset of VectorsU32.c does not match WGSL"
);