Example #1
0
        public EnvironmentCube(string cubemapPath, DescriptorSet dsSkybox, PipelineLayout plLayout, Queue staggingQ, RenderPass renderPass, PipelineCache cache = null)
            : base(renderPass, cache, "EnvCube pipeline")
        {
            using (CommandPool cmdPool = new CommandPool(staggingQ.Dev, staggingQ.index)) {
                vboSkybox = new GPUBuffer <float> (staggingQ, cmdPool, VkBufferUsageFlags.VertexBuffer, box_vertices);

                cubemap = KTX.KTX.Load(staggingQ, cmdPool, cubemapPath,
                                       VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true);
                cubemap.CreateView(VkImageViewType.Cube, VkImageAspectFlags.Color, 6, 0, cubemap.CreateInfo.mipLevels);
                cubemap.CreateSampler(VkSamplerAddressMode.ClampToEdge);
                cubemap.SetName("skybox Texture");
                cubemap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;

                GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault(VkPrimitiveTopology.TriangleList, renderPass.Samples, false);
                cfg.RenderPass = renderPass;
                cfg.Layout     = plLayout;
                cfg.AddVertexBinding(0, 3 * sizeof(float));
                cfg.AddVertexAttributes(0, VkFormat.R32g32b32Sfloat);
                cfg.AddShader(VkShaderStageFlags.Vertex, "shaders/skybox.vert.spv");
                cfg.AddShader(VkShaderStageFlags.Fragment, "shaders/skybox.frag.spv");
                cfg.multisampleState.rasterizationSamples = Samples;

                layout = cfg.Layout;

                init(cfg);

                generateBRDFLUT(staggingQ, cmdPool);
                generateCubemaps(staggingQ, cmdPool);
            }
        }
Example #2
0
        public override void RenderNode(CommandBuffer cmd, PipelineLayout pipelineLayout, Node node, Matrix4x4 currentTransform, bool shadowPass = false)
        {
            Matrix4x4 localMat = node.localMatrix * currentTransform;

            cmd.PushConstant(pipelineLayout, VkShaderStageFlags.Vertex, localMat);

            if (node.Mesh != null)
            {
                foreach (Primitive p in node.Mesh.Primitives)
                {
                    if (!shadowPass)
                    {
                        cmd.PushConstant(pipelineLayout, VkShaderStageFlags.Fragment, (int)p.material, (uint)Marshal.SizeOf <Matrix4x4> ());
                    }
                    cmd.DrawIndexed(p.indexCount, 1, p.indexBase, p.vertexBase, 0);
                }
            }
            if (node.Children == null)
            {
                return;
            }
            foreach (Node child in node.Children)
            {
                RenderNode(cmd, pipelineLayout, child, localMat, shadowPass);
            }
        }
Example #3
0
        /// <summary>
        /// Create a new Pipeline with supplied PipelineLayout
        /// </summary>
        public ComputePipeline(PipelineLayout layout, string spirvPath, PipelineCache cache = null, string name = "pipeline") : base(layout.Dev, cache, name)
        {
            SpirVPath   = spirvPath;
            this.layout = layout;

            Activate();
        }
Example #4
0
 public void Draw(CommandBuffer cmd, PipelineLayout pipelineLayout, Scene scene, bool shadowPass = false)
 {
     if (scene.Root == null)
     {
         return;
     }
     RenderNode(cmd, pipelineLayout, scene.Root, Matrix4x4.Identity, shadowPass);
 }
Example #5
0
 public void DrawAll(CommandBuffer cmd, PipelineLayout pipelineLayout, bool shadowPass = false)
 {
     foreach (Scene sc in Scenes)
     {
         foreach (Node node in sc.Root.Children)
         {
             RenderNode(cmd, pipelineLayout, node, sc.Root.localMatrix, shadowPass);
         }
     }
 }
Example #6
0
        public void Draw(CommandBuffer cmd, PipelineLayout pipelineLayout, Buffer instanceBuf, bool shadowPass = false, params InstancedCmd[] instances)
        {
            cmd.BindVertexBuffer(instanceBuf, 1);
            uint firstInstance = 0;

            for (int i = 0; i < instances.Length; i++)
            {
                foreach (Primitive p in Meshes[instances[i].meshIdx].Primitives)
                {
                    if (!shadowPass)
                    {
                        cmd.PushConstant(pipelineLayout, VkShaderStageFlags.Fragment, (int)p.material, (uint)Marshal.SizeOf <Matrix4x4>());
                    }
                    cmd.DrawIndexed(p.indexCount, instances[i].count, p.indexBase, p.vertexBase, firstInstance);
                }
                firstInstance += instances[i].count;
            }
        }
Example #7
0
 //TODO:destset for binding must be variable
 //TODO: ADD REFAULT MAT IF NO MAT DEFINED
 public abstract void RenderNode(CommandBuffer cmd, PipelineLayout pipelineLayout, Node node, Matrix4x4 currentTransform, bool shadowPass = false);
Example #8
0
 public void PushConstant(PipelineLayout pipelineLayout, VkShaderStageFlags stageFlags, Object data, uint offset = 0)
 {
     vkCmdPushConstants(handle, pipelineLayout.handle, stageFlags, offset, (uint)Marshal.SizeOf(data), data.Pin());
     data.Unpin();
 }
Example #9
0
 public void BindDescriptorSet(VkPipelineBindPoint bindPoint, PipelineLayout pipelineLayout, DescriptorSet descriptorSet, uint firstSet = 0)
 {
     vkCmdBindDescriptorSets(handle, bindPoint, pipelineLayout.handle, firstSet, 1, ref descriptorSet.handle, 0, IntPtr.Zero);
 }