Fix race condition identified by TSAN
Guard global variables 'CompileFailed' and 'LinkFailed' in the StandAlone application with atomics.
This commit is contained in:
parent
90f7810584
commit
b0ed478885
@ -51,15 +51,16 @@
|
|||||||
#include "../SPIRV/doc.h"
|
#include "../SPIRV/doc.h"
|
||||||
#include "../SPIRV/disassemble.h"
|
#include "../SPIRV/disassemble.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <array>
|
||||||
#include <cstdlib>
|
#include <atomic>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <array>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "../glslang/OSDependent/osinclude.h"
|
#include "../glslang/OSDependent/osinclude.h"
|
||||||
|
|
||||||
@ -144,8 +145,9 @@ void FreeFileData(char* data);
|
|||||||
void InfoLogMsg(const char* msg, const char* name, const int num);
|
void InfoLogMsg(const char* msg, const char* name, const int num);
|
||||||
|
|
||||||
// Globally track if any compile or link failure.
|
// Globally track if any compile or link failure.
|
||||||
bool CompileFailed = false;
|
std::atomic<int8_t> CompileFailed{0};
|
||||||
bool LinkFailed = false;
|
std::atomic<int8_t> LinkFailed{0};
|
||||||
|
std::atomic<int8_t> CompileOrLinkFailed{0};
|
||||||
|
|
||||||
// array of unique places to leave the shader names and infologs for the asynchronous compiles
|
// array of unique places to leave the shader names and infologs for the asynchronous compiles
|
||||||
std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
|
std::vector<std::unique_ptr<glslang::TWorkItem>> WorkItems;
|
||||||
@ -1166,6 +1168,7 @@ void CompileShaders(glslang::TWorklist& worklist)
|
|||||||
if (Options & EOptionDebug)
|
if (Options & EOptionDebug)
|
||||||
Error("cannot generate debug information unless linking to generate code");
|
Error("cannot generate debug information unless linking to generate code");
|
||||||
|
|
||||||
|
// NOTE: TWorkList::remove is thread-safe
|
||||||
glslang::TWorkItem* workItem;
|
glslang::TWorkItem* workItem;
|
||||||
if (Options & EOptionStdin) {
|
if (Options & EOptionStdin) {
|
||||||
if (worklist.remove(workItem)) {
|
if (worklist.remove(workItem)) {
|
||||||
@ -1442,7 +1445,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
if (shader->preprocess(GetResources(), defaultVersion, ENoProfile, false, false, messages, &str, includer)) {
|
if (shader->preprocess(GetResources(), defaultVersion, ENoProfile, false, false, messages, &str, includer)) {
|
||||||
PutsIfNonEmpty(str.c_str());
|
PutsIfNonEmpty(str.c_str());
|
||||||
} else {
|
} else {
|
||||||
CompileFailed = true;
|
CompileFailed = 1;
|
||||||
}
|
}
|
||||||
StderrIfNonEmpty(shader->getInfoLog());
|
StderrIfNonEmpty(shader->getInfoLog());
|
||||||
StderrIfNonEmpty(shader->getInfoDebugLog());
|
StderrIfNonEmpty(shader->getInfoDebugLog());
|
||||||
@ -1450,7 +1453,7 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! shader->parse(GetResources(), defaultVersion, false, messages, includer))
|
if (! shader->parse(GetResources(), defaultVersion, false, messages, includer))
|
||||||
CompileFailed = true;
|
CompileFailed = 1;
|
||||||
|
|
||||||
if (!compileOnly)
|
if (!compileOnly)
|
||||||
program.addShader(shader);
|
program.addShader(shader);
|
||||||
@ -1496,7 +1499,9 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
|
|
||||||
// Dump SPIR-V
|
// Dump SPIR-V
|
||||||
if (Options & EOptionSpv) {
|
if (Options & EOptionSpv) {
|
||||||
if (CompileFailed || LinkFailed)
|
CompileOrLinkFailed.fetch_or(CompileFailed);
|
||||||
|
CompileOrLinkFailed.fetch_or(LinkFailed);
|
||||||
|
if (static_cast<bool>(CompileOrLinkFailed.load()))
|
||||||
printf("SPIR-V is not generated for failed compile or link\n");
|
printf("SPIR-V is not generated for failed compile or link\n");
|
||||||
else {
|
else {
|
||||||
std::vector<glslang::TIntermediate*> intermediates;
|
std::vector<glslang::TIntermediate*> intermediates;
|
||||||
@ -1555,7 +1560,9 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depencyFileName && !(CompileFailed || LinkFailed)) {
|
CompileOrLinkFailed.fetch_or(CompileFailed);
|
||||||
|
CompileOrLinkFailed.fetch_or(LinkFailed);
|
||||||
|
if (depencyFileName && !static_cast<bool>(CompileOrLinkFailed.load())) {
|
||||||
std::set<std::string> includedFiles = includer.getIncludedFiles();
|
std::set<std::string> includedFiles = includer.getIncludedFiles();
|
||||||
sources.insert(sources.end(), includedFiles.begin(), includedFiles.end());
|
sources.insert(sources.end(), includedFiles.begin(), includedFiles.end());
|
||||||
|
|
||||||
@ -1731,9 +1738,9 @@ int singleMain()
|
|||||||
ShFinalize();
|
ShFinalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CompileFailed)
|
if (CompileFailed.load())
|
||||||
return EFailCompile;
|
return EFailCompile;
|
||||||
if (LinkFailed)
|
if (LinkFailed.load())
|
||||||
return EFailLink;
|
return EFailLink;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user