Notes on reducing bevy_gltf dependencies on render crates
#18700
Replies: 2 comments
-
|
Two quick thoughts after reading this, which hopefully help you:
|
Beta Was this translation helpful? Give feedback.
-
|
Re materials, my guess is that Re |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
These notes attempt to answer the question "why and how would we make
bevy_gltfless dependent on rendering crates?". For a TLDR jump to the conclusions at the bottom.Why?
bevy_gltfcurrently depends onbevy_renderandbevy_pbr. This puts it on the critical path for compiles:If Bevy acquires more importers then they'll likely have the same issue. Reducing dependencies would also help alternative renderers, but I'm assuming that's more of a bonus than a requirement.
Asking how to reduce dependencies may be useful for the render crate restructure. That discussion has mostly focused on the needs of the renderer, but reducing dependencies is a worthy goal too. Working through a specific case like
bevy_gltfcould be helpful.These notes assume that the render crates will be split into smaller crates (e.g.
bevy_camera), and there's also a possibility of "data only" crates (similar to howwgpuhas a separatewgpu-types).Background
bevy_gltfturns.gltffiles into Bevy-specific assets and scenes. Right nowbevy_gltfis commonly used to load files and hand the results straight to the main world and render world. But it can also be an asset processor that reads glTF files and writes Bevy-specific files, and that might be done by an app without a renderer.There's a possibility that
bevy_gltfcould itself be restructured to reduce dependencies. This might also fit in with sharing code between other file importers. I'm gonna leave that to one side to avoid complicating things.bevy_gltfcurrently depends onwgpu-typesthroughbevy_meshandbevy_imagere-exports. I'm assuming this is not a problem right now.How?
This section works through all the dependencies I could find and speculates on solutions.
bevy_renderalpha::AlphaModemesh::MeshPluginrenderer::RenderDevice.bevy_pbrDirectionalLightMeshMaterial3dPointLightSpotLightStandardMaterialMAX_JOINTSThe Easy Bits
bevy_render::AlphaModeis a simple enum. I'm not sure which crate it should go in, but seems unlikely to be a major issue.bevy_render::MeshPluginis used bybevy_gltftests (source). Maybe that's fine andbevy_rendergoes in[dev-dependencies], or maybe the test moves to another crate.bevy_pbr::MAX_JOINTSis used to print a warning if the glTF has more joints thanbevy_pbrcan handle (source). I think this warning should move intobevy_pbr, because an asset processor shouldn't be limited by a particular renderer. But making it user friendly might be a problem.RenderDevice,CompressedImageFormats(UPDATE: Resolved in #19190)
bevy_render::RenderDeviceis used byGltfPlugin::finishto grabbevy_image::CompressedImageFormatsfor the current GPU (source). This is not used directly bybevy_gltfbut gets forwarded tobevy_image::Image::from_buffer. There it's used to choose transcode formats or bail if a format is not supported.Depending on the current GPU is problematic for asset processing, so there should at least be an option to ignore it. Breaking the crate dependency is trickier. Maybe
bevy_rendercould initialise some global resourceRes<CurrentGpuCompressedImageFormats>that doesn't depend onbevy_rendertypes. Thenbevy_gltforbevy_imagecan find the resource and optionally use it.Render Components/Assets
bevy_gltfcan spawn theDirectionalLight,PointLight,SpotLight,MeshMaterial3dcomponents, and create aStandardMaterialasset.The light component structs have few dependencies, so they could move to a data only crate or a finer grained render crate. The catch is that their required components pull in more low-level render types and functions.
Maybe the solution is for a lower level render crate to do
App::register_required_components, so the crate withPointLightand others can remain independent?The
MeshMaterial3dcomponent struct doesn't seem to have any dependencies, so could probably move to a data only crate or abevy_materialcrate.The
StandardMaterialasset is trickier as it uses attributes likebind_group_dataandbindless. I guess it could be split into a plain data asset type, and a second lower-level non-asset type that does the bind group stuff and is only used in the renderer? I don't know enough about the renderer to say if this is feasible.Conclusions
bevy_gltfmostly depends on creating render component and asset data, not running render code.StandardMaterial, which might have to be refactored to separate the data from lower-level dependencies.Beta Was this translation helpful? Give feedback.
All reactions