public static byte[] GenerateSource(string template, IEnumerable <D3D.SHADER_MACRO> macros, string entry, string version)
        {
            // Macros should never be duplicated
            for (var i = 0; i < macros.Count(); i++)
            {
                for (var j = 0; j < macros.Count(); j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (macros.ElementAt(i).Name == macros.ElementAt(j).Name)
                    {
                        throw new Exception($"Macro {macros.ElementAt(i).Name} is defined multiple times");
                    }
                }
            }

            string fileName = template.Split('\\').Last();

            IncludeManager include = new IncludeManager(template.Replace(fileName, ""));

            string shader_source = include.ReadResource(fileName);

            D3DCompiler.D3DCOMPILE flags = 0;
#if DEBUG
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS;
#endif
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_SKIP_VALIDATION;
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_DEBUG;
            flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL2; // if can't get shader to compile 1-1 add or remove this line
            byte[] shader_code = D3DCompiler.Compile(
                shader_source,
                entry,
                version,
                macros.ToArray(),
                flags,
                0,
                template,
                include
                );

            GC.KeepAlive(include?.NativePointer);
            return(shader_code);
        }
        public static byte[] GenerateSource(string template, IEnumerable <D3D.SHADER_MACRO> macros, string entry, string version)
        {
            // Macros should never be duplicated
            for (var i = 0; i < macros.Count(); i++)
            {
                for (var j = 0; j < macros.Count(); j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (macros.ElementAt(i).Name == macros.ElementAt(j).Name)
                    {
                        throw new Exception($"Macro {macros.ElementAt(i).Name} is defined multiple times");
                    }
                }
            }

            IncludeManager include = new IncludeManager();

            string shader_source = include.ReadResource(template);

            D3DCompiler.D3DCOMPILE flags = 0;
#if DEBUG
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS;
#endif
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_SKIP_OPTIMIZATION;
            flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_SKIP_VALIDATION;
            //flags |= D3DCompiler.D3DCOMPILE.D3DCOMPILE_PREFER_FLOW_CONTROL;

            byte[] shader_code = D3DCompiler.Compile(
                shader_source,
                entry,
                version,
                macros.ToArray(),
                flags,
                0,
                template,
                include
                );

            return(shader_code);
        }