예제 #1
0
        /// <summary>
        /// Allocates a new command buffer and automatically start it.
        /// </summary>
        /// <returns>New command buffer in the recording state.</returns>
        /// <param name="usage">Usage.</param>
        public PrimaryCommandBuffer AllocateAndStart(VkCommandBufferUsageFlags usage = 0)
        {
            PrimaryCommandBuffer cmd = AllocateCommandBuffer();

            cmd.Start(usage);
            return(cmd);
        }
예제 #2
0
        /// <summary>
        /// load bitmap from pointer
        /// </summary>
        void load(Queue staggingQ, CommandPool staggingCmdPool, IntPtr bitmap, bool generateMipmaps = true)
        {
            long size = info.extent.width * info.extent.height * 4 * info.extent.depth;

            if (MemoryFlags.HasFlag(VkMemoryPropertyFlags.HostVisible))
            {
                Map();
                unsafe {
                    System.Buffer.MemoryCopy(bitmap.ToPointer(), MappedData.ToPointer(), size, size);
                }
                Unmap();

                if (generateMipmaps)
                {
                    BuildMipmaps(staggingQ, staggingCmdPool);
                }
            }
            else
            {
                using (HostBuffer stagging = new HostBuffer(Dev, VkBufferUsageFlags.TransferSrc, (UInt64)size, bitmap)) {
                    PrimaryCommandBuffer cmd = staggingCmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit);

                    stagging.CopyTo(cmd, this);
                    if (generateMipmaps)
                    {
                        BuildMipmaps(cmd);
                    }

                    cmd.End();
                    staggingQ.Submit(cmd);
                    staggingQ.WaitIdle();
                    cmd.Free();
                }
            }
        }
예제 #3
0
파일: Queue.cs 프로젝트: jpbruyere/vke.net
 /// <summary>
 /// End command recording, submit, and wait queue idle
 /// </summary>
 public void EndSubmitAndWait(PrimaryCommandBuffer cmd, bool freeCommandBuffer = false)
 {
     cmd.End();
     Submit(cmd);
     WaitIdle();
     if (freeCommandBuffer)
     {
         cmd.Free();
     }
 }
예제 #4
0
        /// <summary>
        /// Begin Render pass with custom render area
        /// </summary>
        public void Begin(PrimaryCommandBuffer cmd, FrameBuffer frameBuffer, uint width, uint height, VkSubpassContents contents = VkSubpassContents.Inline)
        {
            VkRenderPassBeginInfo info = VkRenderPassBeginInfo.New();

            info.renderPass = handle;
            info.renderArea.extent.width  = width;
            info.renderArea.extent.height = height;
            info.clearValueCount          = (uint)ClearValues.Count;
            info.pClearValues             = ClearValues.Pin();
            info.framebuffer = frameBuffer.handle;

            vkCmdBeginRenderPass(cmd.Handle, ref info, contents);

            ClearValues.Unpin();
        }
예제 #5
0
        /// <summary>
        /// Allocates multiple command buffer.
        /// </summary>
        /// <returns>An array of command buffers alloocated from this pool.</returns>
        /// <param name="count">Buffer count to create.</param>
        public PrimaryCommandBuffer[] AllocateCommandBuffer(uint count)
        {
            VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New();

            infos.commandPool        = handle;
            infos.level              = VkCommandBufferLevel.Primary;
            infos.commandBufferCount = count;
            VkCommandBuffer[] buffs = new VkCommandBuffer[count];
            Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, buffs.Pin()));
            buffs.Unpin();
            PrimaryCommandBuffer[] cmds = new PrimaryCommandBuffer[count];
            for (int i = 0; i < count; i++)
            {
                cmds[i] = new PrimaryCommandBuffer(Dev.VkDev, this, buffs[i]);
            }

            return(cmds);
        }
예제 #6
0
        public void BuildMipmaps(Queue copyQ, CommandPool copyCmdPool)
        {
            if (info.mipLevels == 1)
            {
                Debug.WriteLine("Invoking BuildMipmaps on image that has only one mipLevel");
                return;
            }
            PrimaryCommandBuffer cmd = copyCmdPool.AllocateCommandBuffer();

            cmd.Start(VkCommandBufferUsageFlags.OneTimeSubmit);
            BuildMipmaps(cmd);
            cmd.End();

            copyQ.Submit(cmd);
            copyQ.WaitIdle();

            cmd.Free();
        }
예제 #7
0
        /// <summary>
        /// execute the descriptors writes targeting descriptorSets setted on AddWriteInfo call
        /// </summary>
        public void Push(PrimaryCommandBuffer cmd, PipelineLayout plLayout, params object[] descriptors)
        {
            using (PinnedObjects pinCtx = new PinnedObjects()) {
                int i      = 0;
                int wdsPtr = 0;
                while (i < descriptors.Length)
                {
                    int firstDescriptor      = i;
                    VkWriteDescriptorSet wds = WriteDescriptorSets[wdsPtr];
                    wds.dstSet = 0;
                    IntPtr pDescriptors = IntPtr.Zero;

                    if (wds.descriptorCount > 1)
                    {
                        List <IntPtr> descPtrArray = new List <IntPtr> ();
                        for (int d = 0; d < wds.descriptorCount; d++)
                        {
                            descPtrArray.Add(descriptors[i].Pin(pinCtx));
                            i++;
                        }
                        pDescriptors = descPtrArray.Pin(pinCtx);
                    }
                    else
                    {
                        pDescriptors = descriptors[i].Pin(pinCtx);
                        i++;
                    }
                    if (descriptors[firstDescriptor] is VkDescriptorBufferInfo)
                    {
                        wds.pBufferInfo = pDescriptors;
                    }
                    else if (descriptors[firstDescriptor] is VkDescriptorImageInfo)
                    {
                        wds.pImageInfo = pDescriptors;
                    }

                    WriteDescriptorSets[wdsPtr] = wds;
                    wdsPtr++;
                }
                vkCmdPushDescriptorSetKHR(cmd.Handle, VkPipelineBindPoint.Graphics, plLayout.handle, 0,
                                          (uint)WriteDescriptorSets.Count, WriteDescriptorSets.Pin(pinCtx));
            }
        }
예제 #8
0
        protected override void initVulkan()
        {
            base.initVulkan();

            iFace = new Interface((int)Width, (int)Height, WindowHandle);
            iFace.Init();

            CreateRenderPass();

            fsqPl = new FSQPipeline(renderPass,
                                    new PipelineLayout(dev, new DescriptorSetLayout(dev, dslBinding)));

            cmdPoolCrow   = new CommandPool(presentQueue, VkCommandPoolCreateFlags.ResetCommandBuffer);
            cmdUpdateCrow = cmdPoolCrow.AllocateCommandBuffer();

            dsPool  = new DescriptorPool(dev, 1, new VkDescriptorPoolSize(VkDescriptorType.CombinedImageSampler));
            descSet = dsPool.Allocate(fsqPl.Layout.DescriptorSetLayouts[0]);

            Thread ui = new Thread(crowThread);

            ui.IsBackground = true;
            ui.Start();
        }
예제 #9
0
 public void End(PrimaryCommandBuffer cmd, VkPipelineStageFlags stageFlags = VkPipelineStageFlags.BottomOfPipe)
 {
     vkCmdWriteTimestamp(cmd.Handle, stageFlags, handle, 1);
 }
예제 #10
0
 public void Write(PrimaryCommandBuffer cmd, uint query, VkPipelineStageFlags stageFlags = VkPipelineStageFlags.BottomOfPipe)
 {
     vkCmdWriteTimestamp(cmd.Handle, stageFlags, handle, query);
 }
예제 #11
0
 public void End(PrimaryCommandBuffer cmd, uint query = 0)
 {
     vkCmdEndQuery(cmd.Handle, handle, query);
 }
예제 #12
0
 public void Begin(PrimaryCommandBuffer cmd, uint query = 0)
 {
     vkCmdBeginQuery(cmd.Handle, handle, query, VkQueryControlFlags.Precise);
 }
예제 #13
0
 /// <summary>
 /// Begin Render pass with framebuffer extent dimensions
 /// </summary>
 public void Begin(PrimaryCommandBuffer cmd, FrameBuffer frameBuffer, VkSubpassContents contents = VkSubpassContents.Inline)
 {
     Begin(cmd, frameBuffer, frameBuffer.Width, frameBuffer.Height, contents);
 }
예제 #14
0
파일: Queue.cs 프로젝트: jpbruyere/vke.net
 public void Submit(PrimaryCommandBuffer cmd, VkSemaphore wait = default, VkSemaphore signal = default, Fence fence = null)
 {
     cmd.Submit(handle, wait, signal, fence);
 }
예제 #15
0
파일: Model.cs 프로젝트: jpbruyere/vke.net
 public void Draw(PrimaryCommandBuffer cmd, uint instanceCount = 1, uint firstInstance = 0)
 {
     cmd.DrawIndexed(indexCount, instanceCount, indexBase, vertexBase, firstInstance);
 }
예제 #16
0
 /// <summary>
 /// Switch to next subpass
 /// </summary>
 public void BeginSubPass(PrimaryCommandBuffer cmd, VkSubpassContents subpassContents = VkSubpassContents.Inline)
 {
     vkCmdNextSubpass(cmd.Handle, subpassContents);
 }
예제 #17
0
 public void End(PrimaryCommandBuffer cmd)
 {
     vkCmdEndRenderPass(cmd.Handle);
 }