/// <summary> /// Gets all the graphicsBackends, ensuring they have the required features. /// </summary> /// <param name="requiredFeatures">The required features.</param> /// <param name="throwOnFail">if set to <c>true</c> throws an error if any of the <paramref name="graphicsBackends" /> /// do not have the <paramref name="requiredFeatures">required features</paramref>.</param> /// <param name="graphicsBackends">The graphics graphicsBackends.</param> /// <returns></returns> /// <exception cref="ShaderGen.Tests.Tools.RequiredToolFeatureMissingException"></exception> public static IReadOnlyList <ToolChain> Requires( ToolFeatures requiredFeatures, bool throwOnFail, IEnumerable <GraphicsBackend> graphicsBackends) { GraphicsBackend[] backends = (graphicsBackends ?? _toolChainsByGraphicsBackend.Keys).ToArray(); if (backends.Length < 1) { backends = _toolChainsByGraphicsBackend.Keys.ToArray(); } List <string> missingBackends = new List <string>(backends.Length); List <ToolChain> found = new List <ToolChain>(backends.Length); foreach (GraphicsBackend backend in backends) { ToolChain toolChain = Get(backend); if (toolChain == null) { missingBackends.Add($"{backend} backend does not have a tool chain"); continue; } if (!toolChain.Features.HasFlag(requiredFeatures)) { missingBackends.Add( $"{backend} tool chain does not have the required {~toolChain.Features & requiredFeatures} feature(s)"); continue; } found.Add(toolChain); } if (throwOnFail && missingBackends.Count > 0) { string last = missingBackends.LastOrDefault(); throw new RequiredToolFeatureMissingException( missingBackends.Count < 2 ? $"The {last}." : $"The {string.Join(", ", missingBackends.Take(missingBackends.Count - 1))} and {last}."); } found.TrimExcess(); return(found.AsReadOnly()); }
/// <summary> /// Initializes the <see cref="ToolChain"/> class. /// </summary> static ToolChain() { Direct3D11 = new ToolChain( GraphicsBackend.Direct3D11, typeof(HlslBackend), c => new HlslBackend(c), //_fxcPath.Value != null ? FxcCompile : (CompileDelegate)null, SharpDXCompile, CreateHeadlessD3D, null); GlslEs300 = new ToolChain( GraphicsBackend.OpenGLES, typeof(GlslEs300Backend), c => new GlslEs300Backend(c), _glslvPath.Value != null ? GLCompile : (CompileDelegate)null, () => CreateHeadlessGL(GraphicsBackend.OpenGLES), null); Glsl330 = new ToolChain( GraphicsBackend.OpenGL, typeof(Glsl330Backend), c => new Glsl330Backend(c), _glslvPath.Value != null ? GLCompile : (CompileDelegate)null, () => CreateHeadlessGL(GraphicsBackend.OpenGL), null); Glsl450 = new ToolChain( GraphicsBackend.Vulkan, typeof(Glsl450Backend), c => new Glsl450Backend(c), _glslvPath.Value != null ? VulkanCompile : (CompileDelegate)null, CreateHeadlessVulkan, null); Metal = new ToolChain( GraphicsBackend.Metal, typeof(MetalBackend), c => new MetalBackend(c), File.Exists(XcrunPath) ? MetalCompile : (CompileDelegate)null, CreateHeadlessMetal, null); }