public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = GetStageFlag(arguments.GetString("ShaderStage")); var core = arguments.GetString("Core"); var args = string.Empty; if (shaderCode.Language == LanguageNames.SpirV) { var spirVEntryPoint = arguments.GetString("EntryPoint"); args += "--spirv "; args += $"--spirv_entrypoint_name {spirVEntryPoint}"; } using (var tempFile = TempFile.FromShaderCode(shaderCode)) { ProcessHelper.Run( CommonParameters.GetBinaryPath("mali", arguments, "malisc.exe"), $"{stage} -c {core} {args} {tempFile.FilePath}", out var stdOutput, out var stdError); return(new ShaderCompilerResult( true, null, null, new ShaderCompilerOutput("Output", null, stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var encodeFlags = arguments.GetBoolean("StripDebugInfo") ? 1 : 0; ProcessHelper.Run( CommonParameters.GetBinaryPath("smol-v", arguments, "ShaderPlayground.Shims.Smolv.exe"), $"\"{tempFile.FilePath}\" 0 {encodeFlags} \"{outputPath}\"", out var stdOutput, out var _); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); var hasCompilationError = string.IsNullOrEmpty(stdOutput); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, binaryOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Stats", null, stdOutput))); } }
private static string RunGlslValidator(ShaderCompilerArguments arguments, string stage, string codeFilePath, string args) { ProcessHelper.Run( CommonParameters.GetBinaryPath("glslang", arguments, "glslangValidator.exe"), $"-S {stage} -d {args} {codeFilePath}", out var stdOutput, out var stdError); // First line is always full path of input file - remove that. string RemoveCodeFilePath(string value) { return((value != null && value.StartsWith(codeFilePath)) ? value.Substring(codeFilePath.Length).Trim() : value); } stdOutput = RemoveCodeFilePath(stdOutput); stdError = RemoveCodeFilePath(stdError); if (!string.IsNullOrWhiteSpace(stdError)) { return(stdError); } if (!string.IsNullOrWhiteSpace(stdOutput)) { return(stdOutput); } return(null); }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var lang = outputLanguage == LanguageNames.Metal ? 14 // LANG_METAL : 0; // LANG_DEFAULT ProcessHelper.Run( CommonParameters.GetBinaryPath("hlslcc", arguments, "ShaderPlayground.Shims.HLSLcc.exe"), $"\"{tempFile.FilePath}\" {lang} \"{outputPath}\"", out var _, out var _); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, textOutput), null, new ShaderCompilerOutput("Output", outputLanguage, textOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("yari-v", arguments, "ShaderPlayground.Shims.Yariv.exe"), $"\"{tempFile.FilePath}\" 1 0 \"{outputPath}\"", out var stdOutput, out var _); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); var hasCompilationError = string.IsNullOrEmpty(stdOutput); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, binaryOutput) : null, hasCompilationError ? (int?)1 : null)); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var args = "--ispc"; using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-cross-ispc", arguments, "spirv-cross.exe"), $"--ispc-interface-name {arguments.GetString("IspcInterfaceName")} --output \"{outputPath}\" \"{tempFile.FilePath}\" {args}", out var _, out var stdError); var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdError); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( !hasCompilationErrors, new ShaderCode(LanguageNames.Ispc, textOutput), hasCompilationErrors ? (int?)1 : null, new ShaderCompilerOutput("Output", LanguageNames.Ispc, textOutput), new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdError : "<No compilation errors>"))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = arguments.GetString("ShaderStage"); var entryPoint = arguments.GetString("EntryPoint"); var glslVersion = arguments.GetString("GlslVersion"); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( Path.Combine(AppContext.BaseDirectory, "Binaries", "XShaderCompiler", "xsc.exe"), $"-T {stage} -E {entryPoint} -Vout {glslVersion} -o \"{outputPath}\" \"{tempFile.FilePath}\"", out var stdOutput, out var _); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); var hasCompilationErrors = string.IsNullOrWhiteSpace(textOutput); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( new ShaderCode(LanguageNames.Glsl, textOutput), hasCompilationErrors ? (int?)1 : null, new ShaderCompilerOutput("Output", LanguageNames.Glsl, textOutput), new ShaderCompilerOutput("Build output", null, stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("zstd", arguments, "zstd.exe"), $"-{arguments.GetString("CompressionLevel")} -v \"{tempFile.FilePath}\" -o \"{outputPath}\"", out var _, out var stdError); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", null, stdError))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-markv.exe"), $"d --comments --model={arguments.GetString("Model")} -o \"{outputPath}\" \"{tempFile.FilePath}\"", out var stdOutput, out var stdError); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", outputLanguage, stdError))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("miniz", arguments, "ShaderPlayground.Shims.Miniz.exe"), $"\"{tempFile.FilePath}\" {arguments.GetString("CompressionLevel")} \"{outputPath}\"", out var _, out var _); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", null, $"Compressed {shaderCode.Binary.Length} bytes into {binaryOutput.Length} bytes"))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var args = string.Empty; switch (shaderCode.Language) { case LanguageNames.Hlsl: args += $" --function {arguments.GetString("EntryPoint")}"; args += $" --profile {arguments.GetString("TargetProfile")}"; args += $" -s hlsl --api {arguments.GetString("Api")}"; break; case LanguageNames.Dxbc: args += " -s dxbc --api dx11"; break; case LanguageNames.Dxil: args += " -s dxbc --api dx12"; break; default: throw new InvalidOperationException(); } using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPrefix = $"{Path.ChangeExtension(tempFile.FilePath, null)}out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("intelshaderanalyzer", arguments, "IntelShaderAnalyzer.exe"), $"{args} \"{tempFile.FilePath}\" --isa \"{outputPrefix}\"", out var stdOutput, out _); var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdOutput); var outputFileNamePrefix = Path.GetFileNameWithoutExtension(outputPrefix); var outputs = new List <ShaderCompilerOutput>(); foreach (var file in Directory.GetFiles(Path.GetDirectoryName(outputPrefix), outputFileNamePrefix + "*.asm")) { outputs.Add(new ShaderCompilerOutput( Path.GetFileNameWithoutExtension(file).Substring(outputFileNamePrefix.Length), null, File.ReadAllText(file))); File.Delete(file); } outputs.Add(new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdOutput : "<No compilation errors>")); return(new ShaderCompilerResult( !hasCompilationErrors, null, hasCompilationErrors ? (int?)outputs.Count : null, outputs.ToArray())); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var compressionLevelArgs = string.Empty; switch (arguments.GetString("CompressionLevel")) { case "0": compressionLevelArgs = "-a0 -d14 -fb32"; break; case "1": compressionLevelArgs = "-a0 -d16 -fb32"; break; case "2": compressionLevelArgs = "-a0 -d18 -fb32"; break; case "3": compressionLevelArgs = "-a0 -d20 -fb32"; break; case "4": compressionLevelArgs = "-a0 -d22 -fb32"; break; case "5": compressionLevelArgs = "-a1 -d24 -fb32"; break; case "6": compressionLevelArgs = "-a1 -d25 -fb32"; break; } ProcessHelper.Run( CommonParameters.GetBinaryPath("lzma", arguments, "lzma.exe"), $"e \"{tempFile.FilePath}\" \"{outputPath}\" {compressionLevelArgs}", out var stdOutput, out var _); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", null, stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var args = $"-entry {arguments.GetString("EntryPoint")}"; args += $" -profile {arguments.GetString("Profile")}"; var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); switch (outputLanguage) { case LanguageNames.Glsl: args += " -target glsl"; break; case LanguageNames.Hlsl: args += " -target hlsl"; break; case LanguageNames.Cuda: args += " -target cuda"; break; case LanguageNames.Cpp: args += " -target cpp"; break; case LanguageNames.Ptx: args += " -target ptx"; break; } using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("slang", arguments, "slangc.exe"), $"\"{tempFile.FilePath}\" -o \"{outputPath}\" {args}", out var _, out var stdError); var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdError); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( !hasCompilationErrors, new ShaderCode(outputLanguage, textOutput), hasCompilationErrors ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, textOutput), new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdError : "<No compilation errors>"))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = arguments.GetString("ShaderStage"); var target = arguments.GetString("Target"); var targetOption = string.Empty; switch (target) { case SpirVVulkan1_0: targetOption = "--target-env vulkan1.0"; break; case SpirVVulkan1_1: targetOption = "--target-env vulkan1.1"; break; case SpirVOpenGL: targetOption = "--target-env opengl"; break; } if (shaderCode.Language == LanguageNames.Hlsl) { targetOption += " -D"; targetOption += $" -e {arguments.GetString("EntryPoint")}"; } using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var binaryPath = $"{tempFile.FilePath}.o"; var args = targetOption + $" -o \"{binaryPath}\" --auto-map-locations"; var validationErrors = RunGlslValidator(arguments, stage, tempFile, args); var spirv = RunGlslValidator(arguments, stage, tempFile, args + " -H"); var ast = RunGlslValidator(arguments, stage, tempFile, args + " -i"); var binaryOutput = FileHelper.ReadAllBytesIfExists(binaryPath); FileHelper.DeleteIfExists(binaryPath); var hasValidationErrors = !string.IsNullOrWhiteSpace(validationErrors); return(new ShaderCompilerResult( !hasValidationErrors, new ShaderCode(LanguageNames.SpirV, binaryOutput), hasValidationErrors ? 2 : (int?)null, new ShaderCompilerOutput("Disassembly", LanguageNames.SpirV, spirv), new ShaderCompilerOutput("AST", null, ast), new ShaderCompilerOutput("Validation", null, hasValidationErrors ? validationErrors : "<No validation errors>"))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var entryPoint = arguments.GetString("EntryPoint"); var targetProfile = arguments.GetString("TargetProfile"); var disableOptimizations = arguments.GetBoolean("DisableOptimizations"); var optimizationLevel = Convert.ToInt32(arguments.GetString("OptimizationLevel")); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var fcPath = $"{tempFile.FilePath}.fc"; var fePath = $"{tempFile.FilePath}.fe"; var foPath = $"{tempFile.FilePath}.fo"; var args = $"--target {targetProfile} --entrypoint {entryPoint} --optimizationlevel {optimizationLevel}"; args += $" --assemblyfile \"{fcPath}\" --errorsfile \"{fePath}\" --objectfile \"{foPath}\""; if (disableOptimizations) { args += " --disableoptimizations"; } var fxcShimPath = CommonParameters.GetBinaryPath("fxc", arguments, "ShaderPlayground.Shims.Fxc.dll"); ProcessHelper.Run( "dotnet.exe", $"\"{fxcShimPath}\" {args} \"{tempFile.FilePath}\"", out var _, out var _); int?selectedOutputIndex = null; var disassembly = FileHelper.ReadAllTextIfExists(fcPath); if (string.IsNullOrWhiteSpace(disassembly)) { disassembly = "<Compilation error occurred>"; selectedOutputIndex = 1; } var binaryOutput = FileHelper.ReadAllBytesIfExists(foPath); var buildOutput = FileHelper.ReadAllTextIfExists(fePath); FileHelper.DeleteIfExists(fcPath); FileHelper.DeleteIfExists(fePath); FileHelper.DeleteIfExists(foPath); return(new ShaderCompilerResult( selectedOutputIndex == null, new ShaderCode(LanguageNames.Dxbc, binaryOutput), selectedOutputIndex, new ShaderCompilerOutput("Disassembly", LanguageNames.Dxbc, disassembly), new ShaderCompilerOutput("Build output", null, buildOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var args = string.Empty; var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); switch (outputLanguage) { case LanguageNames.Glsl: args += ""; // TODO break; case LanguageNames.Metal: args += " --msl"; break; case LanguageNames.Hlsl: args += " --hlsl"; break; case LanguageNames.Cpp: args += " --cpp"; break; } args += $" --entry {arguments.GetString("EntryPoint")}"; using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( Path.Combine(AppContext.BaseDirectory, "Binaries", "SpirVCross", "spirv-cross.exe"), $"--output \"{outputPath}\" \"{tempFile.FilePath}\" {args}", out var _, out var stdError); var hasCompilationErrors = !string.IsNullOrWhiteSpace(stdError); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( new ShaderCode(outputLanguage, textOutput), hasCompilationErrors ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, textOutput), new ShaderCompilerOutput("Errors", null, hasCompilationErrors ? stdError : "<No compilation errors>"))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var errorPath = $"{tempFile.FilePath}.error"; string outputArg; switch (outputLanguage) { case LanguageNames.Glsl: outputArg = "e"; break; case LanguageNames.Hlsl: outputArg = "h11"; break; default: throw new ArgumentOutOfRangeException(); } string RunCompiler(string arg) { ProcessHelper.Run( CommonParameters.GetBinaryPath("angle", arguments, "shader_translator.exe"), $"{arg} -b={outputArg} \"{tempFile.FilePath}\"", out var result, out var _); return(result); } var intermediateTree = RunCompiler("-i"); var translatedCode = RunCompiler("-o"); var metadata = RunCompiler("-u"); var hasCompilationError = translatedCode.Contains("\nERROR: "); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, translatedCode) : null, hasCompilationError ? (int?)0 : null, new ShaderCompilerOutput("Output", outputLanguage, translatedCode), new ShaderCompilerOutput("Intermediate tree", null, intermediateTree), new ShaderCompilerOutput("Metadata", null, metadata))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var options = string.Empty; if (arguments.GetBoolean("OptimizeForPerformance")) { options += "-O "; } if (arguments.GetBoolean("OptimizeForSize")) { options += "-Os "; } ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-opt.exe"), $"{options} \"{tempFile.FilePath}\" -o \"{outputPath}\"", out var _, out var _); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); var textOutputPath = $"{tempFile.FilePath}.txt"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-dis.exe"), $"-o \"{textOutputPath}\" \"{outputPath}\"", out var _, out var _); FileHelper.DeleteIfExists(outputPath); var textOutput = FileHelper.ReadAllTextIfExists(textOutputPath); FileHelper.DeleteIfExists(textOutputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", outputLanguage, textOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.spv"; ProcessHelper.Run( CommonParameters.GetBinaryPath("clspv", arguments, "clspv.exe"), $"{arguments.GetString(CommonParameters.ExtraOptionsParameter.Name)} \"{tempFile.FilePath}\" -o \"{outputPath}\"", out var stdOutput, out var stdError); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); var hasCompilationError = binaryOutput == null; var textOutput = ""; if (!hasCompilationError) { var textOutputPath = $"{tempFile.FilePath}.txt"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-dis.exe"), $"-o \"{textOutputPath}\" \"{outputPath}\"", out var _, out var _); textOutput = FileHelper.ReadAllTextIfExists(textOutputPath); FileHelper.DeleteIfExists(textOutputPath); } if (!string.IsNullOrWhiteSpace(stdOutput)) { stdError += Environment.NewLine + stdOutput; } FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(LanguageNames.SpirV, binaryOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Assembly", LanguageNames.SpirV, textOutput), new ShaderCompilerOutput("Output", null, stdError))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var shaderType = arguments.GetString("ShaderType") == "Vertex" ? "-vs" : "-fs"; string targetLanguage = null; switch (outputLanguage) { case LanguageNames.Glsl: targetLanguage = "-glsl"; break; case LanguageNames.Hlsl: targetLanguage = "-hlsl"; break; case LanguageNames.Metal: targetLanguage = "-metal"; break; default: throw new InvalidOperationException(); } var entryPoint = arguments.GetString("EntryPoint"); ProcessHelper.Run( CommonParameters.GetBinaryPath("hlslparser", arguments, "hlslparser.exe"), $"{shaderType} {targetLanguage} \"{tempFile.FilePath}\" {entryPoint}", out var stdOutput, out var _); var hasCompilationError = stdOutput.Contains("failed, aborting"); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, stdOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { using (var tempFile = TempFile.FromShaderCode(shaderCode)) { ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-cfg.exe"), $"\"{tempFile.FilePath}\"", out var stdOutput, out var _); return(new ShaderCompilerResult( true, null, null, new ShaderCompilerOutput("Output", "graphviz", stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; Directory.CreateDirectory(outputPath); var stripArgument = string.Empty; if (arguments.GetBoolean("Strip")) { stripArgument = "--strip-all"; } ProcessHelper.Run( CommonParameters.GetBinaryPath("glslang", arguments, "spirv-remap.exe"), $"--map {arguments.GetString("Map")} --dce {arguments.GetString("Dce")} --opt {arguments.GetString("Opt")} {stripArgument} --input \"{tempFile.FilePath}\" --output \"{outputPath}\"", out var _, out var _); var outputFile = Path.Combine(outputPath, Path.GetFileName(tempFile.FilePath)); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputFile); var textOutputPath = $"{tempFile.FilePath}.txt"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-dis.exe"), $"-o \"{textOutputPath}\" \"{outputFile}\"", out var _, out var _); FileHelper.DeleteDirectoryIfExists(outputPath); var textOutput = FileHelper.ReadAllTextIfExists(textOutputPath); FileHelper.DeleteIfExists(textOutputPath); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, binaryOutput), null, new ShaderCompilerOutput("Output", outputLanguage, textOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-as.exe"), $"-o \"{outputPath}\" --preserve-numeric-ids --target-env {arguments.GetString("TargetEnv")} \"{tempFile.FilePath}\"", out var _, out var stdError); var binaryOutput = FileHelper.ReadAllBytesIfExists(outputPath); var hasCompilationError = !string.IsNullOrEmpty(stdError); string textOutput = null; if (!hasCompilationError) { var textOutputPath = $"{tempFile.FilePath}.txt"; ProcessHelper.Run( CommonParameters.GetBinaryPath("spirv-tools", arguments, "spirv-dis.exe"), $"-o \"{textOutputPath}\" \"{outputPath}\"", out var _, out var _); textOutput = FileHelper.ReadAllTextIfExists(textOutputPath); FileHelper.DeleteIfExists(textOutputPath); } FileHelper.DeleteIfExists(outputPath); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, binaryOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, textOutput), new ShaderCompilerOutput("Build errors", null, stdError))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = GetStageFlag(arguments.GetString("ShaderStage")); var core = arguments.GetString("Core"); var maliscBinaryPath = CommonParameters.GetBinaryPath("mali", arguments, "malisc.exe"); var maliocBinaryPath = CommonParameters.GetBinaryPath("mali", arguments, "malioc.exe"); var isMalisc = File.Exists(maliscBinaryPath); var args = string.Empty; if (shaderCode.Language == LanguageNames.SpirV) { args += "--spirv"; if (isMalisc) { var spirVEntryPoint = arguments.GetString("EntryPoint"); args += $" --spirv_entrypoint_name {spirVEntryPoint}"; } } if (!isMalisc) { args += $" --{arguments.GetString("API")}"; } using (var tempFile = TempFile.FromShaderCode(shaderCode)) { ProcessHelper.Run( isMalisc ? maliscBinaryPath : maliocBinaryPath, $"{stage} -c {core} {args} {tempFile.FilePath}", out var stdOutput, out var stdError); return(new ShaderCompilerResult( true, null, !string.IsNullOrWhiteSpace(stdError) ? (int?)1 : null, new ShaderCompilerOutput("Output", null, stdOutput), new ShaderCompilerOutput("Errors", null, stdError))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = arguments.GetString("ShaderStage"); var entryPoint = arguments.GetString("EntryPoint"); var glslVersion = arguments.GetString("GlslVersion"); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; ProcessHelper.Run( CommonParameters.GetBinaryPath("xshadercompiler", arguments, "xsc.exe"), $"-T {stage} -E {entryPoint} -Vout {glslVersion} -o \"{outputPath}\" \"{tempFile.FilePath}\"", out var stdOutput, out var _); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); var hasCompilationErrors = string.IsNullOrWhiteSpace(textOutput); FileHelper.DeleteIfExists(outputPath); string ast = null; if (!hasCompilationErrors) { ProcessHelper.Run( CommonParameters.GetBinaryPath("xshadercompiler", arguments, "xsc.exe"), $"-E {entryPoint} -Valid --show-ast \"{tempFile.FilePath}\"", out ast, out var _); } return(new ShaderCompilerResult( !hasCompilationErrors, new ShaderCode(LanguageNames.Glsl, textOutput), hasCompilationErrors ? (int?)1 : null, new ShaderCompilerOutput("Output", LanguageNames.Glsl, textOutput), new ShaderCompilerOutput("Build output", null, stdOutput), new ShaderCompilerOutput("AST", null, ast))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var errorPath = $"{tempFile.FilePath}.error"; var shaderType = arguments.GetString("ShaderType") == "Vertex" ? 0 // EShLangVertex : 1; // EShLangFragment var targetVersion = Array.IndexOf(TargetVersionOptions, arguments.GetString("TargetVersion")); var entryPoint = arguments.GetString("EntryPoint"); ProcessHelper.Run( CommonParameters.GetBinaryPath("hlsl2glsl", arguments, "ShaderPlayground.Shims.Hlsl2Glsl.exe"), $"\"{tempFile.FilePath}\" {shaderType} {targetVersion} {entryPoint} \"{outputPath}\" \"{errorPath}\"", out var _, out var _); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); var errorOutput = FileHelper.ReadAllTextIfExists(errorPath); FileHelper.DeleteIfExists(outputPath); FileHelper.DeleteIfExists(errorPath); var hasCompilationError = !string.IsNullOrEmpty(errorOutput); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, textOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, textOutput), new ShaderCompilerOutput("Build errors", null, errorOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputPath = $"{tempFile.FilePath}.out"; var errorPath = $"{tempFile.FilePath}.error"; var targetVersion = outputLanguage == LanguageNames.Metal ? 3 // kGlslTargetMetal : 0; // kGlslTargetOpenGL var shaderType = arguments.GetString("ShaderType") == "Vertex" ? 0 // kGlslOptShaderVertex : 1; // kGlslOptShaderFragment ProcessHelper.Run( CommonParameters.GetBinaryPath("glsl-optimizer", arguments, "ShaderPlayground.Shims.GlslOptimizer.exe"), $"\"{tempFile.FilePath}\" {targetVersion} {shaderType} \"{outputPath}\" \"{errorPath}\"", out var _, out var _); var textOutput = FileHelper.ReadAllTextIfExists(outputPath); var errorOutput = FileHelper.ReadAllTextIfExists(errorPath); FileHelper.DeleteIfExists(outputPath); FileHelper.DeleteIfExists(errorPath); var hasCompilationError = !string.IsNullOrEmpty(errorOutput); return(new ShaderCompilerResult( !hasCompilationError, !hasCompilationError ? new ShaderCode(outputLanguage, textOutput) : null, hasCompilationError ? (int?)1 : null, new ShaderCompilerOutput("Output", outputLanguage, textOutput), new ShaderCompilerOutput("Build errors", null, errorOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var stage = arguments.GetString(ShaderStageName); var entryPoint = arguments.GetString(EntryPointName); var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); var exePath = CommonParameters.GetBinaryPath("tint", arguments, "tint.exe"); if (!RunTint(exePath, shaderCode, stage, entryPoint, outputLanguage, out var output, out var error)) { return(ErrorResult(outputLanguage, error)); } if (outputLanguage == LanguageNames.SpirV) { // SPIR-V is currently the only binary format that requires disassembling. if (!RunTint(exePath, shaderCode, stage, entryPoint, LanguageNames.SpirvAssembly, out var asm, out error)) { return(ErrorResult(outputLanguage, error)); } return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, output), 0, new ShaderCompilerOutput("Disassembly", outputLanguage, Encoding.ASCII.GetString(asm)), new ShaderCompilerOutput("Build output", null, ""))); } else { var disassembly = Encoding.ASCII.GetString(output); return(new ShaderCompilerResult( true, new ShaderCode(outputLanguage, disassembly), 0, new ShaderCompilerOutput("Disassembly", outputLanguage, disassembly), new ShaderCompilerOutput("Build output", null, ""))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var version = Version.Parse(arguments.GetString(CommonParameters.VersionParameterName)); var isVersion21OrLater = version >= new Version(2, 1); var isVersion22OrLater = version >= new Version(2, 2); var asic = arguments.GetString("Asic"); var entryPoint = arguments.GetString("EntryPoint"); var targetProfile = arguments.GetString("TargetProfile"); var shaderStage = arguments.GetString(CommonParameters.GlslShaderStage.Name); using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var outputAnalysisPath = $"{tempFile.FilePath}.analysis"; var ilPath = $"{tempFile.FilePath}.il"; var isaPath = $"{tempFile.FilePath}.isa"; var liveRegPath = $"{tempFile.FilePath}.livereg"; var cfgPath = $"{tempFile.FilePath}.cfg"; var args = $"--asic \"{asic}\" --il \"{ilPath}\" --line-numbers --isa \"{isaPath}\" --livereg \"{liveRegPath}\" --cfg \"{cfgPath}\""; switch (shaderCode.Language) { case LanguageNames.Hlsl: args += isVersion22OrLater ? $" -s dx11" : " -s hlsl"; args += $" --profile {targetProfile} --function {entryPoint}"; args += $" \"{tempFile.FilePath}\""; break; case LanguageNames.Glsl: switch (arguments.GetString("GlslTarget")) { case TargetOpenGL: args += $" -s opengl --{shaderStage}"; break; case TargetVulkan: args += $" -s {(isVersion21OrLater ? "vk-offline" : "vulkan")} --{shaderStage}"; break; } args += $" \"{tempFile.FilePath}\""; break; case LanguageNames.SpirvAssembly: args += $" -s {(isVersion21OrLater ? "vk-spv-txt-offline" : "vulkan-spv-text")} --{shaderStage}"; args += $" \"{tempFile.FilePath}\""; break; } var rgaPath = CommonParameters.GetBinaryPath("rga", arguments, "rga.exe"); var result = ProcessHelper.Run( rgaPath, args, out var stdOutput, out _); var actualOutputPathPrefix = Path.GetDirectoryName(tempFile.FilePath); string GetActualOutputPath(string extension) { if (extension == "analysis" && shaderCode.Language == LanguageNames.Hlsl) { return(Path.Combine( Path.GetDirectoryName(tempFile.FilePath), $"{entryPoint}_{Path.GetFileName(tempFile.FilePath)}.analysis")); } switch (shaderCode.Language) { case LanguageNames.Hlsl: return(Path.Combine( actualOutputPathPrefix, $"{asic}_{entryPoint}_{Path.GetFileName(tempFile.FilePath)}.{extension}")); default: if (isVersion21OrLater) { return(Path.Combine( actualOutputPathPrefix, $"{asic}_{Path.GetFileName(tempFile.FilePath)}_{shaderStage}.{extension}")); } else { return(Path.Combine( actualOutputPathPrefix, $"{asic}_{shaderStage}_{Path.GetFileName(tempFile.FilePath)}.{extension}")); } } } outputAnalysisPath = GetActualOutputPath("analysis"); ilPath = GetActualOutputPath("il"); isaPath = GetActualOutputPath("isa"); liveRegPath = GetActualOutputPath("livereg"); cfgPath = GetActualOutputPath("cfg"); var outputAnalysis = FileHelper.ReadAllTextIfExists(outputAnalysisPath); var il = FileHelper.ReadAllTextIfExists(ilPath); var isa = FileHelper.ReadAllTextIfExists(isaPath); var liveReg = FileHelper.ReadAllTextIfExists(liveRegPath); var cfg = FileHelper.ReadAllTextIfExists(cfgPath); FileHelper.DeleteIfExists(outputAnalysisPath); FileHelper.DeleteIfExists(ilPath); FileHelper.DeleteIfExists(isaPath); FileHelper.DeleteIfExists(liveRegPath); FileHelper.DeleteIfExists(cfgPath); var selectedOutputIndex = !result || stdOutput.Contains("\nError: ") || stdOutput.Contains("... failed.") ? 4 : (int?)null; return(new ShaderCompilerResult( selectedOutputIndex == null, null, selectedOutputIndex, new ShaderCompilerOutput("ISA Disassembly", null, isa), new ShaderCompilerOutput("IL Disassembly", null, il), //new ShaderCompilerOutput("Analysis", null, outputAnalysis), new ShaderCompilerOutput("Live register analysis", null, liveReg), new ShaderCompilerOutput("Control flow graph", "graphviz", cfg), new ShaderCompilerOutput("Build output", null, stdOutput))); } }
public ShaderCompilerResult Compile(ShaderCode shaderCode, ShaderCompilerArguments arguments) { var entryPoint = arguments.GetString("EntryPoint"); var targetProfile = arguments.GetString("TargetProfile"); var disableOptimizations = arguments.GetBoolean("DisableOptimizations"); var optimizationLevel = Convert.ToInt32(arguments.GetString("OptimizationLevel")); var outputLanguage = arguments.GetString(CommonParameters.OutputLanguageParameterName); var spirv = (outputLanguage == LanguageNames.SpirV) ? "-spirv" : string.Empty; using (var tempFile = TempFile.FromShaderCode(shaderCode)) { var fcPath = $"{tempFile.FilePath}.fc"; var fePath = $"{tempFile.FilePath}.fe"; var foPath = $"{tempFile.FilePath}.fo"; var args = $"{spirv} -T {targetProfile} -E {entryPoint} -O{optimizationLevel} -Fc \"{fcPath}\" -Fe \"{fePath}\" -Fo \"{foPath}\""; if (disableOptimizations) { args += " -Od"; } args += $" \"{tempFile.FilePath}\""; var dxcPath = Path.Combine(AppContext.BaseDirectory, "Binaries", "Dxc", "dxc.exe"); ProcessHelper.Run( dxcPath, args, out var _, out var _); int?selectedOutputIndex = null; var disassembly = FileHelper.ReadAllTextIfExists(fcPath); if (string.IsNullOrWhiteSpace(disassembly)) { disassembly = "<Compilation error occurred>"; selectedOutputIndex = 2; } var binaryOutput = FileHelper.ReadAllBytesIfExists(foPath); var buildOutput = FileHelper.ReadAllTextIfExists(fePath); FileHelper.DeleteIfExists(fcPath); FileHelper.DeleteIfExists(fePath); FileHelper.DeleteIfExists(foPath); // Run again to get AST (can't be done in combination with output files, above). ProcessHelper.Run( dxcPath, $"-T {targetProfile} -E {entryPoint} -ast-dump \"{tempFile.FilePath}\"", out var stdOutputAst, out var _); return(new ShaderCompilerResult( new ShaderCode(outputLanguage, binaryOutput), selectedOutputIndex, new ShaderCompilerOutput("Disassembly", outputLanguage, disassembly), new ShaderCompilerOutput("AST", null, stdOutputAst), new ShaderCompilerOutput("Build output", null, buildOutput))); } }