From 1641c4f788c21ab4f8723657905527a33593cec0 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 3 Jul 2019 00:10:56 +0100 Subject: [PATCH] Added mesh worker queue limit to prevent throttling of meshing queue --- voxygen/src/scene/terrain.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index ed6544eb8c..463884ac47 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -50,6 +50,8 @@ fn mesh_worker( } } +const MAX_WORKERS_QUEUED: usize = 32; + pub struct Terrain { chunks: HashMap, TerrainChunk>, @@ -58,6 +60,7 @@ pub struct Terrain { mesh_send_tmp: mpsc::Sender, mesh_recv: mpsc::Receiver, mesh_todo: HashMap, 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