Skip to content

Commit d00c97c

Browse files
committed
.
1 parent c397baf commit d00c97c

4 files changed

Lines changed: 11 additions & 78 deletions

File tree

crates/processing_render/src/compute.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ pub struct Buffer {
3838
pub handle: Handle<ShaderBuffer>,
3939
pub readback_buffer: WgpuBuffer,
4040
pub size: u64,
41-
/// True when `ShaderBuffer.data` reflects current GPU contents. Cleared
42-
/// when a pipeline that may write to the buffer runs; the next read or
43-
/// write must readback first.
4441
pub synced: bool,
45-
/// Set permanently once the buffer is bound to any pipeline as read_write
46-
/// storage. When true, any frame tick could have mutated GPU contents via
47-
/// a render pass, so `synced` must be cleared after each `app.update()`.
4842
pub bound_rw: bool,
4943
}
5044

@@ -97,9 +91,6 @@ pub fn create_buffer_with_data(
9791
.id()
9892
}
9993

100-
/// Mutate the CPU-side data of a `ShaderBuffer` in place. Fires
101-
/// `AssetEvent::Modified` so Bevy's render-asset extract uploads the new
102-
/// contents to the GPU at the next sync point.
10394
pub fn write_buffer_cpu(
10495
In((handle, offset, data)): In<(Handle<ShaderBuffer>, u64, Vec<u8>)>,
10596
mut buffers: ResMut<Assets<ShaderBuffer>>,
@@ -117,10 +108,8 @@ pub fn write_buffer_cpu(
117108
Ok(())
118109
}
119110

120-
/// Copy the GPU buffer back to CPU and return its full contents. Runs in the
121-
/// render world; the caller is responsible for writing the bytes back into
122-
/// `ShaderBuffer.data` via `Assets::get_mut_untracked` (avoiding spurious
123-
/// `AssetEvent::Modified`s, since this is a readback, not a stage-for-upload).
111+
/// Caller must write bytes back via `get_mut_untracked` to avoid triggering
112+
/// a re-upload.
124113
pub fn read_buffer_gpu(
125114
In((handle, readback_buffer, size)): In<(Handle<ShaderBuffer>, WgpuBuffer, u64)>,
126115
gpu_buffers: Res<RenderAssets<GpuShaderBuffer>>,
@@ -172,10 +161,6 @@ pub struct Compute {
172161
pub entry_point: String,
173162
pub pipeline_id: CachedComputePipelineId,
174163
pub bind_group_layout_descriptors: Vec<(u32, BindGroupLayoutDescriptor)>,
175-
/// Buffer entities bound to this compute on a `read_write` storage param.
176-
/// Their CPU view of GPU data is invalidated after each dispatch so the
177-
/// next read/write does a readback. Read-only bindings don't need this
178-
/// since the dispatch can't mutate them.
179164
pub rw_buffers: HashMap<String, Entity>,
180165
}
181166

crates/processing_render/src/graphics.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -461,36 +461,6 @@ pub fn flush(app: &mut App, entity: Entity) -> Result<()> {
461461
Ok(())
462462
}
463463

464-
/// Flush all graphics with pending commands and run a frame so any other
465-
/// pending GPU state (asset writes, etc.) is extracted and uploaded. Used as
466-
/// a sync boundary before operations like compute dispatch that may bind
467-
/// graphics targets or recently-mutated assets.
468-
pub fn flush_all(app: &mut App) {
469-
let mut to_flush = Vec::new();
470-
let world = app.world_mut();
471-
let mut q = world.query::<(Entity, &CommandBuffer, &Graphics)>();
472-
for (e, cb, _) in q.iter(world) {
473-
if !cb.commands.is_empty() {
474-
to_flush.push(e);
475-
}
476-
}
477-
478-
for e in &to_flush {
479-
if let Ok(mut em) = world.get_entity_mut(*e) {
480-
em.insert(Flush);
481-
}
482-
}
483-
484-
app.update();
485-
486-
let world = app.world_mut();
487-
for e in &to_flush {
488-
if let Ok(mut em) = world.get_entity_mut(*e) {
489-
em.remove::<Flush>();
490-
}
491-
}
492-
}
493-
494464
pub fn present(app: &mut App, entity: Entity) -> Result<()> {
495465
graphics_mut!(app, entity)
496466
.get_mut::<Camera>()

crates/processing_render/src/lib.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,6 @@ pub fn buffer_write_element(entity: Entity, offset: u64, data: Vec<u8>) -> error
15231523
buffer_write_range(entity, offset, data, false)
15241524
}
15251525

1526-
/// Ensure `ShaderBuffer.data` reflects current GPU contents by reading the
1527-
/// buffer back into the asset if it was invalidated by a prior dispatch.
1528-
/// Subsequent reads/writes can then operate on the in-asset bytes directly.
15291526
fn ensure_buffer_synced(app: &mut App, entity: Entity) -> error::Result<()> {
15301527
let (handle, readback_buffer, size, synced) = {
15311528
let buf = app
@@ -1671,41 +1668,26 @@ pub fn compute_set(
16711668

16721669
pub fn compute_dispatch(entity: Entity, x: u32, y: u32, z: u32) -> error::Result<()> {
16731670
app_mut(|app| {
1674-
// Flush any pending graphics work and let Bevy's render-asset extract
1675-
// upload any CPU-side buffer mutations to the GPU before the dispatch
1676-
// runs. This is the sync boundary for compute inputs.
1677-
crate::graphics::flush_all(app);
1671+
app.update();
16781672

1679-
let (args, rw_entities) = {
1673+
let args = {
16801674
let c = app
16811675
.world()
16821676
.get::<compute::Compute>(entity)
16831677
.ok_or(error::ProcessingError::ComputeNotFound)?;
1684-
let args = (
1678+
(
16851679
c.pipeline_id,
16861680
c.bind_group_layout_descriptors.clone(),
16871681
c.shader.clone(),
16881682
x,
16891683
y,
16901684
z,
1691-
);
1692-
let rw_entities: Vec<Entity> = c.rw_buffers.values().copied().collect();
1693-
(args, rw_entities)
1685+
)
16941686
};
16951687
app.sub_app_mut(bevy::render::RenderApp)
16961688
.world_mut()
16971689
.run_system_cached_with(compute::dispatch, args)
1698-
.unwrap()?;
1699-
1700-
// Invalidate the CPU view of any buffer the dispatch could have
1701-
// written. The next read or write on those buffers will readback first.
1702-
let world = app.world_mut();
1703-
for e in rw_entities {
1704-
if let Some(mut buf) = world.get_mut::<compute::Buffer>(e) {
1705-
buf.synced = false;
1706-
}
1707-
}
1708-
Ok(())
1690+
.unwrap()
17091691
})
17101692
}
17111693

crates/processing_render/src/material/custom.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,10 @@ pub(crate) fn shader_value_to_reflect(value: &ShaderValue) -> Result<Box<dyn Par
305305
ShaderValue::Int4(v) => Box::new(IVec4::from_array(*v)),
306306
ShaderValue::UInt(v) => Box::new(*v),
307307
ShaderValue::Mat4(v) => Box::new(Mat4::from_cols_array(v)),
308-
ShaderValue::Texture(_) => {
309-
return Err(ProcessingError::UnknownShaderProperty(
310-
"Texture properties not yet supported for custom materials".to_string(),
311-
));
312-
}
313-
ShaderValue::Buffer(_) => {
314-
return Err(ProcessingError::UnknownShaderProperty(
315-
"Buffer properties not supported for custom materials".to_string(),
308+
ShaderValue::Texture(_) | ShaderValue::Buffer(_) => {
309+
return Err(ProcessingError::InvalidArgument(
310+
"Texture/Buffer must be bound via set_property, not as a uniform value"
311+
.to_string(),
316312
));
317313
}
318314
})

0 commit comments

Comments
 (0)