wait for job system threads to shut down before exiting

This commit is contained in:
Turánszki János
2025-01-16 09:59:43 +01:00
parent 17bf75fd35
commit 13921bc1b0
7 changed files with 19 additions and 5 deletions
+2
View File
@@ -214,5 +214,7 @@ int main(int argc, char *argv[])
int ret = sdl_loop();
wi::jobsystem::ShutDown();
return ret;
}
+2
View File
@@ -72,6 +72,8 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
}
}
wi::jobsystem::ShutDown();
return (int) msg.wParam;
}
+7
View File
@@ -113,6 +113,8 @@ namespace wi::jobsystem
std::atomic_bool alive{ true };
void ShutDown()
{
if (IsShuttingDown())
return;
alive.store(false); // indicate that new jobs cannot be started from this point
bool wake_loop = true;
std::thread waker([&] {
@@ -322,6 +324,11 @@ namespace wi::jobsystem
internal_state.ShutDown();
}
bool IsShuttingDown()
{
return internal_state.alive.load() == false;
}
uint32_t GetThreadCount(Priority priority)
{
return internal_state.resources[int(priority)].numThreads;
+4
View File
@@ -8,6 +8,10 @@ namespace wi::jobsystem
void Initialize(uint32_t maxThreadCount = ~0u);
void ShutDown();
// Returns true if the job system is shutting down
// Long-running (multi-frame) jobs should ideally check this and exit themselves if true
bool IsShuttingDown();
struct JobArgs
{
uint32_t jobIndex; // job index relative to dispatch (like SV_DispatchThreadID in HLSL)
-1
View File
@@ -11,7 +11,6 @@
#endif
#include <SDKDDKVer.h>
#include <windows.h>
#include <tchar.h>
#if WINAPI_FAMILY == WINAPI_FAMILY_GAMES
#define PLATFORM_XBOX
+3 -3
View File
@@ -1803,11 +1803,8 @@ void LoadShaders()
RegisterCustomShader(customShader);
}
wi::jobsystem::Wait(ctx);
for (uint32_t renderPass = 0; renderPass < RENDERPASS_COUNT; ++renderPass)
{
for (uint32_t mesh_shader = 0; mesh_shader <= (device->CheckCapability(GraphicsDeviceCapability::MESH_SHADER) ? 1u : 0u); ++mesh_shader)
@@ -1976,6 +1973,9 @@ void LoadShaders()
wi::jobsystem::Wait(mesh_shader_ctx);
}
if (wi::jobsystem::IsShuttingDown())
return;
ObjectRenderingVariant variant = {};
variant.bits.renderpass = renderPass;
variant.bits.shadertype = shaderType;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 656;
const int revision = 657;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);