Esempio n. 1
0
        public AmtShaderModule(MgShaderModuleCreateInfo pCreateInfo)
        {
            if (pCreateInfo == null)
            {
                throw new ArgumentNullException(nameof(pCreateInfo));
            }

            Info = pCreateInfo;
        }
Esempio n. 2
0
 public Result CreateShaderModule(MgShaderModuleCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgShaderModule pShaderModule)
 {
     pShaderModule = new AmtShaderModule(pCreateInfo);
     return(Result.SUCCESS);
 }
Esempio n. 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];
                }
        }
Esempio n. 4
0
 public Result CreateShaderModule(MgShaderModuleCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgShaderModule pShaderModule)
 {
     throw new NotImplementedException();
 }
Esempio n. 5
0
 public GLShaderModule(MgShaderModuleCreateInfo pCreateInfo, IGLShaderModuleEntrypoint entrypoint)
 {
     Info        = pCreateInfo;
     mEntrypoint = entrypoint;
 }
Esempio n. 6
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];
                }
        }
Esempio n. 7
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],
                    });
                }
        }
Esempio n. 8
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();
        }