Use deterministic filenames for shader compilation

This commit is contained in:
baldurk
2020-04-24 12:42:38 +01:00
parent 8edcccd1a7
commit 7560960a9d
5 changed files with 31 additions and 16 deletions
+5 -2
View File
@@ -51,7 +51,10 @@ std::string GetEnvVar(const char *var)
return "";
}
void tmpnam_via_mkstemp(char (&buf)[MAX_PATH])
std::string GetExecutableFilename()
{
snprintf(buf, MAX_PATH - 1, "/tmp/rdoc_tmp_%x", rand());
char path[512] = {0};
readlink("/proc/self/exe", path, 511);
return path;
}
+1 -3
View File
@@ -36,6 +36,4 @@
#define EXECUTABLE_SUFFIX ""
#define get_tmpnam tmpnam_via_mkstemp
void tmpnam_via_mkstemp(char (&buf)[MAX_PATH]);
std::string GetExecutableName();
+13 -9
View File
@@ -348,10 +348,14 @@ std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTa
std::string command_line;
char infile[MAX_PATH] = {};
char outfile[MAX_PATH] = {};
get_tmpnam(infile);
get_tmpnam(outfile);
std::string path = GetExecutableName();
path.erase(path.find_last_of("/\\"));
path += "/tmp";
mkdir(path.c_str());
std::string infile = path + "/input";
std::string outfile = path + "/output";
if(externalCompiler == "glslc")
{
@@ -382,7 +386,7 @@ std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTa
}
else
{
strcat(infile, ".spvasm");
infile += ".spvasm";
}
if(target == SPIRVTarget::opengl)
@@ -440,7 +444,7 @@ std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTa
command_line += infile;
}
FILE *f = fopen(infile, "wb");
FILE *f = fopen(infile.c_str(), "wb");
if(f)
{
fwrite(source_text.c_str(), 1, source_text.size(), f);
@@ -465,7 +469,7 @@ std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTa
return ret;
}
f = fopen(outfile, "rb");
f = fopen(outfile.c_str(), "rb");
if(f)
{
fseek(f, 0, SEEK_END);
@@ -475,8 +479,8 @@ std::vector<uint32_t> CompileShaderToSpv(const std::string &source_text, SPIRVTa
fclose(f);
}
unlink(infile);
unlink(outfile);
unlink(infile.c_str());
unlink(outfile.c_str());
return ret;
}
+8
View File
@@ -100,3 +100,11 @@ std::string GetEnvVar(const char *var)
return "";
}
std::string GetExecutableName()
{
wchar_t curFile[512] = {0};
GetModuleFileNameW(NULL, curFile, 511);
return Wide2UTF8(curFile);
}
+4 -2
View File
@@ -34,6 +34,8 @@
std::string Wide2UTF8(const std::wstring &s);
std::wstring UTF82Wide(const std::string &s);
std::string GetExecutableName();
#define DEBUG_BREAK() \
do \
{ \
@@ -44,10 +46,10 @@ std::wstring UTF82Wide(const std::string &s);
#define popen _popen
#define pclose _pclose
#define get_tmpnam tmpnam_s
#define msleep(time) Sleep(time)
#define mkdir(dir) CreateDirectoryA(dir, NULL)
#define WEXITSTATUS(code) code
#define EXECUTABLE_SUFFIX ".exe"