core/command_queue_mt: Customizable size

Partial backport of 9f654b4 to 3.2
This commit is contained in:
Lyuma 2020-09-24 09:03:19 -07:00
parent 037571d08e
commit 074a098df6
2 changed files with 13 additions and 7 deletions

View File

@ -31,6 +31,7 @@
#include "command_queue_mt.h"
#include "core/os/os.h"
#include "core/project_settings.h"
void CommandQueueMT::lock() {
@ -107,17 +108,22 @@ CommandQueueMT::CommandQueueMT(bool p_sync) {
write_ptr = 0;
dealloc_ptr = 0;
mutex = Mutex::create();
command_mem = (uint8_t *)memalloc(COMMAND_MEM_SIZE);
command_mem_size = GLOBAL_DEF_RST("memory/limits/command_queue/multithreading_queue_size_kb", DEFAULT_COMMAND_MEM_SIZE_KB);
ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/command_queue/multithreading_queue_size_kb", PropertyInfo(Variant::INT, "memory/limits/command_queue/multithreading_queue_size_kb", PROPERTY_HINT_RANGE, "1,4096,1,or_greater"));
command_mem_size *= 1024;
command_mem = (uint8_t *)memalloc(command_mem_size);
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
sync_sems[i].sem = Semaphore::create();
sync_sems[i].in_use = false;
}
if (p_sync)
if (p_sync) {
sync = Semaphore::create();
else
} else {
sync = NULL;
}
}
CommandQueueMT::~CommandQueueMT() {

View File

@ -311,8 +311,7 @@ class CommandQueueMT {
/***** BASE *******/
enum {
COMMAND_MEM_SIZE_KB = 256,
COMMAND_MEM_SIZE = COMMAND_MEM_SIZE_KB * 1024,
DEFAULT_COMMAND_MEM_SIZE_KB = 256,
SYNC_SEMAPHORES = 8
};
@ -320,6 +319,7 @@ class CommandQueueMT {
uint32_t read_ptr;
uint32_t write_ptr;
uint32_t dealloc_ptr;
uint32_t command_mem_size;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex *mutex;
Semaphore *sync;
@ -345,7 +345,7 @@ class CommandQueueMT {
} else {
// ahead of dealloc_ptr, check that there is room
if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + sizeof(uint32_t)) {
if ((command_mem_size - write_ptr) < alloc_size + sizeof(uint32_t)) {
// no room at the end, wrap down;
if (dealloc_ptr == 0) { // don't want write_ptr to become dealloc_ptr
@ -358,7 +358,7 @@ class CommandQueueMT {
}
// if this happens, it's a bug
ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < 8, NULL);
ERR_FAIL_COND_V((command_mem_size - write_ptr) < 8, NULL);
// zero means, wrap to beginning
uint32_t *p = (uint32_t *)&command_mem[write_ptr];