Compile a material pipeline. This is the happy-path you call at `loadMaterial()` time.
(
device: &wgpu::Device,
layouts: &MaterialAbiLayouts,
desc: &MaterialCompileDesc<'_>,
)
| 349 | /// Compile a material pipeline. This is the happy-path you call at |
| 350 | /// `loadMaterial()` time. |
| 351 | pub fn compile_material( |
| 352 | device: &wgpu::Device, |
| 353 | layouts: &MaterialAbiLayouts, |
| 354 | desc: &MaterialCompileDesc<'_>, |
| 355 | ) -> Result<MaterialPipeline, MaterialCompileError> { |
| 356 | // 1. Resolve #include chain against the baked library + |
| 357 | // game-supplied overlay. |
| 358 | let baked_entries = BAKED_ENTRIES_SNAPSHOT; // from library snapshot below |
| 359 | let mut entries: Vec<(&str, &str)> = baked_entries.to_vec(); |
| 360 | for &(p, s) in desc.extra_sources { |
| 361 | entries.push((p, s)); |
| 362 | } |
| 363 | let source = BakedSource { entries: &entries }; |
| 364 | let expanded = process(&source, desc.entry_path)?; |
| 365 | |
| 366 | // 2. Create shader module. wgpu's WGSL parser surfaces errors as |
| 367 | // panics through the default handler; we catch them by |
| 368 | // pushing the scope and popping on failure. |
| 369 | let _ = device.push_error_scope(wgpu::ErrorFilter::Validation); |
| 370 | let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { |
| 371 | label: Some(desc.label), |
| 372 | source: wgpu::ShaderSource::Wgsl(expanded.into()), |
| 373 | }); |
| 374 | // Note: we don't poll the error scope here because wgpu 29 returns |
| 375 | // validation errors synchronously via the device's uncaptured-error |
| 376 | // handler; callers should install their own handler for hot-reload. |
| 377 | |
| 378 | // 3. Pipeline layout — always binds groups 0..3; only includes |
| 379 | // scene_inputs when the material declares it. |
| 380 | let mut bg_layouts: Vec<Option<&wgpu::BindGroupLayout>> = vec![ |
| 381 | Some(&layouts.per_frame), |
| 382 | Some(&layouts.per_view), |
| 383 | Some(&layouts.per_material), |
| 384 | Some(&layouts.per_draw), |
| 385 | ]; |
| 386 | if desc.reads_scene { |
| 387 | bg_layouts.push(Some(&layouts.scene_inputs)); |
| 388 | } |
| 389 | let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { |
| 390 | label: Some(desc.label), |
| 391 | bind_group_layouts: &bg_layouts, |
| 392 | immediate_size: 0, |
| 393 | }); |
| 394 | |
| 395 | // 4. Colour targets based on profile. |
| 396 | let opaque_targets = [ |
| 397 | Some(wgpu::ColorTargetState { |
| 398 | format: desc.hdr_format, |
| 399 | blend: None, |
| 400 | write_mask: wgpu::ColorWrites::ALL, |
| 401 | }), |
| 402 | Some(wgpu::ColorTargetState { |
| 403 | format: desc.material_format, |
| 404 | blend: None, |
| 405 | write_mask: wgpu::ColorWrites::ALL, |
| 406 | }), |
| 407 | Some(wgpu::ColorTargetState { |
| 408 | format: desc.velocity_format, |