Ejemplo n.º 1
0
 public EffectLayout(
     IMgDescriptorSetLayout descriptorSetLayout,
     IMgPipelineLayout layout
     )
 {
     DescriptorSetLayout = descriptorSetLayout;
     Layout = layout;
 }
Ejemplo n.º 2
0
        public void CmdPushConstants(IMgPipelineLayout layout, MgShaderStageFlagBits stageFlags, UInt32 offset, UInt32 size, IntPtr pValues)
        {
            var bLayout = (VkPipelineLayout)layout;

            Debug.Assert(bLayout != null);

            Interops.vkCmdPushConstants(this.Handle, bLayout.Handle, (Magnesium.Vulkan.VkShaderStageFlags)stageFlags, offset, size, pValues);
        }
Ejemplo n.º 3
0
 public void CmdBindDescriptorSets(
     MgPipelineBindPoint pipelineBindPoint,
     IMgPipelineLayout layout,
     uint firstSet,
     uint descriptorSetCount,
     IMgDescriptorSet[] pDescriptorSets,
     uint[] pDynamicOffsets)
 {
     if (pipelineBindPoint == MgPipelineBindPoint.GRAPHICS)
     {
         mCommandEncoder.Graphics.BindDescriptorSets(layout,
                                                     firstSet,
                                                     descriptorSetCount,
                                                     pDescriptorSets,
                                                     pDynamicOffsets);
     }
 }
Ejemplo n.º 4
0
        public void CmdBindDescriptorSets(MgPipelineBindPoint pipelineBindPoint, IMgPipelineLayout layout, UInt32 firstSet, UInt32 descriptorSetCount, IMgDescriptorSet[] pDescriptorSets, UInt32[] pDynamicOffsets)
        {
            var bLayout = (VkPipelineLayout)layout;

            Debug.Assert(bLayout != null);

            var    stride = Marshal.SizeOf(typeof(IntPtr));
            IntPtr sets   = Marshal.AllocHGlobal((int)(stride * descriptorSetCount));

            var src = new ulong[descriptorSetCount];

            for (uint i = 0; i < descriptorSetCount; ++i)
            {
                var bDescSet = (VkDescriptorSet)pDescriptorSets[i];
                Debug.Assert(bDescSet != null);
                src[i] = bDescSet.Handle;
            }

            Interops.vkCmdBindDescriptorSets(this.Handle, (VkPipelineBindPoint)pipelineBindPoint, bLayout.Handle, firstSet, descriptorSetCount, src, (uint)pDynamicOffsets.Length, pDynamicOffsets);
        }
Ejemplo n.º 5
0
        public void Bind(MgPipelineBindPoint pipelineBindPoint, IMgPipelineLayout layout, uint firstSet,
                         uint descriptorSetCount, IMgDescriptorSet[] pDescriptorSets, uint[] pDynamicOffsets)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            if (pDescriptorSets == null)
            {
                throw new ArgumentNullException(nameof(pDescriptorSets));
            }

            if (firstSet != 0)
            {
                throw new ArgumentException("Mg.GL : only descriptor set 0 can be bound.");
            }

            var bLayout = (IGLPipelineLayout)layout;

            IsInvalid = false;
            if (!bLayout.Equals(BoundPipelineLayout))
            {
                BoundPipelineLayout = bLayout;
                IsInvalid           = true;
            }

            var isArrayDifferent = CopyDynamicOffsetsIfDifferent(pDynamicOffsets);

            IsInvalid = IsInvalid && isArrayDifferent;

            var bDescSet = (IGLDescriptorSet)pDescriptorSets[0];

            // EXACT DSET ONLY
            if (!bDescSet.Equals(BoundDescriptorSet))
            {
                BoundDescriptorSet = bDescSet;
                IsInvalid          = true;
            }
        }
Ejemplo n.º 6
0
 public void CmdBindDescriptorSets(
     MgPipelineBindPoint pipelineBindPoint,
     IMgPipelineLayout layout,
     uint firstSet,
     uint descriptorSetCount,
     IMgDescriptorSet[] pDescriptorSets,
     uint[] pDynamicOffsets)
 {
     //var parameter = new AmtDescriptorSetRecordingState();
     //parameter.Bindpoint = pipelineBindPoint;
     //parameter.Layout = layout;
     //parameter.FirstSet = firstSet;
     //parameter.DynamicOffsets = pDynamicOffsets;
     //parameter.DescriptorSets = pDescriptorSets;
     //mRepository.DescriptorSets.Add(parameter);
     if (pipelineBindPoint == MgPipelineBindPoint.GRAPHICS)
     {
         mCommandEncoder.Graphics.BindDescriptorSets(layout,
                                                     firstSet,
                                                     descriptorSetCount,
                                                     pDescriptorSets,
                                                     pDynamicOffsets);
     }
 }
Ejemplo n.º 7
0
 public Result CreatePipelineLayout(MgPipelineLayoutCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgPipelineLayout pPipelineLayout)
 {
     pPipelineLayout = new AmtPipelineLayout(pCreateInfo);
     return(Result.SUCCESS);
 }
Ejemplo n.º 8
0
 public Result CreatePipelineLayout(MgPipelineLayoutCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgPipelineLayout pPipelineLayout)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
        public Result CreatePipelineLayout(MgPipelineLayoutCreateInfo pCreateInfo, IMgAllocationCallbacks allocator, out IMgPipelineLayout pPipelineLayout)
        {
            if (pCreateInfo == null)
            {
                throw new ArgumentNullException("pCreateInfo");
            }

            if (pCreateInfo.SetLayouts == null)
            {
                throw new ArgumentNullException("pCreateInfo.SetLayouts");
            }

            if (pCreateInfo.SetLayouts.Length > 1)
            {
                throw new NotSupportedException("DESKTOPGL - SetLayouts must be <= 1");
            }

            pPipelineLayout = new GLNextPipelineLayout(pCreateInfo);
            return(Result.SUCCESS);
        }
Ejemplo n.º 10
0
 public void CmdBindDescriptorSets(MgPipelineBindPoint pipelineBindPoint, IMgPipelineLayout layout, uint firstSet, uint descriptorSetCount, IMgDescriptorSet[] pDescriptorSets, uint[] pDynamicOffsets)
 {
     mBinder.Bind(pipelineBindPoint, layout, firstSet, descriptorSetCount, pDescriptorSets, pDynamicOffsets);
 }
Ejemplo n.º 11
0
 public void CmdPushConstants(IMgPipelineLayout layout, MgShaderStageFlagBits stageFlags, uint offset, uint size, IntPtr pValues)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
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],
                    });
                }
        }
Ejemplo n.º 13
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();
        }