示例#1
0
 public static string GetBinaryPath(string binaryFolderName, ShaderCompilerArguments arguments)
 {
     return(Path.Combine(
                AppContext.BaseDirectory,
                "Binaries",
                binaryFolderName,
                arguments.GetString(VersionParameterName)));
 }
示例#2
0
        public static IReadOnlyList <ShaderCompilerResult> Compile(
            ShaderCode shaderCode,
            params CompilationStep[] compilationSteps)
        {
            if ((shaderCode.Text != null && shaderCode.Text.Length > 1000000) ||
                (shaderCode.Binary != null && shaderCode.Binary.Length > 1000000))
            {
                throw new InvalidOperationException("Code exceeded maximum length.");
            }

            if (compilationSteps.Length == 0 || compilationSteps.Length > 5)
            {
                throw new InvalidOperationException("There must > 0 and <= 5 compilation steps.");
            }

            var eachShaderCode = shaderCode;
            var results        = new List <ShaderCompilerResult>();

            var error = false;

            foreach (var compilationStep in compilationSteps)
            {
                if (error)
                {
                    results.Add(new ShaderCompilerResult(false, null, null, new ShaderCompilerOutput("Output", null, "Error in previous step")));
                    continue;
                }

                var compiler = AllCompilers.First(x => x.Name == compilationStep.CompilerName);

                if (!compiler.InputLanguages.Contains(eachShaderCode.Language))
                {
                    throw new InvalidOperationException($"Invalid input language '{eachShaderCode.Language}' for compiler '{compiler.DisplayName}'.");
                }

                var arguments = new ShaderCompilerArguments(
                    compiler,
                    compilationStep.Arguments);

                var result = compiler.Compile(eachShaderCode, arguments);

                if (!result.Success)
                {
                    error = true;
                }

                results.Add(result);

                eachShaderCode = result.PipeableOutput;
            }

            return(results);
        }
示例#3
0
        public static ShaderCompilerResult Compile(
            ShaderCode shaderCode,
            params CompilationStep[] compilationSteps)
        {
            if ((shaderCode.Text != null && shaderCode.Text.Length > 1000000) ||
                (shaderCode.Binary != null && shaderCode.Binary.Length > 1000000))
            {
                throw new InvalidOperationException("Code exceeded maximum length.");
            }

            if (compilationSteps.Length == 0 || compilationSteps.Length > 5)
            {
                throw new InvalidOperationException("There must > 0 and <= 5 compilation steps.");
            }

            var eachShaderCode          = shaderCode;
            ShaderCompilerResult result = null;

            foreach (var compilationStep in compilationSteps)
            {
                var compiler = AllCompilers.First(x => x.Name == compilationStep.CompilerName);

                if (!compiler.InputLanguages.Contains(eachShaderCode.Language))
                {
                    throw new InvalidOperationException($"Invalid input language '{eachShaderCode.Language}' for compiler '{compiler.DisplayName}'.");
                }

                var arguments = new ShaderCompilerArguments(
                    compiler,
                    compilationStep.Arguments);

                result = compiler.Compile(eachShaderCode, arguments);

                eachShaderCode = result.PipeableOutput;
            }

            return(result);
        }
示例#4
0
 public static string GetBinaryPath(string binaryFolderName, ShaderCompilerArguments arguments, string executableFileName)
 {
     return(Path.Combine(
                GetBinaryPath(binaryFolderName, arguments),
                executableFileName));
 }