mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Use deterministic filenames for shader compilation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,4 @@
|
||||
|
||||
#define EXECUTABLE_SUFFIX ""
|
||||
|
||||
#define get_tmpnam tmpnam_via_mkstemp
|
||||
|
||||
void tmpnam_via_mkstemp(char (&buf)[MAX_PATH]);
|
||||
std::string GetExecutableName();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user