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_gltf
less dependent on rendering crates?". For a TLDR jump to the conclusions at the bottom.Why?
bevy_gltf
currently depends onbevy_render
andbevy_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_gltf
could 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 howwgpu
has a separatewgpu-types
).Background
bevy_gltf
turns.gltf
files into Bevy-specific assets and scenes. Right nowbevy_gltf
is 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_gltf
could 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_gltf
currently depends onwgpu-types
throughbevy_mesh
andbevy_image
re-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_render
alpha::AlphaMode
mesh::MeshPlugin
renderer::RenderDevice
.bevy_pbr
DirectionalLight
MeshMaterial3d
PointLight
SpotLight
StandardMaterial
MAX_JOINTS
The Easy Bits
bevy_render::AlphaMode
is a simple enum. I'm not sure which crate it should go in, but seems unlikely to be a major issue.bevy_render::MeshPlugin
is used bybevy_gltf
tests (source). Maybe that's fine andbevy_render
goes in[dev-dependencies]
, or maybe the test moves to another crate.bevy_pbr::MAX_JOINTS
is used to print a warning if the glTF has more joints thanbevy_pbr
can 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::RenderDevice
is used byGltfPlugin::finish
to grabbevy_image::CompressedImageFormats
for the current GPU (source). This is not used directly bybevy_gltf
but 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_render
could initialise some global resourceRes<CurrentGpuCompressedImageFormats>
that doesn't depend onbevy_render
types. Thenbevy_gltf
orbevy_image
can find the resource and optionally use it.Render Components/Assets
bevy_gltf
can spawn theDirectionalLight
,PointLight
,SpotLight
,MeshMaterial3d
components, and create aStandardMaterial
asset.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 withPointLight
and others can remain independent?The
MeshMaterial3d
component struct doesn't seem to have any dependencies, so could probably move to a data only crate or abevy_material
crate.The
StandardMaterial
asset is trickier as it uses attributes likebind_group_data
andbindless
. 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_gltf
mostly 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