Example #1
0
 protected override void OnUnregisterImage(VKImage image)
 {
     Framebuffers[image].Dispose();
     Framebuffers.Remove(image);
     ComputeCommandBuffers[image].Dispose();
     ComputeCommandBuffers.Remove(image);
 }
 public override void OnDraw(Semaphore start, VKImage image)
 {
     // Submit the command buffer
     Graphics.GraphicsQueueFamily.First.Submit(
             start, InitialStage, GetCommandBuffer(image), FinishedSemaphore
         );
 }
Example #3
0
 protected override void OnRecordCommandBuffer(VKImage image, CommandBuffer buffer)
 {
     // Begin recording
     buffer.Begin(new CommandBufferBeginInfo());
     // Write commands
     buffer.CmdPipelineBarrier(
         srcStageMask: InitialStage,
         dstStageMask: PipelineStages.ColorAttachmentOutput,
         imageMemoryBarriers: new ImageMemoryBarrier[]
     {
         new ImageMemoryBarrier(
             image: image.Image,
             subresourceRange: image.SubresourceRange,
             srcAccessMask: InitialAccess,
             dstAccessMask: Accesses.ColorAttachmentWrite,
             oldLayout: InitialLayout,
             newLayout: ImageLayout.ColorAttachmentOptimal
             )
     }
         );
     buffer.CmdBeginRenderPass(new RenderPassBeginInfo(
                                   Framebuffers[image],
                                   RenderPass.RenderPass,
                                   new Rect2D(0, 0, image.Extent.Width, image.Extent.Height)
                                   ));
     buffer.CmdBindPipeline(PipelineBindPoint.Graphics, Pipeline);
     buffer.CmdBindDescriptorSet(PipelineBindPoint.Graphics, PipelineLayout, TextureDescriptorSet);
     buffer.CmdDraw(3);
     buffer.CmdEndRenderPass();
     // Finish recording
     buffer.End();
 }
Example #4
0
 protected override void OnRecordCommandBuffer(VKImage image, CommandBuffer buffer)
 {
     // Begin recording
     buffer.Begin(new CommandBufferBeginInfo());
     // Write commands
     buffer.CmdPipelineBarrier(
         srcStageMask: InitialStage,
         dstStageMask: PipelineStages.Transfer,
         imageMemoryBarriers: new ImageMemoryBarrier[]
     {
         new ImageMemoryBarrier(
             image: image.Image,
             subresourceRange: image.SubresourceRange,
             srcAccessMask: InitialAccess,
             dstAccessMask: Accesses.TransferWrite,
             oldLayout: InitialLayout,
             newLayout: ImageLayout.TransferDstOptimal
             )
     }
         );
     buffer.CmdClearColorImage(
         image.Image,
         ImageLayout.TransferDstOptimal,
         ClearColor,
         image.SubresourceRange
         );
     // Finish recording
     buffer.End();
 }
Example #5
0
 public override void OnDraw(Semaphore start, VKImage image)
 {
     // Submit the command buffer
     Graphics.TransferQueueFamily.First.Submit(
         start, PipelineStages.Transfer, GetCommandBuffer(image), FinishedSemaphore
         );
 }
Example #6
0
 public override void OnDraw(Semaphore start, VKImage image)
 {
     // Submit the command buffer
     Graphics.GraphicsQueueFamily.First.Submit(
         start, PipelineStages.ColorAttachmentOutput, GetCommandBuffer(image), FinishedSemaphore
         );
 }
Example #7
0
        public override void OnDraw(Semaphore start, VKImage image)
        {
            if (AnyUpdatedInstanceLists)
            {
                UpdateLists();
                RecreateInstanceBuffers();
                RecreateAnimations();
                RecreateDescriptorSets();
                FinishUpdateLists();
                Refresh();
            }
            unsafe
            {
                var nonEmpty = InstanceLists.Values.Where(e => e.Count > 0);
                var ptr      = TimeUniform.Map(0, nonEmpty.Count());
                foreach (var list in nonEmpty)
                {
                    *(ptr++) = new ListTime
                    {
                        Time = (float)list.TimeSinceLastUpdate
                    };
                }
                TimeUniform.Unmap();
            }
            var graphicsCommandBuffer = GetCommandBuffer(image);

            Graphics.ComputeQueueFamily.First.Submit(
                start, PipelineStages.ComputeShader, ComputeCommandBuffers[image], ComputeSemaphore
                );
            Graphics.GraphicsQueueFamily.First.Submit(
                ComputeSemaphore, PipelineStages.ColorAttachmentOutput, graphicsCommandBuffer, FinishedSemaphore
                );
        }
Example #8
0
        public void Draw(VKImage image, float tick)
        {
            if (Count == 0)
            {
                return;
            }

            var vp = new ViewProjection {
                View = View, Projection = Projection
            };

            UProjection.Write(ref vp);
            UTime.Write(ref tick);

            var cb = CBuffer[image];

            cb.Begin();
            cb.BeginPass(Pipeline);
            cb.Draw(Graphics.SquareSprite, Instances, Count);
            cb.EndPass();
            cb.End();

            cb.Submit(true);
            cb.Reset();
        }
Example #9
0
 protected override void OnRegisterImage(VKImage image)
 {
     // Create image view and framebuffer
     {
         Framebuffers.Add(image, RenderPass.RenderPass.CreateFramebuffer(new FramebufferCreateInfo(
                                                                             attachments: new[] { image.ImageView },
                                                                             width: image.Extent.Width,
                                                                             height: image.Extent.Height
                                                                             )));
     }
 }
Example #10
0
        protected override void OnDrawToSwapchainImage(VKImage image)
        {
            base.OnDrawToSwapchainImage(image);

            CommandBuffer[image].Submit(true);

            MeshRenderer.Draw(image, Tick);

            ParticleRenderer.Draw(image, Tick);

            TextRenderer.Draw(image, Tick);
        }
Example #11
0
 protected override void OnRegisterImage(VKImage image)
 {
     Framebuffers.Add(image, RenderPass.RenderPass.CreateFramebuffer(new FramebufferCreateInfo(
                                                                         attachments: new[] { image.ImageView },
                                                                         width: image.Extent.Width,
                                                                         height: image.Extent.Height
                                                                         )));
     ComputeCommandBuffers.Add(
         image,
         Graphics.ComputeQueueFamily.CreateCommandBuffers(
             CommandBufferLevel.Primary,
             1
             )[0]
         );
 }
Example #12
0
        protected override void OnDeleteSwapchainImage(VKImage image)
        {
            base.OnCreateSwapchainImage(image);

            CommandBufferController cb;

            if (CommandBuffer.TryGetValue(image, out cb))
            {
                cb?.Dispose();
                CommandBuffer.Remove(image);
            }

            TextRenderer.RemoveImage(image);

            MeshRenderer.RemoveImage(image);

            ParticleRenderer.RemoveImage(image);
        }
Example #13
0
        protected override void OnCreateSwapchainImage(VKImage image)
        {
            base.OnCreateSwapchainImage(image);

            CommandBufferController cb;

            CommandBuffer[image] = cb = new CommandBufferController(Graphics, image);
            cb.Begin();
            cb.Clear(Color.CornflowerBlue);
            cb.BeginPass(Pipeline);
            cb.Draw(Graphics.Square, Instances, Billboards);
            cb.EndPass();
            cb.End();

            TextRenderer.AddImage(image);

            MeshRenderer.AddImage(image);

            ParticleRenderer.AddImage(image);
        }
Example #14
0
 protected override void OnRecordCommandBuffer(VKImage image, CommandBuffer buffer)
 {
     // Begin recording
     buffer.Begin(new CommandBufferBeginInfo());
     // Write commands
     buffer.CmdPipelineBarrier(
             srcStageMask: InitialStage,
             dstStageMask: FinalStage,
             imageMemoryBarriers: new ImageMemoryBarrier[]
             {
                     new ImageMemoryBarrier(
                             image: image.Image,
                             subresourceRange: image.SubresourceRange,
                             srcAccessMask: InitialAccess,
                             dstAccessMask: FinalAccess,
                             oldLayout: InitialLayout,
                             newLayout: FinalLayout
                         )
             }
         );
     // Finish recording
     buffer.End();
 }
Example #15
0
 public void RemoveImage(VKImage image)
 {
     CBuffer[image].Dispose();
     CBuffer.Remove(image);
 }
Example #16
0
        public void AddImage(VKImage image)
        {
            var cb = new CommandBufferController(Graphics, image);

            CBuffer.Add(image, cb);
        }
Example #17
0
 public void AddImage(VKImage image)
 {
     CharRenderer.AddImage(image);
 }
Example #18
0
 public void RemoveImage(VKImage image)
 {
     CharRenderer.RemoveImage(image);
 }
Example #19
0
 public void Draw(VKImage image, float tick)
 {
     CharRenderer.Draw(image, tick);
 }
Example #20
0
        protected override void OnRecordCommandBuffer(VKImage image, CommandBuffer buffer)
        {
            buffer.Begin(new CommandBufferBeginInfo());
            var nonEmptyLists = InstanceLists.Values.Where(e => e.Count > 0);

            if (nonEmptyLists.Any())
            {
                buffer.CmdPipelineBarrier(
                    srcStageMask: InitialStage,
                    dstStageMask: PipelineStages.ColorAttachmentOutput,
                    imageMemoryBarriers: new ImageMemoryBarrier[]
                {
                    new ImageMemoryBarrier(
                        image: image.Image,
                        subresourceRange: image.SubresourceRange,
                        srcAccessMask: InitialAccess,
                        dstAccessMask: Accesses.ColorAttachmentWrite,
                        oldLayout: InitialLayout,
                        newLayout: ImageLayout.ColorAttachmentOptimal
                        )
                }
                    );
                buffer.CmdBeginRenderPass(new RenderPassBeginInfo(
                                              Framebuffers[image],
                                              RenderPass.RenderPass,
                                              new Rect2D(0, 0, image.Extent.Width, image.Extent.Height)
                                              ));
                buffer.CmdBindPipeline(PipelineBindPoint.Graphics, GraphicsPipeline);
                foreach (var list in nonEmptyLists)
                {
                    if (!GraphicsDescriptorSets.TryGetValue(list, out var descriptorSet))
                    {
                        throw new InvalidOperationException(
                                  $"No graphics {nameof(DescriptorSet)} corresponding to {nameof(InstanceList)} {list}"
                                  );
                    }

                    buffer.CmdBindDescriptorSet(PipelineBindPoint.Graphics, GraphicsPipelineLayout, descriptorSet);
                    buffer.CmdBindVertexBuffers(0, 1, new VulkanCore.Buffer[] { VertexInstanceBuffers[list].Buffer }, new long[] { 0L });
                    buffer.CmdDraw(6, list.Count);
                }
                buffer.CmdEndRenderPass();
            }
            buffer.End();

            buffer = ComputeCommandBuffers[image];
            buffer.Begin(new CommandBufferBeginInfo());
            if (nonEmptyLists.Any())
            {
                buffer.CmdBindPipeline(PipelineBindPoint.Compute, ComputePipeline);
                foreach (var list in nonEmptyLists)
                {
                    if (!ComputeDescriptorSets.TryGetValue(list, out var descriptorSet))
                    {
                        throw new InvalidOperationException(
                                  $"No compute {nameof(DescriptorSet)} corresponding to {nameof(InstanceList)} {list}"
                                  );
                    }
                    buffer.CmdBindDescriptorSet(PipelineBindPoint.Compute, ComputePipelineLayout, descriptorSet);
                    buffer.CmdDispatch((int)MathF.Ceiling(list.Count / 512f), 1, 1);
                }
            }
            buffer.End();
        }