Compile a material and return its handle. Handles are 1-based; 0 is reserved for "invalid material".
(
&mut self,
device: &wgpu::Device,
wgsl_source: &str,
profile: FragmentProfile,
bucket: Bucket,
reads_scene: bool,
wants_instancing: bool,
| 630 | /// Compile a material and return its handle. Handles are 1-based; |
| 631 | /// 0 is reserved for "invalid material". |
| 632 | pub fn compile( |
| 633 | &mut self, |
| 634 | device: &wgpu::Device, |
| 635 | wgsl_source: &str, |
| 636 | profile: FragmentProfile, |
| 637 | bucket: Bucket, |
| 638 | reads_scene: bool, |
| 639 | wants_instancing: bool, |
| 640 | hdr_format: wgpu::TextureFormat, |
| 641 | material_format: wgpu::TextureFormat, |
| 642 | velocity_format: wgpu::TextureFormat, |
| 643 | albedo_format: wgpu::TextureFormat, |
| 644 | depth_format: wgpu::TextureFormat, |
| 645 | ) -> Result<MaterialHandle, MaterialCompileError> { |
| 646 | // Inject the user's WGSL under a synthetic path so the |
| 647 | // preprocessor can resolve `#include "material_abi.wgsl"` etc. |
| 648 | let entry_path = "__user_material.wgsl"; |
| 649 | let desc = MaterialCompileDesc { |
| 650 | label: "user_material", |
| 651 | entry_path, |
| 652 | extra_sources: &[(entry_path, wgsl_source)], |
| 653 | profile, |
| 654 | bucket, |
| 655 | reads_scene, |
| 656 | hdr_format, |
| 657 | material_format, |
| 658 | velocity_format, |
| 659 | albedo_format, |
| 660 | depth_format, |
| 661 | vertex_buffers: &[Vertex3D::desc()], |
| 662 | wants_instancing, |
| 663 | }; |
| 664 | let pipeline = compile_material(device, &self.layouts, &desc)?; |
| 665 | self.pipelines.push(Some(pipeline)); |
| 666 | Ok(self.pipelines.len() as MaterialHandle) |
| 667 | } |
| 668 | |
| 669 | // --- Frame lifecycle ---------------------------------------------- |
| 670 |