Esempio n. 1
0
        void init(VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4)
        {
            descriptorPool = new DescriptorPool(dev, 2,
                                                new VkDescriptorPoolSize(VkDescriptorType.UniformBuffer),
                                                new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler)
                                                );

            descLayoutMatrix = new DescriptorSetLayout(dev,
                                                       new VkDescriptorSetLayoutBinding(0, VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer),
                                                       new VkDescriptorSetLayoutBinding(1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
                                                       );

            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)
                                                         );

            dsMats = descriptorPool.Allocate(descLayoutMatrix);

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

            cfg.Layout = new PipelineLayout(dev, descLayoutMatrix, descLayoutTextures);
            cfg.Layout.AddPushConstants(
                new VkPushConstantRange(VkShaderStageFlags.Vertex, (uint)Marshal.SizeOf <Matrix4x4> ()),
                new VkPushConstantRange(VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf <Model.PbrMaterial> (), 64)
                );
            cfg.RenderPass = new RenderPass(dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat(), samples);

            cfg.AddVertexBinding <Model.Vertex> (0);
            cfg.SetVertexAttributes(0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);

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

            pipeline = new GraphicPipeline(cfg);

            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);

            uboMats = new HostBuffer(dev, VkBufferUsageFlags.UniformBuffer, (ulong)Marshal.SizeOf <Matrices>());
            uboMats.Map();             //permanent map

            DescriptorSetWrites uboUpdate = new DescriptorSetWrites(dsMats, descLayoutMatrix.Bindings[0]);

            uboUpdate.Write(dev, uboMats.Descriptor);

            cfg.Layout.SetName("Main Pipeline layout");
            uboMats.SetName("uboMats");
            descriptorPool.SetName("main pool");
            descLayoutTextures.SetName("descLayoutTextures");

            statPool = new PipelineStatisticsQueryPool(dev,
                                                       VkQueryPipelineStatisticFlags.InputAssemblyVertices |
                                                       VkQueryPipelineStatisticFlags.InputAssemblyPrimitives |
                                                       VkQueryPipelineStatisticFlags.ClippingInvocations |
                                                       VkQueryPipelineStatisticFlags.ClippingPrimitives |
                                                       VkQueryPipelineStatisticFlags.FragmentShaderInvocations);

            timestampQPool = new TimestampQueryPool(dev);
        }