Enum bevy_hikari::Upscale

source ·
pub enum Upscale {
    Fsr1 {
        ratio: f32,
        sharpness: f32,
    },
    SmaaTu4x {
        ratio: f32,
    },
    None,
}
Expand description

Upscale method to use.

Variants§

§

Fsr1

Fields

§ratio: f32

Renders the main pass and post process on a low resolution texture.

§sharpness: f32

From 0.0 - 2.0 where 0.0 means max sharpness.

§

SmaaTu4x

Fields

§ratio: f32

Renders the main pass and post process on a low resolution texture.

§

None

Implementations§

Examples found in repository?
src/post_process.rs (line 524)
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
    fn extract_component((camera, settings): QueryItem<Self::Query>) -> Self {
        let size = camera.physical_target_size().unwrap_or_default();
        let scale = settings.upscale.ratio().recip();
        let scaled_size = (scale * size.as_vec2()).ceil();
        Self {
            input_viewport_in_pixels: scaled_size,
            input_size_in_pixels: scaled_size,
            output_size_in_pixels: size.as_vec2(),
            sharpness: settings.upscale.sharpness(),
            hdr: 0,
        }
    }
}

// NOTE! Don't delete, might be used soon, instead of calulating this on GPU
// fn get_fsr_constants(ratio: f32, hdr_rcas: bool, camera: &ExtractedCamera) -> FSRConstantsUniform {
//     let mut fsr_constant = FSRConstantsUniform::default();
//     let size = camera.physical_target_size.unwrap();
//     let size_x = size.x as f32;
//     let size_y = size.x as f32;
//     compute_fsr_constants(
//         &mut fsr_constant.const_0,
//         &mut fsr_constant.const_1,
//         &mut fsr_constant.const_2,
//         &mut fsr_constant.const_3,
//         size_x,
//         size_y,
//         size_x,
//         size_y,
//         size_x * ratio,
//         size_y * ratio,
//     );

//     fsr_constant.sample.x = if hdr_rcas { 1 } else { 0 };
//     fsr_constant
// }

// pub union U32F32Union {
//     pub u: u32,
//     pub f: f32,
// }

// fn f32_u32(a: f32) -> u32 {
//     let uf = U32F32Union { f: a };
//     unsafe { uf.u }
// }

// fn compute_fsr_constants(
//     con0: &mut UVec4,
//     con1: &mut UVec4,
//     con2: &mut UVec4,
//     con3: &mut UVec4,
//     // This the rendered image resolution being upscaled
//     input_viewport_in_pixels_x: f32,
//     input_viewport_in_pixels_y: f32,
//     // This is the resolution of the resource containing the input image (useful for dynamic resolution)
//     input_size_in_pixels_x: f32,
//     input_size_in_pixels_y: f32,
//     // This is the display resolution which the input image gets upscaled to
//     output_size_in_pixels_x: f32,
//     output_size_in_pixels_y: f32,
// ) {
//     // Output integer position to a pixel position in viewport.
//     con0[0] = f32_u32(input_viewport_in_pixels_x * (1.0 / output_size_in_pixels_x));
//     con0[1] = f32_u32(input_viewport_in_pixels_y * (1.0 / output_size_in_pixels_y));
//     con0[2] = f32_u32(0.5 * input_viewport_in_pixels_x * (1.0 / output_size_in_pixels_x) - 0.5);
//     con0[3] = f32_u32(0.5 * input_viewport_in_pixels_y * (1.0 / output_size_in_pixels_y) - 0.5);

//     // Viewport pixel position to normalized image space.
//     // This is used to get upper-left of 'F' tap.
//     con1[0] = (1.0 / input_size_in_pixels_x) as u32;
//     con1[1] = (1.0 / input_size_in_pixels_y) as u32;
//     // Centers of gather4, first offset from upper-left of 'F'.
//     //      +---+---+
//     //      |   |   |
//     //      +--(0)--+
//     //      | b | c |
//     //  +---F---+---+---+
//     //  | e | f | g | h |
//     //  +--(1)--+--(2)--+
//     //  | i | j | k | l |
//     //  +---+---+---+---+
//     //      | n | o |
//     //      +--(3)--+
//     //      |   |   |
//     //      +---+---+
//     con1[2] = f32_u32(1.0 * (1.0 / input_size_in_pixels_x));
//     con1[3] = f32_u32(-1.0 * (1.0 / input_size_in_pixels_y));
//     // These are from (0) instead of 'F'.
//     con2[0] = f32_u32(-1.0 * (1.0 / input_size_in_pixels_x));
//     con2[1] = f32_u32(2.0 * (1.0 / input_size_in_pixels_y));
//     con2[2] = f32_u32(1.0 * (1.0 / input_size_in_pixels_x));
//     con2[3] = f32_u32(2.0 * (1.0 / input_size_in_pixels_y));
//     con3[0] = f32_u32(0.0 * (1.0 / input_size_in_pixels_x));
//     con3[1] = f32_u32(4.0 * (1.0 / input_size_in_pixels_y));
//     con3[2] = 0;
//     con3[3] = 0;
// }

#[derive(Component)]
pub struct PostProcessTextures {
    pub head: usize,
    pub nearest_sampler: Sampler,
    pub linear_sampler: Sampler,
    pub fallback: TextureView,
    pub denoise_internal: [TextureView; 4],
    pub denoise_internal_variance: TextureView,
    pub denoise_render: [TextureView; 3],
    pub tone_mapping_output: [TextureView; 2],
    pub taa_output: [TextureView; 2],
    pub upscale_output: [TextureView; 2],
}

fn prepare_post_process_textures(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    mut texture_cache: ResMut<TextureCache>,
    cameras: Query<(Entity, &ExtractedCamera, &FrameCounter, &HikariSettings)>,
) {
    let texture_usage = TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING;
    let fallback = texture_cache
        .get(
            &render_device,
            TextureDescriptor {
                label: None,
                size: Extent3d {
                    width: 1,
                    height: 1,
                    depth_or_array_layers: 1,
                },
                mip_level_count: 1,
                sample_count: 1,
                dimension: TextureDimension::D2,
                format: HDR_TEXTURE_FORMAT,
                usage: texture_usage,
            },
        )
        .default_view;

    for (entity, camera, counter, settings) in &cameras {
        if let Some(size) = camera.physical_target_size {
            let mut create_texture = |texture_format, scale: f32| {
                let extent = Extent3d {
                    width: (size.x as f32 * scale).ceil() as u32,
                    height: (size.y as f32 * scale).ceil() as u32,
                    depth_or_array_layers: 1,
                };
                texture_cache
                    .get(
                        &render_device,
                        TextureDescriptor {
                            label: None,
                            size: extent,
                            mip_level_count: 1,
                            sample_count: 1,
                            dimension: TextureDimension::D2,
                            format: texture_format,
                            usage: texture_usage,
                        },
                    )
                    .default_view
            };

            macro_rules! create_texture_array {
                [$texture_format:ident, $scale:ident; $count:literal] => {
                    [(); $count].map(|_| create_texture($texture_format, $scale))
                };
                [$texture_format:ident, $scale:literal; $count:literal] => {
                    [(); $count].map(|_| create_texture($texture_format, $scale))
                };
                [$texture:ident; $count:literal] => {
                    [(); $count].map(|_| $texture.clone())
                };
            }

            let nearest_sampler = render_device.create_sampler(&SamplerDescriptor {
                mag_filter: FilterMode::Nearest,
                min_filter: FilterMode::Nearest,
                mipmap_filter: FilterMode::Nearest,
                ..Default::default()
            });
            let linear_sampler = render_device.create_sampler(&SamplerDescriptor {
                mag_filter: FilterMode::Linear,
                min_filter: FilterMode::Linear,
                mipmap_filter: FilterMode::Linear,
                ..Default::default()
            });

            let mut scale = settings.upscale.ratio().recip();

            let denoise_internal_variance = create_texture(VARIANCE_TEXTURE_FORMAT, scale);
            let denoise_internal = create_texture_array![HDR_TEXTURE_FORMAT, scale; 4];
            let denoise_render = create_texture_array![HDR_TEXTURE_FORMAT, scale; 3];

            let tone_mapping_output = create_texture_array![HDR_TEXTURE_FORMAT, scale; 2];

            let upscale_output = match settings.upscale {
                Upscale::SmaaTu4x { .. } => {
                    scale *= 2.0;
                    create_texture_array![HDR_TEXTURE_FORMAT, scale; 2]
                }
                Upscale::Fsr1 { .. } => create_texture_array![HDR_TEXTURE_FORMAT, 1.0; 2],
                Upscale::None => create_texture_array![fallback; 2],
            };

            let taa_output = match settings.taa {
                Taa::Jasmine => {
                    create_texture_array![HDR_TEXTURE_FORMAT, scale; 2]
                }
                Taa::None => create_texture_array![fallback; 2],
            };

            commands.entity(entity).insert(PostProcessTextures {
                head: counter.0 % 2,
                nearest_sampler,
                linear_sampler,
                fallback: fallback.clone(),
                denoise_internal,
                denoise_internal_variance,
                denoise_render,
                tone_mapping_output,
                taa_output,
                upscale_output,
            });
        }
    }
}

#[allow(dead_code)]
#[derive(Resource)]
pub struct CachedPostProcessPipelines {
    demodulation: CachedComputePipelineId,
    denoise_direct: [CachedComputePipelineId; 4],
    denoise: [CachedComputePipelineId; 4],
    tone_mapping: CachedComputePipelineId,
    taa_jasmine: CachedComputePipelineId,
    smaa_tu4x: CachedComputePipelineId,
    smaa_tu4x_extrapolate: CachedComputePipelineId,
    upscale: CachedComputePipelineId,
    upscale_sharpen: CachedComputePipelineId,
}

fn queue_post_process_pipelines(
    mut commands: Commands,
    pipeline: Res<PostProcessPipeline>,
    mut pipelines: ResMut<SpecializedComputePipelines<PostProcessPipeline>>,
    mut pipeline_cache: ResMut<PipelineCache>,
) {
    let demodulation = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::Demodulation);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let denoise_direct = [0, 1, 2, 3].map(|level| {
        let mut key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::Denoise);
        key |= PostProcessPipelineKey::from_denoise_level(level);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    });
    let denoise = [0, 1, 2, 3].map(|level| {
        let mut key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::Denoise);
        key |= PostProcessPipelineKey::from_denoise_level(level);
        key |= PostProcessPipelineKey::FIREFLY_FILTERING_BITS;
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    });

    let tone_mapping = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::ToneMapping);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let taa_jasmine = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::TaaJasmine);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let smaa_tu4x = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::SmaaTu4x);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let smaa_tu4x_extrapolate = {
        let key =
            PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::SmaaTu4xExtrapolate);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let upscale = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::Upscale);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let upscale_sharpen = {
        let key = PostProcessPipelineKey::from_entry_point(PostProcessEntryPoint::UpscaleSharpen);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    commands.insert_resource(CachedPostProcessPipelines {
        demodulation,
        denoise_direct,
        denoise,
        tone_mapping,
        taa_jasmine,
        smaa_tu4x,
        smaa_tu4x_extrapolate,
        upscale,
        upscale_sharpen,
    })
}

#[derive(Component, Clone)]
pub struct PostProcessBindGroup {
    pub sampler: BindGroup,
    pub denoise_internal: BindGroup,
    pub denoise_render: Vec<BindGroup>,
    pub tone_mapping: BindGroup,
    pub tone_mapping_output: BindGroup,
    pub smaa: BindGroup,
    pub smaa_output: BindGroup,
    pub taa: BindGroup,
    pub taa_output: BindGroup,
    pub upscale: BindGroup,
    pub upscale_output: BindGroup,
    pub upscale_sharpen: BindGroup,
    pub upscale_sharpen_output: BindGroup,
}

#[allow(clippy::type_complexity)]
fn queue_post_process_bind_groups(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline: Res<PostProcessPipeline>,
    fsr_constants_uniforms: Res<ComponentUniforms<FsrConstantsUniform>>,
    query: Query<
        (
            Entity,
            &LightTextures,
            &PostProcessTextures,
            &HikariSettings,
        ),
        With<ExtractedCamera>,
    >,
) {
    let fsr_constants_binding = match fsr_constants_uniforms.binding() {
        Some(binding) => binding,
        None => return,
    };

    for (entity, light, post_process, settings) in &query {
        let current = post_process.head;
        let previous = 1 - current;

        let sampler = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.sampler_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: BindingResource::Sampler(&post_process.nearest_sampler),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::Sampler(&post_process.linear_sampler),
                },
            ],
        });

        let denoise_internal = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.denoise_internal_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: BindingResource::TextureView(&post_process.denoise_internal[0]),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(&post_process.denoise_internal[1]),
                },
                BindGroupEntry {
                    binding: 2,
                    resource: BindingResource::TextureView(&post_process.denoise_internal[2]),
                },
                BindGroupEntry {
                    binding: 3,
                    resource: BindingResource::TextureView(&post_process.denoise_internal[3]),
                },
                BindGroupEntry {
                    binding: 4,
                    resource: BindingResource::TextureView(&post_process.denoise_internal_variance),
                },
            ],
        });

        let mut denoise_render = [0, 1, 2]
            .map(|id| {
                render_device.create_bind_group(&BindGroupDescriptor {
                    label: None,
                    layout: &pipeline.denoise_render_layout,
                    entries: &[
                        BindGroupEntry {
                            binding: 0,
                            resource: BindingResource::TextureView(&light.albedo),
                        },
                        BindGroupEntry {
                            binding: 1,
                            resource: BindingResource::TextureView(&light.variance[id]),
                        },
                        BindGroupEntry {
                            binding: 2,
                            resource: BindingResource::TextureView(&light.render[id]),
                        },
                        BindGroupEntry {
                            binding: 3,
                            resource: BindingResource::TextureView(
                                &post_process.denoise_render[id],
                            ),
                        },
                    ],
                })
            })
            .to_vec();

        let (direct_render, emissive_render, mut indirect_render) = match settings.denoise {
            false => (&light.render[0], &light.render[1], &light.render[2]),
            true => (
                &post_process.denoise_render[0],
                &post_process.denoise_render[1],
                &post_process.denoise_render[2],
            ),
        };

        if settings.indirect_bounces == 0 {
            // Do not denoise when there is no indirect rendering pass.
            denoise_render.pop();
            // Use fallback texture when there is no indirect denoise pass.
            indirect_render = &post_process.fallback;
        }

        let tone_mapping = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.tone_mapping_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: BindingResource::TextureView(direct_render),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(emissive_render),
                },
                BindGroupEntry {
                    binding: 2,
                    resource: BindingResource::TextureView(indirect_render),
                },
            ],
        });
        let tone_mapping_output = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.output_layout,
            entries: &[BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&post_process.tone_mapping_output[current]),
            }],
        });

        let smaa = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.smaa_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: BindingResource::TextureView(
                        &post_process.tone_mapping_output[previous],
                    ),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(
                        &post_process.tone_mapping_output[current],
                    ),
                },
            ],
        });
        let smaa_output = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.output_layout,
            entries: &[BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&post_process.upscale_output[0]),
            }],
        });

        let taa_input_texture = match settings.upscale {
            Upscale::SmaaTu4x { .. } => &post_process.upscale_output[0],
            _ => &post_process.tone_mapping_output[current],
        };
        let taa = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.taa_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: BindingResource::TextureView(&post_process.taa_output[previous]),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(taa_input_texture),
                },
            ],
        });
        let taa_output = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.output_layout,
            entries: &[BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&post_process.taa_output[current]),
            }],
        });

        let upscale_input_texture = match settings.taa {
            Taa::Jasmine => &post_process.taa_output[current],
            Taa::None => &post_process.tone_mapping_output[current],
        };

        let upscale = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.upscale_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: fsr_constants_binding.clone(),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(upscale_input_texture),
                },
            ],
        });
        let upscale_output = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.output_layout,
            entries: &[BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&post_process.upscale_output[0]),
            }],
        });

        let upscale_sharpen = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.upscale_layout,
            entries: &[
                BindGroupEntry {
                    binding: 0,
                    resource: fsr_constants_binding.clone(),
                },
                BindGroupEntry {
                    binding: 1,
                    resource: BindingResource::TextureView(&post_process.upscale_output[0]),
                },
            ],
        });
        let upscale_sharpen_output = render_device.create_bind_group(&BindGroupDescriptor {
            label: None,
            layout: &pipeline.output_layout,
            entries: &[BindGroupEntry {
                binding: 0,
                resource: BindingResource::TextureView(&post_process.upscale_output[1]),
            }],
        });

        commands.entity(entity).insert(PostProcessBindGroup {
            sampler,
            denoise_internal,
            denoise_render,
            tone_mapping,
            tone_mapping_output,
            smaa,
            smaa_output,
            taa,
            taa_output,
            upscale,
            upscale_output,
            upscale_sharpen,
            upscale_sharpen_output,
        });
    }
}

#[allow(clippy::type_complexity)]
pub struct PostProcessNode {
    query: QueryState<(
        &'static ExtractedCamera,
        &'static DynamicUniformIndex<FrameUniform>,
        &'static ViewUniformOffset,
        &'static PreviousViewUniformOffset,
        &'static ViewLightsUniformOffset,
        &'static DeferredBindGroup,
        &'static PostProcessBindGroup,
        &'static DynamicUniformIndex<FsrConstantsUniform>,
        &'static HikariSettings,
    )>,
}

impl PostProcessNode {
    pub const IN_VIEW: &'static str = "view";

    pub fn new(world: &mut World) -> Self {
        Self {
            query: world.query_filtered(),
        }
    }
}

impl Node for PostProcessNode {
    fn input(&self) -> Vec<SlotInfo> {
        vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
    }

    fn update(&mut self, world: &mut World) {
        self.query.update_archetypes(world);
    }

    fn run(
        &self,
        graph: &mut RenderGraphContext,
        render_context: &mut RenderContext,
        world: &World,
    ) -> Result<(), NodeRunError> {
        let entity = graph.get_input_entity(Self::IN_VIEW)?;
        let (
            camera,
            frame_uniform,
            view_uniform,
            previous_view_uniform,
            view_lights,
            deferred_bind_group,
            post_process_bind_group,
            fsr_constants_uniform,
            settings,
        ) = match self.query.get_manual(world, entity) {
            Ok(query) => query,
            Err(_) => return Ok(()),
        };
        let view_bind_group = match world.get_resource::<PrepassBindGroup>() {
            Some(bind_group) => &bind_group.view,
            None => return Ok(()),
        };

        let pipelines = world.resource::<CachedPostProcessPipelines>();
        let pipeline_cache = world.resource::<PipelineCache>();

        let size = camera.physical_target_size.unwrap();
        let scale = settings.upscale.ratio().recip();
        let mut scaled_size = (scale * size.as_vec2()).ceil().as_uvec2();

        let mut pass = render_context
            .command_encoder
            .begin_compute_pass(&ComputePassDescriptor::default());

        pass.set_bind_group(
            0,
            view_bind_group,
            &[
                frame_uniform.index(),
                view_uniform.offset,
                previous_view_uniform.offset,
                view_lights.offset,
            ],
        );
        pass.set_bind_group(1, &deferred_bind_group.0, &[]);
        pass.set_bind_group(2, &post_process_bind_group.sampler, &[]);

        if settings.denoise {
            pass.set_bind_group(3, &post_process_bind_group.denoise_internal, &[]);

            let denoise_pipelines = [
                pipelines.denoise_direct,
                pipelines.denoise,
                pipelines.denoise,
            ];

            for (render_bind_group, denoise) in post_process_bind_group
                .denoise_render
                .iter()
                .zip(denoise_pipelines.iter())
            {
                pass.set_bind_group(4, render_bind_group, &[]);

                if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.demodulation)
                {
                    pass.set_pipeline(pipeline);

                    let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                    pass.dispatch_workgroups(count.x, count.y, 1);
                }

                for pipeline in denoise
                    .iter()
                    .filter_map(|pipeline| pipeline_cache.get_compute_pipeline(*pipeline))
                {
                    pass.set_pipeline(pipeline);

                    let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                    pass.dispatch_workgroups(count.x, count.y, 1);
                }
            }
        }

        pass.set_bind_group(3, &post_process_bind_group.tone_mapping, &[]);
        pass.set_bind_group(4, &post_process_bind_group.tone_mapping_output, &[]);

        if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.tone_mapping) {
            pass.set_pipeline(pipeline);

            let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
            pass.dispatch_workgroups(count.x, count.y, 1);
        }

        if matches!(settings.upscale, Upscale::SmaaTu4x { .. }) {
            pass.set_bind_group(3, &post_process_bind_group.smaa, &[]);
            pass.set_bind_group(4, &post_process_bind_group.smaa_output, &[]);

            if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.smaa_tu4x) {
                pass.set_pipeline(pipeline);

                let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                pass.dispatch_workgroups(count.x, count.y, 1);
            }

            if let Some(pipeline) =
                pipeline_cache.get_compute_pipeline(pipelines.smaa_tu4x_extrapolate)
            {
                pass.set_pipeline(pipeline);

                let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                pass.dispatch_workgroups(count.x, count.y, 1);
            }

            // The in-out size after the upscale pass is 4x larger.
            scaled_size *= 2;
        }

        if matches!(settings.taa, Taa::Jasmine) {
            pass.set_bind_group(3, &post_process_bind_group.taa, &[]);
            pass.set_bind_group(4, &post_process_bind_group.taa_output, &[]);

            // if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.taa_short) {
            //     pass.set_pipeline(pipeline);

            //     let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
            //     pass.dispatch_workgroups(count.x, count.y, 1);
            // }

            if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.taa_jasmine) {
                pass.set_pipeline(pipeline);

                let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                pass.dispatch_workgroups(count.x, count.y, 1);
            }
        }

        if matches!(settings.upscale, Upscale::Fsr1 { .. }) {
            pass.set_bind_group(0, &post_process_bind_group.sampler, &[]);
            pass.set_bind_group(
                1,
                &post_process_bind_group.upscale,
                &[fsr_constants_uniform.index()],
            );
            pass.set_bind_group(2, &post_process_bind_group.upscale_output, &[]);

            if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.upscale) {
                pass.set_pipeline(pipeline);

                let count = (size * 2 + 15) / 16;
                pass.dispatch_workgroups(count.x, count.y, 1);
            }

            pass.set_bind_group(
                1,
                &post_process_bind_group.upscale_sharpen,
                &[fsr_constants_uniform.index()],
            );
            pass.set_bind_group(2, &post_process_bind_group.upscale_sharpen_output, &[]);

            if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.upscale_sharpen) {
                pass.set_pipeline(pipeline);

                let count = (size * 2 + 15) / 16;
                pass.dispatch_workgroups(count.x, count.y, 1);
            }
        }

        Ok(())
    }
More examples
Hide additional examples
src/view.rs (line 172)
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
    fn extract_component((settings, counter): QueryItem<Self::Query>) -> Self {
        let HikariSettings {
            direct_validate_interval,
            emissive_validate_interval,
            max_temporal_reuse_count,
            max_spatial_reuse_count,
            max_reservoir_lifetime,
            solar_angle,
            indirect_bounces,
            max_indirect_luminance,
            clear_color,
            temporal_reuse,
            emissive_spatial_reuse,
            indirect_spatial_reuse,
            ..
        } = settings.clone();

        let number = counter.0 as u32;
        let direct_validate_interval = direct_validate_interval as u32;
        let emissive_validate_interval = emissive_validate_interval as u32;
        let indirect_bounces = indirect_bounces as u32;
        let clear_color = clear_color.into();
        let max_temporal_reuse_count = max_temporal_reuse_count as u32;
        let max_spatial_reuse_count = max_spatial_reuse_count as u32;
        let temporal_reuse = temporal_reuse.into();
        let emissive_spatial_reuse = emissive_spatial_reuse.into();
        let indirect_spatial_reuse = indirect_spatial_reuse.into();
        let upscale_ratio = settings.upscale.ratio();

        Self {
            kernel: KERNEL,
            halton: HALTON,
            clear_color,
            number,
            direct_validate_interval,
            emissive_validate_interval,
            indirect_bounces,
            temporal_reuse,
            emissive_spatial_reuse,
            indirect_spatial_reuse,
            max_temporal_reuse_count,
            max_spatial_reuse_count,
            max_reservoir_lifetime,
            solar_angle,
            max_indirect_luminance,
            upscale_ratio,
        }
    }
src/light.rs (line 318)
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
fn prepare_light_textures(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    render_queue: Res<RenderQueue>,
    mut texture_cache: ResMut<TextureCache>,
    mut reservoir_cache: ResMut<ReservoirCache>,
    cameras: Query<(Entity, &ExtractedCamera, &FrameCounter, &HikariSettings)>,
) {
    for (entity, camera, counter, settings) in &cameras {
        if let Some(size) = camera.physical_target_size {
            let texture_usage = TextureUsages::TEXTURE_BINDING | TextureUsages::STORAGE_BINDING;
            let scale = settings.upscale.ratio().recip();
            let scaled_size = (scale * size.as_vec2()).ceil().as_uvec2();
            let mut create_texture = |texture_format, size: UVec2| {
                let extent = Extent3d {
                    width: size.x,
                    height: size.y,
                    depth_or_array_layers: 1,
                };
                texture_cache
                    .get(
                        &render_device,
                        TextureDescriptor {
                            label: None,
                            size: extent,
                            mip_level_count: 1,
                            sample_count: 1,
                            dimension: TextureDimension::D2,
                            format: texture_format,
                            usage: texture_usage,
                        },
                    )
                    .default_view
            };

            if match reservoir_cache.get(&entity) {
                Some(reservoirs) => {
                    let len = (size.x * size.y) as usize;
                    reservoirs
                        .iter()
                        .any(|buffer| buffer.get().data.len() != len)
                }
                None => true,
            } {
                // Reservoirs of this entity should be updated.
                let len = (size.x * size.y) as usize;
                let reservoirs = (0..10)
                    .map(|_| {
                        let mut buffer = StorageBuffer::from(GpuReservoirBuffer {
                            data: vec![GpuPackedReservoir::default(); len],
                        });
                        buffer.write_buffer(&render_device, &render_queue);
                        buffer
                    })
                    .collect();
                reservoir_cache.insert(entity, reservoirs);
            }

            macro_rules! create_texture_array {
                [$texture_format:ident, $size:ident; $count:literal] => {
                    [(); $count].map(|_| create_texture($texture_format, $size))
                };
            }

            let variance = create_texture_array![VARIANCE_TEXTURE_FORMAT, scaled_size; 3];
            let render = create_texture_array![RENDER_TEXTURE_FORMAT, scaled_size; 3];
            let albedo = create_texture(ALBEDO_TEXTURE_FORMAT, size);

            commands.entity(entity).insert(LightTextures {
                head: counter.0 % 2,
                albedo,
                variance,
                render,
            });
        }
    }
}

#[derive(Resource)]
pub struct CachedLightPipelines {
    full_screen_albedo: CachedComputePipelineId,
    direct_lit: CachedComputePipelineId,
    direct_emissive: CachedComputePipelineId,
    indirect: CachedComputePipelineId,
    indirect_multiple_bounces: CachedComputePipelineId,
    emissive_spatial_reuse: CachedComputePipelineId,
    indirect_spatial_reuse: CachedComputePipelineId,
}

fn queue_light_pipelines(
    mut commands: Commands,
    pipeline: Res<LightPipeline>,
    mut pipelines: ResMut<SpecializedComputePipelines<LightPipeline>>,
    mut pipeline_cache: ResMut<PipelineCache>,
) {
    let key = LightPipelineKey::from_texture_count(pipeline.texture_count);

    let full_screen_albedo = {
        let key = key | LightPipelineKey::from_entry_point(LightEntryPoint::FullScreenAlbedo);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let direct_lit = {
        let key = key
            | LightPipelineKey::from_entry_point(LightEntryPoint::DirectLit)
            | LightPipelineKey::RENDER_EMISSIVE_BIT;
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let direct_emissive = {
        let key = key
            | LightPipelineKey::from_entry_point(LightEntryPoint::DirectLit)
            | LightPipelineKey::EMISSIVE_LIT_BIT;
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let indirect = {
        let key = key | LightPipelineKey::from_entry_point(LightEntryPoint::IndirectLitAmbient);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let indirect_multiple_bounces = {
        let key = key
            | LightPipelineKey::from_entry_point(LightEntryPoint::IndirectLitAmbient)
            | LightPipelineKey::MULTIPLE_BOUNCES_BIT;
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    let emissive_spatial_reuse = {
        let key = key
            | LightPipelineKey::from_entry_point(LightEntryPoint::SpatialReuse)
            | LightPipelineKey::EMISSIVE_LIT_BIT;
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };
    let indirect_spatial_reuse = {
        let key = key | LightPipelineKey::from_entry_point(LightEntryPoint::SpatialReuse);
        pipelines.specialize(&mut pipeline_cache, &pipeline, key)
    };

    commands.insert_resource(CachedLightPipelines {
        full_screen_albedo,
        direct_lit,
        direct_emissive,
        indirect,
        indirect_multiple_bounces,
        emissive_spatial_reuse,
        indirect_spatial_reuse,
    })
}

#[derive(Component, Clone)]
pub struct LightBindGroup {
    pub noise: BindGroup,
    pub render: [BindGroup; 3],
    pub reservoir: [BindGroup; 3],
}

#[allow(clippy::too_many_arguments)]
fn queue_light_bind_groups(
    mut commands: Commands,
    render_device: Res<RenderDevice>,
    pipeline: Res<LightPipeline>,
    noise: Res<NoiseTextures>,
    images: Res<RenderAssets<Image>>,
    fallback: Res<FallbackImage>,
    reservoir_cache: Res<ReservoirCache>,
    query: Query<(Entity, &LightTextures), With<ExtractedCamera>>,
) {
    for (entity, light) in &query {
        let reservoirs = reservoir_cache.get(&entity).unwrap();
        if let Some(reservoir_bindings) = reservoirs
            .iter()
            .map(|buffer| buffer.binding())
            .collect::<Option<Vec<_>>>()
        {
            let current = light.head;
            let previous = 1 - current;

            let noise = match noise.as_bind_group(
                &pipeline.noise_layout,
                &render_device,
                &images,
                &fallback,
            ) {
                Ok(noise) => noise,
                Err(_) => continue,
            }
            .bind_group;

            let render = [0, 1, 2].map(|id| {
                let variance = &light.variance[id];
                let render = &light.render[id];

                render_device.create_bind_group(&BindGroupDescriptor {
                    label: None,
                    layout: &pipeline.render_layout,
                    entries: &[
                        BindGroupEntry {
                            binding: 0,
                            resource: BindingResource::TextureView(&light.albedo),
                        },
                        BindGroupEntry {
                            binding: 1,
                            resource: BindingResource::TextureView(variance),
                        },
                        BindGroupEntry {
                            binding: 2,
                            resource: BindingResource::TextureView(render),
                        },
                    ],
                })
            });

            let reservoir = [(0, 4), (2, 4), (6, 8)].map(|(temporal, spatial)| {
                let current_temporal = reservoir_bindings[current + temporal].clone();
                let previous_temporal = reservoir_bindings[previous + temporal].clone();
                let current_spatial = reservoir_bindings[current + spatial].clone();
                let previous_spatial = reservoir_bindings[previous + spatial].clone();

                render_device.create_bind_group(&BindGroupDescriptor {
                    label: None,
                    layout: &pipeline.reservoir_layout,
                    entries: &[
                        BindGroupEntry {
                            binding: 0,
                            resource: current_temporal,
                        },
                        BindGroupEntry {
                            binding: 1,
                            resource: previous_temporal,
                        },
                        BindGroupEntry {
                            binding: 2,
                            resource: current_spatial,
                        },
                        BindGroupEntry {
                            binding: 3,
                            resource: previous_spatial,
                        },
                    ],
                })
            });

            commands.entity(entity).insert(LightBindGroup {
                noise,
                render,
                reservoir,
            });
        }
    }
}

#[allow(clippy::type_complexity)]
pub struct LightNode {
    query: QueryState<(
        &'static ExtractedCamera,
        &'static DynamicUniformIndex<FrameUniform>,
        &'static ViewUniformOffset,
        &'static PreviousViewUniformOffset,
        &'static ViewLightsUniformOffset,
        &'static DeferredBindGroup,
        &'static LightBindGroup,
        &'static HikariSettings,
    )>,
}

impl LightNode {
    pub const IN_VIEW: &'static str = "view";

    pub fn new(world: &mut World) -> Self {
        Self {
            query: world.query_filtered(),
        }
    }
}

impl Node for LightNode {
    fn input(&self) -> Vec<SlotInfo> {
        vec![SlotInfo::new(Self::IN_VIEW, SlotType::Entity)]
    }

    fn update(&mut self, world: &mut World) {
        self.query.update_archetypes(world);
    }

    fn run(
        &self,
        graph: &mut RenderGraphContext,
        render_context: &mut RenderContext,
        world: &World,
    ) -> Result<(), NodeRunError> {
        let entity = graph.get_input_entity(Self::IN_VIEW)?;
        let (
            camera,
            frame_uniform,
            view_uniform,
            previous_view_uniform,
            view_lights,
            deferred_bind_group,
            light_bind_group,
            settings,
        ) = match self.query.get_manual(world, entity) {
            Ok(query) => query,
            Err(_) => return Ok(()),
        };
        let view_bind_group = match world.get_resource::<PrepassBindGroup>() {
            Some(bind_group) => &bind_group.view,
            None => return Ok(()),
        };
        let mesh_material_bind_group = match world.get_resource::<MeshMaterialBindGroup>() {
            Some(bind_group) => bind_group,
            None => return Ok(()),
        };

        let pipelines = world.resource::<CachedLightPipelines>();
        let pipeline_cache = world.resource::<PipelineCache>();

        let size = camera.physical_target_size.unwrap();
        let scale = settings.upscale.ratio().recip();
        let scaled_size = (scale * size.as_vec2()).ceil().as_uvec2();

        let mut pass = render_context
            .command_encoder
            .begin_compute_pass(&ComputePassDescriptor::default());

        pass.set_bind_group(
            0,
            view_bind_group,
            &[
                frame_uniform.index(),
                view_uniform.offset,
                previous_view_uniform.offset,
                view_lights.offset,
            ],
        );
        pass.set_bind_group(1, &deferred_bind_group.0, &[]);
        pass.set_bind_group(2, &mesh_material_bind_group.mesh_material, &[]);
        pass.set_bind_group(3, &mesh_material_bind_group.texture, &[]);
        pass.set_bind_group(4, &light_bind_group.noise, &[]);

        // Full screen albedo pass.
        if let Some(pipeline) = pipeline_cache.get_compute_pipeline(pipelines.full_screen_albedo) {
            pass.set_bind_group(5, &light_bind_group.render[0], &[]);
            pass.set_bind_group(6, &light_bind_group.reservoir[0], &[]);
            pass.set_pipeline(pipeline);

            let count = (size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
            pass.dispatch_workgroups(count.x, count.y, 1);
        }

        // Direct, emissive and indirect passes.
        for (render, reservoir, temporal_pipeline, spatial_pipeline, enable_spatial_reuse) in
            multizip((
                light_bind_group.render.iter(),
                light_bind_group.reservoir.iter(),
                [
                    &pipelines.direct_lit,
                    &pipelines.direct_emissive,
                    match settings.indirect_bounces {
                        x if x < 2 => &pipelines.indirect,
                        _ => &pipelines.indirect_multiple_bounces,
                    },
                ],
                [
                    None,
                    Some(&pipelines.emissive_spatial_reuse),
                    Some(&pipelines.indirect_spatial_reuse),
                ],
                [
                    false,
                    settings.emissive_spatial_reuse,
                    settings.indirect_spatial_reuse,
                ],
            ))
        {
            pass.set_bind_group(5, render, &[]);
            pass.set_bind_group(6, reservoir, &[]);

            if let Some(pipeline) = pipeline_cache.get_compute_pipeline(*temporal_pipeline) {
                pass.set_pipeline(pipeline);

                let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                pass.dispatch_workgroups(count.x, count.y, 1);

                if let Some(pipeline) = spatial_pipeline
                    .filter(|_| enable_spatial_reuse)
                    .and_then(|pipeline| pipeline_cache.get_compute_pipeline(*pipeline))
                {
                    pass.set_pipeline(pipeline);

                    let count = (scaled_size + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE;
                    pass.dispatch_workgroups(count.x, count.y, 1);
                }
            }
        }

        Ok(())
    }
Examples found in repository?
src/post_process.rs (line 530)
522
523
524
525
526
527
528
529
530
531
532
533
    fn extract_component((camera, settings): QueryItem<Self::Query>) -> Self {
        let size = camera.physical_target_size().unwrap_or_default();
        let scale = settings.upscale.ratio().recip();
        let scaled_size = (scale * size.as_vec2()).ceil();
        Self {
            input_viewport_in_pixels: scaled_size,
            input_size_in_pixels: scaled_size,
            output_size_in_pixels: size.as_vec2(),
            sharpness: settings.upscale.sharpness(),
            hdr: 0,
        }
    }

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Returns a reference to the value of the field (in the current variant) with the given name. Read more
Returns a reference to the value of the field (in the current variant) at the given index.
Returns a mutable reference to the value of the field (in the current variant) with the given name. Read more
Returns a mutable reference to the value of the field (in the current variant) at the given index.
Returns the index of the field (in the current variant) with the given name. Read more
Returns the name of the field (in the current variant) with the given index. Read more
Returns an iterator over the values of the current variant’s fields.
Returns the number of fields in the current variant.
The name of the current variant.
The index of the current variant.
The type of the current variant.
Returns true if the current variant’s type matches the given one.
Returns the full path to the current variant.
Returns the type name of the underlying type.
Returns the [TypeInfo] of the underlying type. Read more
Returns the value as a Box<dyn Any>.
Returns the value as a &dyn Any.
Returns the value as a &mut dyn Any.
Casts this type to a boxed reflected value.
Casts this type to a reflected value.
Casts this type to a mutable reflected value.
Clones the value as a Reflect trait object. Read more
Performs a type-checked assignment of a reflected value to this value. Read more
Applies a reflected value to this value. Read more
Returns an enumeration of “kinds” of type. Read more
Returns a mutable enumeration of “kinds” of type. Read more
Returns an owned enumeration of “kinds” of type. Read more
Returns a hash of the value (which includes the type). Read more
Returns a “partial equality” comparison result. Read more
Debug formatter for the value. Read more
Returns a serializable version of the value. Read more
Returns the compile-time info for the underlying type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Return the T [ShaderType] for self. When used in [AsBindGroup] derives, it is safe to assume that all images in self exist.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.

Returns the argument unchanged.

Creates Self using data from the given [World]
Returns a reference to the value specified by path. Read more
Returns a mutable reference to the value specified by path. Read more
Returns a statically typed reference to the value specified by path.
Returns a statically typed mutable reference to the value specified by path.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more