bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Change default vertex layout to seperate buffers

Open julhe opened this issue 6 years ago • 9 comments

Right now the vertex layout is interleave, meaning data is stored like (VVVNNNCCC). It would make sense to use seperate buffers, like in (VVV) (NNN) (CCC).

Pro:

  • Easier adding of new attributes / more modular approach
  • More controlled binding, like only bind position buffer for shadow rendering
  • Faster modification of certain buffers, like changing the vertex color on the CPU without uploading the entire mesh again

Cons:

  • More binding code -> slightly worse CPU performance?
  • Unkown performance implications? https://www.khronos.org/opengl/wiki/Vertex_Specification_Best_Practices puts it as GPU Vendor dependen, but could do some profiling how bad it really is.

julhe avatar Sep 27 '20 16:09 julhe

I think this is a good idea. When we were looking into this for Amethyst, benchmarks basically said performance was a wash or slightly better for the separate version, and that's without taking into account stuff like shadow map where you're actually using less of the data. The flexibility gains on top of that makes it very worth it.

fu5ha avatar Sep 27 '20 20:09 fu5ha

I'm not sure if we should keep the possiblity to have multiple attributes per buffer, as it just takes up code and is likely to be never used (?). Also the buffers are set up multiple times per frame now. I will fix that once I got more feedback from you people. 🙂

julhe avatar Sep 28 '20 23:09 julhe

I don't think it's particularly useful to have multiple attributes per buffer tbh

fu5ha avatar Sep 28 '20 23:09 fu5ha

Hi, I am curious if this solves/affects the issue https://github.com/bevyengine/bevy/issues/155 and if so would it be possible to get an example added as part of the PR that demonstrates how to use separate buffers to add colour data to a mesh or similar?

Forgive me if I am way off on the intentions for this one.

nickbryan avatar Sep 29 '20 07:09 nickbryan

@nickbryan Yes this would affect #155... I think the scope of this PR isn't necessarily to fully solve that but it will make solving it much easier for sure. Once this lands, #155 and an associated example should be fairly easy.

fu5ha avatar Sep 29 '20 18:09 fu5ha

That's awesome news! Thanks for the information.

nickbryan avatar Sep 29 '20 19:09 nickbryan

Okay, I have some additional Info:

Prefere Seperate:

  • recent AMD (Page 26 https://frostbite-wp-prd.s3.amazonaws.com/wp-content/uploads/2016/03/29204330/GDC_2016_Compute.pdf )
  • Nvidia (?)
  • CPUs (Page 27 https://frostbite-wp-prd.s3.amazonaws.com/wp-content/uploads/2016/03/29204330/GDC_2016_Compute.pdf)

Prefere Interleaved:

  • PowerVR (https://docs.imgtec.com/Profiling_and_Optimisations/PerfRec/topics/c_PerfRec_primitive_types.html)
  • Adreno (page 53: https://developer.qualcomm.com/download/adrenosdk/vulkan-developer-guide.pdf?referrer=node/6114)

Would say we still make this PR and then at some point provide functions that converts seperate buffers into interleaved ones for mobile if the user/platform demands.

julhe avatar Oct 01 '20 09:10 julhe

Something also to consider is that WGPU has limits to the max number of vertex buffers that can be bound. Interleaving is one way to work around that limitation. Ideally the vertex format would be fully customizable as there are use cases for both separate and interleaved.

See also: https://github.com/gpuweb/gpuweb/issues/693 https://github.com/gfx-rs/wgpu/issues/558

aloucks avatar Oct 07 '20 04:10 aloucks

I think I'm going to call this resolved by #592. Midway through the implementation it changed from "separate buffers" back to "interleaved" (but still bound as separate buffers). But it lays solid foundations for both approaches. I think we should open new issues for specific changes to the new approach.

cart avatar Oct 31 '20 02:10 cart