/// <summary> /// Compiles the given GLSL source code into SPIR-V. /// </summary> /// <param name="sourceText">The shader source code.</param> /// <param name="fileName">A descriptive name for the shader. May be null.</param> /// <param name="stage">The <see cref="ShaderStages"/> which the shader is used in.</param> /// <param name="options">Parameters for the GLSL compiler.</param> /// <returns>A <see cref="SpirvCompilationResult"/> containing the compiled SPIR-V bytecode.</returns> public static unsafe SpirvCompilationResult CompileGlslToSpirv( string sourceText, string fileName, ShaderStages stage, GlslCompileOptions options) { int sourceAsciiCount = Encoding.ASCII.GetByteCount(sourceText); byte *sourceAsciiPtr = stackalloc byte[sourceAsciiCount]; fixed(char *sourceTextPtr = sourceText) { Encoding.ASCII.GetBytes(sourceTextPtr, sourceText.Length, sourceAsciiPtr, sourceAsciiCount); } int macroCount = options.Macros.Length; NativeMacroDefinition *macros = stackalloc NativeMacroDefinition[(int)macroCount]; for (int i = 0; i < macroCount; i++) { macros[i] = new NativeMacroDefinition(options.Macros[i]); } return(CompileGlslToSpirv( (uint)sourceAsciiCount, sourceAsciiPtr, fileName, stage, options.Debug, (uint)macroCount, macros)); }
private byte[] CompileToSpirv( ShaderVariantDescription variant, string fileName, ShaderStages stage) { GlslCompileOptions glslOptions = GetOptions(variant); string glsl = LoadGlsl(fileName); SpirvCompilationResult result = SpirvCompilation.CompileGlslToSpirv( glsl, fileName, stage, glslOptions); return(result.SpirvBytes); }