/// <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)); }
/// <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)); } } }
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); }