Skip to content

Commit 42d3db3

Browse files
committed
.
1 parent 0bf44b7 commit 42d3db3

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
@@ -453,36 +453,6 @@ pub fn flush(app: &mut App, entity: Entity) -> Result<()> {
453453
Ok(())
454454
}
455455

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

crates/processing_render/src/lib.rs

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

1680-
/// Ensure `ShaderBuffer.data` reflects current GPU contents by reading the
1681-
/// buffer back into the asset if it was invalidated by a prior dispatch.
1682-
/// Subsequent reads/writes can then operate on the in-asset bytes directly.
16831680
fn ensure_buffer_synced(app: &mut App, entity: Entity) -> error::Result<()> {
16841681
let (handle, readback_buffer, size, synced) = {
16851682
let buf = app
@@ -1825,41 +1822,26 @@ pub fn compute_set(
18251822

18261823
pub fn compute_dispatch(entity: Entity, x: u32, y: u32, z: u32) -> error::Result<()> {
18271824
app_mut(|app| {
1828-
// Flush any pending graphics work and let Bevy's render-asset extract
1829-
// upload any CPU-side buffer mutations to the GPU before the dispatch
1830-
// runs. This is the sync boundary for compute inputs.
1831-
crate::graphics::flush_all(app);
1825+
app.update();
18321826

1833-
let (args, rw_entities) = {
1827+
let args = {
18341828
let c = app
18351829
.world()
18361830
.get::<compute::Compute>(entity)
18371831
.ok_or(error::ProcessingError::ComputeNotFound)?;
1838-
let args = (
1832+
(
18391833
c.pipeline_id,
18401834
c.bind_group_layout_descriptors.clone(),
18411835
c.shader.clone(),
18421836
x,
18431837
y,
18441838
z,
1845-
);
1846-
let rw_entities: Vec<Entity> = c.rw_buffers.values().copied().collect();
1847-
(args, rw_entities)
1839+
)
18481840
};
18491841
app.sub_app_mut(bevy::render::RenderApp)
18501842
.world_mut()
18511843
.run_system_cached_with(compute::dispatch, args)
1852-
.unwrap()?;
1853-
1854-
// Invalidate the CPU view of any buffer the dispatch could have
1855-
// written. The next read or write on those buffers will readback first.
1856-
let world = app.world_mut();
1857-
for e in rw_entities {
1858-
if let Some(mut buf) = world.get_mut::<compute::Buffer>(e) {
1859-
buf.synced = false;
1860-
}
1861-
}
1862-
Ok(())
1844+
.unwrap()
18631845
})
18641846
}
18651847

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)