コード例 #1
0
        public int Compile(MgGraphicsPipelineCreateInfo info)
        {
            var modules = new List <int>();

            foreach (var stage in info.Stages)
            {
                //var shaderType = ShaderType.VertexShader;
                //if (stage.Stage == MgShaderStageFlagBits.FRAGMENT_BIT)
                //{
                //	shaderType = ShaderType.FragmentShader;
                //}
                //else if (stage.Stage == MgShaderStageFlagBits.VERTEX_BIT)
                //{
                //	shaderType = ShaderType.VertexShader;
                //}
                //else if (stage.Stage == MgShaderStageFlagBits.COMPUTE_BIT)
                //{
                //	shaderType = ShaderType.ComputeShader;
                //}
                //else if (stage.Stage == MgShaderStageFlagBits.GEOMETRY_BIT)
                //{
                //	shaderType = ShaderType.GeometryShader;
                //}
                var module = (GLShaderModule)stage.Module;
                Debug.Assert(module != null);
                if (module.ShaderId.HasValue)
                {
                    modules.Add(module.ShaderId.Value);
                }
                else
                {
                    using (var ms = new MemoryStream())
                    {
                        module.Info.Code.CopyTo(ms, (int)module.Info.CodeSize.ToUInt32());
                        ms.Seek(0, SeekOrigin.Begin);
                        // FIXME : Encoding type
                        using (var sr = new StreamReader(ms))
                        {
                            string fileContents = sr.ReadToEnd();
                            module.ShaderId = CompileShader(mShaderModuleEntrypoint, stage.Stage, fileContents, string.Empty, stage.Name);
                            modules.Add(module.ShaderId.Value);
                        }
                    }
                }
            }
            return(LinkShaders(mProgramEntrypoint, mErrHandler, modules.ToArray()));
        }
コード例 #2
0
        public GLGraphicsPipeline(
            IGLGraphicsPipelineEntrypoint entrypoint,
            int programId,
            MgGraphicsPipelineCreateInfo info,
            GLInternalCache internalCache,
            IGLPipelineLayout layout
            )
        {
            mEntrypoint = entrypoint;

            if (info.VertexInputState == null)
            {
                throw new ArgumentNullException("info.VertexInputState");
            }

            if (info.InputAssemblyState == null)
            {
                throw new ArgumentNullException("info.InputAssemblyState");
            }

            if (info.RasterizationState == null)
            {
                throw new ArgumentNullException("info.RasterizationState");
            }

            ProgramID     = programId;
            InternalCache = internalCache;
            Layout        = layout;

            PopulateVertexDefinition(info.VertexInputState);

            PopulatePipelineConstants(info.RasterizationState);

            PopulateCmdFallbacks(info.RasterizationState);

            PopulateInputAssembly(info.InputAssemblyState);

            PopulateDepthStencilState(info.DepthStencilState);

            PopulateDynamicStates(info.DynamicState);

            PopulateColorBlend(info.ColorBlendState);

            PopulateViewports(info.ViewportState);
        }
コード例 #3
0
        void preparePipelines()
        {
            Debug.Assert(mManager.Configuration != null);
            var device = mManager.Configuration.Device;

            using (var vertFs = System.IO.File.OpenRead("Shaders/texture1.vert.spv"))
                using (var fragFs = System.IO.File.OpenRead("Shaders/texture1.frag.spv"))
                {
                    // Load shaders
                    IMgShaderModule vertSM;
                    {
                        var vsCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = vertFs,
                            CodeSize = new UIntPtr((ulong)vertFs.Length),
                        };
                        // shaderStages[0] = loadShader(getAssetPath() + "shaders/texture/texture.vert.spv", IMg_SHADER_STAGE_VERTEX_BIT);
                        var localErr = device.CreateShaderModule(vsCreateInfo, null, out vertSM);
                        Debug.Assert(localErr == Result.SUCCESS);
                    }

                    IMgShaderModule fragSM;
                    {
                        var fsCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = fragFs,
                            CodeSize = new UIntPtr((ulong)fragFs.Length),
                        };
                        //shaderStages[1] = loadShader(getAssetPath() + "shaders/texture/texture.frag.spv", IMg_SHADER_STAGE_FRAGMENT_BIT);
                        var localErr = device.CreateShaderModule(fsCreateInfo, null, out fragSM);
                        Debug.Assert(localErr == Result.SUCCESS);
                    }

                    var pipelineCreateInfo = new MgGraphicsPipelineCreateInfo
                    {
                        Stages = new MgPipelineShaderStageCreateInfo[]
                        {
                            new MgPipelineShaderStageCreateInfo
                            {
                                Module = vertSM,
                                Stage  = MgShaderStageFlagBits.VERTEX_BIT,
                                Name   = "vertFunc",
                            },
                            new MgPipelineShaderStageCreateInfo
                            {
                                Module = fragSM,
                                Stage  = MgShaderStageFlagBits.FRAGMENT_BIT,
                                Name   = "fragFunc",
                            }
                        },

                        Layout           = mPipelineLayout,
                        RenderPass       = mManager.Graphics.Renderpass,
                        VertexInputState = vertices.inputState,

                        InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                        {
                            Topology = MgPrimitiveTopology.TRIANGLE_LIST,
                            PrimitiveRestartEnable = false,
                        },

                        RasterizationState = new MgPipelineRasterizationStateCreateInfo
                        {
                            PolygonMode = MgPolygonMode.FILL,
                            CullMode    = MgCullModeFlagBits.NONE,
                            FrontFace   = MgFrontFace.COUNTER_CLOCKWISE,
                        },

                        ColorBlendState = new MgPipelineColorBlendStateCreateInfo
                        {
                            Attachments = new MgPipelineColorBlendAttachmentState[]
                            {
                                new MgPipelineColorBlendAttachmentState
                                {
                                    ColorWriteMask = MgColorComponentFlagBits.R_BIT | MgColorComponentFlagBits.G_BIT | MgColorComponentFlagBits.B_BIT | MgColorComponentFlagBits.A_BIT,
                                    BlendEnable    = false,
                                },
                            }
                        },

                        MultisampleState = new MgPipelineMultisampleStateCreateInfo
                        {
                            RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT,
                        },

                        // pipelineCreateInfo.pViewportState = &viewportState;
                        // MgPipelineViewportStateCreateInfo viewportState =
                        //    IMgTools::initializers::pipelineViewportStateCreateInfo(1, 1, 0);

                        //ViewportState = new MgPipelineViewportStateCreateInfo
                        //{
                        //    Scissors = new []
                        //    {
                        //        mManager.Graphics.Scissor,
                        //    },
                        //    Viewports = new []
                        //    {
                        //        mManager.Graphics.CurrentViewport,
                        //    }
                        //},

                        DepthStencilState = new MgPipelineDepthStencilStateCreateInfo
                        {
                            DepthTestEnable       = true,
                            DepthWriteEnable      = true,
                            DepthCompareOp        = MgCompareOp.LESS_OR_EQUAL,
                            DepthBoundsTestEnable = false,
                            Back = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                            StencilTestEnable = false,
                            Front             = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                        },

                        DynamicState = new MgPipelineDynamicStateCreateInfo
                        {
                            DynamicStates = new[] {
                                MgDynamicState.VIEWPORT,
                                MgDynamicState.SCISSOR
                            },
                        }
                    };

                    IMgPipeline[] pipelines;
                    var           err = device.CreateGraphicsPipelines(null, new[] { pipelineCreateInfo }, null, out pipelines);
                    Debug.Assert(err == Result.SUCCESS);
                    mSolidPipeline = pipelines[0];
                }
        }
コード例 #4
0
        public void Preamble()
        {
            // PRIVATE IMPLEMENTATION UNIT TESTING
            mContainer = new Container();

            mContainer.Register <IMgQueue, GLCmdQueue>(Reuse.Singleton);
            mContainer.Register <IGLCmdStateRenderer, GLCmdStateRenderer>(Reuse.Singleton);

            mContainer.Register <IGLCmdBlendEntrypoint, MockGLCmdBlendEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdStencilEntrypoint, MockGLCmdStencilEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdRasterizationEntrypoint, MockGLCmdRasterizationEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdDepthEntrypoint, MockGLCmdDepthEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdScissorsEntrypoint, MockGLCmdScissorsEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdDrawEntrypoint, MockGLCmdDrawEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdClearEntrypoint, MockGLCmdClearEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLErrorHandler, MockGLErrorHandler>(Reuse.Singleton);


            mContainer.Register <IGLNextCmdShaderProgramCache, GLNextCmdShaderProgramCache>(Reuse.Singleton);
            mContainer.Register <IGLCmdShaderProgramEntrypoint, MockGLCmdShaderProgramEntrypoint>(Reuse.Singleton);


            mContainer.Register <IGLBlitOperationEntrypoint, MockGLBlitOperationEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLSemaphoreEntrypoint, MockGLSemaphoreEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLCmdImageEntrypoint, MockGLCmdImageEntrypoint>(Reuse.Singleton);

            mContainer.Register <IGLCmdBlitEncoder, GLCmdBlitEncoder>(Reuse.Singleton);
            mContainer.Register <GLCmdBlitBag>(Reuse.Singleton);
            mContainer.Register <IGLCmdComputeEncoder, GLCmdComputeEncoder>(Reuse.Singleton);
            mContainer.Register <IGLCmdGraphicsEncoder, GLCmdGraphicsEncoder>(Reuse.Singleton);

            mContainer.Register <GLCmdGraphicsBag>(Reuse.Singleton);
            mContainer.Register <IGLCmdVBOEntrypoint, MockGLCmdVBOEntrypoint>(Reuse.Singleton);
            mContainer.Register <IGLDescriptorSetBinder, GLNextDescriptorSetBinder>(Reuse.Singleton);


            mContainer.Register <IGLCmdEncoderContextSorter, GLCmdIncrementalContextSorter>(Reuse.Singleton);
            mContainer.Register <GLCmdCommandEncoder>(Reuse.Singleton);


            mContainer.Register <GLInternalCache>(Reuse.Singleton);
            mContainer.Register <IMgPipeline, GLGraphicsPipeline>(Reuse.Singleton);
            mContainer.Register <IGLGraphicsPipelineCompiler, MockGLGraphicsPipelineCompiler>(Reuse.Singleton);
            mContainer.Register <IGLGraphicsPipelineEntrypoint, MockGLGraphicsPipelineEntrypoint>(Reuse.Singleton);

            queue = mContainer.Resolve <IMgQueue>();
            var cmdEncoder = mContainer.Resolve <GLCmdCommandEncoder>();

            cmdBuf = new Magnesium.OpenGL.Internals.GLCmdCommandBuffer(true, cmdEncoder);

            framebuffer = new Magnesium.OpenGL.Internals.GLFramebuffer();
            renderpass  = new GLRenderPass(new MgAttachmentDescription[] { });

            vertexBuffer = new MockGLBuffer
            {
                BufferId = 1,
                Usage    = MgBufferUsageFlagBits.VERTEX_BUFFER_BIT,
            };
            indexBuffer = new MockGLBuffer
            {
                BufferId = 2,
                Usage    = MgBufferUsageFlagBits.INDEX_BUFFER_BIT,
            };

            var layout = new MockGLPipelineLayout
            {
            };

            mContainer.RegisterInstance <IGLPipelineLayout>(layout, Reuse.Singleton);

            var blockEntries = new GLUniformBlockEntry[]
            {
            };
            var arrayMapper = new Magnesium.OpenGL.Internals.GLInternalCacheArrayMapper(layout, blockEntries);

            mContainer.RegisterInstance <GLInternalCacheArrayMapper>(arrayMapper, Reuse.Singleton);

            var entrypoint    = mContainer.Resolve <IGLGraphicsPipelineEntrypoint>();
            var internalCache = mContainer.Resolve <GLInternalCache>();
            var info          = new MgGraphicsPipelineCreateInfo
            {
                VertexInputState = new MgPipelineVertexInputStateCreateInfo
                {
                    VertexAttributeDescriptions = new[]
                    {
                        new MgVertexInputAttributeDescription
                        {
                            Binding  = 0,
                            Location = 0,
                            Format   = MgFormat.R8G8B8A8_SNORM,
                        }
                    },
                    VertexBindingDescriptions = new[]
                    {
                        new MgVertexInputBindingDescription
                        {
                            Binding   = 0,
                            InputRate = MgVertexInputRate.VERTEX,
                            Stride    = 32,
                        }
                    }
                },
                RasterizationState = new MgPipelineRasterizationStateCreateInfo
                {
                    PolygonMode = MgPolygonMode.FILL,
                },
                InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                {
                    Topology = MgPrimitiveTopology.TRIANGLE_LIST,
                }
            };

            pipeline = new Magnesium.OpenGL.Internals.GLGraphicsPipeline(entrypoint, 1, info, internalCache, layout);


            var stateRenderer = mContainer.Resolve <IGLCmdStateRenderer>();

            stateRenderer.Initialize();
        }
コード例 #5
0
 public int Compile(MgGraphicsPipelineCreateInfo info)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
        public AmtGraphicsPipeline(IAmtMetalLibraryLoader generator, IMTLDevice device, MgGraphicsPipelineCreateInfo info)
        {
            var layout = (AmtPipelineLayout)info.Layout;

            if (layout == null)
            {
                throw new ArgumentException(nameof(info.Layout));
            }
            Layout = layout;

            if (info.VertexInputState == null)
            {
                throw new ArgumentNullException(nameof(info.VertexInputState));
            }

            if (info.InputAssemblyState == null)
            {
                throw new ArgumentNullException(nameof(info.InputAssemblyState));
            }

            if (info.RasterizationState == null)
            {
                throw new ArgumentNullException(nameof(info.RasterizationState));
            }

            // TODO : WHY DO I NEED RENDERPASS HERE
            if (info.RenderPass == null)
            {
                throw new ArgumentNullException(nameof(info.RenderPass));
            }

            RenderPass           = (AmtRenderPass)info.RenderPass;
            CompatibilityProfile = RenderPass.Profile;

            InitializeShaderFunctions(generator, device, info.Stages);
            InitializeVertexDescriptor(info.VertexInputState);
            InitiailizeDepthStateDescriptor(info.DepthStencilState);
            InitializeRasterization(info.RasterizationState);
            InitializationInputAssembly(info.InputAssemblyState);
            InitializeColorBlending(info.ColorBlendState);
            InitializeDynamicStates(info.DynamicState);
            InitializeResources(info.VertexInputState);
            InitializeViewportAndScissor(info.ViewportState);
            InitializeMultisampleInfo(info.MultisampleState);

            GeneratePipelineStates(device);
        }
コード例 #7
0
        void PreparePipelines()
        {
            using (var vertFs = mTrianglePath.OpenVertexShader())
                using (var fragFs = mTrianglePath.OpenFragmentShader())
                {
                    IMgShaderModule vsModule;
                    {
                        var vsCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = vertFs,
                            CodeSize = new UIntPtr((ulong)vertFs.Length),
                        };
                        mConfiguration.Device.CreateShaderModule(vsCreateInfo, null, out vsModule);
                    }

                    IMgShaderModule fsModule;
                    {
                        var fsCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = fragFs,
                            CodeSize = new UIntPtr((ulong)fragFs.Length),
                        };
                        mConfiguration.Device.CreateShaderModule(fsCreateInfo, null, out fsModule);
                    }

                    var pipelineCreateInfo = new MgGraphicsPipelineCreateInfo
                    {
                        Stages = new []
                        {
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.VERTEX_BIT,
                                Module = vsModule,
                                Name   = "vertFunc",
                            },
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.FRAGMENT_BIT,
                                Module = fsModule,
                                Name   = "fragFunc",
                            },
                        },
                        VertexInputState   = vertices.inputState,
                        InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                        {
                            // GL002 - TRIANGLE STRIP TEST
                            Topology = MgPrimitiveTopology.TRIANGLE_STRIP,
                        },
                        RasterizationState = new MgPipelineRasterizationStateCreateInfo
                        {
                            PolygonMode             = MgPolygonMode.FILL,
                            CullMode                = MgCullModeFlagBits.NONE,
                            FrontFace               = MgFrontFace.COUNTER_CLOCKWISE,
                            DepthClampEnable        = false,
                            RasterizerDiscardEnable = false,
                            DepthBiasEnable         = false,
                            LineWidth               = 1.0f,
                        },
                        ColorBlendState = new MgPipelineColorBlendStateCreateInfo
                        {
                            Attachments = new []
                            {
                                new MgPipelineColorBlendAttachmentState
                                {
                                    ColorWriteMask = MgColorComponentFlagBits.R_BIT | MgColorComponentFlagBits.G_BIT | MgColorComponentFlagBits.B_BIT | MgColorComponentFlagBits.A_BIT,
                                    BlendEnable    = false,
                                }
                            },
                        },
                        MultisampleState = new MgPipelineMultisampleStateCreateInfo
                        {
                            RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT,
                            SampleMask           = null,
                        },
                        Layout            = mPipelineLayout,
                        RenderPass        = mGraphicsDevice.Renderpass,
                        ViewportState     = null,
                        DepthStencilState = new MgPipelineDepthStencilStateCreateInfo
                        {
                            DepthTestEnable       = true,
                            DepthWriteEnable      = true,
                            DepthCompareOp        = MgCompareOp.LESS_OR_EQUAL,
                            DepthBoundsTestEnable = false,
                            Back = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                            StencilTestEnable = false,
                            Front             = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                        },
                        DynamicState = new MgPipelineDynamicStateCreateInfo
                        {
                            DynamicStates = new[]
                            {
                                MgDynamicState.VIEWPORT,
                                MgDynamicState.SCISSOR,
                            }
                        },
                    };

                    var err = mConfiguration.Device.CreateGraphicsPipelines(null, new[] { pipelineCreateInfo }, null, out IMgPipeline[] pipelines);
                    Debug.Assert(err == Result.SUCCESS);

                    vsModule.DestroyShaderModule(mConfiguration.Device, null);
                    fsModule.DestroyShaderModule(mConfiguration.Device, null);

                    mPipeline = pipelines[0];
                }
        }
コード例 #8
0
        public EffectVariant Initialize(
            IMgDevice device,
            IMgPipelineLayout layout,
            IMgRenderPass renderPass,
            PerVertexInputPipelineState vertexInput,
            EffectVariantOptions options
            )
        {
            using (var vertFs = mPath.OpenVertexShader())
                using (var fragFs = mPath.OpenFragmentShader())
                {
                    var vsCreateInfo = new MgShaderModuleCreateInfo
                    {
                        Code     = vertFs,
                        CodeSize = new UIntPtr((ulong)vertFs.Length),
                    };
                    device.CreateShaderModule(vsCreateInfo, null, out IMgShaderModule vsModule);

                    var fsCreateInfo = new MgShaderModuleCreateInfo
                    {
                        Code     = fragFs,
                        CodeSize = new UIntPtr((ulong)fragFs.Length),
                    };
                    device.CreateShaderModule(fsCreateInfo, null, out IMgShaderModule fsModule);

                    var createInfo = new MgGraphicsPipelineCreateInfo
                    {
                        Stages = new MgPipelineShaderStageCreateInfo[]
                        {
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.VERTEX_BIT,
                                Module = vsModule,
                                Name   = "vertFunc",
                            },
                            new MgPipelineShaderStageCreateInfo
                            {
                                Stage  = MgShaderStageFlagBits.FRAGMENT_BIT,
                                Module = fsModule,
                                Name   = "fragFunc",
                            },
                        },

                        ColorBlendState = new MgPipelineColorBlendStateCreateInfo
                        {
                            Attachments = new[]
                            {
                                new MgPipelineColorBlendAttachmentState
                                {
                                    ColorWriteMask = MgColorComponentFlagBits.ALL_BITS,
                                    BlendEnable    = false,
                                }
                            },
                        },
                        DepthStencilState = new MgPipelineDepthStencilStateCreateInfo
                        {
                            DepthTestEnable       = true,
                            DepthWriteEnable      = true,
                            DepthCompareOp        = MgCompareOp.LESS_OR_EQUAL,
                            DepthBoundsTestEnable = false,
                            Back = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                            StencilTestEnable = false,
                            Front             = new MgStencilOpState
                            {
                                FailOp    = MgStencilOp.KEEP,
                                PassOp    = MgStencilOp.KEEP,
                                CompareOp = MgCompareOp.ALWAYS,
                            },
                        },
                        DynamicState = new MgPipelineDynamicStateCreateInfo
                        {
                            DynamicStates = new[]
                            {
                                MgDynamicState.VIEWPORT,
                                MgDynamicState.SCISSOR,
                            }
                        },
                        InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                        {
                            Topology = options.Topology,
                        },
                        Layout           = layout,
                        MultisampleState = new MgPipelineMultisampleStateCreateInfo
                        {
                            RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT,
                            SampleMask           = null,
                        },
                        RasterizationState = new MgPipelineRasterizationStateCreateInfo
                        {
                            PolygonMode             = MgPolygonMode.FILL,
                            FrontFace               = options.FrontFace,
                            CullMode                = options.CullMode,
                            DepthClampEnable        = false,
                            RasterizerDiscardEnable = false,
                            DepthBiasEnable         = false,
                            LineWidth               = 1.0f,
                        },
                        RenderPass       = renderPass,
                        VertexInputState = vertexInput.VertexInputState,
                        ViewportState    = null,
                    };

                    var err = device.CreateGraphicsPipelines(null,
                                                             new[] { createInfo }, null, out IMgPipeline[] pPipelines);

                    Debug.Assert(err == Result.SUCCESS);

                    vsModule.DestroyShaderModule(device, null);
                    fsModule.DestroyShaderModule(device, null);

                    return(new EffectVariant
                    {
                        Key = new EffectVariantKey
                        {
                            Definition = vertexInput.VertexMask,
                            Options = EffectVariantEncoder.Encode(options),
                        },
                        Pipeline = pPipelines[0],
                    });
                }
        }
コード例 #9
0
        void InitializeGraphicsPipeline()
        {
            using (var shaderSrc = System.IO.File.OpenRead("Fragment.metal"))
                using (var fragMemory = new System.IO.MemoryStream())
                    using (var vertMemory = new System.IO.MemoryStream())
                    {
                        shaderSrc.CopyTo(fragMemory);
                        // Magnesium uses like open files i.e. open the stream and let it process the data
                        fragMemory.Seek(0, System.IO.SeekOrigin.Begin);

                        // Load the fragment program into the library
                        IMgShaderModule fragmentProgram = null;

                        //IMTLFunction fragmentProgram = defaultLibrary.CreateFunction("lighting_fragment");
                        MgShaderModuleCreateInfo fragCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = fragMemory,
                            CodeSize = new UIntPtr((ulong)fragMemory.Length),
                        };
                        var err = mConfiguration.Device.CreateShaderModule(fragCreateInfo, null, out fragmentProgram);
                        Debug.Assert(err == Result.SUCCESS);

                        // REWIND AFTER USE
                        shaderSrc.Seek(0, System.IO.SeekOrigin.Begin);
                        shaderSrc.CopyTo(vertMemory);

                        vertMemory.Seek(0, System.IO.SeekOrigin.Begin);

                        // Load the vertex program into the library
                        //IMTLFunction vertexProgram = defaultLibrary.CreateFunction("lighting_vertex");
                        MgShaderModuleCreateInfo vertCreateInfo = new MgShaderModuleCreateInfo
                        {
                            Code     = vertMemory,
                            CodeSize = new UIntPtr((ulong)vertMemory.Length),
                        };

                        IMgShaderModule vertexProgram = null;
                        err = mConfiguration.Device.CreateShaderModule(vertCreateInfo, null, out vertexProgram);
                        Debug.Assert(err == Result.SUCCESS);

                        IMgPipelineLayout          pipelineLayout;
                        MgPipelineLayoutCreateInfo plCreateInfo = new MgPipelineLayoutCreateInfo
                        {
                            SetLayouts = new IMgDescriptorSetLayout[]
                            {
                                mSetLayout,
                            },
                        };
                        err             = mConfiguration.Device.CreatePipelineLayout(plCreateInfo, null, out pipelineLayout);
                        mPipelineLayout = pipelineLayout;

                        var vertexStride = Marshal.SizeOf <Vector3>();


                        IMgPipeline[] pipelines;
                        var           pCreateInfos = new MgGraphicsPipelineCreateInfo[]
                        {
                            new MgGraphicsPipelineCreateInfo
                            {
                                Stages = new MgPipelineShaderStageCreateInfo[]
                                {
                                    new MgPipelineShaderStageCreateInfo
                                    {
                                        Module = fragmentProgram,
                                        Stage  = MgShaderStageFlagBits.FRAGMENT_BIT,
                                        Name   = "lighting_fragment",
                                    },
                                    new MgPipelineShaderStageCreateInfo
                                    {
                                        Module = vertexProgram,
                                        Stage  = MgShaderStageFlagBits.VERTEX_BIT,
                                        Name   = "lighting_vertex",
                                    },
                                },
                                InputAssemblyState = new MgPipelineInputAssemblyStateCreateInfo
                                {
                                    Topology = MgPrimitiveTopology.TRIANGLE_LIST,
                                },
                                DepthStencilState = new MgPipelineDepthStencilStateCreateInfo
                                {
                                    DepthCompareOp   = MgCompareOp.LESS,
                                    DepthWriteEnable = true,
                                    DepthTestEnable  = true,
                                },
                                MultisampleState = new MgPipelineMultisampleStateCreateInfo
                                {
                                    // TODO : METALSample uses 4 bits, have to investigated multisampling in
                                    // Vulkan ( => Magnesium) for correct code
                                    RasterizationSamples = MgSampleCountFlagBits.COUNT_1_BIT,
                                },
                                RasterizationState = new MgPipelineRasterizationStateCreateInfo
                                {
                                    FrontFace   = MgFrontFace.COUNTER_CLOCKWISE,
                                    PolygonMode = MgPolygonMode.FILL,
                                    CullMode    = MgCullModeFlagBits.BACK_BIT,
                                },
                                VertexInputState = new MgPipelineVertexInputStateCreateInfo
                                {
                                    VertexBindingDescriptions = new MgVertexInputBindingDescription[]
                                    {
                                        new MgVertexInputBindingDescription
                                        {
                                            Binding   = 0,
                                            InputRate = MgVertexInputRate.VERTEX,
                                            Stride    = (uint)(2 * vertexStride),
                                        },
                                    },
                                    VertexAttributeDescriptions = new MgVertexInputAttributeDescription[]
                                    {
                                        new MgVertexInputAttributeDescription
                                        {
                                            Binding  = 0,
                                            Location = 0,
                                            Format   = MgFormat.R32G32B32_SFLOAT,
                                            Offset   = 0,
                                        },
                                        new MgVertexInputAttributeDescription
                                        {
                                            Binding  = 0,
                                            Location = 1,
                                            Format   = MgFormat.R32G32B32_SFLOAT,
                                            Offset   = (uint)vertexStride,
                                        },
                                    },
                                },
                                ViewportState = new MgPipelineViewportStateCreateInfo
                                {
                                    Viewports = new MgViewport[]
                                    {
                                        mGraphicsDevice.CurrentViewport,
                                    },
                                    Scissors = new MgRect2D[]
                                    {
                                        mGraphicsDevice.Scissor,
                                    }
                                },
                                //DynamicState = new MgPipelineDynamicStateCreateInfo
                                //{
                                //	DynamicStates = new MgDynamicState[]
                                //	{
                                //		MgDynamicState.VIEWPORT,
                                //		MgDynamicState.SCISSOR,
                                //	}
                                //},
                                RenderPass = mGraphicsDevice.Renderpass,
                                Layout     = pipelineLayout,
                            },
                        };
                        err = mConfiguration.Device.CreateGraphicsPipelines(
                            null, pCreateInfos, null, out pipelines);
                        Debug.Assert(err == Result.SUCCESS);

                        fragmentProgram.DestroyShaderModule(mConfiguration.Device, null);
                        vertexProgram.DestroyShaderModule(mConfiguration.Device, null);

                        mPipelineState = pipelines[0];
                    }

            GenerateRenderingCommandBuffers();
        }