docs/bevy/release-content/migration-guides/downsample_shader_specialization.md 1.4 K · 25 lines · raw · history

1 ---
2 title: "`DownsampleShaders::general` is now a `Handle<Shader>`"
3 pull_requests: [25744]
4 ---
5
6 `DownsampleShaders::general` is now a single `Handle<Shader>` instead of a `HashMap<TextureFormat, Handle<Shader>>`.
7
8 Code that looked up a shader in `DownsampleShaders::general` and queued its own compute pipelines should specialize the new `DownsamplePipeline` resource instead. It adds the required shader defs itself. Build a `DownsamplePipelineKey` for each pass, then get the pipeline from `SpecializedComputePipelines<DownsamplePipeline>` and the bind group layout from the key:
9
10 ```rust
11 let first = DownsamplePipelineKey {
12 texture_format: TextureFormat::Rgba16Float,
13 array_texture: true, // for cubemaps and other 2D array textures
14 combine_bind_groups: can_combine_downsampling_bind_groups(&render_adapter, &render_device),
15 pass: DownsamplePass::First,
16 };
17 let second = DownsamplePipelineKey { pass: DownsamplePass::Second, ..first };
18
19 let first_pipeline = specialized_pipelines.specialize(&pipeline_cache, &downsample_pipeline, first);
20 let first_layout = first.bind_group_layout();
21 ```
22
23 If you do this in a `RenderStartup` system, order it after `init_gpu_resource::<DownsamplePipeline>` and `init_gpu_resource::<SpecializedComputePipelines<DownsamplePipeline>>`, since both resources are created there.
24
25 The `FIRST_PASS` and `SECOND_PASS` shader defs in `downsample.wesl` are now `SPLIT_BIND_GROUP_FIRST` and `SPLIT_BIND_GROUP_SECOND`.