bevy/crates/bevy_render/src/render_resource
James Liu 12032cd296
Directly copy data into uniform buffers (#9865)
# Objective
This is a minimally disruptive version of #8340. I attempted to update
it, but failed due to the scope of the changes added in #8204.

Fixes #8307. Partially addresses #4642. As seen in
https://github.com/bevyengine/bevy/issues/8284, we're actually copying
data twice in Prepare stage systems. Once into a CPU-side intermediate
scratch buffer, and once again into a mapped buffer. This is inefficient
and effectively doubles the time spent and memory allocated to run these
systems.

## Solution
Skip the scratch buffer entirely and use
`wgpu::Queue::write_buffer_with` to directly write data into mapped
buffers.

Separately, this also directly uses
`wgpu::Limits::min_uniform_buffer_offset_alignment` to set up the
alignment when writing to the buffers. Partially addressing the issue
raised in #4642.

Storage buffers and the abstractions built on top of
`DynamicUniformBuffer` will need to come in followup PRs.

This may not have a noticeable performance difference in this PR, as the
only first-party systems affected by this are view related, and likely
are not going to be particularly heavy.

---

## Changelog
Added: `DynamicUniformBuffer::get_writer`.
Added: `DynamicUniformBufferWriter`.
2023-09-25 19:15:37 +00:00
..
batched_uniform_buffer.rs Automatic batching/instancing of draw commands (#9685) 2023-09-21 22:12:34 +00:00
bind_group.rs Use a single line for of large binding lists (#9849) 2023-09-19 22:17:44 +00:00
bind_group_layout.rs Replace UUID based IDs with a atomic-counted ones (#6988) 2022-12-25 00:23:15 +00:00
buffer.rs Replace UUID based IDs with a atomic-counted ones (#6988) 2022-12-25 00:23:15 +00:00
buffer_vec.rs Use instancing for sprites (#9597) 2023-09-02 18:03:19 +00:00
gpu_array_buffer.rs Automatic batching/instancing of draw commands (#9685) 2023-09-21 22:12:34 +00:00
mod.rs Add GpuArrayBuffer and BatchedUniformBuffer (#8204) 2023-07-21 16:46:56 +00:00
pipeline.rs Add push contant config to layout (#7681) 2023-02-17 06:20:16 +00:00
pipeline_cache.rs Bevy Asset V2 (#8624) 2023-09-07 02:07:27 +00:00
pipeline_specializer.rs added multi-line string formatting (#8350) 2023-04-13 18:00:17 +00:00
resource_macros.rs remove potential ub in render_resource_wrapper (#7279) 2023-02-06 17:14:00 +00:00
shader.rs Fix the clippy::explicit_iter_loop lint (#9834) 2023-09-19 03:35:22 +00:00
storage_buffer.rs Add GpuArrayBuffer and BatchedUniformBuffer (#8204) 2023-07-21 16:46:56 +00:00
texture.rs Add screenshot api (#7163) 2023-04-19 21:28:42 +00:00
uniform_buffer.rs Directly copy data into uniform buffers (#9865) 2023-09-25 19:15:37 +00:00