mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added mesh worker queue limit to prevent throttling of meshing queue
This commit is contained in:
parent
064832fe87
commit
1641c4f788
@ -50,6 +50,8 @@ fn mesh_worker(
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_WORKERS_QUEUED: usize = 32;
|
||||
|
||||
pub struct Terrain {
|
||||
chunks: HashMap<Vec2<i32>, TerrainChunk>,
|
||||
|
||||
@ -58,6 +60,7 @@ pub struct Terrain {
|
||||
mesh_send_tmp: mpsc::Sender<MeshWorkerResponse>,
|
||||
mesh_recv: mpsc::Receiver<MeshWorkerResponse>,
|
||||
mesh_todo: HashMap<Vec2<i32>, ChunkMeshState>,
|
||||
workers_queued: usize,
|
||||
}
|
||||
|
||||
impl Terrain {
|
||||
@ -72,6 +75,7 @@ impl Terrain {
|
||||
mesh_send_tmp: send,
|
||||
mesh_recv: recv,
|
||||
mesh_todo: HashMap::new(),
|
||||
workers_queued: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +153,10 @@ impl Terrain {
|
||||
// Only spawn workers for meshing jobs without an active worker already.
|
||||
.filter(|todo| !todo.active_worker)
|
||||
{
|
||||
if self.workers_queued >= MAX_WORKERS_QUEUED {
|
||||
break;
|
||||
}
|
||||
|
||||
// Find the area of the terrain we want. Because meshing needs to compute things like
|
||||
// ambient occlusion and edge elision, we also need the borders of the chunk's
|
||||
// neighbours too (hence the `- 1` and `+ 1`).
|
||||
@ -199,6 +207,7 @@ impl Terrain {
|
||||
));
|
||||
});
|
||||
todo.active_worker = true;
|
||||
self.workers_queued += 1;
|
||||
}
|
||||
|
||||
// Receive a chunk mesh from a worker thread and upload it to the GPU, then store it.
|
||||
@ -236,6 +245,8 @@ impl Terrain {
|
||||
// since it's either out of date or no longer needed.
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.workers_queued -= 1;
|
||||
}
|
||||
|
||||
// Construct view frustum
|
||||
|
Loading…
Reference in New Issue
Block a user