internal static unsafe extern void vkCmdEndQuery(CommandBuffer commandBuffer, QueryPool queryPool, uint query);
internal static unsafe extern Result vkAllocateCommandBuffers(Device device, CommandBufferAllocateInfo* allocateInfo, CommandBuffer* commandBuffers);
protected virtual void CreateCommandBuffer() { // Command pool var commandPoolCreateInfo = new CommandPoolCreateInfo { StructureType = StructureType.CommandPoolCreateInfo, QueueFamilyIndex = 0, Flags = CommandPoolCreateFlags.ResetCommandBuffer }; commandPool = device.CreateCommandPool(ref commandPoolCreateInfo); // Command buffer var commandBufferAllocationInfo = new CommandBufferAllocateInfo { StructureType = StructureType.CommandBufferAllocateInfo, Level = CommandBufferLevel.Primary, CommandPool = commandPool, CommandBufferCount = 1 }; CommandBuffer commandBuffer; device.AllocateCommandBuffers(ref commandBufferAllocationInfo, &commandBuffer); this.commandBuffer = commandBuffer; }
internal static unsafe extern Result vkEndCommandBuffer(CommandBuffer commandBuffer);
public unsafe void AllocateCommandBuffers(ref CommandBufferAllocateInfo allocateInfo, CommandBuffer* commandBuffers) { fixed (CommandBufferAllocateInfo* __allocateInfo__ = &allocateInfo) { vkAllocateCommandBuffers(this, __allocateInfo__, commandBuffers).CheckError(); } }
internal static unsafe extern void vkCmdSetViewport(CommandBuffer commandBuffer, uint firstViewport, uint viewportCount, Viewport* viewports);
internal static unsafe extern void vkCmdWaitEvents(CommandBuffer commandBuffer, uint eventCount, Event* events, PipelineStageFlags sourceStageMask, PipelineStageFlags destinationStageMask, uint memoryBarrierCount, MemoryBarrier* memoryBarriers, uint bufferMemoryBarrierCount, BufferMemoryBarrier* bufferMemoryBarriers, uint imageMemoryBarrierCount, ImageMemoryBarrier* imageMemoryBarriers);
internal static unsafe extern void vkCmdPushConstants(CommandBuffer commandBuffer, PipelineLayout layout, ShaderStageFlags stageFlags, uint offset, uint size, IntPtr values);
internal static unsafe extern void vkCmdResetQueryPool(CommandBuffer commandBuffer, QueryPool queryPool, uint firstQuery, uint queryCount);
internal static unsafe extern void vkCmdNextSubpass(CommandBuffer commandBuffer, SubpassContents contents);
internal static unsafe extern void vkCmdPipelineBarrier(CommandBuffer commandBuffer, PipelineStageFlags sourceStageMask, PipelineStageFlags destinationStageMask, DependencyFlags dependencyFlags, uint memoryBarrierCount, MemoryBarrier* memoryBarriers, uint bufferMemoryBarrierCount, BufferMemoryBarrier* bufferMemoryBarriers, uint imageMemoryBarrierCount, ImageMemoryBarrier* imageMemoryBarriers);
internal static unsafe extern void vkCmdFillBuffer(CommandBuffer commandBuffer, Buffer destinationBuffer, ulong destinationOffset, ulong size, uint data);
internal static unsafe extern void vkCmdExecuteCommands(CommandBuffer commandBuffer, uint commandBufferCount, CommandBuffer* commandBuffers);
internal static unsafe extern void vkCmdEndRenderPass(CommandBuffer commandBuffer);
internal static unsafe extern void vkCmdSetStencilReference(CommandBuffer commandBuffer, StencilFaceFlags faceMask, uint reference);
internal static unsafe extern void vkCmdResolveImage(CommandBuffer commandBuffer, Image sourceImage, ImageLayout sourceImageLayout, Image destinationImage, ImageLayout destinationImageLayout, uint regionCount, ImageResolve* regions);
internal static unsafe extern void vkCmdSetStencilWriteMask(CommandBuffer commandBuffer, StencilFaceFlags faceMask, uint writeMask);
internal static unsafe extern void vkCmdSetBlendConstants(CommandBuffer commandBuffer, float blendConstants);
internal static unsafe extern void vkCmdUpdateBuffer(CommandBuffer commandBuffer, Buffer destinationBuffer, ulong destinationOffset, ulong dataSize, uint* data);
internal static unsafe extern void vkCmdSetDepthBias(CommandBuffer commandBuffer, float depthBiasConstantFactor, float depthBiasClamp, float depthBiasSlopeFactor);
internal static unsafe extern void vkCmdWriteTimestamp(CommandBuffer commandBuffer, PipelineStageFlags pipelineStage, QueryPool queryPool, uint query);
internal static unsafe extern void vkCmdSetDepthBounds(CommandBuffer commandBuffer, float minDepthBounds, float maxDepthBounds);
internal static unsafe extern Result vkResetCommandBuffer(CommandBuffer commandBuffer, CommandBufferResetFlags flags);
internal static unsafe extern void vkCmdSetEvent(CommandBuffer commandBuffer, Event @event, PipelineStageFlags stageMask);
public unsafe void FreeCommandBuffers(CommandPool commandPool, uint commandBufferCount, CommandBuffer* commandBuffers) { vkFreeCommandBuffers(this, commandPool, commandBufferCount, commandBuffers); }
internal static unsafe extern void vkCmdSetLineWidth(CommandBuffer commandBuffer, float lineWidth);
public void Flush() { if (this.setupCommanBuffer == CommandBuffer.Null) return; var setupCommanBuffer = this.setupCommanBuffer; this.setupCommanBuffer.End(); var submitInfo = new SubmitInfo { StructureType = StructureType.SubmitInfo, CommandBufferCount = 1, CommandBuffers = new IntPtr(&setupCommanBuffer) }; queue.Submit(1, &submitInfo, Fence.Null); queue.WaitIdle(); device.FreeCommandBuffers(commandPool, 1, &setupCommanBuffer); this.setupCommanBuffer = CommandBuffer.Null; }
internal static unsafe extern void vkCmdSetScissor(CommandBuffer commandBuffer, uint firstScissor, uint scissorCount, Rect2D* scissors);
private void SetImageLayout(Image image, ImageAspectFlags imageAspect, ImageLayout oldLayout, ImageLayout newLayout) { if (setupCommanBuffer == CommandBuffer.Null) { // Create command buffer CommandBuffer setupCommandBuffer; var allocateInfo = new CommandBufferAllocateInfo { StructureType = StructureType.CommandBufferAllocateInfo, CommandPool = commandPool, Level = CommandBufferLevel.Primary, CommandBufferCount = 1, }; device.AllocateCommandBuffers(ref allocateInfo, &setupCommandBuffer); setupCommanBuffer = setupCommandBuffer; // Begin command buffer var inheritanceInfo = new CommandBufferInheritanceInfo { StructureType = StructureType.CommandBufferInheritanceInfo }; var beginInfo = new CommandBufferBeginInfo { StructureType = StructureType.CommandBufferBeginInfo, InheritanceInfo = new IntPtr(&inheritanceInfo) }; setupCommanBuffer.Begin(ref beginInfo); } var imageMemoryBarrier = new ImageMemoryBarrier { StructureType = StructureType.ImageMemoryBarrier, OldLayout = oldLayout, NewLayout = newLayout, Image = image, SubresourceRange = new ImageSubresourceRange(imageAspect, 0, 1, 0, 1) }; switch (newLayout) { case ImageLayout.TransferDestinationOptimal: imageMemoryBarrier.DestinationAccessMask = AccessFlags.TransferRead; break; case ImageLayout.ColorAttachmentOptimal: imageMemoryBarrier.DestinationAccessMask = AccessFlags.ColorAttachmentWrite; break; case ImageLayout.DepthStencilAttachmentOptimal: imageMemoryBarrier.DestinationAccessMask = AccessFlags.DepthStencilAttachmentWrite; break; case ImageLayout.ShaderReadOnlyOptimal: imageMemoryBarrier.DestinationAccessMask = AccessFlags.ShaderRead | AccessFlags.InputAttachmentRead; break; } var sourceStages = PipelineStageFlags.TopOfPipe; var destinationStages = PipelineStageFlags.TopOfPipe; setupCommanBuffer.PipelineBarrier(sourceStages, destinationStages, DependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier); }
internal static unsafe extern void vkCmdDrawIndirect(CommandBuffer commandBuffer, Buffer buffer, ulong offset, uint drawCount, uint stride);