mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove even more wgpu commands from the main thread.
This commit is contained in:
parent
d38ce95b22
commit
2301b7f47a
@ -171,7 +171,7 @@ impl Locals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type BoundLocals = Bound<()>;
|
pub type BoundLocals = Arc<Bound<()>>;
|
||||||
|
|
||||||
pub struct TerrainLayout {
|
pub struct TerrainLayout {
|
||||||
pub locals: wgpu::BindGroupLayout,
|
pub locals: wgpu::BindGroupLayout,
|
||||||
@ -189,7 +189,7 @@ impl TerrainLayout {
|
|||||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||||
ty: wgpu::BindingType::Buffer {
|
ty: wgpu::BindingType::Buffer {
|
||||||
ty: wgpu::BufferBindingType::Uniform,
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
has_dynamic_offset: false,
|
has_dynamic_offset: true,
|
||||||
min_binding_size: None,
|
min_binding_size: None,
|
||||||
},
|
},
|
||||||
count: None,
|
count: None,
|
||||||
@ -199,7 +199,7 @@ impl TerrainLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bind_locals(&self, device: &wgpu::Device, locals: &Consts<Locals>, offset: usize) -> BoundLocals {
|
pub fn bind_locals(&self, device: &wgpu::Device, locals: &Consts<Locals>/*, offset: usize*/) -> BoundLocals {
|
||||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
layout: &self.locals,
|
layout: &self.locals,
|
||||||
@ -207,16 +207,16 @@ impl TerrainLayout {
|
|||||||
binding: 0,
|
binding: 0,
|
||||||
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
|
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
|
||||||
buffer: locals.buf(),
|
buffer: locals.buf(),
|
||||||
offset: (offset * mem::size_of::<Locals>()) as wgpu::BufferAddress,
|
offset: /* (offset * mem::size_of::<Locals>()) */0 as wgpu::BufferAddress,
|
||||||
size: wgpu::BufferSize::new(mem::size_of::<Locals>() as u64),
|
size: wgpu::BufferSize::new(mem::size_of::<Locals>() as u64),
|
||||||
})
|
})
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
||||||
BoundLocals {
|
Arc::new(Bound {
|
||||||
bind_group,
|
bind_group,
|
||||||
with: /*locals*/(),
|
with: /*locals*/(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ impl Renderer {
|
|||||||
pub fn create_terrain_bound_locals(
|
pub fn create_terrain_bound_locals(
|
||||||
&mut self,
|
&mut self,
|
||||||
locals: /*Arc<*/&Consts<terrain::Locals>/*>*/,
|
locals: /*Arc<*/&Consts<terrain::Locals>/*>*/,
|
||||||
offset: usize,
|
/* offset: usize, */
|
||||||
) -> /*for<'a> Fn(&'a [terrain::Locals]) -> terrain::BoundLocals + Send + Sync*//* impl Fn() -> terrain::BoundLocals + Send + Sync */terrain::BoundLocals {
|
) -> /*for<'a> Fn(&'a [terrain::Locals]) -> terrain::BoundLocals + Send + Sync*//* impl Fn() -> terrain::BoundLocals + Send + Sync */terrain::BoundLocals {
|
||||||
/* let device = Arc::clone(&self.device);
|
/* let device = Arc::clone(&self.device);
|
||||||
let immutable = Arc::clone(&self.layouts.immutable);
|
let immutable = Arc::clone(&self.layouts.immutable);
|
||||||
@ -87,7 +87,7 @@ impl Renderer {
|
|||||||
let locals = Consts::new_mapped(&device, 1);
|
let locals = Consts::new_mapped(&device, 1);
|
||||||
immutable.terrain.bind_locals(&device, locals)
|
immutable.terrain.bind_locals(&device, locals)
|
||||||
} */
|
} */
|
||||||
self.layouts.immutable.terrain.bind_locals(&self.device, locals, offset)
|
self.layouts.immutable.terrain.bind_locals(&self.device, locals/* , offset */)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_shadow_bound_locals(&mut self, locals: &[shadow::Locals]) -> shadow::BoundLocals {
|
pub fn create_shadow_bound_locals(&mut self, locals: &[shadow::Locals]) -> shadow::BoundLocals {
|
||||||
|
@ -465,7 +465,7 @@ impl<'frame> Drawer<'frame> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
matrices: &[shadow::PointLightMatrix; 126],
|
matrices: &[shadow::PointLightMatrix; 126],
|
||||||
chunks: impl Clone
|
chunks: impl Clone
|
||||||
+ Iterator<Item = (&'data Model<terrain::Vertex>, &'data terrain::BoundLocals)>,
|
+ Iterator<Item = (&'data Model<terrain::Vertex>, &'data (wgpu::DynamicOffset, terrain::BoundLocals))>,
|
||||||
) {
|
) {
|
||||||
if !self.borrow.pipeline_modes.shadow.is_map() {
|
if !self.borrow.pipeline_modes.shadow.is_map() {
|
||||||
return;
|
return;
|
||||||
@ -524,8 +524,8 @@ impl<'frame> Drawer<'frame> {
|
|||||||
&data[(6 * (point_light + 1) * STRIDE + face as usize * STRIDE)
|
&data[(6 * (point_light + 1) * STRIDE + face as usize * STRIDE)
|
||||||
..(6 * (point_light + 1) * STRIDE + (face + 1) as usize * STRIDE)],
|
..(6 * (point_light + 1) * STRIDE + (face + 1) as usize * STRIDE)],
|
||||||
);
|
);
|
||||||
chunks.clone().for_each(|(model, locals)| {
|
chunks.clone().for_each(|(model, &(locals_offset, ref locals))| {
|
||||||
render_pass.set_bind_group(1, &locals.bind_group, &[]);
|
render_pass.set_bind_group(1, &locals.bind_group, &[locals_offset]);
|
||||||
render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||||
render_pass.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
render_pass.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
||||||
});
|
});
|
||||||
@ -746,9 +746,9 @@ impl<'pass_ref, 'pass: 'pass_ref> TerrainShadowDrawer<'pass_ref, 'pass> {
|
|||||||
pub fn draw<'data: 'pass>(
|
pub fn draw<'data: 'pass>(
|
||||||
&mut self,
|
&mut self,
|
||||||
model: &'data Model<terrain::Vertex>,
|
model: &'data Model<terrain::Vertex>,
|
||||||
locals: &'data terrain::BoundLocals,
|
&(locals_offset, ref locals): &'data (wgpu::DynamicOffset, terrain::BoundLocals),
|
||||||
) {
|
) {
|
||||||
self.render_pass.set_bind_group(1, &locals.bind_group, &[]);
|
self.render_pass.set_bind_group(1, &locals.bind_group, &[locals_offset]);
|
||||||
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
||||||
@ -924,7 +924,7 @@ impl<'pass_ref, 'pass: 'pass_ref> TerrainDrawer<'pass_ref, 'pass> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
model: &'data Model<terrain::Vertex>,
|
model: &'data Model<terrain::Vertex>,
|
||||||
col_lights: &'data Arc<ColLights<terrain::Locals>>,
|
col_lights: &'data Arc<ColLights<terrain::Locals>>,
|
||||||
locals: &'data terrain::BoundLocals,
|
&(locals_offset, ref locals): &'data (wgpu::DynamicOffset, terrain::BoundLocals),
|
||||||
) {
|
) {
|
||||||
if self.col_lights
|
if self.col_lights
|
||||||
// Check if we are still using the same atlas texture as the previous drawn
|
// Check if we are still using the same atlas texture as the previous drawn
|
||||||
@ -937,7 +937,7 @@ impl<'pass_ref, 'pass: 'pass_ref> TerrainDrawer<'pass_ref, 'pass> {
|
|||||||
self.col_lights = Some(col_lights);
|
self.col_lights = Some(col_lights);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.render_pass.set_bind_group(3, &locals.bind_group, &[]);
|
self.render_pass.set_bind_group(3, &locals.bind_group, &[locals_offset]);
|
||||||
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
||||||
@ -975,11 +975,11 @@ pub struct SpriteDrawer<'pass_ref, 'pass: 'pass_ref> {
|
|||||||
impl<'pass_ref, 'pass: 'pass_ref> SpriteDrawer<'pass_ref, 'pass> {
|
impl<'pass_ref, 'pass: 'pass_ref> SpriteDrawer<'pass_ref, 'pass> {
|
||||||
pub fn draw<'data: 'pass>(
|
pub fn draw<'data: 'pass>(
|
||||||
&mut self,
|
&mut self,
|
||||||
terrain_locals: &'data terrain::BoundLocals,
|
&(terrain_locals_offset, ref terrain_locals): &'data (wgpu::DynamicOffset, terrain::BoundLocals),
|
||||||
instances: &'data Instances<sprite::Instance>,
|
instances: &'data Instances<sprite::Instance>,
|
||||||
) {
|
) {
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.set_bind_group(3, &terrain_locals.bind_group, &[]);
|
.set_bind_group(3, &terrain_locals.bind_group, &[terrain_locals_offset]);
|
||||||
|
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.set_vertex_buffer(0, instances.buf().slice(..));
|
.set_vertex_buffer(0, instances.buf().slice(..));
|
||||||
@ -1027,10 +1027,10 @@ impl<'pass_ref, 'pass: 'pass_ref> FluidDrawer<'pass_ref, 'pass> {
|
|||||||
pub fn draw<'data: 'pass>(
|
pub fn draw<'data: 'pass>(
|
||||||
&mut self,
|
&mut self,
|
||||||
model: &'data Model<fluid::Vertex>,
|
model: &'data Model<fluid::Vertex>,
|
||||||
locals: &'data terrain::BoundLocals,
|
&(locals_offset, ref locals): &'data (wgpu::DynamicOffset, terrain::BoundLocals),
|
||||||
) {
|
) {
|
||||||
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||||
self.render_pass.set_bind_group(2, &locals.bind_group, &[]);
|
self.render_pass.set_bind_group(2, &locals.bind_group, &[locals_offset]);
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
.draw_indexed(0..model.len() as u32 / 4 * 6, 0, 0..1);
|
||||||
}
|
}
|
||||||
@ -1187,3 +1187,5 @@ fn set_quad_index_buffer<'a, V: super::Vertex>(
|
|||||||
pass.set_index_buffer(slice, format);
|
pass.set_index_buffer(slice, format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pub struct TerrainChunkData {
|
|||||||
light_map: LightMapFn,
|
light_map: LightMapFn,
|
||||||
glow_map: LightMapFn,
|
glow_map: LightMapFn,
|
||||||
sprite_instances: [Instances<SpriteInstance>; SPRITE_LOD_LEVELS],
|
sprite_instances: [Instances<SpriteInstance>; SPRITE_LOD_LEVELS],
|
||||||
locals: pipelines::terrain::BoundLocals,
|
locals: (wgpu::DynamicOffset, pipelines::terrain::BoundLocals),
|
||||||
pub blocks_of_interest: BlocksOfInterest,
|
pub blocks_of_interest: BlocksOfInterest,
|
||||||
|
|
||||||
visible: Visibility,
|
visible: Visibility,
|
||||||
@ -1339,7 +1339,7 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
scene_data.state.get_delta_time() * CHUNKS_PER_SECOND + self.mesh_recv_overflow;
|
scene_data.state.get_delta_time() * CHUNKS_PER_SECOND + self.mesh_recv_overflow;
|
||||||
self.mesh_recv_overflow = recv_count.fract();
|
self.mesh_recv_overflow = recv_count.fract();
|
||||||
let mesh_recv = &self.mesh_recv;
|
let mesh_recv = &self.mesh_recv;
|
||||||
let max_recv_count = self.mesh_todos_active.load(Ordering::Relaxed).min(recv_count.floor() as u64);
|
let max_recv_count = self.mesh_todos_active.load(Ordering::Relaxed)/*.min(recv_count.floor() as u64)*/;
|
||||||
let incoming_chunks =
|
let incoming_chunks =
|
||||||
std::iter::from_fn(|| mesh_recv.try_recv().ok())
|
std::iter::from_fn(|| mesh_recv.try_recv().ok())
|
||||||
.take(/* recv_count.floor() as usize */max_recv_count as usize);
|
.take(/* recv_count.floor() as usize */max_recv_count as usize);
|
||||||
@ -1349,6 +1349,7 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
// be some unused slots, which is fine.
|
// be some unused slots, which is fine.
|
||||||
let locals = /*Arc::new(*/renderer.create_consts_mapped(max_recv_count as usize)/*)*/;
|
let locals = /*Arc::new(*/renderer.create_consts_mapped(max_recv_count as usize)/*)*/;
|
||||||
let mut locals_buffer = renderer.get_consts_mapped(&locals);
|
let mut locals_buffer = renderer.get_consts_mapped(&locals);
|
||||||
|
let mut locals_bound = renderer.create_terrain_bound_locals(&locals/*, locals_offset */);
|
||||||
let mut encoder = renderer.device
|
let mut encoder = renderer.device
|
||||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||||
label: Some("Update textures."),
|
label: Some("Update textures."),
|
||||||
@ -1459,6 +1460,8 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
depth_or_array_layers: 1,
|
depth_or_array_layers: 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
// Drop image on background thread.
|
||||||
|
slowjob.spawn(&"TERRAIN_DROP", move || { drop(tex); });
|
||||||
|
|
||||||
// Update the memory mapped locals.
|
// Update the memory mapped locals.
|
||||||
let locals_buffer_ =
|
let locals_buffer_ =
|
||||||
@ -1483,7 +1486,8 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
light_map: mesh.light_map,
|
light_map: mesh.light_map,
|
||||||
glow_map: mesh.glow_map,
|
glow_map: mesh.glow_map,
|
||||||
sprite_instances,
|
sprite_instances,
|
||||||
locals: /* mesh.locals */renderer.create_terrain_bound_locals(&locals, locals_offset),
|
locals: /* mesh.locals *//*renderer.create_terrain_bound_locals(&locals/*, locals_offset */)*/
|
||||||
|
((locals_offset * core::mem::size_of::<TerrainLocals>()) as wgpu::DynamicOffset, Arc::clone(&locals_bound)),
|
||||||
visible: Visibility {
|
visible: Visibility {
|
||||||
in_range: false,
|
in_range: false,
|
||||||
in_frustum: false,
|
in_frustum: false,
|
||||||
@ -1514,6 +1518,8 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
// Drop the memory mapping and unmap the locals.
|
// Drop the memory mapping and unmap the locals.
|
||||||
drop(locals_buffer);
|
drop(locals_buffer);
|
||||||
renderer.unmap_consts(&locals);
|
renderer.unmap_consts(&locals);
|
||||||
|
// Drop buffer on background thread.
|
||||||
|
slowjob.spawn(&"TERRAIN_DROP", move || { drop(locals); });
|
||||||
/* // TODO: Delay submission, don't just submit immediately out of convenience!
|
/* // TODO: Delay submission, don't just submit immediately out of convenience!
|
||||||
renderer.queue.submit(std::iter::once(encoder.finish())); */
|
renderer.queue.submit(std::iter::once(encoder.finish())); */
|
||||||
self.command_buffers.push(encoder.finish());
|
self.command_buffers.push(encoder.finish());
|
||||||
@ -1829,7 +1835,7 @@ impl/*<V: RectRasterableVol>*/ Terrain<V> {
|
|||||||
+ Iterator<
|
+ Iterator<
|
||||||
Item = (
|
Item = (
|
||||||
&Model<pipelines::terrain::Vertex>,
|
&Model<pipelines::terrain::Vertex>,
|
||||||
&pipelines::terrain::BoundLocals,
|
&(wgpu::DynamicOffset, pipelines::terrain::BoundLocals),
|
||||||
),
|
),
|
||||||
> {
|
> {
|
||||||
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
|
let focus_chunk = Vec2::from(focus_pos).map2(TerrainChunk::RECT_SIZE, |e: f32, sz| {
|
||||||
|
Loading…
Reference in New Issue
Block a user