1//! Types needed for GPU mesh uniform building.3/// Per-frame data that the CPU supplies to the GPU.4struct MeshInput {5 /// The model transform.6 world_from_local: mat3x4<f32>,7 /// The lightmap UV rect, packed into 64 bits.8 lightmap_uv_rect: vec2<u32>,9 /// Various flags.10 flags: u32,11 /// The index of the `PreviousMeshInput` uniform in the buffer, or `u32::MAX`12 /// if there's no such uniform.13 previous_input_index: u32,14 first_vertex_index: u32,15 first_index_index: u32,16 index_count: u32,17 current_skin_index: u32,18 /// Low 16 bits: index of the material inside the bind group data.19 /// High 16 bits: index of the lightmap in the binding array.20 material_and_lightmap_bind_group_slot: u32,21 timestamp: u32,22 /// User supplied index to identify the mesh instance23 tag: u32,24 /// The index of the morph descriptor for this mesh instance in the25 /// `morph_descriptors` table.26 ///27 /// If the mesh has no morph targets, this is `u32::MAX`.28 morph_descriptor_index: u32,29 metadata_index: u3230}32/// Per-mesh-instance data that we retain from the previous frame.33struct PreviousMeshInput {34 /// The model transform.35 world_from_local: mat3x4<f32>,36};38/// The `wgpu` indirect parameters structure. This is a union of two structures.39/// For more information, see the corresponding comment in40/// `gpu_preprocessing.rs`.41struct IndirectParametersIndexed {42 /// `vertex_count` or `index_count`.43 index_count: u32,44 /// `instance_count` in both structures.45 instance_count: u32,46 /// `first_vertex` or `first_index`.47 first_index: u32,48 /// `base_vertex` or `first_instance`.49 base_vertex: u32,50 /// A read-only copy of `instance_index`.51 first_instance: u32,52}54struct IndirectParametersNonIndexed {55 vertex_count: u32,56 instance_count: u32,57 base_vertex: u32,58 first_instance: u32,59}61/// Information needed to construct indirect draw parameters for a single draw.62///63/// Note that is per-*draw* (i.e. per-mesh), not per-mesh-instance or64/// per-batch-set. A single multi-draw indirect call can perform multiple draws.65///66/// Typically, the uniform allocation and mesh preprocessing phases fill in this67/// structure. However, parts of it may be filled in on the CPU for objects that68/// aren't multidrawn.69struct IndirectParametersMetadata {70 /// The index of the first `MeshUniform` for this draw in the mesh uniform71 /// buffer.72 ///73 /// `MeshUniform`s for all instances are stored consecutively.74 ///75 /// This is filled in in the `allocate_uniforms` shader, or on the CPU when76 /// multidraw isn't in use.77 base_output_index: u32,79 /// The index of this batch set in the `IndirectBatchSet` array.80 ///81 /// This is filled in in the `allocate_uniforms` shader, or on the CPU when82 /// multidraw isn't in use.83 batch_set_index: u32,85 /// The index of the mesh in the `MeshInput` buffer.86 ///87 /// The mesh preprocessing shader fills this in.88 mesh_index: u32,90 /// The number of instances that were visible last frame (if occlusion91 /// culling is in use) or that were visible at all (if occlusion culling92 /// isn't in use).93 @if(WRITE_INDIRECT_PARAMETERS_METADATA)94 early_instance_count: atomic<u32>,95 /// The number of instances that were visible this frame if occlusion culling96 /// is in use.97 @if(WRITE_INDIRECT_PARAMETERS_METADATA)98 late_instance_count: atomic<u32>,99 /// The number of instances that were visible last frame (if occlusion100 /// culling is in use) or that were visible at all (if occlusion culling101 /// isn't in use).102 @if(!WRITE_INDIRECT_PARAMETERS_METADATA)103 early_instance_count: u32,104 /// The number of instances that were visible this frame if occlusion culling105 /// is in use.106 @if(!WRITE_INDIRECT_PARAMETERS_METADATA)107 late_instance_count: u32,108}110struct IndirectBatchSet {111 indirect_parameters_count: atomic<u32>,112 indirect_parameters_base: u32,113}115/// One invocation of this compute shader: i.e. one mesh instance in a view.116struct PreprocessWorkItem {117 /// The index of the `MeshInput` in the `current_input` buffer that we read118 /// from.119 input_index: u32,120 /// In direct mode, the index of the `Mesh` in `output` that we write to. In121 /// indirect mode, the index of the `IndirectParameters` in122 /// `indirect_parameters` that we write to.123 output_or_indirect_parameters_index: u32,124}126/// Information about each bin in a batch set.127///128/// This is maintained by the CPU and cached for bins that don't change from129/// frame to frame.130struct BinMetadata {131 /// The index of the indirect parameters for this bin, relative to the first132 /// indirect parameter index for the batch set.133 ///134 /// That is, the final indirect parameters index for this bin is135 /// `first_indirect_parameters_index` in the `UniformAllocationMetadata` plus136 /// this value.137 indirect_parameters_offset: u32,139 /// The index of the bin that this metadata corresponds to.140 ///141 /// The GPU doesn't use this, but the CPU does in order to perform the142 /// reverse mapping from bin metadata index back to the bin. We could store143 /// this in a non-GPU-accessible buffer, but I figured the extra complexity144 /// wasn't worth it.145 bin_index: u32,147 /// The number of mesh instances in this bin.148 instance_count: u32,149};