Exemple #1
0
        private static ShaderBytecodeId CreateBytecode()
        {
            var id = new ShaderBytecodeId {
                Index = Bytecodes.Allocate()
            };

            return(id);
        }
Exemple #2
0
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            var path = Path.Combine(MyFileSystem.ContentPath, MyShadersDefines.ShadersContentPath, info.File.ToString());

            if (!File.Exists(path))
            {
                string message = "ERROR: Shaders Compile - can not find file: " + path;
                MyRender11.Log.WriteLine(message);
                throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
            }

            ShaderMacro[] macros = MyRender11.GlobalShaderMacro;
            if (info.Macros != null && info.Macros.Length > 0 || MyRender11.DebugMode)
            {
                macros = new ShaderMacro[MyRender11.GlobalShaderMacro.Length + (info.Macros != null ? info.Macros.Length : 0)];
                MyRender11.GlobalShaderMacro.CopyTo(macros, 0);
                if (info.Macros != null)
                {
                    info.Macros.CopyTo(macros, MyRender11.GlobalShaderMacro.Length);
                }
            }
            string shaderSource;

            using (var reader = new StreamReader(path))
            {
                shaderSource = reader.ReadToEnd();
            }
            var compiled = Compile(shaderSource, macros, info.Profile, info.File.ToString(), false);

            Bytecodes.Data[bytecode.Index].Bytecode = compiled ?? Bytecodes.Data[bytecode.Index].Bytecode;

            if (compiled == null)
            {
                string message = "Failed to compile " + info.File + " @ profile " + info.Profile + " with defines " + macros.GetString();
                MyRender11.Log.WriteLine(message);
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                    Compile(bytecode, true);
                }
                else
                {
                    throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
                }
            }
        }
Exemple #3
0
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            using (var reader = new StreamReader(Path.Combine(MyFileSystem.ContentPath, ShadersContentPath, info.File.ToString())))
            {
                var compiled = Compile(MyRender11.GlobalShaderHeader + info.Header + reader.ReadToEnd(), info.Function.ToString(), info.Profile.Value(), info.Name, invalidateCache);
                Bytecodes.Data[bytecode.Index].Bytecode = compiled != null ? compiled : Bytecodes.Data[bytecode.Index].Bytecode;

                if (Bytecodes.Data[bytecode.Index].Bytecode == null)
                {
                    MyRender11.Log.WriteLine("Failed to compile shader" + info.Name);
                    throw new MyRenderException("Failed to compile shader" + info.Name, MyRenderExceptionEnum.Unassigned);
                }
            }
        }
Exemple #4
0
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            var path = Path.Combine(ShadersPath, info.File.ToString());

            if (!File.Exists(path))
            {
                string message = "ERROR: Shaders Compile - can not find file: " + path;
                MyRender11.Log.WriteLine(message);
                Debug.WriteLine(message);
                Debugger.Break();
                if (Debugger.IsAttached)
                {
                    Compile(bytecode, true);
                }
                else
                {
                    throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
                }
            }

            var macros = new List <ShaderMacro>();

            if (info.Macros != null)
            {
                macros.AddRange(info.Macros);
            }

            var compiled = Compile(path, macros.ToArray(), info.Profile, info.File.ToString(), false);

            Bytecodes.Data[bytecode.Index].Bytecode = compiled ?? Bytecodes.Data[bytecode.Index].Bytecode;

            if (compiled == null)
            {
                string message = "Failed to compile " + info.File + " @ profile " + info.Profile + " with defines " + macros.GetString();
                MyRender11.Log.WriteLine(message);
                if (Debugger.IsAttached)
                {
                    Compile(bytecode, true);
                }
                else
                {
                    throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
                }
            }
        }
Exemple #5
0
        internal static InputLayoutId CreateIL(ShaderBytecodeId bytecode, VertexLayoutId layout)
        {
            var id = new InputLayoutId {
                Index = InputLayouts.Allocate()
            };

            MyArrayHelpers.Reserve(ref ILObjects, id.Index + 1);

            InputLayouts.Data[id.Index] = new InputLayoutInfo
            {
                BytecodeId = bytecode,
                VLayoutId  = layout
            };

            ILObjects[id.Index] = null;

            InitIL(id);
            ILIndex.Add(id);

            return(id);
        }
 static ShaderBytecodeId CreateBytecode()
 { 
     var id = new ShaderBytecodeId { Index = Bytecodes.Allocate() };
     return id;
 }
        internal static InputLayoutId CreateIL(ShaderBytecodeId bytecode, VertexLayoutId layout)
        {
            var id = new InputLayoutId { Index = InputLayouts.Allocate() };
            MyArrayHelpers.Reserve(ref ILObjects, id.Index + 1);

            InputLayouts.Data[id.Index] = new InputLayoutInfo
            {
                BytecodeId = bytecode,
                VLayoutId = layout
            };

            ILObjects[id.Index] = null;

            InitIL(id);
            ILIndex.Add(id);

            return id;
        }
 internal static byte[] GetBytecode(ShaderBytecodeId id)
 {
     return Bytecodes.Data[id.Index].Bytecode;
 }
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            using (var reader = new StreamReader(Path.Combine(MyFileSystem.ContentPath, ShadersContentPath, info.File.ToString())))
            {
                var compiled = Compile(MyRender11.GlobalShaderHeader + info.Header + reader.ReadToEnd(), info.Function.ToString(), info.Profile.Value(), info.Name, invalidateCache);
                Bytecodes.Data[bytecode.Index].Bytecode = compiled != null ? compiled : Bytecodes.Data[bytecode.Index].Bytecode; 

                if(Bytecodes.Data[bytecode.Index].Bytecode == null)
                {
                    MyRender11.Log.WriteLine("Failed to compile shader" + info.Name);
                    throw new MyRenderException("Failed to compile shader" + info.Name, MyRenderExceptionEnum.Unassigned);
                }
            }
        }
Exemple #10
0
 internal static byte[] GetBytecode(ShaderBytecodeId id)
 {
     return(Bytecodes.Data[id.Index].Bytecode);
 }
Exemple #11
0
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            var path = Path.Combine(MyFileSystem.ContentPath, MyShadersDefines.ShadersContentPath, info.File.ToString());
            if (!File.Exists(path))
            {
                string message = "ERROR: Shaders Compile - can not find file: " + path;
                MyRender11.Log.WriteLine(message);
                throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
            }

            ShaderMacro[] macros = MyRender11.GlobalShaderMacro;
            if (info.Macros != null && info.Macros.Length > 0 || MyRender11.DebugMode)
            {
                macros = new ShaderMacro[MyRender11.GlobalShaderMacro.Length + (info.Macros != null ? info.Macros.Length : 0)];
                MyRender11.GlobalShaderMacro.CopyTo(macros, 0);
                if (info.Macros != null)
                    info.Macros.CopyTo(macros, MyRender11.GlobalShaderMacro.Length);
            }
            string shaderSource;
            using (var reader = new StreamReader(path))
            {
                shaderSource = reader.ReadToEnd();
            }
            var compiled = Compile(shaderSource, macros, info.Profile, info.File.ToString(), false);

            Bytecodes.Data[bytecode.Index].Bytecode = compiled ?? Bytecodes.Data[bytecode.Index].Bytecode;

            if (compiled == null)
            {
                string message = "Failed to compile " + info.File + " @ profile " + info.Profile + " with defines " + macros.GetString();
                MyRender11.Log.WriteLine(message);
                if (Debugger.IsAttached)
                {
                    Compile(bytecode, true);
                }
                else throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
            }
        }
Exemple #12
0
        internal static void Compile(ShaderBytecodeId bytecode, bool invalidateCache = false)
        {
            var info = Shaders[bytecode];

            var path = Path.Combine(ShadersPath, info.File.ToString());
            if (!File.Exists(path))
            {
                string message = "ERROR: Shaders Compile - can not find file: " + path;
                MyRender11.Log.WriteLine(message);
                Debug.WriteLine(message);
                Debugger.Break();
                if (Debugger.IsAttached)
                {
                    Compile(bytecode, true);
                }
                else throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
            }

            var macros = new List<ShaderMacro>();
            if (info.Macros != null)
                macros.AddRange(info.Macros);

            var compiled = Compile(path, macros.ToArray(), info.Profile, info.File.ToString(), false);

            Bytecodes.Data[bytecode.Index].Bytecode = compiled ?? Bytecodes.Data[bytecode.Index].Bytecode;

            if (compiled == null)
            {
                string message = "Failed to compile " + info.File + " @ profile " + info.Profile + " with defines " + macros.GetString();
                MyRender11.Log.WriteLine(message);
                if (Debugger.IsAttached)
                {
                    Compile(bytecode, true);
                }
                else throw new MyRenderException(message, MyRenderExceptionEnum.Unassigned);
            }
        }