/// <summary>
        /// Executes multiple deferred command lists.
        /// </summary>
        /// <param name="count">Number of command lists to execute.</param>
        /// <param name="commandLists">The deferred command lists.</param>
        public unsafe void ExecuteCommandLists(int count, CompiledCommandList[] commandLists)
        {
            if (commandLists == null)
            {
                throw new ArgumentNullException(nameof(commandLists));
            }
            if (count > commandLists.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            var fenceValue = NextFenceValue++;

            // Create a fence
            var fenceCreateInfo = new VkFenceCreateInfo {
                sType = VkStructureType.FenceCreateInfo
            };

            vkCreateFence(nativeDevice, &fenceCreateInfo, null, out var fence);

            using (FenceLock.WriteLock())
            {
                nativeFences.Add(new KeyValuePair <long, VkFence>(fenceValue, fence));
            }

            // Collect resources
            var commandBuffers = stackalloc VkCommandBuffer[count];

            for (int i = 0; i < count; i++)
            {
                commandBuffers[i] = commandLists[i].NativeCommandBuffer;
                RecycleCommandListResources(commandLists[i], fenceValue);
            }

            // Submit commands
            var pipelineStageFlags = VkPipelineStageFlags.BottomOfPipe;
            var submitInfo         = new VkSubmitInfo
            {
                sType = VkStructureType.SubmitInfo,
                commandBufferCount = (uint)count,
                pCommandBuffers    = commandBuffers,
                waitSemaphoreCount = 0U,
                pWaitSemaphores    = null,
                pWaitDstStageMask  = &pipelineStageFlags,
            };

            using (QueueLock.ReadLock())
            {
                vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, fence);
            }

            nativeResourceCollector.Release();
            graphicsResourceLinkCollector.Release();
        }
예제 #2
0
        /// <summary>
        /// Executes multiple deferred command lists.
        /// </summary>
        /// <param name="count">Number of command lists to execute.</param>
        /// <param name="commandLists">The deferred command lists.</param>
        public unsafe void ExecuteCommandLists(int count, CompiledCommandList[] commandLists)
        {
            if (commandLists == null)
            {
                throw new ArgumentNullException(nameof(commandLists));
            }
            if (count > commandLists.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            var fenceValue = NextFenceValue++;

            // Create a fence
            var fenceCreateInfo = new FenceCreateInfo {
                StructureType = StructureType.FenceCreateInfo
            };
            var fence = nativeDevice.CreateFence(ref fenceCreateInfo);

            nativeFences.Enqueue(new KeyValuePair <long, Fence>(fenceValue, fence));

            // Collect resources
            var commandBuffers = stackalloc CommandBuffer[count];

            for (int i = 0; i < count; i++)
            {
                commandBuffers[i] = commandLists[i].NativeCommandBuffer;
                RecycleCommandListResources(commandLists[i], fenceValue);
            }

            // Submit commands
            var pipelineStageFlags   = PipelineStageFlags.BottomOfPipe;
            var presentSemaphoreCopy = presentSemaphore;
            var submitInfo           = new SubmitInfo
            {
                StructureType      = StructureType.SubmitInfo,
                CommandBufferCount = (uint)count,
                CommandBuffers     = new IntPtr(commandBuffers),
                WaitSemaphoreCount = presentSemaphore != Semaphore.Null ? 1U : 0U,
                WaitSemaphores     = new IntPtr(&presentSemaphoreCopy),
                WaitDstStageMask   = new IntPtr(&pipelineStageFlags),
            };

            lock (QueueLock) {
                NativeCommandQueue.Submit(1, &submitInfo, fence);
            }

            presentSemaphore = Semaphore.Null;
            nativeResourceCollector.Release();
            graphicsResourceLinkCollector.Release();
        }