Create the bloom mip-chain texture + per-mip render views + a full-chain view for sampling. Mip 0 starts at surface/2 size and each subsequent mip halves down to ~surface/2^N. Caller is responsible for deciding N (usually BLOOM_MIP_COUNT). At least 1×1 is enforced per mip. Build the bloom chain as N separate single-mip textures rather than one multi-mip texture. Multi-mip textures with one mip bou
(
device: &wgpu::Device,
width: u32,
height: u32,
mip_count: u32,
)
| 742 | /// read/write hits a distinct texture). `bloom_full_view` is a |
| 743 | /// view onto mip 0's texture, kept for backward compatibility. |
| 744 | pub(super) fn create_bloom_chain( |
| 745 | device: &wgpu::Device, |
| 746 | width: u32, |
| 747 | height: u32, |
| 748 | mip_count: u32, |
| 749 | ) -> (Vec<wgpu::Texture>, Vec<wgpu::TextureView>, wgpu::TextureView) { |
| 750 | let mut textures = Vec::with_capacity(mip_count as usize); |
| 751 | let mut views = Vec::with_capacity(mip_count as usize); |
| 752 | for i in 0..mip_count { |
| 753 | let w = ((width / 2) >> i).max(1); |
| 754 | let h = ((height / 2) >> i).max(1); |
| 755 | let tex = device.create_texture(&wgpu::TextureDescriptor { |
| 756 | label: Some("bloom_mip_tex"), |
| 757 | size: wgpu::Extent3d { width: w, height: h, depth_or_array_layers: 1 }, |
| 758 | mip_level_count: 1, |
| 759 | sample_count: 1, |
| 760 | dimension: wgpu::TextureDimension::D2, |
| 761 | format: HDR_FORMAT, |
| 762 | usage: wgpu::TextureUsages::RENDER_ATTACHMENT |
| 763 | | wgpu::TextureUsages::TEXTURE_BINDING, |
| 764 | view_formats: &[], |
| 765 | }); |
| 766 | let view = tex.create_view(&wgpu::TextureViewDescriptor::default()); |
| 767 | textures.push(tex); |
| 768 | views.push(view); |
| 769 | } |
| 770 | let full_view = textures[0].create_view(&wgpu::TextureViewDescriptor::default()); |
| 771 | (textures, views, full_view) |
| 772 | } |