|
1 | 1 | use super::{ |
2 | 2 | SolariGlobalIlluminationPipelines, SolariGlobalIlluminationSettings, WORLD_CACHE_SIZE, |
3 | 3 | }; |
4 | | -use crate::solari::SpatiotemporalBlueNoise; |
| 4 | +use crate::{bind_group_layout_entries::*, solari::SpatiotemporalBlueNoise}; |
5 | 5 | use bevy_core::FrameCount; |
6 | 6 | use bevy_core_pipeline::prepass::{ |
7 | 7 | DepthPrepass, MotionVectorPrepass, NormalPrepass, ViewPrepassTextures, DEPTH_PREPASS_FORMAT, |
@@ -242,173 +242,70 @@ pub fn prepare_resources( |
242 | 242 | }); |
243 | 243 | } |
244 | 244 | } |
245 | | - |
246 | 245 | pub fn create_bind_group_layouts( |
247 | 246 | render_device: &RenderDevice, |
248 | 247 | ) -> (BindGroupLayout, BindGroupLayout) { |
249 | | - let mut entry_i = 0; |
250 | | - let mut entry = |ty| { |
251 | | - entry_i += 1; |
252 | | - BindGroupLayoutEntry { |
253 | | - binding: entry_i - 1, |
254 | | - visibility: ShaderStages::COMPUTE, |
255 | | - ty, |
256 | | - count: None, |
257 | | - } |
258 | | - }; |
259 | | - |
260 | | - let entries = &[ |
261 | | - // View |
262 | | - entry(BindingType::Buffer { |
263 | | - ty: BufferBindingType::Uniform, |
264 | | - has_dynamic_offset: true, |
265 | | - min_binding_size: Some(ViewUniform::min_size()), |
266 | | - }), |
267 | | - // Spatiotemporal blue noise |
268 | | - entry(BindingType::Texture { |
269 | | - sample_type: TextureSampleType::Float { filterable: false }, |
270 | | - view_dimension: TextureViewDimension::D2Array, |
271 | | - multisampled: false, |
272 | | - }), |
273 | | - // Previous depth buffer |
274 | | - entry(BindingType::Texture { |
275 | | - sample_type: TextureSampleType::Depth, |
276 | | - view_dimension: TextureViewDimension::D2, |
277 | | - multisampled: false, |
278 | | - }), |
279 | | - // Depth buffer |
280 | | - entry(BindingType::Texture { |
281 | | - sample_type: TextureSampleType::Depth, |
282 | | - view_dimension: TextureViewDimension::D2, |
283 | | - multisampled: false, |
284 | | - }), |
285 | | - // Normals buffer |
286 | | - entry(BindingType::Texture { |
287 | | - sample_type: TextureSampleType::Float { filterable: false }, |
288 | | - view_dimension: TextureViewDimension::D2, |
289 | | - multisampled: false, |
290 | | - }), |
291 | | - // Motion vectors |
292 | | - entry(BindingType::Texture { |
293 | | - sample_type: TextureSampleType::Float { filterable: false }, |
294 | | - view_dimension: TextureViewDimension::D2, |
295 | | - multisampled: false, |
296 | | - }), |
297 | | - // Screen probes history |
298 | | - entry(BindingType::Texture { |
299 | | - sample_type: TextureSampleType::Float { filterable: false }, |
300 | | - view_dimension: TextureViewDimension::D2Array, |
301 | | - multisampled: false, |
302 | | - }), |
303 | | - // Screen probes |
304 | | - entry(BindingType::StorageTexture { |
305 | | - access: StorageTextureAccess::ReadWrite, |
306 | | - format: TextureFormat::Rgba16Float, |
307 | | - view_dimension: TextureViewDimension::D2Array, |
308 | | - }), |
309 | | - // Screen probes confidence history |
310 | | - entry(BindingType::Texture { |
311 | | - sample_type: TextureSampleType::Uint, |
312 | | - view_dimension: TextureViewDimension::D2Array, |
313 | | - multisampled: false, |
314 | | - }), |
315 | | - // Screen probes confidence |
316 | | - entry(BindingType::StorageTexture { |
317 | | - access: StorageTextureAccess::WriteOnly, |
318 | | - format: TextureFormat::R8Uint, |
319 | | - view_dimension: TextureViewDimension::D2Array, |
320 | | - }), |
321 | | - // Screen probes merge buffer |
322 | | - entry(BindingType::StorageTexture { |
323 | | - access: StorageTextureAccess::ReadWrite, |
324 | | - format: TextureFormat::Rgba16Float, |
325 | | - view_dimension: TextureViewDimension::D2Array, |
326 | | - }), |
327 | | - // Screen probe spherical harmonics |
328 | | - entry(BindingType::Buffer { |
329 | | - ty: BufferBindingType::Storage { read_only: false }, |
330 | | - has_dynamic_offset: false, |
331 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(112) }), |
332 | | - }), |
333 | | - // Diffuse irradiance output |
334 | | - entry(BindingType::StorageTexture { |
335 | | - access: StorageTextureAccess::WriteOnly, |
336 | | - format: TextureFormat::Rgba16Float, |
337 | | - view_dimension: TextureViewDimension::D2, |
338 | | - }), |
339 | | - // World cache checksums |
340 | | - entry(BindingType::Buffer { |
341 | | - ty: BufferBindingType::Storage { read_only: false }, |
342 | | - has_dynamic_offset: false, |
343 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
344 | | - }), |
345 | | - // World cache life |
346 | | - entry(BindingType::Buffer { |
347 | | - ty: BufferBindingType::Storage { read_only: false }, |
348 | | - has_dynamic_offset: false, |
349 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
350 | | - }), |
351 | | - // World cache irradiance |
352 | | - entry(BindingType::Buffer { |
353 | | - ty: BufferBindingType::Storage { read_only: false }, |
354 | | - has_dynamic_offset: false, |
355 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(16) }), |
356 | | - }), |
357 | | - // World cache cell data |
358 | | - entry(BindingType::Buffer { |
359 | | - ty: BufferBindingType::Storage { read_only: false }, |
360 | | - has_dynamic_offset: false, |
361 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(32) }), |
362 | | - }), |
363 | | - // World cache active cells new irradiance |
364 | | - entry(BindingType::Buffer { |
365 | | - ty: BufferBindingType::Storage { read_only: false }, |
366 | | - has_dynamic_offset: false, |
367 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(16) }), |
368 | | - }), |
369 | | - // World cache a |
370 | | - entry(BindingType::Buffer { |
371 | | - ty: BufferBindingType::Storage { read_only: false }, |
372 | | - has_dynamic_offset: false, |
373 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
374 | | - }), |
375 | | - // World cache b |
376 | | - entry(BindingType::Buffer { |
377 | | - ty: BufferBindingType::Storage { read_only: false }, |
378 | | - has_dynamic_offset: false, |
379 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
380 | | - }), |
381 | | - // World cache active cell indices |
382 | | - entry(BindingType::Buffer { |
383 | | - ty: BufferBindingType::Storage { read_only: false }, |
384 | | - has_dynamic_offset: false, |
385 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
386 | | - }), |
387 | | - // World cache active cells count |
388 | | - entry(BindingType::Buffer { |
389 | | - ty: BufferBindingType::Storage { read_only: false }, |
390 | | - has_dynamic_offset: false, |
391 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(4) }), |
392 | | - }), |
393 | | - // World cache active cells dispatch |
394 | | - entry(BindingType::Buffer { |
395 | | - ty: BufferBindingType::Storage { read_only: false }, |
396 | | - has_dynamic_offset: false, |
397 | | - min_binding_size: Some(unsafe { NonZeroU64::new_unchecked(12) }), |
398 | | - }), |
399 | | - ]; |
| 248 | + let entries = BindGroupLayoutEntries::sequential( |
| 249 | + ShaderStages::COMPUTE, |
| 250 | + ( |
| 251 | + // View |
| 252 | + uniform_buffer(true, Some(ViewUniform::min_size())), |
| 253 | + // Spatiotemporal blue noise |
| 254 | + texture_2d_array(TextureSampleType::Float { filterable: false }), |
| 255 | + // Previous depth buffer |
| 256 | + texture_depth_2d(), |
| 257 | + // Depth buffer |
| 258 | + texture_depth_2d(), |
| 259 | + // Normals buffer |
| 260 | + texture_2d(TextureSampleType::Float { filterable: false }), |
| 261 | + // Motion vectors |
| 262 | + texture_2d(TextureSampleType::Float { filterable: false }), |
| 263 | + // Screen probes history |
| 264 | + texture_2d_array(TextureSampleType::Float { filterable: false }), |
| 265 | + // Screen probes |
| 266 | + texture_storage_2d_array(TextureFormat::Rgba16Float, StorageTextureAccess::ReadWrite), |
| 267 | + // Screen probes confidence history |
| 268 | + texture_2d_array(TextureSampleType::Uint), |
| 269 | + // Screen probes confidence |
| 270 | + texture_storage_2d_array(TextureFormat::R8Uint, StorageTextureAccess::WriteOnly), |
| 271 | + // Screen probes merge buffer |
| 272 | + texture_storage_2d_array(TextureFormat::Rgba16Float, StorageTextureAccess::ReadWrite), |
| 273 | + // Screen probe spherical harmonics |
| 274 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(112) })), |
| 275 | + // Diffuse irradiance output |
| 276 | + texture_storage_2d(TextureFormat::Rgba16Float, StorageTextureAccess::WriteOnly), |
| 277 | + // World cache checksums |
| 278 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 279 | + // World cache life |
| 280 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 281 | + // World cache irradiance |
| 282 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(16) })), |
| 283 | + // World cache cell data |
| 284 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(32) })), |
| 285 | + // World cache active cells new irradiance |
| 286 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(16) })), |
| 287 | + // World cache a |
| 288 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 289 | + // World cache b |
| 290 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 291 | + // World cache active cell indices |
| 292 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 293 | + // World cache active cells count |
| 294 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(4) })), |
| 295 | + // World cache active cells dispatch |
| 296 | + storage_buffer(false, Some(unsafe { NonZeroU64::new_unchecked(12) })), |
| 297 | + ), |
| 298 | + ); |
400 | 299 |
|
401 | 300 | ( |
402 | | - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { |
403 | | - label: Some("solari_global_illumination_view_bind_group_layout"), |
404 | | - entries: &entries[0..entries.len() - 1], |
405 | | - }), |
406 | | - render_device.create_bind_group_layout(&BindGroupLayoutDescriptor { |
407 | | - label: Some( |
408 | | - "solari_global_illumination_view_with_world_cache_dispatch_bind_group_layout", |
409 | | - ), |
410 | | - entries, |
411 | | - }), |
| 301 | + render_device.create_bind_group_layout_ext( |
| 302 | + "solari_global_illumination_view_bind_group_layout", |
| 303 | + &entries[0..entries.len() - 1], |
| 304 | + ), |
| 305 | + render_device.create_bind_group_layout_ext( |
| 306 | + "solari_global_illumination_view_with_world_cache_dispatch_bind_group_layout", |
| 307 | + &entries, |
| 308 | + ), |
412 | 309 | ) |
413 | 310 | } |
414 | 311 |
|
|
0 commit comments