Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for Interleaved Vertex Attributes #1358

Closed
legends2k opened this issue Mar 26, 2021 · 5 comments
Closed

Option for Interleaved Vertex Attributes #1358

legends2k opened this issue Mar 26, 2021 · 5 comments
Labels
enhancement New feature or request exporter This involves or affects the export process Mesh_&_Object

Comments

@legends2k
Copy link

legends2k commented Mar 26, 2021

Having interleaved vertex attributes is supported by glTF format. However, the exported doesn't expose interleaving of attributes; it would be more performant to have attributes intersparsed. It'd be great to get an option to enable it if needed.

This would mean

  • Making the interleaved array
  • Giving the right byteStride for each attribute
@donmccurdy
Copy link
Contributor

So far we've mostly avoided providing low-level technical options in this Blender exporter. Generally speaking, it is much easier to leave advanced optimizations to dedicated tools (glTF-Pipeline, gltfpack, glTF-Transform) and to focus on supporting Blender's features the best that we can. I'll leave to others whether this optimization falls into that category, or should be supported.

In any case, a quick workaround would be to interleave the vertices after exporting. This is pretty easy in the CLI:

https://gltf-transform.donmccurdy.com/cli.html

npm install --global @gltf-transform/cli@alpha
gltf-transform copy input.glb output.glb --vertex-layout interleaved

The default for any command in that tool is actually interleaved, but I've heard complaints that some viewers do not support interleaved vertices (that would be a bug in the viewer, but is out of my control) and so added the global option --vertex-layout separate as an alternative.

@donmccurdy donmccurdy added enhancement New feature or request exporter This involves or affects the export process Mesh_&_Object labels Mar 26, 2021
@hrydgard
Copy link

Interleaving vertex attributes is outdated advice. There's little benefit these days - you'd be hard pressed to measure a difference.

If you're doing stuff like a depth prepass when you only use a few of the attributes, you will instead win a lot by keeping them separated instead of interleaved.

@donmccurdy
Copy link
Contributor

There are some indirect benefits of interleaved vertex attributes, like minimizing the total number of WebGL buffers used for the scene (see this thread). But I don't have real numbers on this, and would be very interested in a real comparison on modern graphics APIs.

But I think I'm inclined to agree that this is out of the scope that Blender's exporter should need to deal with, and should be left to tools focused on glTF optimization (e.g. glTF-Pipeline, gltfpack, glTF-Transform, RapidCompact, ...). Correct import/export in Blender is a big enough project.

@legends2k
Copy link
Author

legends2k commented Apr 29, 2021

Interleaving vertex attributes is outdated advice. There's little benefit these days - you'd be hard pressed to measure a difference.

@hrydgard Any references for your claim? Would really be interested in understanding this deeper. Thanks!

@hrydgard
Copy link

Your original link is from 2013. Since then GPUs have gained more general caching systems that work more like on CPU, and with that, it's pretty obvious that if you sometimes need to access one of the vertex streams separately, as with Z-prepass or shadow map rendering where you only use position, it'll be better to have them separate, otherwise when doing so the GPU will load lots of irrelevant data into the cache.

Depending on attribute usage patterns, the optimum can even be to have positions separate and everything else interleaved, but the wins either way are very small.

This is all kind of received knowledge in the graphics community, not so easy to find good references, but there's this from 2016:

https://anteru.net/blog/2016/storing-vertex-data-to-interleave-or-not-to-interleave/

ARM actually recommends mixed deinterleave: https://developer.arm.com/solutions/graphics-and-gaming/developer-guides/learn-the-basics/the-bifrost-shader-core/index-driven-geometry-pipeline

Anyway, again, it's generally not what's gonna be your bottleneck these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request exporter This involves or affects the export process Mesh_&_Object
Projects
None yet
Development

No branches or pull requests

3 participants