@@ -79,7 +79,6 @@ static struct {
7979} g_dumpFlags[static_cast <int >(IGC ::Debug::DumpType::END )] = {};
8080
8181std::string g_shaderCorpusName;
82- std::string g_shaderOutputFolder;
8382std::string g_shaderOutputName;
8483
8584} // namespace
@@ -295,101 +294,8 @@ void IGC_DEBUG_API_CALL SetShaderCorpusName(CorpusName name) { g_shaderCorpusNam
295294
296295CorpusName IGC_DEBUG_API_CALL GetShaderCorpusName () { return g_shaderCorpusName.c_str (); }
297296
298- void IGC_DEBUG_API_CALL SetShaderOutputFolder (OutputFolderName name) { g_shaderOutputFolder = name; }
299297void IGC_DEBUG_API_CALL SetShaderOutputName (OutputName name) { g_shaderOutputName = name; }
300298
301- bool needMkDir () {
302- return IGC_IS_FLAG_ENABLED (DumpLLVMIR) || IGC_IS_FLAG_ENABLED (EnableCosDump) ||
303- IGC_IS_FLAG_ENABLED (EnableVISAOutput) || IGC_IS_FLAG_ENABLED (EnableVISABinary) ||
304- IGC_IS_FLAG_ENABLED (EnableVISADumpCommonISA) ||
305- GetDebugFlag (DebugFlag::DUMP_AFTER_PASSES ) || GetDebugFlag (DebugFlag::VISA_OUTPUT ) ||
306- GetDebugFlag (DebugFlag::VISA_BINARY ) || GetDebugFlag (DebugFlag::VISA_DUMPCOMMONISA ) ||
307- IGC_IS_FLAG_ENABLED (EnableCapsDump) || IGC_IS_FLAG_ENABLED (ShaderOverride) ||
308- IGC_IS_FLAG_ENABLED (GenerateOptionsFile);
309- }
310-
311- OutputFolderName IGC_DEBUG_API_CALL GetBaseIGCOutputFolder () {
312- static std::mutex m;
313- std::lock_guard<std::mutex> lck (m);
314- static std::string IGCBaseFolder;
315- if (IGCBaseFolder != " " ) {
316- return IGCBaseFolder.c_str ();
317- }
318- #if defined(_WIN64) || defined(_WIN32)
319- if (!IGC_IS_FLAG_ENABLED (DumpToCurrentDir) && !IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
320- bool needMkdir = needMkDir ();
321-
322- char dumpPath[256 ];
323-
324- sprintf_s (dumpPath, " c:\\ Intel\\ " );
325- if (GetFileAttributesA (dumpPath) != FILE_ATTRIBUTE_DIRECTORY && needMkdir) {
326- _mkdir (dumpPath);
327- }
328-
329- sprintf_s (dumpPath, " c:\\ Intel\\ IGC\\ " );
330- if (GetFileAttributesA (dumpPath) != FILE_ATTRIBUTE_DIRECTORY && needMkdir) {
331- _mkdir (dumpPath);
332- }
333-
334- // Make sure we can write in the dump folder as the app may be sandboxed
335- if (needMkdir) {
336- int tmp_id = _getpid ();
337- std::string testFilename = std::string (dumpPath) + " testfile" + std::to_string (tmp_id);
338- HANDLE testFile =
339- CreateFileA (testFilename.c_str (), GENERIC_WRITE , 0 , NULL , CREATE_ALWAYS , FILE_FLAG_DELETE_ON_CLOSE , NULL );
340- if (testFile == INVALID_HANDLE_VALUE ) {
341- char temppath[256 ];
342- if (GetTempPathA (sizeof (temppath), temppath) != 0 ) {
343- sprintf_s (dumpPath, " %sIGC\\ " , temppath);
344- }
345- } else {
346- CloseHandle (testFile);
347- }
348- }
349-
350- if (GetFileAttributesA (dumpPath) != FILE_ATTRIBUTE_DIRECTORY && needMkdir) {
351- _mkdir (dumpPath);
352- }
353-
354- IGCBaseFolder = dumpPath;
355- } else if (IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
356- std::string dumpPath = " c:\\ Intel\\ IGC\\ " ; // default if something goes wrong
357- const char *custom_dir = IGC_GET_REGKEYSTRING (DumpToCustomDir);
358- if (custom_dir != nullptr && strlen (custom_dir) > 0 ) {
359- dumpPath = custom_dir;
360- }
361-
362- char pathBuf[256 ];
363- iSTD::CreateAppOutputDir (pathBuf, 256 , dumpPath.c_str (), false , false , false );
364-
365- IGCBaseFolder = pathBuf;
366- }
367- #elif defined ANDROID
368-
369- if (IGC_IS_FLAG_ENABLED (DumpToCurrentDir))
370- return " " ;
371- IGCBaseFolder = " /sdcard/intel/igc/" ;
372-
373- #elif defined __linux__
374- if (!IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
375- IGCBaseFolder = " /tmp/IntelIGC/" ;
376- } else {
377- std::string dumpPath = " /tmp/IntelIGC/" ; // default if something goes wrong
378- const char *custom_dir = IGC_GET_REGKEYSTRING (DumpToCustomDir);
379- if (custom_dir != nullptr && strlen (custom_dir) > 0 ) {
380- dumpPath = custom_dir;
381- dumpPath += " /" ;
382- }
383-
384- char pathBuf[256 ];
385- iSTD::CreateAppOutputDir (pathBuf, 256 , dumpPath.c_str (), false , false , false );
386-
387- IGCBaseFolder = pathBuf;
388- }
389- #endif
390- return IGCBaseFolder.c_str ();
391- }
392-
393299std::string &GetShaderOverridePathString () {
394300 static std::string path = []() -> std::string {
395301 if (IGC_IS_FLAG_DISABLED (ShaderOverride)) {
@@ -425,82 +331,6 @@ OutputFolderName IGC_DEBUG_API_CALL GetShaderOverridePath() {
425331 return overridePath.c_str ();
426332}
427333
428- OutputFolderName IGC_DEBUG_API_CALL GetShaderOutputFolder () {
429- static std::mutex m;
430- std::lock_guard<std::mutex> lck (m);
431- if (g_shaderOutputFolder != " " && doesRegexMatch (g_shaderOutputFolder, IGC_GET_REGKEYSTRING (ShaderDumpRegexFilter))) {
432- return g_shaderOutputFolder.c_str ();
433- }
434- #if defined(_WIN64) || defined(_WIN32)
435- if (!IGC_IS_FLAG_ENABLED (DumpToCurrentDir) && !IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
436- char dumpPath[256 ];
437- sprintf_s (dumpPath, " %s" , GetBaseIGCOutputFolder ());
438- char appPath[MAX_PATH ] = {0 };
439- // check a process id and make an adequate directory for it:
440-
441- if (::GetModuleFileNameA (NULL , appPath, sizeof (appPath) - 1 )) {
442- std::string appPathStr = std::string (appPath);
443- int pos = appPathStr.find_last_of (" \\ " ) + 1 ;
444-
445- if (IGC_IS_FLAG_ENABLED (ShaderDumpPidDisable)) {
446- sprintf_s (dumpPath, " %s%s\\ " , dumpPath, appPathStr.substr (pos, MAX_PATH ).c_str ());
447- } else {
448- sprintf_s (dumpPath, " %s%s_%d\\ " , dumpPath, appPathStr.substr (pos, MAX_PATH ).c_str (), _getpid ());
449- }
450- } else {
451- sprintf_s (dumpPath, " %sunknownProcess_%d\\ " , dumpPath, _getpid ());
452- }
453-
454- if (needMkDir () && doesRegexMatch (dumpPath, IGC_GET_REGKEYSTRING (ShaderDumpRegexFilter))) {
455- if (GetFileAttributesA (dumpPath) != FILE_ATTRIBUTE_DIRECTORY ) {
456- _mkdir (dumpPath);
457- }
458- g_shaderOutputFolder = dumpPath;
459- } else {
460- // To make the path always invalid.
461- g_shaderOutputFolder = " NUL\\ " ;
462- }
463- } else if (IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
464- char pathBuf[256 ];
465- iSTD::CreateAppOutputDir (pathBuf, 256 , GetBaseIGCOutputFolder (), false , true ,
466- !IGC_IS_FLAG_ENABLED (ShaderDumpPidDisable));
467- g_shaderOutputFolder = pathBuf;
468- }
469- #elif defined ANDROID
470-
471- if (IGC_IS_FLAG_ENABLED (DumpToCurrentDir))
472- return " " ;
473-
474- if (!SysUtils::CreateDir (GetBaseIGCOutputFolder (), true , IGC_IS_FLAG_DISABLED (ShaderDumpPidDisable),
475- &g_shaderOutputFolder))
476-
477- g_shaderOutputFolder = " " ;
478-
479- #elif defined __linux__
480- if (!IGC_IS_FLAG_ENABLED (DumpToCurrentDir) && g_shaderOutputFolder == " " && !IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
481- bool needMkdir =
482- needMkDir () && doesRegexMatch (GetBaseIGCOutputFolder (), IGC_GET_REGKEYSTRING (ShaderDumpRegexFilter));
483-
484- char path[MAX_PATH ] = {0 };
485- bool pidEnabled = IGC_IS_FLAG_DISABLED (ShaderDumpPidDisable);
486-
487- if (needMkdir) {
488- iSTD::CreateAppOutputDir (path, MAX_PATH , GetBaseIGCOutputFolder (), false , true , pidEnabled);
489- g_shaderOutputFolder = path;
490- } else {
491- // To make the path always invalid.
492- g_shaderOutputFolder = " /dev/null/" ;
493- }
494- } else if (IGC_IS_FLAG_ENABLED (DumpToCustomDir)) {
495- char pathBuf[256 ];
496- iSTD::CreateAppOutputDir (pathBuf, 256 , GetBaseIGCOutputFolder (), false , false , false );
497- g_shaderOutputFolder = pathBuf;
498- }
499-
500- #endif
501- return g_shaderOutputFolder.c_str ();
502- }
503-
504334OutputName IGC_DEBUG_API_CALL GetFunctionDebugFile () {
505335 if (IGC_GET_FLAG_VALUE (SelectiveFunctionControl) != 0 ) {
506336 static std::mutex m;
0 commit comments