Browse Source

Do not create ShaderCompiler worker threads when only compiling a single shader variation.

Lasse Öörni 13 years ago
parent
commit
8a0581af7e
1 changed files with 21 additions and 13 deletions
  1. 21 13
      Tools/ShaderCompiler/ShaderCompiler.cpp

+ 21 - 13
Tools/ShaderCompiler/ShaderCompiler.cpp

@@ -361,21 +361,29 @@ void CompileShader(const String& fileName)
             hlslCode_ += hlslFile.ReadLine() + "\n";
             hlslCode_ += hlslFile.ReadLine() + "\n";
     }
     }
     
     
-    // Create and start worker threads. Use all logical CPUs except one to not lock up the computer completely
-    unsigned numWorkerThreads = GetNumLogicalCPUs() - 1;
-    if (!numWorkerThreads)
-        numWorkerThreads = 1;
-    
-    Vector<SharedPtr<WorkerThread> > workerThreads;
-    workerThreads.Resize(numWorkerThreads);
-    for (unsigned i = 0; i < workerThreads.Size(); ++i)
+    if (!compileVariation_)
+    {
+        // Create and start worker threads. Use all logical CPUs except one to not lock up the computer completely
+        unsigned numWorkerThreads = GetNumLogicalCPUs() - 1;
+        if (!numWorkerThreads)
+            numWorkerThreads = 1;
+        
+        Vector<SharedPtr<WorkerThread> > workerThreads;
+        workerThreads.Resize(numWorkerThreads);
+        for (unsigned i = 0; i < workerThreads.Size(); ++i)
+        {
+            workerThreads[i] = new WorkerThread();
+            workerThreads[i]->Start();
+        }
+        // This will wait until the thread functions have stopped
+        for (unsigned i = 0; i < workerThreads.Size(); ++i)
+            workerThreads[i]->Stop();
+    }
+    else
     {
     {
-        workerThreads[i] = new WorkerThread();
-        workerThreads[i]->Start();
+        WorkerThread dummyThread;
+        dummyThread.ThreadFunction();
     }
     }
-    // This will wait until the thread functions have stopped
-    for (unsigned i = 0; i < workerThreads.Size(); ++i)
-        workerThreads[i]->Stop();
     
     
     // Check that all shaders compiled
     // Check that all shaders compiled
     for (List<CompiledVariation>::Iterator i = variations_.Begin(); i != variations_.End(); ++i)
     for (List<CompiledVariation>::Iterator i = variations_.Begin(); i != variations_.End(); ++i)