Esempio n. 1
0
        public unsafe override void Run(Frame frame, CommandBuffer cmd)
        {
            Vk vk = renderer.Vk;

            Pipelines.Pipeline fPipeline = Pipelines.Pipeline.GetPipeline(renderPipeline, renderer);
            fPipeline.Bind(cmd);

            DescriptorSet descriptorSet = frame.DescriptorSetManager.GetDescriptorSet();

            renderer.Shader.SetUniforms(frame, descriptorSet, uniformOffset, image);
            vk.CmdBindDescriptorSets(cmd, PipelineBindPoint.Graphics, renderer.Shader.PipelineLayout, 0, 1, descriptorSet, 0, 0);

            foreach (Path path in paths)
            {
                vk.CmdDraw(cmd, path.FillCount, 1, path.FillOffset, 0);
            }

            if (renderer.EdgeAntiAlias)
            {
                Pipelines.Pipeline aaPipeline = Pipelines.Pipeline.GetPipeline(antiAliasPipeline, renderer);
                aaPipeline.Bind(cmd);

                foreach (Path path in paths)
                {
                    vk.CmdDraw(cmd, path.StrokeCount, 1, path.StrokeOffset, 0);
                }
            }
        }
        private void CreateDescriptorSet()
        {
            var allocInfo = new DescriptorSetAllocateInfo()
            {
                DescriptorPool = vkDescriptorPool,
                SetLayouts     = new DescriptorSetLayout[] { vkDescriptorSetLayout },
            };

            vkDescriptorSet = vkDevice.AllocateDescriptorSets(allocInfo)[0];

            var bufferInfo = new DescriptorBufferInfo()
            {
                Buffer = vkUniformBuffer,
                Offset = 0,
                Range  = Marshal.SizeOf <UniformBufferObject>(),
            };

            var descriptorWrite = new WriteDescriptorSet()
            {
                DstSet          = vkDescriptorSet,
                DstBinding      = 0,
                DstArrayElement = 0,
                DescriptorType  = DescriptorType.UniformBuffer,
                DescriptorCount = 1,
                BufferInfo      = new DescriptorBufferInfo[] { bufferInfo },
            };

            vkDevice.UpdateDescriptorSet(descriptorWrite, null);
        }
Esempio n. 3
0
        public void UpdateSetsDescriptorWrite()
        {
            const int bufferSize = 256;

            var layoutCreateInfo = new DescriptorSetLayoutCreateInfo(
                new DescriptorSetLayoutBinding(0, DescriptorType.StorageBuffer, 1));
            var poolCreateInfo = new DescriptorPoolCreateInfo(
                1,
                new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, 1) },
                DescriptorPoolCreateFlags.FreeDescriptorSet);

            using (Buffer buffer = Device.CreateBuffer(new BufferCreateInfo(bufferSize, BufferUsages.StorageBuffer)))
                using (DeviceMemory memory = Device.AllocateMemory(new MemoryAllocateInfo(bufferSize, 0)))
                    using (DescriptorSetLayout layout = Device.CreateDescriptorSetLayout(layoutCreateInfo))
                        using (DescriptorPool pool = Device.CreateDescriptorPool(poolCreateInfo))
                            using (DescriptorSet set = pool.AllocateSets(new DescriptorSetAllocateInfo(1, layout))[0])
                            {
                                // Required to satisfy the validation layer.
                                buffer.GetMemoryRequirements();

                                buffer.BindMemory(memory);

                                var descriptorWrite = new WriteDescriptorSet(set, 0, 0, 1, DescriptorType.StorageBuffer,
                                                                             bufferInfo: new[] { new DescriptorBufferInfo(buffer) });
                                pool.UpdateSets(new[] { descriptorWrite });
                            }
        }
 public IncludeComposingExpressionVisitor(
     IModel model,
     DescriptorSet descriptorSet)
 {
     this.model         = model;
     this.descriptorSet = descriptorSet;
 }
Esempio n. 5
0
        void init_final_pl()
        {
            descriptorPool = new DescriptorPool(dev, 3,
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 2),
                                                new VkDescriptorPoolSize(VkDescriptorType.StorageImage, 4)
                                                );

            GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, DeferredPbrRenderer.NUM_SAMPLES);

            if (DeferredPbrRenderer.NUM_SAMPLES != VkSampleCountFlags.SampleCount1)
            {
                cfg.multisampleState.sampleShadingEnable = true;
                cfg.multisampleState.minSampleShading    = 0.5f;
            }
            cfg.Layout = new PipelineLayout(dev,
                                            new VkPushConstantRange(VkShaderStageFlags.Fragment, 2 * sizeof(float)),
                                            new DescriptorSetLayout(dev, 0,
                                                                    new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                                    ));

            cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, DeferredPbrRenderer.NUM_SAMPLES);

            using (ShaderInfo vs = new ShaderInfo(dev, VkShaderStageFlags.Vertex, "#vke.FullScreenQuad.vert.spv"))
                using (ShaderInfo fs = new ShaderInfo(dev, VkShaderStageFlags.Fragment, "#shaders.tone_mapping.frag.spv"))
                {
                    cfg.AddShaders(vs, fs);

                    plToneMap = new GraphicPipeline(cfg);
                }

            descriptorSet = descriptorPool.Allocate(cfg.Layout.DescriptorSetLayouts[0]);
        }
Esempio n. 6
0
        /// <summary>
        /// Write the contents of a descriptor set object.
        /// </summary>
        /// <param name="destinationSet">
        /// The destination descriptor set to update.
        /// </param>
        /// <param name="destinationBinding">
        /// The descriptor binding within the set.
        /// </param>
        /// <param name="destinationArrayElement">
        /// The starting element in the binding array.
        /// </param>
        /// <param name="descriptorType">
        /// A DescriptorType specifying the type of each descriptor in
        /// imageInfos.
        /// It must be the same type as that specified in
        /// DescriptorSetLayoutBinding for destinationSet at
        /// destinationBinding. The type of the descriptor also controls which
        /// array the descriptors are taken from.
        /// </param>
        /// <param name="imageInfos">
        /// An array of DescriptorImageInfo structures.
        /// </param>
        public unsafe void WriteDescriptorSet(DescriptorSet destinationSet, uint destinationBinding, uint destinationArrayElement, DescriptorType descriptorType, ArrayProxy <DescriptorImageInfo>?imageInfos)
        {
            int bufferInfosLength = imageInfos?.Length ?? 0;
            var marshalledInfos   = (Interop.DescriptorImageInfo *)Interop.HeapUtil.Allocate <Interop.DescriptorImageInfo>(bufferInfosLength);

            for (int index = 0; index < bufferInfosLength; index++)
            {
                imageInfos.Value[index].MarshalTo(&marshalledInfos[index]);
            }

            Interop.WriteDescriptorSet info = new Interop.WriteDescriptorSet
            {
                SType                   = StructureType.WriteDescriptorSet,
                ImageInfo               = marshalledInfos,
                DestinationSet          = destinationSet.handle,
                DestinationBinding      = destinationBinding,
                DestinationArrayElement = destinationArrayElement,
                DescriptorCount         = (uint)bufferInfosLength,
                DescriptorType          = descriptorType
            };

            var commandDelegate = commandCache.GetCommandDelegate <Interop.VkDeviceUpdateDescriptorSetsDelegate>("vkUpdateDescriptorSets", "");

            commandDelegate(this.handle, 1, &info, 0, null);
        }
Esempio n. 7
0
        public void CreatePipelineState()
        {
            string images   = Constants.ImagesFile;
            string fragment = Constants.ShadersFile + @"SpecularLighting\Fragment.hlsl";
            string vertex   = Constants.ShadersFile + @"SpecularLighting\Vertex.hlsl";

            Image text1 = ImageFile.Load2DFromFile(Device, images + "UV_Grid_Sm.jpg");

            Sampler sampler = new Sampler(Device);


            GraphicsPipelineDescription Pipelinedescription0 = new();

            Pipelinedescription0.SetFramebuffer(Framebuffer);
            Pipelinedescription0.SetShader(new ShaderBytecode(fragment, ShaderStage.Fragment));
            Pipelinedescription0.SetShader(new ShaderBytecode(vertex, ShaderStage.Vertex));
            Pipelinedescription0.SetVertexBinding(VertexInputRate.Vertex, VertexPositionNormalTexture.Size);
            Pipelinedescription0.SetVertexAttribute(VertexType.Position);
            Pipelinedescription0.SetVertexAttribute(VertexType.Normal);
            Pipelinedescription0.SetVertexAttribute(VertexType.TextureCoordinate);
            //Pipelinedescription0.SetFillMode(VkPolygonMode.Line);
            PipelineState_0 = new(Pipelinedescription0);

            DescriptorData descriptorData_0 = new();

            descriptorData_0.SetUniformBuffer(0, ConstBuffer);
            descriptorData_0.SetImage(1, text1);
            descriptorData_0.SetSampler(2, sampler);
            descriptorData_0.SetUniformBuffer(3, ConstBuffer2);
            DescriptorSet_0 = new(PipelineState_0, descriptorData_0);
        }
Esempio n. 8
0
        void init(VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4)
        {
            descriptorPool = new DescriptorPool(dev, 2,
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler)
                                                );

            descLayout = new DescriptorSetLayout(dev,
                                                 new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                 );

            GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, samples);

            cfg.Layout     = new PipelineLayout(dev, descLayout);
            cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), samples);

            cfg.ResetShadersAndVerticesInfos();
            cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/FullScreenQuad.vert.spv");
            cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/simpletexture.frag.spv");

            cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState(true);

            uiPipeline = new GraphicPipeline(cfg);

            dsVkvg = descriptorPool.Allocate(descLayout);
        }
Esempio n. 9
0
        private void CreateDescriptorSet()
        {
            this.descriptorSet = this.device.AllocateDescriptorSets(new DescriptorSetAllocateInfo
            {
                DescriptorPool = this.descriptorPool,
                SetLayouts     = new[]
                {
                    this.descriptorSetLayout
                }
            }).Single();

            this.device.UpdateDescriptorSets(new[]
            {
                new WriteDescriptorSet
                {
                    BufferInfo = new []
                    {
                        new DescriptorBufferInfo
                        {
                            Buffer = this.uniformBuffer,
                            Offset = 0,
                            Range  = MemUtil.SizeOf <UniformBufferObject>()
                        }
                    },
                    DestinationSet          = this.descriptorSet,
                    DestinationBinding      = 0,
                    DestinationArrayElement = 0,
                    DescriptorType          = DescriptorType.UniformBuffer
                }
            }, null);
        }
Esempio n. 10
0
        private void CreateDescriptors()
        {
            int bindingCount = Inputs.Count + 1; // + 1 output.

            // Setup bindings.
            var bindings = new DescriptorSetLayoutBinding[bindingCount];

            for (int i = 0; i < Inputs.Count; i++)
            {
                bindings[i] = Inputs[i].GetDescriptorSetLayoutBinding(i);
            }
            bindings[Inputs.Count] = Output.GetDescriptorSetLayoutBinding(Inputs.Count);

            _descriptorSetLayout = Device.Logical.CreateDescriptorSetLayout(new DescriptorSetLayoutCreateInfo(bindings));
            var descriptorPoolCreateInfo = new DescriptorPoolCreateInfo(
                1,
                new[] { new DescriptorPoolSize(DescriptorType.StorageBuffer, bindingCount) });

            _descriptorPool = Device.Logical.CreateDescriptorPool(descriptorPoolCreateInfo);
            _descriptorSet  = _descriptorPool.AllocateSets(new DescriptorSetAllocateInfo(1, _descriptorSetLayout))[0];

            // Setup write descriptors.
            var writeDescriptorSets = new WriteDescriptorSet[bindingCount];

            for (int i = 0; i < Inputs.Count; i++)
            {
                writeDescriptorSets[i] = Inputs[i].GetWriteDescriptorSet(_descriptorSet, i);
            }
            writeDescriptorSets[Inputs.Count] = Output.GetWriteDescriptorSet(_descriptorSet, Inputs.Count);

            _descriptorPool.UpdateSets(writeDescriptorSets);
        }
Esempio n. 11
0
        private static void SetupUniformMatrices()
        {
            Matrix4 projectionMatrix =
                new Matrix4(
                    1.0f, 0.0f, 0.0f, 0.0f,
                    0.0f, -1.0f, 0.0f, 0.0f,
                    0.0f, 0.0f, 0.5f, 0.0f,
                    0.0f, 0.0f, 0.5f, 1.0f)
                * Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Context.SurfaceWidth / (float)Context.SurfaceHeight, 0.1f, 100.0f);


            VulkanBase.Camera.Position = new Vector3(0.0f, 10f, 0.0f);
            VulkanBase.Camera.Rotation = new Vector3(0, (float)Math.PI / 2f, 0);

            Matrix4 viewMatrix = VulkanBase.Camera.CalculateViewMatrix();


            uint bufferSize = graphicsPipeline.ShaderUniformSets[0].GetSize();

            Matrix4[] matrices = new Matrix4[]
            {
                projectionMatrix,
                viewMatrix
            };

            uniformBuffer = Context.BufferManager.CreateBuffer(BufferUsageFlags.UniformBuffer, bufferSize, matrices);


            uniformDescriptorSet = graphicsPipeline.CreateDescriptorSet(0, 0, uniformBuffer);
        }
 public DefaultQueryProcessingContextFactory(
     DescriptorSet descriptorSet,
     ImpatientCompatibility compatibility)
 {
     this.descriptorSet = descriptorSet ?? throw new ArgumentNullException(nameof(descriptorSet));
     this.compatibility = compatibility;
 }
Esempio n. 13
0
        public Program()
        {
            instance = new Instance();
            phy      = instance.GetAvailablePhysicalDevice().FirstOrDefault();
            dev      = new Device(phy);
            computeQ = new Queue(dev, VkQueueFlags.Compute);

            dev.Activate(default(VkPhysicalDeviceFeatures));

            createRandomDatas();

            inBuff  = new HostBuffer <int> (dev, VkBufferUsageFlags.StorageBuffer, datas);
            outBuff = new HostBuffer <int> (dev, VkBufferUsageFlags.StorageBuffer, data_size);

            dsPool   = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.StorageBuffer, 2));
            dsLayout = new DescriptorSetLayout(dev,
                                               new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer),
                                               new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Compute, VkDescriptorType.StorageBuffer)
                                               );

            plCompute = new ComputePipeline(new PipelineLayout(dev, dsLayout), "#shaders.compute.comp.spv");

            dset = dsPool.Allocate(dsLayout);
            DescriptorSetWrites dsUpdate = new DescriptorSetWrites(dset, dsLayout);

            dsUpdate.Write(dev, inBuff.Descriptor, outBuff.Descriptor);
        }
Esempio n. 14
0
        Program() : base(false)
        {
            vbo     = new HostBuffer <Vertex> (dev, VkBufferUsageFlags.VertexBuffer, vertices);
            ibo     = new HostBuffer <ushort> (dev, VkBufferUsageFlags.IndexBuffer, indices);
            uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, matrices);

            descriptorPool = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer));
            dsLayout       = new DescriptorSetLayout(dev,
                                                     new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer));

            GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1);

            cfg.Layout     = new PipelineLayout(dev, dsLayout);
            cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), cfg.Samples);
            cfg.AddVertexBinding <Vertex> (0);
            cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat);

            cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/triangle.vert.spv");
            cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/triangle.frag.spv");

            pipeline = new GraphicPipeline(cfg);

            descriptorSet = descriptorPool.Allocate(dsLayout);
            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descriptorSet, dsLayout);

            uboUpdate.Write(dev, uboMats.Descriptor);

            uboMats.Map();
        }
Esempio n. 15
0
        private DescriptorSet[] AllocateDescriptorSets()
        {
            fixed(DescriptorSetLayout *pLayouts = this.DescriptorSetLayouts)
            {
                DescriptorSetAllocateInfo allocInfo = new DescriptorSetAllocateInfo
                {
                    SType              = StructureType.DescriptorSetAllocateInfo,
                    DescriptorPool     = this.DescriptorPool,
                    DescriptorSetCount = (uint)this.DescriptorSetLayouts.Length,
                    PSetLayouts        = pLayouts
                };

                var arr = new DescriptorSet[this.DescriptorSetLayouts.Length];

                fixed(DescriptorSet *pSets = arr)
                {
                    var res = VkApi.AllocateDescriptorSets(this.Device, &allocInfo, pSets);

                    if (res != Result.Success)
                    {
                        throw new VMASharp.VulkanResultException("Failed to allocate Descriptor Sets!", res);
                    }

                    return(arr);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Write the contents of a descriptor set object.
        /// </summary>
        /// <param name="destinationSet">
        /// The destination descriptor set to update.
        /// </param>
        /// <param name="destinationBinding">
        /// The descriptor binding within the set.
        /// </param>
        /// <param name="destinationArrayElement">
        /// The starting element in the binding array.
        /// </param>
        /// <param name="descriptorType">
        /// A DescriptorType specifying the type of each descriptor in
        /// texelBufferViews.
        /// It must be the same type as that specified in
        /// DescriptorSetLayoutBinding for destinationSet at
        /// destinationBinding. The type of the descriptor also controls which
        /// array the descriptors are taken from.
        /// </param>
        /// <param name="texelBufferViews">
        /// An array of BufferViews.
        /// </param>
        public unsafe void WriteDescriptorSet(DescriptorSet destinationSet, uint destinationBinding, uint destinationArrayElement, DescriptorType descriptorType, ArrayProxy <BufferView>?texelBufferViews)
        {
            int bufferInfosLength = texelBufferViews?.Length ?? 0;
            var marshalledViews   = (Interop.BufferView *)Interop.HeapUtil.Allocate <Interop.BufferView>(bufferInfosLength);

            for (int index = 0; index < bufferInfosLength; index++)
            {
                marshalledViews[index] = texelBufferViews.Value[index].handle;
            }

            Interop.WriteDescriptorSet info = new Interop.WriteDescriptorSet
            {
                SType                   = StructureType.WriteDescriptorSet,
                TexelBufferView         = marshalledViews,
                DestinationSet          = destinationSet.handle,
                DestinationBinding      = destinationBinding,
                DestinationArrayElement = destinationArrayElement,
                DescriptorCount         = (uint)bufferInfosLength,
                DescriptorType          = descriptorType
            };

            var commandDelegate = commandCache.GetCommandDelegate <Interop.VkDeviceUpdateDescriptorSetsDelegate>("vkUpdateDescriptorSets", "");

            commandDelegate(this.handle, 1, &info, 0, null);
        }
Esempio n. 17
0
        public static DescriptorSet CreateDescriptorSet(DescriptorPool pool, DescriptorSetLayout setLayout, DescriptorItem[] items, out Sampler[] samplers)
        {
            DescriptorSet descriptorSet = pool.AllocateSets(new DescriptorSetAllocateInfo(1, setLayout))[0];

            var writeDescriptorSets = new WriteDescriptorSet[items.Length];

            for (var i = 0; i < items.Length; i++)
            {
                var item = items[i];
                switch (item.Type)
                {
                case DescriptorItem.DescriptorType.UniformBuffer:
                    writeDescriptorSets[i] = new WriteDescriptorSet(descriptorSet, i, 0, item.Count, DescriptorType.UniformBuffer,
                                                                    bufferInfo: new[] { new DescriptorBufferInfo(item.Buffer, 0, item.Buffer.Size) });
                    break;

                case DescriptorItem.DescriptorType.CombinedImageSampler:
                    _SamplerCollection.Add(item.Sampler);
                    writeDescriptorSets[i] = new WriteDescriptorSet(descriptorSet, i, 0, 1, DescriptorType.CombinedImageSampler,
                                                                    imageInfo: new[] { new DescriptorImageInfo(item.Sampler, item.Texture.View, VulkanCore.ImageLayout.General) });
                    break;

                default:
                    throw new NotImplementedException($"No case for {item.Type}");
                }
            }

            pool.UpdateSets(writeDescriptorSets);

            samplers = _SamplerCollection.ToArray();
            _SamplerCollection.Clear();
            return(descriptorSet);
        }
Esempio n. 18
0
            public unsafe DescriptorSetCollection AllocateDescriptorSets(ReadOnlySpan <DescriptorSetLayout> layouts)
            {
                Debug.Assert(!_done);
                _totalSets += layouts.Length;
                _setsInUse += layouts.Length;

                DescriptorSet[] descriptorSets = new DescriptorSet[layouts.Length];

                fixed(DescriptorSet *pDescriptorSets = descriptorSets)
                {
                    fixed(DescriptorSetLayout *pLayouts = layouts)
                    {
                        var descriptorSetAllocateInfo = new DescriptorSetAllocateInfo()
                        {
                            SType              = StructureType.DescriptorSetAllocateInfo,
                            DescriptorPool     = _pool,
                            DescriptorSetCount = (uint)layouts.Length,
                            PSetLayouts        = pLayouts
                        };

                        Api.AllocateDescriptorSets(Device, &descriptorSetAllocateInfo, pDescriptorSets).ThrowOnError();
                    }
                }

                return(new DescriptorSetCollection(this, descriptorSets));
            }
Esempio n. 19
0
            public new static DescriptorSet Parse(WordReader reader, uint wordCount)
            {
                var end = reader.Position + wordCount;
                var res = new DescriptorSet();

                res.DescriptorSetValue = Spv.LiteralInteger.Parse(reader, end - reader.Position);
                return(res);
            }
Esempio n. 20
0
 public WriteDescriptorSet CreateDescriptorWrite(DescriptorSet set, int binding)
 => new WriteDescriptorSet(
     dstSet: set,
     dstBinding: binding,
     dstArrayElement: 0,
     descriptorCount: 1,
     descriptorType: DescriptorType,
     bufferInfo: new [] { new DescriptorBufferInfo(buffer, offset: 0, range: size) });
Esempio n. 21
0
 public EFCoreQueryProcessingContextFactory(
     ICurrentDbContext currentDbContext,
     DescriptorSet descriptorSet,
     ImpatientCompatibility compatibility)
 {
     this.currentDbContext = currentDbContext ?? throw new ArgumentNullException(nameof(currentDbContext));
     this.descriptorSet    = descriptorSet ?? throw new ArgumentNullException(nameof(descriptorSet));
     this.compatibility    = compatibility;
 }
Esempio n. 22
0
 public QueryProcessingContext(
     IQueryProvider queryProvider,
     DescriptorSet descriptorSet)
 {
     QueryProvider    = queryProvider;
     DescriptorSet    = descriptorSet;
     ParameterMapping = new Dictionary <object, ParameterExpression>();
     //ExecutionContextParameter = Expression.Parameter(typeof(IDbCommandExecutor), "executor");
 }
Esempio n. 23
0
        public PBRPipeline(Queue staggingQ, RenderPass renderPass, string cubeMapPath, PipelineCache pipelineCache = null) :
            base(renderPass, pipelineCache, "pbr pipeline")
        {
            descriptorPool = new DescriptorPool(Dev, 2,
                                                new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer, 2),
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler, 8)
                                                );

            descLayoutMain = new DescriptorSetLayout(Dev,
                                                     new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),
                                                     new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                     new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer));

            descLayoutTextures = new DescriptorSetLayout(Dev,
                                                         new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                                         new VkDescriptorSetLayoutBinding(4, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                         );

            using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples)) {
                cfg.Layout = new PipelineLayout(Dev, descLayoutMain, descLayoutTextures);
                cfg.Layout.AddPushConstants(
                    new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()),
                    new VkPushConstantRange(VkShaderStageFlags.Fragment, sizeof(int), 64)
                    );
                cfg.RenderPass = renderPass;
                cfg.AddVertexBinding <PbrModel.Vertex> (0);
                cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat, VkFormat.R32g32Sfloat);

                cfg.AddShader(Dev, VkShaderStageFlags.Vertex, "#shaders.pbr.vert.spv");
                cfg.AddShader(Dev, VkShaderStageFlags.Fragment, "#shaders.pbr_khr.frag.spv");

                layout = cfg.Layout;

                init(cfg);
            }

            dsMain = descriptorPool.Allocate(descLayoutMain);

            envCube = new EnvironmentCube(cubeMapPath, layout, staggingQ, RenderPass);

            matrices.prefilteredCubeMipLevels = envCube.prefilterCube.CreateInfo.mipLevels;
            uboMats = new HostBuffer(Dev, VkBufferUsageFlags.UniformBuffer, matrices, true);

            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(descLayoutMain.Bindings.GetRange(0, 4).ToArray());

            uboUpdate.Write(Dev, dsMain,
                            uboMats.Descriptor,
                            envCube.irradianceCube.Descriptor,
                            envCube.prefilterCube.Descriptor,
                            envCube.lutBrdf.Descriptor);
        }
Esempio n. 24
0
        public static IServiceProvider CreateServiceProvider(
            DescriptorSet descriptorSet          = null,
            string connectionString              = null,
            ImpatientCompatibility compatibility = ImpatientCompatibility.Default)
        {
            var services = new ServiceCollection();

            #region services that would typically be DI-handled

            services.AddSingleton <IImpatientQueryCache, DefaultImpatientQueryCache>();

            services.AddSingleton <TranslatabilityAnalyzingExpressionVisitor>();

            services.AddSingleton <ITypeMappingProvider, DefaultTypeMappingProvider>();

            services.AddSingleton <IQueryFormattingProvider, SqlServerQueryFormattingProvider>();

            services.AddScoped <IReadValueExpressionFactoryProvider, DefaultReadValueExpressionFactoryProvider>();

            services.AddScoped <IRewritingExpressionVisitorProvider, DefaultRewritingExpressionVisitorProvider>();

            services.AddScoped <IProviderSpecificRewritingExpressionVisitorProvider, SqlServerRewritingExpressionVisitorProvider>();

            services.AddScoped <IOptimizingExpressionVisitorProvider, DefaultOptimizingExpressionVisitorProvider>();

            services.AddScoped <IComposingExpressionVisitorProvider, DefaultComposingExpressionVisitorProvider>();

            services.AddScoped <ICompilingExpressionVisitorProvider, DefaultCompilingExpressionVisitorProvider>();

            services.AddScoped <IQueryableInliningExpressionVisitorFactory, DefaultQueryInliningExpressionVisitorFactory>();

            services.AddScoped <IQueryTranslatingExpressionVisitorFactory, DefaultQueryTranslatingExpressionVisitorFactory>();

            services.AddScoped <IQueryProcessingContextFactory>(provider =>
            {
                return(new DefaultQueryProcessingContextFactory(
                           provider.GetRequiredService <DescriptorSet>(),
                           compatibility));
            });

            services.AddScoped <IDbCommandExecutorFactory>(provider => provider.GetRequiredService <TestDbCommandExecutorFactory>());

            services.AddScoped <IImpatientQueryProcessor, DefaultImpatientQueryProcessor>();

            #endregion

            services.AddSingleton(descriptorSet ?? DescriptorSet.Empty);

            services.AddSingleton <ImpatientQueryProvider>();

            services.AddScoped <NorthwindQueryContext>();

            services.AddScoped(provider => new TestDbCommandExecutorFactory(connectionString));

            return(services.BuildServiceProvider());
        }
Esempio n. 25
0
 public WriteDescriptorSet GetWriteDescriptorSet(DescriptorSet set, int binding)
 {
     return(new WriteDescriptorSet(
                set,
                binding,
                0,
                1,
                DescriptorType.StorageBuffer,
                bufferInfo: new[] { new DescriptorBufferInfo(this) }));
 }
 public QueryProcessingContext(
     IQueryProvider queryProvider,
     DescriptorSet descriptorSet,
     ImpatientCompatibility compatibility)
 {
     QueryProvider    = queryProvider;
     DescriptorSet    = descriptorSet;
     Compatibility    = compatibility;
     ParameterMapping = new Dictionary <object, ParameterExpression>();
 }
 public WriteDescriptorSet CreateDescriptorWrite(DescriptorSet set, int binding)
 => new WriteDescriptorSet(
     dstSet: set,
     dstBinding: binding,
     dstArrayElement: 0,
     descriptorCount: 1,
     descriptorType: DescriptorType,
     imageInfo: new [] {
     new DescriptorImageInfo(sampler, texture.View, texture.DesiredLayout)
 });
Esempio n. 28
0
 /// <param name="SrcSet">Source descriptor set</param>
 /// <param name="SrcBinding">Binding within the source descriptor set to copy from</param>
 /// <param name="SrcArrayElement">Array element within the source binding to copy from</param>
 /// <param name="DstSet">Destination descriptor set</param>
 /// <param name="DstBinding">Binding within the destination descriptor set to copy to</param>
 /// <param name="DstArrayElement">Array element within the destination binding to copy to</param>
 /// <param name="DescriptorCount">Number of descriptors to write (determines the size of the array pointed by pDescriptors)</param>
 public CopyDescriptorSet(DescriptorSet SrcSet, UInt32 SrcBinding, UInt32 SrcArrayElement, DescriptorSet DstSet, UInt32 DstBinding, UInt32 DstArrayElement, UInt32 DescriptorCount) : this()
 {
     this.SrcSet          = SrcSet;
     this.SrcBinding      = SrcBinding;
     this.SrcArrayElement = SrcArrayElement;
     this.DstSet          = DstSet;
     this.DstBinding      = DstBinding;
     this.DstArrayElement = DstArrayElement;
     this.DescriptorCount = DescriptorCount;
 }
Esempio n. 29
0
 /// <param name="DstSet">Destination descriptor set</param>
 /// <param name="DstBinding">Binding within the destination descriptor set to write</param>
 /// <param name="DstArrayElement">Array element within the destination binding to write</param>
 /// <param name="DescriptorType">Descriptor type to write (determines which members of the array pointed by pDescriptors are going to be used)</param>
 /// <param name="ImageInfo">Sampler, image view, and layout for SAMPLER, COMBINED_IMAGE_SAMPLER, {SAMPLED,STORAGE}_IMAGE, and INPUT_ATTACHMENT descriptor types.</param>
 /// <param name="BufferInfo">Raw buffer, size, and offset for {UNIFORM,STORAGE}_BUFFER[_DYNAMIC] descriptor types.</param>
 /// <param name="TexelBufferView">Buffer view to write to the descriptor for {UNIFORM,STORAGE}_TEXEL_BUFFER descriptor types.</param>
 public WriteDescriptorSet(DescriptorSet DstSet, UInt32 DstBinding, UInt32 DstArrayElement, DescriptorType DescriptorType, DescriptorImageInfo[] ImageInfo, DescriptorBufferInfo[] BufferInfo, BufferView[] TexelBufferView) : this()
 {
     this.DstSet          = DstSet;
     this.DstBinding      = DstBinding;
     this.DstArrayElement = DstArrayElement;
     this.DescriptorType  = DescriptorType;
     this.ImageInfo       = ImageInfo;
     this.BufferInfo      = BufferInfo;
     this.TexelBufferView = TexelBufferView;
 }
Esempio n. 30
0
        private DescriptorSet CreateGraphicsDescriptorSet()
        {
            DescriptorSet descriptorSet = _descriptorPool.AllocateSets(new DescriptorSetAllocateInfo(1, _graphicsDescriptorSetLayout))[0];

            _descriptorPool.UpdateSets(new[]
            {
                // Particle diffuse map.
                new WriteDescriptorSet(descriptorSet, 0, 0, 1, DescriptorType.CombinedImageSampler,
                                       new[] { new DescriptorImageInfo(_sampler, _particleDiffuseMap.View, ImageLayout.ColorAttachmentOptimal) })
            });
            return(descriptorSet);
        }
Esempio n. 31
0
 internal static unsafe extern Result vkFreeDescriptorSets(Device device, DescriptorPool descriptorPool, uint descriptorSetCount, DescriptorSet* descriptorSets);
Esempio n. 32
0
 internal static unsafe extern void vkCmdBindDescriptorSets(CommandBuffer commandBuffer, PipelineBindPoint pipelineBindPoint, PipelineLayout layout, uint firstSet, uint descriptorSetCount, DescriptorSet* descriptorSets, uint dynamicOffsetCount, uint* dynamicOffsets);
Esempio n. 33
0
 public unsafe void BindDescriptorSets(PipelineBindPoint pipelineBindPoint, PipelineLayout layout, uint firstSet, uint descriptorSetCount, DescriptorSet* descriptorSets, uint dynamicOffsetCount, uint* dynamicOffsets)
 {
     vkCmdBindDescriptorSets(this, pipelineBindPoint, layout, firstSet, descriptorSetCount, descriptorSets, dynamicOffsetCount, dynamicOffsets);
 }
Esempio n. 34
0
 public unsafe void AllocateDescriptorSets(ref DescriptorSetAllocateInfo allocateInfo, DescriptorSet* descriptorSets)
 {
     fixed (DescriptorSetAllocateInfo* __allocateInfo__ = &allocateInfo)
     {
         vkAllocateDescriptorSets(this, __allocateInfo__, descriptorSets).CheckError();
     }
 }
Esempio n. 35
0
 public unsafe void FreeDescriptorSets(DescriptorPool descriptorPool, uint descriptorSetCount, DescriptorSet* descriptorSets)
 {
     vkFreeDescriptorSets(this, descriptorPool, descriptorSetCount, descriptorSets).CheckError();
 }
Esempio n. 36
0
 internal static unsafe extern Result vkAllocateDescriptorSets(Device device, DescriptorSetAllocateInfo* allocateInfo, DescriptorSet* descriptorSets);