[flame_3d] Support instanced drawing of repeated meshes
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- dart
- Área
- computer-graphics, game-dev
Línea de trabajo
Start by reading the flame_3d rendering backend and RenderContext3D, then check how flutter_gpu exposes instance-rate vertex layouts and instance counts. The issue proposes backend support, shader changes, and either an explicit game API or automatic grouping, so first agree on the API and scope with maintainers. Done means repeated compatible meshes can be drawn with instancing while existing and skinned rendering paths continue to work.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem to solve
Every surface in flame_3d is drawn with its own draw call, even when the same mesh with the same material is repeated many times in a scene: trees, grass tufts, fences, rocks, crowds. Each draw rebinds the pipeline, the uniforms and the geometry, and on mobile that per-draw CPU cost, on the Dart side and in flutter_gpu's command encoding, quickly dominates the frame.
flutter_gpu now has what is needed to draw such meshes once: vertex layouts with instance-rate buffers (VertexLayout, VertexStepMode.instance) and draw/drawIndexed with an instanceCount. flame_3d has no way to use them today.
Proposal
A backend layer that changes nothing for existing code:
GpuBackend.createInstancedPipeline({vertexShader, fragmentShader, layout}), returningnullwhen the backend cannot instance (the WebGPU backend could start there).GpuInstanceLayout, describing the per-vertex attributes of the surface buffer and the per-instance attributes (stride and named attributes for each).GpuInstancedRenderPass.drawInstances(ByteData instances, int instanceCount), implemented by the flutter_gpu render pass by emplacing the instance data in the host buffer and binding it as the second vertex buffer.GraphicsDevice.supportsInstancing, true only while a pass that supports it is open, andGraphicsDevice.bindInstancedGeometry(surface, instances, instanceCount).
On the shader side, an instanced variant of the built-in vertex shaders that reads the model matrix from four per-instance vec4 attributes instead of VertexInfo.model. Skinned surfaces would keep the regular path.
The open question is how games would use it:
- An explicit API, such as a component or a method taking one mesh and a list of transforms.
- Automatic grouping in
RenderContext3D: draws captured during a pass are grouped by surface, and a group is drawn instanced when every member shares the same material and the same material state. Anything else, including alpha-blended surfaces that must stay depth-sorted, is drawn as today.
Option 2 needs no change in games but adds bookkeeping to every frame. Option 1 is more predictable. Both could build on the same backend layer, which could also land first on its own.
More information
We implemented the backend layer and option 2 in a 3D engine built on flame_3d, with its own material. In a village scene measured on an AYN Thor (Android handheld), 165 repeated decor draws became 17 instanced draws, and the UI thread time per frame (Animator::BeginFrame) went from 7.0 ms to 5.1 ms. The flutter_gpu instancing API was used with Flutter 3.47.5.
Limits of that first version: only the model matrix varies per instance, and instanced groups are drawn after the other opaque draws of the pass, which depth testing makes invisible for opaque and alpha-tested surfaces.
I'd be happy to port it as a PR, starting with whichever part and shape you prefer.
- Lenguaje dominante
- Dart
- Estrellas
- 10.8k
- Forks
- 1.1k
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 52
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de flame-engine/flame
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
flame-engine/flame#4176 ·
Los mantenedores suelen responder en 1 día
-
discussion enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
flame-engine/flame#4175 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
flame-engine/flame#4174 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
flame-engine/flame#4173 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
flame-engine/flame#4172 ·
Los mantenedores suelen responder en 1 día
Todos los issues de flame-engine/flame
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
aaronified/fluenough#918 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
VeryGoodOpenSource/very_good_analysis#255 ·
Los mantenedores suelen responder en 1 día
-
TButton 小尺寸时文字在垂直方向不居中,有点偏下Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Tencent/tdesign-flutter#1233 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
fossasia/badgemagic-app#2025 · 1 comentario ·
Los mantenedores suelen responder en 1 día