public async Task <EffectBytecodeCompilerResult> Compile(ShaderMixinSource mixinTree, EffectCompilerParameters effectParameters) { // Make sure we are connected // TODO: Handle reconnections, etc... var socketMessageLayer = await GetOrCreateConnection(cancellationTokenSource.Token); var shaderCompilerAnswer = (RemoteEffectCompilerEffectAnswer)await socketMessageLayer.SendReceiveAsync(new RemoteEffectCompilerEffectRequest { MixinTree = mixinTree, EffectParameters = effectParameters, }); var result = new EffectBytecodeCompilerResult(shaderCompilerAnswer.EffectBytecode, EffectBytecodeCacheLoadSource.JustCompiled); foreach (var message in shaderCompilerAnswer.LogMessages) { result.CompilationLog.Messages.Add(message); } result.CompilationLog.HasErrors = shaderCompilerAnswer.LogHasErrors; return(result); }
private Effect CreateEffect(string effectName, EffectBytecodeCompilerResult effectBytecodeCompilerResult, CompilerResults compilerResult) { Effect effect; lock (cachedEffects) { if (!isInitialized) throw new ObjectDisposedException(nameof(EffectSystem), "EffectSystem has been disposed. This Effect compilation has been cancelled."); if (effectBytecodeCompilerResult.CompilationLog.HasErrors) { // Unregister result (or should we keep it so that failure never change?) List<CompilerResults> effectCompilerResults; if (earlyCompilerCache.TryGetValue(effectName, out effectCompilerResults)) { effectCompilerResults.Remove(compilerResult); } } CheckResult(effectBytecodeCompilerResult.CompilationLog); var bytecode = effectBytecodeCompilerResult.Bytecode; if (bytecode == null) throw new InvalidOperationException("EffectCompiler returned no shader and no compilation error."); if (!cachedEffects.TryGetValue(bytecode, out effect)) { effect = new Effect(graphicsDeviceService.GraphicsDevice, bytecode) { Name = effectName }; cachedEffects.Add(bytecode, effect); #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP foreach (var type in bytecode.HashSources.Keys) { // TODO: the "/path" is hardcoded, used in ImportStreamCommand and ShaderSourceManager. Find a place to share this correctly. using (var pathStream = FileProvider.OpenStream(EffectCompilerBase.GetStoragePathFromShaderType(type) + "/path", VirtualFileMode.Open, VirtualFileAccess.Read)) using (var reader = new StreamReader(pathStream)) { var path = reader.ReadToEnd(); directoryWatcher.Track(path); } } #endif } } return effect; }