From 1a431b3894933df75bae4cc5a26fe10bbb3352ec Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 28 Jan 2025 09:53:34 +0100 Subject: [PATCH] glgsg: make async texture transfer threads configurable --- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 6 +++--- panda/src/glstuff/glmisc_src.cxx | 13 +++++++++++++ panda/src/glstuff/glmisc_src.h | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 1d3315aa52..b29387463b 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -715,10 +715,10 @@ CLP(GraphicsStateGuardian)(GraphicsEngine *engine, GraphicsPipe *pipe) : #endif #ifdef HAVE_THREADS - //XXX having a fixed number of threads is not a great idea. We ought to have - // a common thread pool that is sized based on the available number of CPUs. AsyncTaskManager *task_mgr = AsyncTaskManager::get_global_ptr(); - _async_chain = task_mgr->make_task_chain("texture_copy", 2, TP_normal); + _async_chain = task_mgr->make_task_chain("gl_texture_transfer", + gl_texture_transfer_num_threads, + gl_texture_transfer_thread_priority); #endif #ifdef DO_PSTATS diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 184b83523c..0cc5326a15 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -326,6 +326,19 @@ ConfigVariableBool gl_depth_zero_to_one "range from 0 to 1, matching other graphics APIs. This setting " "requires OpenGL 4.5, or NVIDIA GeForce 8+ hardware.")); +ConfigVariableInt gl_texture_reload_num_threads + ("gl-texture-transfer-num-threads", 2, + PRC_DESC("The number of threads that will be started to upload and download " + "texture data asynchronously, either via the setup_async_transfer " + "interface on the the Texture class or via the async screenshot " + "interface.")); + +ConfigVariableEnum gl_texture_transfer_thread_priority + ("gl-texture-transfer-thread-priority", TP_normal, + PRC_DESC("The default thread priority to assign to the threads created for " + "asynchronous texture transfers. The default is 'normal'; you may " + "also specify 'low', 'high', or 'urgent'.")); + extern ConfigVariableBool gl_parallel_arrays; void CLP(init_classes)() { diff --git a/panda/src/glstuff/glmisc_src.h b/panda/src/glstuff/glmisc_src.h index 7ee108d02e..deb219dc5a 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -17,6 +17,7 @@ #include "configVariableEnum.h" #include "geomEnums.h" #include "coordinateSystem.h" +#include "threadPriority.h" // Define some macros to transparently map to the double or float versions of // the OpenGL function names. @@ -76,6 +77,8 @@ extern ConfigVariableBool gl_support_shadow_filter; extern ConfigVariableBool gl_support_vertex_array_bgra; extern ConfigVariableBool gl_force_image_bindings_writeonly; extern ConfigVariableEnum gl_coordinate_system; +extern ConfigVariableInt gl_texture_transfer_num_threads; +extern ConfigVariableEnum gl_texture_transfer_thread_priority; extern EXPCL_GL void CLP(init_classes)();