#include "tier0/lib.h" #include "tier0/commandline.h" #include "tier1/appinit.h" #include "tier1/utlstring.h" #include "tier2/ifilesystem.h" #include "shadercompiler/icompiler.h" #include "materialsystem/compiledshadermgr.h" static IShaderCompiler *s_pVulkanSpirvCompiler; static const char *s_szGameRoot; ICompiledShaderManager *g_pShaderManager; void CompileShader( const char *szShader ) { CCompiledShader shader; if (V_strcmp("shader",Plat_GetExtension(szShader))) return; s_pVulkanSpirvCompiler->CompileShader(szShader, &shader); Plat_MakeDir("../build", 0755); Plat_MakeDir("../build/funnygame", 0755); Plat_MakeDir("../build/funnygame/assets", 0755); Plat_MakeDir("../build/funnygame/assets/shaders", 0755); CUtlString szOutputDirectory = szShader; szOutputDirectory.RemoveHead(strlen(s_szGameRoot)+1); szOutputDirectory.AppendHead("../build/funnygame/assets/"); szOutputDirectory.AppendTail("_c"); printf("%s\n",szOutputDirectory.GetString()); g_pShaderManager->WriteToFile(&shader, szOutputDirectory); }; void PrintHelp() { printf("Usage: fsc -i [shader folder] -o [game root]"); Plat_Exit(0); } int main( int c, char **v ) { CUtlString szExePath = Plat_GetExecutablePath(); CUtlString szOriginalPath = Plat_GetWorkingDir(); CommandLine()->CreateCommandLine(c, v); Plat_SetWorkingDir(szExePath.GetDirectory()); CreateInterfaceFn g_pCompilerFactory = Sys_GetFactory("ShaderCompiler"); Plat_SetWorkingDir(szOriginalPath); g_pShaderManager = (ICompiledShaderManager*)g_pCompilerFactory(COMPILED_SHADER_MANAGER_INTERFACE_VERSION, NULL); CreateInterfaceFn pFilesystemFactory = Sys_GetFactory("filesystem_std"); filesystem = (IFileSystem*)pFilesystemFactory(FILESYSTEM_INTERFACE_VERSION, NULL); filesystem->Init(); s_pVulkanSpirvCompiler = (IShaderCompiler*)g_pCompilerFactory(SLANG_SHADER_COMPILER_SPIRV_VULKAN, NULL); s_pVulkanSpirvCompiler->Init(); const char *szInputDirectory = CommandLine()->ParamValue("-i"); if (!szInputDirectory) PrintHelp(); s_szGameRoot = szInputDirectory; CUtlString szShaderDirectory = CUtlString("%s/shaders\n", szInputDirectory); Plat_ListDirRecursive(szInputDirectory, CompileShader, NULL); s_pVulkanSpirvCompiler->Shutdown(); return 0; }