void CreateCommandBuffer()
        {
            /*
             * We are getting closer to the end. In order to send commands to the device(GPU),
             * we must first record commands into a command buffer.
             * To allocate a command buffer, we must first create a command pool. So let us do that.
             */
            CommandPoolCreateInfo commandPoolCreateInfo = new CommandPoolCreateInfo()
            {
                Flags = 0,
                // the queue family of this command pool. All command buffers allocated from this command pool,
                // must be submitted to queues of this family ONLY.
                QueueFamilyIndex = computeQueueFamilyIndex
            };

            commandPool = device.CreateCommandPool(commandPoolCreateInfo);

            /*
             * Now allocate a command buffer from the command pool.
             */
            CommandBufferAllocateInfo commandBufferAllocateInfo = new CommandBufferAllocateInfo()
            {
                //commandBufferAllocateInfo.commandPool = commandPool; // specify the command pool to allocate from.
                // if the command buffer is primary, it can be directly submitted to queues.
                // A secondary buffer has to be called from some primary command buffer, and cannot be directly
                // submitted to a queue. To keep things simple, we use a primary command buffer.
                Level = CommandBufferLevel.Primary, // VK_COMMAND_BUFFER_LEVEL_PRIMARY;
                CommandBufferCount = 1              // allocate a single command buffer.
            };

            commandBuffers = commandPool.AllocateBuffers(commandBufferAllocateInfo); // allocate command buffer.

            /*
             * Now we shall start recording commands into the newly allocated command buffer.
             */
            CommandBufferBeginInfo beginInfo = new CommandBufferBeginInfo()
            {
                Flags = CommandBufferUsages.OneTimeSubmit// VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; // the buffer is only submitted and used once in this application.
            };

            commandBuffers[0].Begin(beginInfo); // start recording commands.

            /*
             * We need to bind a pipeline, AND a descriptor set before we dispatch.
             * The validation layer will NOT give warnings if you forget these, so be very careful not to forget them.
             */
            commandBuffers[0].CmdBindPipeline(PipelineBindPoint.Compute, pipelines[0]);                                     // VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
            commandBuffers[0].CmdBindDescriptorSets(PipelineBindPoint.Compute, pipelineLayout, 0, new[] { descriptorSet }); // VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0, 1, &descriptorSet, 0, NULL);

            /*
             * Calling vkCmdDispatch basically starts the compute pipeline, and executes the compute shader.
             * The number of workgroups is specified in the arguments.
             * If you are already familiar with compute shaders from OpenGL, this should be nothing new to you.
             */
            commandBuffers[0].CmdDispatch((int)Math.Ceiling((double)(WIDTH / WORKGROUP_SIZE)), (int)Math.Ceiling((double)(HEIGHT / WORKGROUP_SIZE)), 1);

            commandBuffers[0].End(); // end recording commands.
        }
Exemple #2
0
        public CommandBuffer[] GimmeCommandBuffers(string queueName)
        {
            CommandBufferAllocateInfo cbai = new CommandBufferAllocateInfo();

            cbai.Level = CommandBufferLevel.Primary;
            cbai.CommandBufferCount = mChainBuffers.Length;

            CommandPool cp = mDevices.GetCommandPool(queueName);

            return(cp.AllocateBuffers(cbai));
        }
Exemple #3
0
        internal TransientExecutor(Device logicalDevice, int queueFamilyIndex)
        {
            queue = logicalDevice.GetQueue(
                queueFamilyIndex: queueFamilyIndex,
                queueIndex: 0);

            commandPool = logicalDevice.CreateCommandPool(new CommandPoolCreateInfo(
                                                              queueFamilyIndex: queueFamilyIndex,
                                                              flags: CommandPoolCreateFlags.ResetCommandBuffer));

            transientBuffer = commandPool.AllocateBuffers(new CommandBufferAllocateInfo(
                                                              level: CommandBufferLevel.Primary,
                                                              count: 1))[0];

            fence = logicalDevice.CreateFence(new FenceCreateInfo(flags: FenceCreateFlags.None));
        }
Exemple #4
0
        private void CreateRenderCommands(RenderScene scene)
        {
            scene.CreateResources(swapchainSize, swapchainTextures);

            //Reset the pool (to release any previously created buffers)
            commandPool.Reset(CommandPoolResetFlags.ReleaseResources);

            //Allocate new command buffers
            commandbuffers = commandPool.AllocateBuffers(new CommandBufferAllocateInfo(
                                                             level: CommandBufferLevel.Primary,
                                                             count: swapchainTextures.Length
                                                             ));

            //Record the primary command-buffers
            for (int i = 0; i < commandbuffers.Length; i++)
            {
                commandbuffers[i].Begin(new CommandBufferBeginInfo(flags: CommandBufferUsages.None));
                scene.Record(commandbuffers[i], i);
                commandbuffers[i].End();
            }

            logger?.Log(nameof(Window), $"Rendercommands recorded ({commandbuffers.Length} command-buffers)");
        }
Exemple #5
0
 public CommandBufferTest(DefaultHandles defaults, ITestOutputHelper output) : base(defaults, output)
 {
     CommandPool = Device.CreateCommandPool(
         new CommandPoolCreateInfo(defaults.GraphicsQueue.FamilyIndex, CommandPoolCreateFlags.ResetCommandBuffer));
     CommandBuffer = CommandPool.AllocateBuffers(new CommandBufferAllocateInfo(CommandBufferLevel.Primary, 1))[0];
 }
Exemple #6
0
 public void Free()
 {
     using (CommandPool.AllocateBuffers(new CommandBufferAllocateInfo(CommandBufferLevel.Primary, 1))[0]) { }
     CommandBuffer[] buffers = CommandPool.AllocateBuffers(new CommandBufferAllocateInfo(CommandBufferLevel.Primary, 1));
     CommandPool.FreeBuffers(buffers);
 }
Exemple #7
0
 private void CreateCommandBuffer()
 {
     _commandPool   = Device.Logical.CreateCommandPool(new CommandPoolCreateInfo(Device.QueueFamilyIndex));
     _commandBuffer = _commandPool.AllocateBuffers(new CommandBufferAllocateInfo(CommandBufferLevel.Primary, 1))[0];
 }
Exemple #8
0
 /// <summary>
 /// Create a set of command buffers
 /// </summary>
 /// <param name="level"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public CommandBuffer[] CreateCommandBuffers(CommandBufferLevel level, int count)
 {
     return(CommandPool.AllocateBuffers(new CommandBufferAllocateInfo(level, count)));
 }