Example #1
0
        public void CmdPushConstants(IVkPipelineLayout layout, VkShaderStage stageFlags, int offset, int size, IntPtr values)
        {
            var _commandBuffer = Handle;
            var _layout        = layout?.Handle ?? VkPipelineLayout.HandleType.Null;
            var _stageFlags    = stageFlags;
            var _offset        = offset;
            var _size          = size;
            var _pValues       = values;

            Direct.CmdPushConstants(_commandBuffer, _layout, _stageFlags, _offset, _size, _pValues);
        }
Example #2
0
        public void CmdBindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, IVkPipelineLayout layout, int firstSet, IReadOnlyList <IVkDescriptorSet> descriptorSets, IReadOnlyList <int> dynamicOffsets)
        {
            var unmanagedSize =
                descriptorSets.SizeOfMarshalDirect() +
                dynamicOffsets.SizeOfMarshalDirect();
            var unmanagedArray = new byte[unmanagedSize];

            fixed(byte *unmanagedStart = unmanagedArray)
            {
                var unmanaged           = unmanagedStart;
                var _commandBuffer      = Handle;
                var _pipelineBindPoint  = pipelineBindPoint;
                var _layout             = layout?.Handle ?? VkPipelineLayout.HandleType.Null;
                var _firstSet           = firstSet;
                var _descriptorSetCount = descriptorSets?.Count ?? 0;
                var _pDescriptorSets    = descriptorSets.MarshalDirect(ref unmanaged);
                var _dynamicOffsetCount = dynamicOffsets?.Count ?? 0;
                var _pDynamicOffsets    = dynamicOffsets.MarshalDirect(ref unmanaged);

                Direct.CmdBindDescriptorSets(_commandBuffer, _pipelineBindPoint, _layout, _firstSet, _descriptorSetCount, _pDescriptorSets, _dynamicOffsetCount, _pDynamicOffsets);
            }
        }
Example #3
0
        private void CreateGraphicsPipeline()
        {
            var vertShaderModule = CreateShaderModule(File.ReadAllBytes("../../Resources/Shaders/vert.spv"));
            var fragShaderModule = CreateShaderModule(File.ReadAllBytes("../../Resources/Shaders/frag.spv"));

            var vertShaderStageInfo = new VkPipelineShaderStageCreateInfo()
            {
                Stage  = VkShaderStage.Vertex,
                Module = vertShaderModule,
                Name   = "main"
            };

            var fragShaderStageInfo = new VkPipelineShaderStageCreateInfo()
            {
                Stage  = VkShaderStage.Fragment,
                Module = fragShaderModule,
                Name   = "main"
            };

            var shaderStages    = new[] { vertShaderStageInfo, fragShaderStageInfo };
            var vertexInputInfo = new VkPipelineVertexInputStateCreateInfo
            {
                VertexBindingDescriptions   = new[] { Vertex.GetBindingDescription(0) },
                VertexAttributeDescriptions = Vertex.GetAttributeDescriptions(0)
            };
            var inputAssemblyInfo = new VkPipelineInputAssemblyStateCreateInfo
            {
                Topology = VkPrimitiveTopology.TriangleList,
                PrimitiveRestartEnable = false
            };
            var viewport = new VkViewport
            {
                X        = 0,
                Y        = 0,
                Width    = swapChainExtent.Width,
                Height   = swapChainExtent.Height,
                MinDepth = 0,
                MaxDepth = 1
            };
            var scissor           = new VkRect2D(new VkOffset2D(0, 0), swapChainExtent);
            var viewportStateInfo = new VkPipelineViewportStateCreateInfo
            {
                Viewports = new [] { viewport },
                Scissors  = new [] { scissor }
            };
            var rasterizerInfo = new VkPipelineRasterizationStateCreateInfo
            {
                DepthClampEnable        = false,
                RasterizerDiscardEnable = false,
                PolygonMode             = VkPolygonMode.Fill,
                LineWidth               = 1f,
                CullMode                = VkCullMode.Back,
                FrontFace               = VkFrontFace.Clockwise,
                DepthBiasEnable         = false,
                DepthBiasConstantFactor = 0f,
                DepthBiasClamp          = 0f,
                DepthBiasSlopeFactor    = 0f
            };
            var multisamplingInfo = new VkPipelineMultisampleStateCreateInfo
            {
                SampleShadingEnable   = false,
                RasterizationSamples  = VkSampleCount.B1,
                MinSampleShading      = 1f,
                SampleMask            = null,
                AlphaToCoverageEnable = false,
                AlphaToOneEnable      = false
            };
            var colorBlendAttachment = new VkPipelineColorBlendAttachmentState
            {
                ColorWriteMask      = VkColorComponent.R | VkColorComponent.G | VkColorComponent.B | VkColorComponent.A,
                BlendEnable         = (VkBool32)false,
                SrcColorBlendFactor = VkBlendFactor.One,
                SrcAlphaBlendFactor = VkBlendFactor.One,
                ColorBlendOp        = VkBlendOp.Add,
                AlphaBlendOp        = VkBlendOp.Add,
                DstColorBlendFactor = VkBlendFactor.Zero,
                DstAlphaBlendFactor = VkBlendFactor.Zero
            };
            var colorBlendingInfo = new VkPipelineColorBlendStateCreateInfo
            {
                LogicOpEnable  = false,
                LogicOp        = VkLogicOp.Copy,
                Attachments    = new[] { colorBlendAttachment },
                BlendConstants = new VkColor4(0, 0, 0, 0)
            };
            var dynamicStates = new[]
            {
                VkDynamicState.Viewport,
                VkDynamicState.LineWidth,
            };
            var dynamicStateInfo = new VkPipelineDynamicStateCreateInfo
            {
                DynamicStates = dynamicStates
            };
            var pipelineLayoutInfo = new VkPipelineLayoutCreateInfo
            {
                SetLayouts         = null,
                PushConstantRanges = null
            };

            pipelineLayout = device.CreatePipelineLayout(pipelineLayoutInfo, null).Object;

            var pipelineInfo = new VkGraphicsPipelineCreateInfo
            {
                Stages             = shaderStages,
                VertexInputState   = vertexInputInfo,
                InputAssemblyState = inputAssemblyInfo,
                TessellationState  = null,
                ViewportState      = viewportStateInfo,
                RasterizationState = rasterizerInfo,
                MultisampleState   = multisamplingInfo,
                DepthStencilState  = null,
                ColorBlendState    = colorBlendingInfo,
                DynamicState       = null,
                Layout             = pipelineLayout,
                RenderPass         = renderPass,
                Subpass            = 0,
                BasePipelineHandle = null,
                BasePipelineIndex  = -1,
                Flags = VkPipelineCreateFlags.None
            };

            graphicsPipeline = device.CreateGraphicsPipelines(null, new[] { pipelineInfo }, null).Object.Single();

            vertShaderModule.Dispose();
            fragShaderModule.Dispose();
        }
Example #4
0
 public void CmdPushConstants(IVkPipelineLayout layout, VkShaderStageFlagBits stageFlags, int offset, int size, IntPtr values)
 {
     var _commandBuffer = Handle;
     var _layout = layout?.Handle ?? VkPipelineLayout.HandleType.Null;
     var _stageFlags = stageFlags;
     var _offset = offset;
     var _size = size;
     var _pValues = values;
     Direct.CmdPushConstants(_commandBuffer, _layout, _stageFlags, _offset, _size, _pValues);
 }
Example #5
0
 public void CmdBindDescriptorSets(VkPipelineBindPoint pipelineBindPoint, IVkPipelineLayout layout, int firstSet, IReadOnlyList<IVkDescriptorSet> descriptorSets, IReadOnlyList<int> dynamicOffsets)
 {
     var unmanagedSize =
         descriptorSets.SizeOfMarshalDirect() +
         dynamicOffsets.SizeOfMarshalDirect();
     var unmanagedArray = new byte[unmanagedSize];
     fixed (byte* unmanagedStart = unmanagedArray)
     {
         var unmanaged = unmanagedStart;
         var _commandBuffer = Handle;
         var _pipelineBindPoint = pipelineBindPoint;
         var _layout = layout?.Handle ?? VkPipelineLayout.HandleType.Null;
         var _firstSet = firstSet;
         var _descriptorSetCount = descriptorSets?.Count ?? 0;
         var _pDescriptorSets = descriptorSets.MarshalDirect(ref unmanaged);
         var _dynamicOffsetCount = dynamicOffsets?.Count ?? 0;
         var _pDynamicOffsets = dynamicOffsets.MarshalDirect(ref unmanaged);
         Direct.CmdBindDescriptorSets(_commandBuffer, _pipelineBindPoint, _layout, _firstSet, _descriptorSetCount, _pDescriptorSets, _dynamicOffsetCount, _pDynamicOffsets);
     }
 }