/// <summary> /// Loads the source from file /// </summary> /// <param name="file"></param> private static List <string> LoadSource(string file, int channelCount) { Logger.Log("Loading Source..", DebugChannel.Log | DebugChannel.OpenFL | DebugChannel.IO, 9); Dictionary <string, bool> defs = new Dictionary <string, bool>(); for (int i = 0; i < channelCount; i++) { defs.Add("channel" + i, true); } List <string> lines = TextProcessorAPI.PreprocessLines(file, defs).ToList(); for (int i = lines.Count - 1; i >= 0; i--) { string line = lines[i].Trim(); if (line.StartsWith(CommentPrefix)) { lines.RemoveAt(i); //Remove otherwise emtpty lines after removing comments } else { lines[i] = line.Split(CommentPrefix)[0].Trim(); } } return(lines); }
/// <summary> /// Loads the source from file /// </summary> /// <param name="file"></param> /// <param name="channelCount"></param> private List <string> LoadSource(string file, int channelCount) { Logger.Log(DebugChannel.Log | DebugChannel.OpenFL, Verbosity.Level8, "Loading Source.."); Dictionary <string, bool> defs = new Dictionary <string, bool>(); for (int i = 0; i < channelCount; i++) { defs.Add("channel" + i, true); } List <string> lines = TextProcessorAPI.PreprocessLines(file, defs).ToList(); for (int i = lines.Count - 1; i >= 0; i--) { string line = lines[i].Trim(); if (line.StartsWith(COMMENT_PREFIX)) { lines.RemoveAt(i); //Remove otherwise emtpty lines after removing comments } else { lines[i] = line.Split(new[] { COMMENT_PREFIX }, StringSplitOptions.None)[0].Trim(); } } return(lines); }
/// <summary> /// Loads the source and initializes the CLProgram /// </summary> private void Initialize(CLAPI instance) { int vnum = GetVectorNum(genType); string source = TextProcessorAPI.PreprocessSource(filePath, new Dictionary <string, bool>()); string[] kernelNames = FindKernelNames(source); ClProgramHandle = CLAPI.CreateClProgramFromSource(instance, source); foreach (string kernelName in kernelNames) { Kernel k = CLAPI.CreateKernelFromName(ClProgramHandle, kernelName); int kernelNameIndex = source.IndexOf(" " + kernelName + " ", StringComparison.InvariantCulture); kernelNameIndex = kernelNameIndex == -1 ? source.IndexOf(" " + kernelName + "(", StringComparison.InvariantCulture) : kernelNameIndex; KernelParameter[] parameter = KernelParameter.CreateKernelParametersFromKernelCode(source, kernelNameIndex, source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1); if (k == null) { ContainedKernels.Add(kernelName, new CLKernel(instance, null, kernelName, parameter)); } else { ContainedKernels.Add(kernelName, new CLKernel(instance, k, kernelName, parameter)); } } }
public static CLProgramBuildResult TryBuildProgram(CLAPI instance, string filePath, out CLProgram program) { //string source = TextProcessorAPI.PreprocessSource(IOManager.ReadAllLines(filePath), // Path.GetDirectoryName(filePath), Path.GetExtension(filePath), new Dictionary<string, bool>()); string source = TextProcessorAPI.PreprocessSource(filePath, new Dictionary <string, bool>()); // program = null; return(TryBuildProgram(instance, source, filePath, out program)); }
/// <summary> /// Tries to Create a Shader from source /// </summary> /// <param name="subshaders">The source paths of the sub shader</param> /// <param name="program">The Program that will be created</param> /// <returns></returns> public static bool TryCreate(Dictionary <ShaderType, string> subshaders, out ShaderProgram program) { Dictionary <ShaderType, string> ret = new Dictionary <ShaderType, string>(); foreach (KeyValuePair <ShaderType, string> subshader in subshaders) { Logger.Log("Loading Shader: " + subshader.Value, DebugChannel.Log | DebugChannel.EngineRendering, 7); ret.Add(subshader.Key, TextProcessorAPI.PreprocessSource(subshader.Value, null)); } return(TryCreateFromSource(ret, out program)); }
private string Merge(string src, params CLProgram[] progs) { string source = ""; IEnumerable <CLProgram> unique = progs.Distinct(new ProgramComparer()); foreach (CLProgram clProgram in unique) { source += $"#include {clProgram.FilePath}\n"; } source += src; string[] lines = source.Split('\n'); string content = TextProcessorAPI.PreprocessLines(lines, "./", ".cl", new Dictionary <string, bool>()) .Unpack("\n"); return(content); }
/// <summary> /// Loads the source and initializes the CLProgram /// </summary> private void Initialize() { int vnum = GetVectorNum(_genType); string[] lines = TextProcessorAPI.GenericIncludeToSource(".cl", _filePath, _genType, vnum == 0 || vnum == 1 ? "float" : "float" + vnum); Dictionary <string, bool> defs = new Dictionary <string, bool> { { "V_" + vnum, true } }; string source = TextProcessorAPI.PreprocessSource(lines, _filePath, defs); string[] kernelNames = FindKernelNames(source); ClProgramHandle = CLAPI.CreateCLProgramFromSource(source); foreach (string kernelName in kernelNames) { Kernel k = CLAPI.CreateKernelFromName(ClProgramHandle, kernelName); int kernelNameIndex = source.IndexOf(" " + kernelName + " ", StringComparison.InvariantCulture); kernelNameIndex = kernelNameIndex == -1 ? source.IndexOf(" " + kernelName + "(", StringComparison.InvariantCulture) : kernelNameIndex; KernelParameter[] parameter = KernelParameter.CreateKernelParametersFromKernelCode(source, kernelNameIndex, source.Substring(kernelNameIndex, source.Length - kernelNameIndex).IndexOf(')') + 1); if (k == null) { ContainedKernels.Add(kernelName, new CLKernel(null, kernelName, parameter)); } else { ContainedKernels.Add(kernelName, new CLKernel(k, kernelName, parameter)); } } }
/// <summary> /// Tries to Create a Shader from source /// </summary> /// <param name="subshaders">The source paths of the sub shader</param> /// <param name="program">The Program that will be created</param> /// <returns></returns> public static bool TryCreate(Dictionary <ShaderType, string> subshaders, out ShaderProgram program) { Dictionary <ShaderType, string> ret = new Dictionary <ShaderType, string>(); foreach (KeyValuePair <ShaderType, string> subshader in subshaders) { Logger.Log(DebugChannel.Log | DebugChannel.EngineRendering, "Loading Shader: " + subshader.Value, 7); Stream s = IOManager.GetStream(subshader.Value); TextReader tr = new StreamReader(s); string dirName = Path.GetDirectoryName(subshader.Value); StringBuilder src = new StringBuilder(); string[] lines = TextProcessorAPI.PreprocessLines(tr.ReadToEnd().Replace("\r", "").Split('\n'), dirName, Path.GetExtension(subshader.Value), null); tr.Close(); for (int i = 0; i < lines.Length; i++) { src.AppendLine(lines[i]); } ret.Add(subshader.Key, src.ToString()); } return(TryCreateFromSource(ret, out program)); }
public override LoadSourceStageResult Process(FLParserInput input) { if (input.Source != null) { return(new LoadSourceStageResult( input.Filename, input.Source.ToList(), input.MainFile, input.KernelData )); } Logger.Log(LogType.Log, "Loading Source: " + input.Filename, 1); Dictionary <string, bool> defines = input.Defines; return(new LoadSourceStageResult( input.Filename, TextProcessorAPI.PreprocessLines(input.Filename, defines).ToList(), input.MainFile, input.KernelData )); }
public override LoadSourceStageResult Process(FLParserInput input) { Logger.Log(LogType.Log, "Loading Source: " + input.Filename, 2); return(new LoadSourceStageResult(input.Filename, TextProcessorAPI.PreprocessLines(input.Filename, new Dictionary <string, bool>()).ToList())); }
private void Initialize() { CLAPI instance = CLAPI.GetInstance(); string path = FLScriptEditor.Settings.KernelPath; StartupSequence.loaderForm.SetStatus("Discovering Files in Path: " + path); string[] files = IOManager.DirectoryExists(path) ? IOManager.GetFiles(path, "*.cl") : new string[0]; if (files.Length == 0) { DialogResult res = StyledMessageBox.Show( "Error", "No Files found at path: " + path, MessageBoxButtons.AbortRetryIgnore, SystemIcons.Error ); if (res == DialogResult.Retry) { Initialize(); return; } if (res == DialogResult.Abort) { StartupSequence.loaderForm.DialogResult = DialogResult.Abort; StartupSequence.loaderForm.Close(); return; } if (res == DialogResult.Ignore) { StartupSequence.loaderForm.DialogResult = DialogResult.OK; } } KernelDatabase dataBase = new KernelDatabase(DataVectorTypes.Uchar1); List <CLProgramBuildResult> results = new List <CLProgramBuildResult>(); bool throwEx = false; int kernelCount = 0; int fileCount = 0; if (FLScriptEditor.Settings.ExperimentalKernelLoading) { try { string source = TextProcessorAPI.PreprocessSource(files, new Dictionary <string, bool>()); CLProgram prog = dataBase.AddProgram(instance, source, "./", false, out CLProgramBuildResult res); throwEx |= !res; if (res) { kernelCount += prog.ContainedKernels.Count; } results.Add(res); StartupSequence.loaderForm.SetStatus($"File Loaded(Kernels Loaded): ({kernelCount})"); } catch (Exception e) { throw new SoftException(e); } } else { foreach (string file in files) { StartupSequence.loaderForm.SetStatus( $"[{fileCount}/{files.Length}]Loading: {file} ({kernelCount})" ); try { CLProgram prog = dataBase.AddProgram(instance, file, false, out CLProgramBuildResult res); kernelCount += prog.ContainedKernels.Count; throwEx |= !res; results.Add(res); } catch (Exception e) { StartupSequence.loaderForm.Log("ERROR: " + e.Message, Color.Red); throw e; //Let the Exception Viewer Catch that } fileCount++; } } StartupSequence.loaderForm.SetStatus("Loading Finished"); StartupSequence.loaderForm.Log("Loading Finished", Color.White); StartupSequence.loaderForm.Log("Kernels Loaded: " + kernelCount, Color.White); if (throwEx) { DialogResult res = StyledMessageBox.Show( "OpenCL Build Errors", "There are errors in one or more OpenCL kernels. Do you want to open the OpenCL Build Excepion Viewer?", MessageBoxButtons.YesNoCancel, SystemIcons.Warning ); if (res == DialogResult.Cancel) { StartupSequence.loaderForm.DialogResult = DialogResult.Abort; StartupSequence.loaderForm.Close(); } else if (res == DialogResult.Yes) { BuildExceptionViewer bvr = new BuildExceptionViewer(new CLBuildException(results)); if (bvr.ShowDialog() == DialogResult.Retry) { dataBase.Dispose(); Initialize(); } } } FLInstructionSet iset = FLInstructionSet.CreateWithBuiltInTypes(dataBase); BufferCreator creator = BufferCreator.CreateWithBuiltInTypes(); FLParser parser = new FLParser(iset, creator, new WorkItemRunnerSettings(true, 2)); StartupSequence.FlContainer = new FLDataContainer(instance, iset, creator, parser); }