rafx-plugins 0.0.16

Rendering framework built on an extensible asset pipeline
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
// This code is auto-generated by the shader processor.

#[allow(unused_imports)]
use rafx::RafxResult;

#[allow(unused_imports)]
use rafx::framework::{
    DescriptorSetAllocator, DescriptorSetArc, DescriptorSetBindings, DescriptorSetInitializer,
    DescriptorSetWriter, DescriptorSetWriterContext, DynDescriptorSet, ImageViewResource,
    ResourceArc,
};

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct ShadowMap2DDataStd140 {
    pub shadow_map_view_proj: [[f32; 4]; 4], // +0 (size: 64)
    pub shadow_map_light_dir: [f32; 3],      // +64 (size: 12)
    pub _padding0: [u8; 4],                  // +76 (size: 4)
} // 80 bytes

impl Default for ShadowMap2DDataStd140 {
    fn default() -> Self {
        ShadowMap2DDataStd140 {
            shadow_map_view_proj: <[[f32; 4]; 4]>::default(),
            shadow_map_light_dir: <[f32; 3]>::default(),
            _padding0: [u8::default(); 4],
        }
    }
}

pub type ShadowMap2DDataUniform = ShadowMap2DDataStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct MaterialDataStd140 {
    pub base_color_factor: [f32; 4],               // +0 (size: 16)
    pub emissive_factor: [f32; 3],                 // +16 (size: 12)
    pub metallic_factor: f32,                      // +28 (size: 4)
    pub roughness_factor: f32,                     // +32 (size: 4)
    pub normal_texture_scale: f32,                 // +36 (size: 4)
    pub alpha_threshold: f32,                      // +40 (size: 4)
    pub enable_alpha_blend: u32,                   // +44 (size: 4)
    pub enable_alpha_clip: u32,                    // +48 (size: 4)
    pub has_base_color_texture: u32,               // +52 (size: 4)
    pub base_color_texture_has_alpha_channel: u32, // +56 (size: 4)
    pub has_metallic_roughness_texture: u32,       // +60 (size: 4)
    pub has_normal_texture: u32,                   // +64 (size: 4)
    pub has_emissive_texture: u32,                 // +68 (size: 4)
    pub _padding0: [u8; 8],                        // +72 (size: 8)
} // 80 bytes

impl Default for MaterialDataStd140 {
    fn default() -> Self {
        MaterialDataStd140 {
            base_color_factor: <[f32; 4]>::default(),
            emissive_factor: <[f32; 3]>::default(),
            metallic_factor: <f32>::default(),
            roughness_factor: <f32>::default(),
            normal_texture_scale: <f32>::default(),
            alpha_threshold: <f32>::default(),
            enable_alpha_blend: <u32>::default(),
            enable_alpha_clip: <u32>::default(),
            has_base_color_texture: <u32>::default(),
            base_color_texture_has_alpha_channel: <u32>::default(),
            has_metallic_roughness_texture: <u32>::default(),
            has_normal_texture: <u32>::default(),
            has_emissive_texture: <u32>::default(),
            _padding0: [u8::default(); 8],
        }
    }
}

pub type MaterialDataUniform = MaterialDataStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct PerViewDataStd140 {
    pub view: [[f32; 4]; 4],                                 // +0 (size: 64)
    pub view_proj: [[f32; 4]; 4],                            // +64 (size: 64)
    pub ambient_light: [f32; 4],                             // +128 (size: 16)
    pub point_light_count: u32,                              // +144 (size: 4)
    pub directional_light_count: u32,                        // +148 (size: 4)
    pub spot_light_count: u32,                               // +152 (size: 4)
    pub _padding0: [u8; 4],                                  // +156 (size: 4)
    pub point_lights: [PointLightStd140; 16],                // +160 (size: 1024)
    pub directional_lights: [DirectionalLightStd140; 16],    // +1184 (size: 768)
    pub spot_lights: [SpotLightStd140; 16],                  // +1952 (size: 1280)
    pub shadow_map_2d_data: [ShadowMap2DDataStd140; 32],     // +3232 (size: 2560)
    pub shadow_map_cube_data: [ShadowMapCubeDataStd140; 16], // +5792 (size: 256)
} // 6048 bytes

impl Default for PerViewDataStd140 {
    fn default() -> Self {
        PerViewDataStd140 {
            view: <[[f32; 4]; 4]>::default(),
            view_proj: <[[f32; 4]; 4]>::default(),
            ambient_light: <[f32; 4]>::default(),
            point_light_count: <u32>::default(),
            directional_light_count: <u32>::default(),
            spot_light_count: <u32>::default(),
            _padding0: [u8::default(); 4],
            point_lights: [<PointLightStd140>::default(); 16],
            directional_lights: [<DirectionalLightStd140>::default(); 16],
            spot_lights: [<SpotLightStd140>::default(); 16],
            shadow_map_2d_data: [<ShadowMap2DDataStd140>::default(); 32],
            shadow_map_cube_data: [<ShadowMapCubeDataStd140>::default(); 16],
        }
    }
}

pub type PerViewDataUniform = PerViewDataStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct SpotLightStd140 {
    pub position_ws: [f32; 3],     // +0 (size: 12)
    pub spotlight_half_angle: f32, // +12 (size: 4)
    pub direction_ws: [f32; 3],    // +16 (size: 12)
    pub range: f32,                // +28 (size: 4)
    pub position_vs: [f32; 3],     // +32 (size: 12)
    pub intensity: f32,            // +44 (size: 4)
    pub color: [f32; 4],           // +48 (size: 16)
    pub direction_vs: [f32; 3],    // +64 (size: 12)
    pub shadow_map: i32,           // +76 (size: 4)
} // 80 bytes

impl Default for SpotLightStd140 {
    fn default() -> Self {
        SpotLightStd140 {
            position_ws: <[f32; 3]>::default(),
            spotlight_half_angle: <f32>::default(),
            direction_ws: <[f32; 3]>::default(),
            range: <f32>::default(),
            position_vs: <[f32; 3]>::default(),
            intensity: <f32>::default(),
            color: <[f32; 4]>::default(),
            direction_vs: <[f32; 3]>::default(),
            shadow_map: <i32>::default(),
        }
    }
}

pub type SpotLightUniform = SpotLightStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct DirectionalLightStd140 {
    pub direction_ws: [f32; 3], // +0 (size: 12)
    pub intensity: f32,         // +12 (size: 4)
    pub color: [f32; 4],        // +16 (size: 16)
    pub direction_vs: [f32; 3], // +32 (size: 12)
    pub shadow_map: i32,        // +44 (size: 4)
} // 48 bytes

impl Default for DirectionalLightStd140 {
    fn default() -> Self {
        DirectionalLightStd140 {
            direction_ws: <[f32; 3]>::default(),
            intensity: <f32>::default(),
            color: <[f32; 4]>::default(),
            direction_vs: <[f32; 3]>::default(),
            shadow_map: <i32>::default(),
        }
    }
}

pub type DirectionalLightUniform = DirectionalLightStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct PointLightStd140 {
    pub position_ws: [f32; 3], // +0 (size: 12)
    pub range: f32,            // +12 (size: 4)
    pub position_vs: [f32; 3], // +16 (size: 12)
    pub intensity: f32,        // +28 (size: 4)
    pub color: [f32; 4],       // +32 (size: 16)
    pub shadow_map: i32,       // +48 (size: 4)
    pub _padding0: [u8; 12],   // +52 (size: 12)
} // 64 bytes

impl Default for PointLightStd140 {
    fn default() -> Self {
        PointLightStd140 {
            position_ws: <[f32; 3]>::default(),
            range: <f32>::default(),
            position_vs: <[f32; 3]>::default(),
            intensity: <f32>::default(),
            color: <[f32; 4]>::default(),
            shadow_map: <i32>::default(),
            _padding0: [u8::default(); 12],
        }
    }
}

pub type PointLightUniform = PointLightStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct ShadowMapCubeDataStd140 {
    pub cube_map_projection_near_z: f32, // +0 (size: 4)
    pub cube_map_projection_far_z: f32,  // +4 (size: 4)
    pub _padding0: [u8; 8],              // +8 (size: 8)
} // 16 bytes

impl Default for ShadowMapCubeDataStd140 {
    fn default() -> Self {
        ShadowMapCubeDataStd140 {
            cube_map_projection_near_z: <f32>::default(),
            cube_map_projection_far_z: <f32>::default(),
            _padding0: [u8::default(); 8],
        }
    }
}

pub type ShadowMapCubeDataUniform = ShadowMapCubeDataStd140;

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct MaterialDataUboStd140 {
    pub data: MaterialDataStd140, // +0 (size: 80)
} // 80 bytes

impl Default for MaterialDataUboStd140 {
    fn default() -> Self {
        MaterialDataUboStd140 {
            data: <MaterialDataStd140>::default(),
        }
    }
}

pub type MaterialDataUboUniform = MaterialDataUboStd140;

pub const PER_VIEW_DATA_DESCRIPTOR_SET_INDEX: usize = 0;
pub const PER_VIEW_DATA_DESCRIPTOR_BINDING_INDEX: usize = 0;
pub const SMP_DESCRIPTOR_SET_INDEX: usize = 0;
pub const SMP_DESCRIPTOR_BINDING_INDEX: usize = 1;
pub const SMP_DEPTH_DESCRIPTOR_SET_INDEX: usize = 0;
pub const SMP_DEPTH_DESCRIPTOR_BINDING_INDEX: usize = 2;
pub const SHADOW_MAP_IMAGES_DESCRIPTOR_SET_INDEX: usize = 0;
pub const SHADOW_MAP_IMAGES_DESCRIPTOR_BINDING_INDEX: usize = 3;
pub const SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_SET_INDEX: usize = 0;
pub const SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_BINDING_INDEX: usize = 4;
pub const PER_MATERIAL_DATA_DESCRIPTOR_SET_INDEX: usize = 1;
pub const PER_MATERIAL_DATA_DESCRIPTOR_BINDING_INDEX: usize = 0;
pub const BASE_COLOR_TEXTURE_DESCRIPTOR_SET_INDEX: usize = 1;
pub const BASE_COLOR_TEXTURE_DESCRIPTOR_BINDING_INDEX: usize = 1;
pub const METALLIC_ROUGHNESS_TEXTURE_DESCRIPTOR_SET_INDEX: usize = 1;
pub const METALLIC_ROUGHNESS_TEXTURE_DESCRIPTOR_BINDING_INDEX: usize = 2;
pub const NORMAL_TEXTURE_DESCRIPTOR_SET_INDEX: usize = 1;
pub const NORMAL_TEXTURE_DESCRIPTOR_BINDING_INDEX: usize = 3;
pub const EMISSIVE_TEXTURE_DESCRIPTOR_SET_INDEX: usize = 1;
pub const EMISSIVE_TEXTURE_DESCRIPTOR_BINDING_INDEX: usize = 4;

pub struct DescriptorSet0Args<'a> {
    pub per_view_data: &'a PerViewDataUniform,
    pub shadow_map_images: &'a [Option<&'a ResourceArc<ImageViewResource>>; 32],
    pub shadow_map_images_cube: &'a [Option<&'a ResourceArc<ImageViewResource>>; 16],
}

impl<'a> DescriptorSetInitializer<'a> for DescriptorSet0Args<'a> {
    type Output = DescriptorSet0;

    fn create_dyn_descriptor_set(
        descriptor_set: DynDescriptorSet,
        args: Self,
    ) -> Self::Output {
        let mut descriptor = DescriptorSet0(descriptor_set);
        descriptor.set_args(args);
        descriptor
    }

    fn create_descriptor_set(
        descriptor_set_allocator: &mut DescriptorSetAllocator,
        descriptor_set: DynDescriptorSet,
        args: Self,
    ) -> RafxResult<DescriptorSetArc> {
        let mut descriptor = Self::create_dyn_descriptor_set(descriptor_set, args);
        descriptor.0.flush(descriptor_set_allocator)?;
        Ok(descriptor.0.descriptor_set().clone())
    }
}

impl<'a> DescriptorSetWriter<'a> for DescriptorSet0Args<'a> {
    fn write_to(
        descriptor_set: &mut DescriptorSetWriterContext,
        args: Self,
    ) {
        descriptor_set.set_buffer_data(
            PER_VIEW_DATA_DESCRIPTOR_BINDING_INDEX as u32,
            args.per_view_data,
        );
        descriptor_set.set_images(
            SHADOW_MAP_IMAGES_DESCRIPTOR_BINDING_INDEX as u32,
            args.shadow_map_images,
        );
        descriptor_set.set_images(
            SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_BINDING_INDEX as u32,
            args.shadow_map_images_cube,
        );
    }
}

pub struct DescriptorSet0(pub DynDescriptorSet);

impl DescriptorSet0 {
    pub fn set_args_static(
        descriptor_set: &mut DynDescriptorSet,
        args: DescriptorSet0Args,
    ) {
        descriptor_set.set_buffer_data(
            PER_VIEW_DATA_DESCRIPTOR_BINDING_INDEX as u32,
            args.per_view_data,
        );
        descriptor_set.set_images(
            SHADOW_MAP_IMAGES_DESCRIPTOR_BINDING_INDEX as u32,
            args.shadow_map_images,
        );
        descriptor_set.set_images(
            SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_BINDING_INDEX as u32,
            args.shadow_map_images_cube,
        );
    }

    pub fn set_args(
        &mut self,
        args: DescriptorSet0Args,
    ) {
        self.set_per_view_data(args.per_view_data);
        self.set_shadow_map_images(args.shadow_map_images);
        self.set_shadow_map_images_cube(args.shadow_map_images_cube);
    }

    pub fn set_per_view_data(
        &mut self,
        per_view_data: &PerViewDataUniform,
    ) {
        self.0
            .set_buffer_data(PER_VIEW_DATA_DESCRIPTOR_BINDING_INDEX as u32, per_view_data);
    }

    pub fn set_shadow_map_images(
        &mut self,
        shadow_map_images: &[Option<&ResourceArc<ImageViewResource>>; 32],
    ) {
        self.0.set_images(
            SHADOW_MAP_IMAGES_DESCRIPTOR_BINDING_INDEX as u32,
            shadow_map_images,
        );
    }

    pub fn set_shadow_map_images_element(
        &mut self,
        index: usize,
        element: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image_at_index(
            SHADOW_MAP_IMAGES_DESCRIPTOR_BINDING_INDEX as u32,
            index,
            element,
        );
    }

    pub fn set_shadow_map_images_cube(
        &mut self,
        shadow_map_images_cube: &[Option<&ResourceArc<ImageViewResource>>; 16],
    ) {
        self.0.set_images(
            SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_BINDING_INDEX as u32,
            shadow_map_images_cube,
        );
    }

    pub fn set_shadow_map_images_cube_element(
        &mut self,
        index: usize,
        element: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image_at_index(
            SHADOW_MAP_IMAGES_CUBE_DESCRIPTOR_BINDING_INDEX as u32,
            index,
            element,
        );
    }

    pub fn flush(
        &mut self,
        descriptor_set_allocator: &mut DescriptorSetAllocator,
    ) -> RafxResult<()> {
        self.0.flush(descriptor_set_allocator)
    }
}

pub struct DescriptorSet1Args<'a> {
    pub per_material_data: &'a MaterialDataUboUniform,
    pub base_color_texture: &'a ResourceArc<ImageViewResource>,
    pub metallic_roughness_texture: &'a ResourceArc<ImageViewResource>,
    pub normal_texture: &'a ResourceArc<ImageViewResource>,
    pub emissive_texture: &'a ResourceArc<ImageViewResource>,
}

impl<'a> DescriptorSetInitializer<'a> for DescriptorSet1Args<'a> {
    type Output = DescriptorSet1;

    fn create_dyn_descriptor_set(
        descriptor_set: DynDescriptorSet,
        args: Self,
    ) -> Self::Output {
        let mut descriptor = DescriptorSet1(descriptor_set);
        descriptor.set_args(args);
        descriptor
    }

    fn create_descriptor_set(
        descriptor_set_allocator: &mut DescriptorSetAllocator,
        descriptor_set: DynDescriptorSet,
        args: Self,
    ) -> RafxResult<DescriptorSetArc> {
        let mut descriptor = Self::create_dyn_descriptor_set(descriptor_set, args);
        descriptor.0.flush(descriptor_set_allocator)?;
        Ok(descriptor.0.descriptor_set().clone())
    }
}

impl<'a> DescriptorSetWriter<'a> for DescriptorSet1Args<'a> {
    fn write_to(
        descriptor_set: &mut DescriptorSetWriterContext,
        args: Self,
    ) {
        descriptor_set.set_buffer_data(
            PER_MATERIAL_DATA_DESCRIPTOR_BINDING_INDEX as u32,
            args.per_material_data,
        );
        descriptor_set.set_image(
            BASE_COLOR_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.base_color_texture,
        );
        descriptor_set.set_image(
            METALLIC_ROUGHNESS_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.metallic_roughness_texture,
        );
        descriptor_set.set_image(
            NORMAL_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.normal_texture,
        );
        descriptor_set.set_image(
            EMISSIVE_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.emissive_texture,
        );
    }
}

pub struct DescriptorSet1(pub DynDescriptorSet);

impl DescriptorSet1 {
    pub fn set_args_static(
        descriptor_set: &mut DynDescriptorSet,
        args: DescriptorSet1Args,
    ) {
        descriptor_set.set_buffer_data(
            PER_MATERIAL_DATA_DESCRIPTOR_BINDING_INDEX as u32,
            args.per_material_data,
        );
        descriptor_set.set_image(
            BASE_COLOR_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.base_color_texture,
        );
        descriptor_set.set_image(
            METALLIC_ROUGHNESS_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.metallic_roughness_texture,
        );
        descriptor_set.set_image(
            NORMAL_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.normal_texture,
        );
        descriptor_set.set_image(
            EMISSIVE_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            args.emissive_texture,
        );
    }

    pub fn set_args(
        &mut self,
        args: DescriptorSet1Args,
    ) {
        self.set_per_material_data(args.per_material_data);
        self.set_base_color_texture(args.base_color_texture);
        self.set_metallic_roughness_texture(args.metallic_roughness_texture);
        self.set_normal_texture(args.normal_texture);
        self.set_emissive_texture(args.emissive_texture);
    }

    pub fn set_per_material_data(
        &mut self,
        per_material_data: &MaterialDataUboUniform,
    ) {
        self.0.set_buffer_data(
            PER_MATERIAL_DATA_DESCRIPTOR_BINDING_INDEX as u32,
            per_material_data,
        );
    }

    pub fn set_base_color_texture(
        &mut self,
        base_color_texture: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image(
            BASE_COLOR_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            base_color_texture,
        );
    }

    pub fn set_metallic_roughness_texture(
        &mut self,
        metallic_roughness_texture: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image(
            METALLIC_ROUGHNESS_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            metallic_roughness_texture,
        );
    }

    pub fn set_normal_texture(
        &mut self,
        normal_texture: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image(
            NORMAL_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            normal_texture,
        );
    }

    pub fn set_emissive_texture(
        &mut self,
        emissive_texture: &ResourceArc<ImageViewResource>,
    ) {
        self.0.set_image(
            EMISSIVE_TEXTURE_DESCRIPTOR_BINDING_INDEX as u32,
            emissive_texture,
        );
    }

    pub fn flush(
        &mut self,
        descriptor_set_allocator: &mut DescriptorSetAllocator,
    ) -> RafxResult<()> {
        self.0.flush(descriptor_set_allocator)
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_struct_shadow_map2_d_data_std140() {
        assert_eq!(std::mem::size_of::<ShadowMap2DDataStd140>(), 80);
        assert_eq!(std::mem::size_of::<[[f32; 4]; 4]>(), 64);
        assert_eq!(std::mem::align_of::<[[f32; 4]; 4]>(), 4);
        assert_eq!(
            memoffset::offset_of!(ShadowMap2DDataStd140, shadow_map_view_proj),
            0
        );
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(
            memoffset::offset_of!(ShadowMap2DDataStd140, shadow_map_light_dir),
            64
        );
        assert_eq!(std::mem::size_of::<[u8; 4]>(), 4);
        assert_eq!(std::mem::align_of::<[u8; 4]>(), 1);
        assert_eq!(memoffset::offset_of!(ShadowMap2DDataStd140, _padding0), 76);
    }

    #[test]
    fn test_struct_material_data_std140() {
        assert_eq!(std::mem::size_of::<MaterialDataStd140>(), 80);
        assert_eq!(std::mem::size_of::<[f32; 4]>(), 16);
        assert_eq!(std::mem::align_of::<[f32; 4]>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, base_color_factor),
            0
        );
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, emissive_factor),
            16
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, metallic_factor),
            28
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, roughness_factor),
            32
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, normal_texture_scale),
            36
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, alpha_threshold),
            40
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, enable_alpha_blend),
            44
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, enable_alpha_clip),
            48
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, has_base_color_texture),
            52
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, base_color_texture_has_alpha_channel),
            56
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, has_metallic_roughness_texture),
            60
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, has_normal_texture),
            64
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(MaterialDataStd140, has_emissive_texture),
            68
        );
        assert_eq!(std::mem::size_of::<[u8; 8]>(), 8);
        assert_eq!(std::mem::align_of::<[u8; 8]>(), 1);
        assert_eq!(memoffset::offset_of!(MaterialDataStd140, _padding0), 72);
    }

    #[test]
    fn test_struct_per_view_data_std140() {
        assert_eq!(std::mem::size_of::<PerViewDataStd140>(), 6048);
        assert_eq!(std::mem::size_of::<[[f32; 4]; 4]>(), 64);
        assert_eq!(std::mem::align_of::<[[f32; 4]; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, view), 0);
        assert_eq!(std::mem::size_of::<[[f32; 4]; 4]>(), 64);
        assert_eq!(std::mem::align_of::<[[f32; 4]; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, view_proj), 64);
        assert_eq!(std::mem::size_of::<[f32; 4]>(), 16);
        assert_eq!(std::mem::align_of::<[f32; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, ambient_light), 128);
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, point_light_count),
            144
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, directional_light_count),
            148
        );
        assert_eq!(std::mem::size_of::<u32>(), 4);
        assert_eq!(std::mem::align_of::<u32>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, spot_light_count),
            152
        );
        assert_eq!(std::mem::size_of::<[u8; 4]>(), 4);
        assert_eq!(std::mem::align_of::<[u8; 4]>(), 1);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, _padding0), 156);
        assert_eq!(std::mem::size_of::<[PointLightStd140; 16]>(), 1024);
        assert_eq!(std::mem::align_of::<[PointLightStd140; 16]>(), 4);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, point_lights), 160);
        assert_eq!(std::mem::size_of::<[DirectionalLightStd140; 16]>(), 768);
        assert_eq!(std::mem::align_of::<[DirectionalLightStd140; 16]>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, directional_lights),
            1184
        );
        assert_eq!(std::mem::size_of::<[SpotLightStd140; 16]>(), 1280);
        assert_eq!(std::mem::align_of::<[SpotLightStd140; 16]>(), 4);
        assert_eq!(memoffset::offset_of!(PerViewDataStd140, spot_lights), 1952);
        assert_eq!(std::mem::size_of::<[ShadowMap2DDataStd140; 32]>(), 2560);
        assert_eq!(std::mem::align_of::<[ShadowMap2DDataStd140; 32]>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, shadow_map_2d_data),
            3232
        );
        assert_eq!(std::mem::size_of::<[ShadowMapCubeDataStd140; 16]>(), 256);
        assert_eq!(std::mem::align_of::<[ShadowMapCubeDataStd140; 16]>(), 4);
        assert_eq!(
            memoffset::offset_of!(PerViewDataStd140, shadow_map_cube_data),
            5792
        );
    }

    #[test]
    fn test_struct_spot_light_std140() {
        assert_eq!(std::mem::size_of::<SpotLightStd140>(), 80);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, position_ws), 0);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(SpotLightStd140, spotlight_half_angle),
            12
        );
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, direction_ws), 16);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, range), 28);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, position_vs), 32);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, intensity), 44);
        assert_eq!(std::mem::size_of::<[f32; 4]>(), 16);
        assert_eq!(std::mem::align_of::<[f32; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, color), 48);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, direction_vs), 64);
        assert_eq!(std::mem::size_of::<i32>(), 4);
        assert_eq!(std::mem::align_of::<i32>(), 4);
        assert_eq!(memoffset::offset_of!(SpotLightStd140, shadow_map), 76);
    }

    #[test]
    fn test_struct_directional_light_std140() {
        assert_eq!(std::mem::size_of::<DirectionalLightStd140>(), 48);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(
            memoffset::offset_of!(DirectionalLightStd140, direction_ws),
            0
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(memoffset::offset_of!(DirectionalLightStd140, intensity), 12);
        assert_eq!(std::mem::size_of::<[f32; 4]>(), 16);
        assert_eq!(std::mem::align_of::<[f32; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(DirectionalLightStd140, color), 16);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(
            memoffset::offset_of!(DirectionalLightStd140, direction_vs),
            32
        );
        assert_eq!(std::mem::size_of::<i32>(), 4);
        assert_eq!(std::mem::align_of::<i32>(), 4);
        assert_eq!(
            memoffset::offset_of!(DirectionalLightStd140, shadow_map),
            44
        );
    }

    #[test]
    fn test_struct_point_light_std140() {
        assert_eq!(std::mem::size_of::<PointLightStd140>(), 64);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, position_ws), 0);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, range), 12);
        assert_eq!(std::mem::size_of::<[f32; 3]>(), 12);
        assert_eq!(std::mem::align_of::<[f32; 3]>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, position_vs), 16);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, intensity), 28);
        assert_eq!(std::mem::size_of::<[f32; 4]>(), 16);
        assert_eq!(std::mem::align_of::<[f32; 4]>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, color), 32);
        assert_eq!(std::mem::size_of::<i32>(), 4);
        assert_eq!(std::mem::align_of::<i32>(), 4);
        assert_eq!(memoffset::offset_of!(PointLightStd140, shadow_map), 48);
        assert_eq!(std::mem::size_of::<[u8; 12]>(), 12);
        assert_eq!(std::mem::align_of::<[u8; 12]>(), 1);
        assert_eq!(memoffset::offset_of!(PointLightStd140, _padding0), 52);
    }

    #[test]
    fn test_struct_shadow_map_cube_data_std140() {
        assert_eq!(std::mem::size_of::<ShadowMapCubeDataStd140>(), 16);
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(ShadowMapCubeDataStd140, cube_map_projection_near_z),
            0
        );
        assert_eq!(std::mem::size_of::<f32>(), 4);
        assert_eq!(std::mem::align_of::<f32>(), 4);
        assert_eq!(
            memoffset::offset_of!(ShadowMapCubeDataStd140, cube_map_projection_far_z),
            4
        );
        assert_eq!(std::mem::size_of::<[u8; 8]>(), 8);
        assert_eq!(std::mem::align_of::<[u8; 8]>(), 1);
        assert_eq!(memoffset::offset_of!(ShadowMapCubeDataStd140, _padding0), 8);
    }

    #[test]
    fn test_struct_material_data_ubo_std140() {
        assert_eq!(std::mem::size_of::<MaterialDataUboStd140>(), 80);
        assert_eq!(std::mem::size_of::<MaterialDataStd140>(), 80);
        assert_eq!(std::mem::align_of::<MaterialDataStd140>(), 4);
        assert_eq!(memoffset::offset_of!(MaterialDataUboStd140, data), 0);
    }
}