mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
bc34216929
This commit uses the [`offset-allocator`] crate to combine vertex and index arrays from different meshes into single buffers. Since the primary source of `wgpu` overhead is from validation and synchronization when switching buffers, this significantly improves Bevy's rendering performance on many scenes. This patch is a more flexible version of #13218, which also used slabs. Unlike #13218, which used slabs of a fixed size, this commit implements slabs that start small and can grow. In addition to reducing memory usage, supporting slab growth reduces the number of vertex and index buffer switches that need to happen during rendering, leading to improved performance. To prevent pathological fragmentation behavior, slabs are capped to a maximum size, and mesh arrays that are too large get their own dedicated slabs. As an additional improvement over #13218, this commit allows the application to customize all allocator heuristics. The `MeshAllocatorSettings` resource contains values that adjust the minimum and maximum slab sizes, the cutoff point at which meshes get their own dedicated slabs, and the rate at which slabs grow. Hopefully-sensible defaults have been chosen for each value. Unfortunately, WebGL 2 doesn't support the *base vertex* feature, which is necessary to pack vertex arrays from different meshes into the same buffer. `wgpu` represents this restriction as the downlevel flag `BASE_VERTEX`. This patch detects that bit and ensures that all vertex buffers get dedicated slabs on that platform. Even on WebGL 2, though, we can combine all *index* arrays into single buffers to reduce buffer changes, and we do so. The following measurements are on Bistro: Overall frame time improves from 8.74 ms to 5.53 ms (1.58x speedup): ![Screenshot 2024-07-09 163521](https://github.com/bevyengine/bevy/assets/157897/5d83c824-c0ee-434c-bbaf-218ff7212c48) Render system time improves from 6.57 ms to 3.54 ms (1.86x speedup): ![Screenshot 2024-07-09 163559](https://github.com/bevyengine/bevy/assets/157897/d94e2273-c3a0-496a-9f88-20d394129610) Opaque pass time improves from 4.64 ms to 2.33 ms (1.99x speedup): ![Screenshot 2024-07-09 163536](https://github.com/bevyengine/bevy/assets/157897/e4ef6e48-d60e-44ae-9a71-b9a731c99d9a) ## Migration Guide ### Changed * Vertex and index buffers for meshes may now be packed alongside other buffers, for performance. * `GpuMesh` has been renamed to `RenderMesh`, to reflect the fact that it no longer directly stores handles to GPU objects. * Because meshes no longer have their own vertex and index buffers, the responsibility for the buffers has moved from `GpuMesh` (now called `RenderMesh`) to the `MeshAllocator` resource. To access the vertex data for a mesh, use `MeshAllocator::mesh_vertex_slice`. To access the index data for a mesh, use `MeshAllocator::mesh_index_slice`. [`offset-allocator`]: https://github.com/pcwalton/offset-allocator
134 lines
4.4 KiB
TOML
134 lines
4.4 KiB
TOML
[package]
|
|
name = "bevy_render"
|
|
version = "0.15.0-dev"
|
|
edition = "2021"
|
|
description = "Provides rendering functionality for Bevy Engine"
|
|
homepage = "https://bevyengine.org"
|
|
repository = "https://github.com/bevyengine/bevy"
|
|
license = "MIT OR Apache-2.0"
|
|
keywords = ["bevy"]
|
|
|
|
[features]
|
|
png = ["image/png"]
|
|
exr = ["image/exr"]
|
|
hdr = ["image/hdr"]
|
|
tga = ["image/tga"]
|
|
jpeg = ["image/jpeg"]
|
|
bmp = ["image/bmp"]
|
|
webp = ["image/webp"]
|
|
dds = ["ddsfile"]
|
|
pnm = ["image/pnm"]
|
|
multi_threaded = ["bevy_tasks/multi_threaded"]
|
|
|
|
shader_format_glsl = ["naga/glsl-in", "naga/wgsl-out", "naga_oil/glsl"]
|
|
shader_format_spirv = ["wgpu/spirv", "naga/spv-in", "naga/spv-out"]
|
|
|
|
# For ktx2 supercompression
|
|
zlib = ["flate2"]
|
|
zstd = ["ruzstd"]
|
|
|
|
trace = ["profiling"]
|
|
tracing-tracy = []
|
|
wgpu_trace = ["wgpu/trace"]
|
|
ci_limits = []
|
|
webgl = ["wgpu/webgl"]
|
|
webgpu = ["wgpu/webgpu"]
|
|
ios_simulator = []
|
|
|
|
[dependencies]
|
|
# bevy
|
|
bevy_app = { path = "../bevy_app", version = "0.15.0-dev" }
|
|
bevy_asset = { path = "../bevy_asset", version = "0.15.0-dev" }
|
|
bevy_color = { path = "../bevy_color", version = "0.15.0-dev", features = [
|
|
"serialize",
|
|
"wgpu-types",
|
|
] }
|
|
bevy_core = { path = "../bevy_core", version = "0.15.0-dev" }
|
|
bevy_derive = { path = "../bevy_derive", version = "0.15.0-dev" }
|
|
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.15.0-dev" }
|
|
bevy_ecs = { path = "../bevy_ecs", version = "0.15.0-dev" }
|
|
bevy_encase_derive = { path = "../bevy_encase_derive", version = "0.15.0-dev" }
|
|
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.15.0-dev" }
|
|
bevy_math = { path = "../bevy_math", version = "0.15.0-dev" }
|
|
bevy_mikktspace = { path = "../bevy_mikktspace", version = "0.15.0-dev" }
|
|
bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
|
|
"bevy",
|
|
] }
|
|
bevy_render_macros = { path = "macros", version = "0.15.0-dev" }
|
|
bevy_time = { path = "../bevy_time", version = "0.15.0-dev" }
|
|
bevy_transform = { path = "../bevy_transform", version = "0.15.0-dev" }
|
|
bevy_window = { path = "../bevy_window", version = "0.15.0-dev" }
|
|
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }
|
|
bevy_tasks = { path = "../bevy_tasks", version = "0.15.0-dev" }
|
|
|
|
# rendering
|
|
image = { version = "0.25", default-features = false }
|
|
|
|
# misc
|
|
codespan-reporting = "0.11.0"
|
|
# `fragile-send-sync-non-atomic-wasm` feature means we can't use WASM threads for rendering
|
|
# It is enabled for now to avoid having to do a significant overhaul of the renderer just for wasm.
|
|
# When the 'atomics' feature is enabled `fragile-send-sync-non-atomic` does nothing
|
|
# and Bevy instead wraps `wgpu` types to verify they are not used off their origin thread.
|
|
wgpu = { version = "0.20", default-features = false, features = [
|
|
"wgsl",
|
|
"dx12",
|
|
"metal",
|
|
"naga",
|
|
"naga-ir",
|
|
"fragile-send-sync-non-atomic-wasm",
|
|
] }
|
|
naga = { version = "0.20", features = ["wgsl-in"] }
|
|
serde = { version = "1", features = ["derive"] }
|
|
bitflags = { version = "2.3", features = ["serde"] }
|
|
bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
|
|
downcast-rs = "1.2.0"
|
|
thiserror = "1.0"
|
|
futures-lite = "2.0.1"
|
|
hexasphere = "12.0"
|
|
ddsfile = { version = "0.5.2", optional = true }
|
|
ktx2 = { version = "0.3.0", optional = true }
|
|
# For ktx2 supercompression
|
|
flate2 = { version = "1.0.22", optional = true }
|
|
ruzstd = { version = "0.7.0", optional = true }
|
|
# For transcoding of UASTC/ETC1S universal formats, and for .basis file support
|
|
basis-universal = { version = "0.3.0", optional = true }
|
|
encase = { version = "0.8", features = ["glam"] }
|
|
# For wgpu profiling using tracing. Use `RUST_LOG=info` to also capture the wgpu spans.
|
|
profiling = { version = "1", features = [
|
|
"profile-with-tracing",
|
|
], optional = true }
|
|
async-channel = "2.2.0"
|
|
nonmax = "0.5"
|
|
smallvec = { version = "1.11", features = ["const_new"] }
|
|
offset-allocator = "0.2"
|
|
|
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
# Omit the `glsl` feature in non-WebAssembly by default.
|
|
naga_oil = { version = "0.14", default-features = false, features = [
|
|
"test_shader",
|
|
] }
|
|
|
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
naga_oil = "0.14"
|
|
js-sys = "0.3"
|
|
web-sys = { version = "0.3.67", features = [
|
|
'Blob',
|
|
'Document',
|
|
'Element',
|
|
'HtmlElement',
|
|
'Node',
|
|
'Url',
|
|
'Window',
|
|
] }
|
|
wasm-bindgen = "0.2"
|
|
|
|
[target.'cfg(all(target_arch = "wasm32", target_feature = "atomics"))'.dependencies]
|
|
send_wrapper = "0.6.0"
|
|
|
|
[lints]
|
|
workspace = true
|
|
|
|
[package.metadata.docs.rs]
|
|
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
|
|
all-features = true
|