public override void Run(Frame frame, CommandBuffer cmd) { Vk vk = renderer.Vk; Pipelines.Pipeline sPipeline = Pipelines.Pipeline.GetPipeline(stencilPipeline, renderer); sPipeline.Bind(cmd); DescriptorSet descriptorSet = frame.DescriptorSetManager.GetDescriptorSet(); renderer.Shader.SetUniforms(frame, descriptorSet, uniformOffset, 0); vk.CmdBindDescriptorSets(cmd, PipelineBindPoint.Graphics, renderer.Shader.PipelineLayout, 0, 1, descriptorSet, 0, 0); foreach (Path path in paths) { vk.CmdDraw(cmd, path.FillCount, 1, path.FillOffset, 0); } descriptorSet = frame.DescriptorSetManager.GetDescriptorSet(); renderer.Shader.SetUniforms(frame, descriptorSet, uniformOffset + renderer.Shader.FragSize, image); vk.CmdBindDescriptorSets(cmd, PipelineBindPoint.Graphics, renderer.Shader.PipelineLayout, 0, 1, descriptorSet, 0, 0); if (renderer.EdgeAntiAlias) { Pipelines.Pipeline aaPipeline = Pipelines.Pipeline.GetPipeline(antiAliasPipeline, renderer); aaPipeline.Bind(cmd); foreach (Path path in paths) { vk.CmdDraw(cmd, path.StrokeCount, 1, path.StrokeOffset, 0); } } Pipelines.Pipeline fPipeline = Pipelines.Pipeline.GetPipeline(renderPipeline, renderer); fPipeline.Bind(cmd); vk.CmdDraw(cmd, triangleCount, 1, triangleOffset, 0); }
public override void Run(Frame frame, CommandBuffer cmd) { Vk vk = renderer.Vk; Pipelines.Pipeline pipeline = Pipelines.Pipeline.GetPipeline(renderPipeline, renderer); pipeline.Bind(cmd); DescriptorSet descriptorSet = frame.DescriptorSetManager.GetDescriptorSet(); renderer.Shader.SetUniforms(frame, descriptorSet, uniformOffset, image); vk.CmdBindDescriptorSets(cmd, PipelineBindPoint.Graphics, renderer.Shader.PipelineLayout, 0, 1, descriptorSet, 0, 0); vk.CmdDraw(cmd, triangleCount, 1, triangleOffset, 0); }
public void Bind(CommandBuffer commandBuffer, PipelineBindPoint pipelineBindPoint, int frame) { _vk.CmdBindDescriptorSets(commandBuffer, pipelineBindPoint, _pipelineLayout, 0, 1, _descriptorSets[frame].DescriptorSet, 0, null); }
public unsafe void Run(int currentFrameIndex, int imageIndex, Semaphore waitSemaphore, Semaphore signalSemaphore, Fence signal) { var bufferInfo = new DescriptorBufferInfo(_commandBuffers[currentFrameIndex], 0, (ulong)(sizeof(uint) * _commandBufferCapacities[currentFrameIndex])); _vk.UpdateDescriptorSets(_device, 1, new WriteDescriptorSet(dstSet: _targetDescriptorSets[currentFrameIndex], dstBinding: 1, dstArrayElement: 0, descriptorCount: 1, descriptorType: DescriptorType.StorageBuffer, pBufferInfo: &bufferInfo), 0, null); var currentFrame = _frames[currentFrameIndex]; _vk.ResetCommandPool(_device, currentFrame.CommandPool, 0).ThrowCode(); _vk.AllocateCommandBuffers(_device, new CommandBufferAllocateInfo(commandPool: currentFrame.CommandPool, level: CommandBufferLevel.Primary, commandBufferCount: 1), out var commandBuffer).ThrowCode(); Name(ObjectType.CommandBuffer, (ulong)commandBuffer.Handle, $"Command Buffer Frame {currentFrameIndex}"); var renderContext = new RenderContext(_targetImageViews[imageIndex], _targetSize, currentFrameIndex); _vk.BeginCommandBuffer(commandBuffer, new CommandBufferBeginInfo(flags: CommandBufferUsageFlags.CommandBufferUsageOneTimeSubmitBit)) .ThrowCode(); // var memoryBarrier = new ImageMemoryBarrier2KHR(srcStageMask: PipelineStageFlags2KHR.PipelineStage2TopOfPipeBitKhr, // srcAccessMask: AccessFlags2KHR.Access2NoneKhr, dstStageMask: PipelineStageFlags2KHR.PipelineStage2TransferBitKhr, // dstAccessMask: AccessFlags2KHR.Access2TransferWriteBitKhr, // oldLayout: ImageLayout.Undefined, newLayout: ImageLayout.TransferDstOptimal, // srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, // image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1), // sType: StructureType.ImageMemoryBarrier2Khr, pNext: null); // _khrSynchronization2.CmdPipelineBarrier2(commandBuffer, new DependencyInfoKHR(imageMemoryBarrierCount: 1, // pImageMemoryBarriers: &memoryBarrier, dependencyFlags: 0, memoryBarrierCount: 0, pMemoryBarriers: null, bufferMemoryBarrierCount: 0, pBufferMemoryBarriers: null)); _vk.CmdPipelineBarrier(commandBuffer, PipelineStageFlags.PipelineStageTopOfPipeBit, PipelineStageFlags.PipelineStageTransferBit, 0, 0, null, 0, null, 1, new ImageMemoryBarrier(srcAccessMask: AccessFlags.AccessNoneKhr, dstAccessMask: AccessFlags.AccessTransferWriteBit, oldLayout: ImageLayout.Undefined, newLayout: ImageLayout.TransferDstOptimal, srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1))); _vk.CmdClearColorImage(commandBuffer, _targetImages.Span[imageIndex], ImageLayout.TransferDstOptimal, new ClearColorValue(0f, 0f, 0f, 1f), 1, new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1)); // var memoryBarrier2 = new ImageMemoryBarrier2KHR(srcStageMask: PipelineStageFlags2KHR.PipelineStage2TransferBitKhr, // srcAccessMask: AccessFlags2KHR.Access2TransferWriteBitKhr, dstStageMask: PipelineStageFlags2KHR.PipelineStage2ComputeShaderBitKhr, // dstAccessMask: AccessFlags2KHR.Access2ShaderReadBitKhr | AccessFlags2KHR.Access2ShaderWriteBitKhr, // oldLayout: ImageLayout.TransferDstOptimal, newLayout: ImageLayout.General, // srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, // image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1)); // _khrSynchronization2.CmdPipelineBarrier2(commandBuffer, new DependencyInfoKHR(imageMemoryBarrierCount: 1, // pImageMemoryBarriers: &memoryBarrier2)); _vk.CmdPipelineBarrier(commandBuffer, PipelineStageFlags.PipelineStageTransferBit, PipelineStageFlags.PipelineStageComputeShaderBit, 0, 0, null, 0, null, 1, new ImageMemoryBarrier(srcAccessMask: AccessFlags.AccessTransferWriteBit, dstAccessMask: AccessFlags.AccessShaderReadBit | AccessFlags.AccessShaderWriteBit, oldLayout: ImageLayout.TransferDstOptimal, newLayout: ImageLayout.General, srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1))); Span <uint> pValues = stackalloc uint[] { _targetSize.X, _targetSize.Y }; _vk.CmdPushConstants(commandBuffer, _pipelineLayout, ShaderStageFlags.ShaderStageComputeBit, 0, (uint)pValues.Length * sizeof(uint), pValues); _vk.CmdBindDescriptorSets(commandBuffer, PipelineBindPoint.Compute, _pipelineLayout, 0, 1, _targetDescriptorSets[imageIndex], 0, null); _computeShader.Record(renderContext, commandBuffer); // var memoryBarrier3 = new ImageMemoryBarrier2KHR(srcStageMask: PipelineStageFlags2KHR.PipelineStage2ComputeShaderBitKhr, // srcAccessMask: AccessFlags2KHR.Access2ShaderReadBitKhr | AccessFlags2KHR.Access2ShaderWriteBitKhr, dstStageMask: PipelineStageFlags2KHR.PipelineStage2BottomOfPipeBitKhr, // dstAccessMask: AccessFlags2KHR.Access2NoneKhr, // oldLayout: ImageLayout.General, newLayout: ImageLayout.PresentSrcKhr, // srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, // image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1)); // _khrSynchronization2.CmdPipelineBarrier2(commandBuffer, new DependencyInfoKHR(imageMemoryBarrierCount: 1, // pImageMemoryBarriers: &memoryBarrier3)); _vk.CmdPipelineBarrier(commandBuffer, PipelineStageFlags.PipelineStageComputeShaderBit, PipelineStageFlags.PipelineStageBottomOfPipeBit, 0, 0, null, 0, null, 1, new ImageMemoryBarrier(srcAccessMask: AccessFlags.AccessShaderReadBit | AccessFlags.AccessShaderWriteBit, dstAccessMask: AccessFlags.AccessNoneKhr, oldLayout: ImageLayout.General, newLayout: ImageLayout.PresentSrcKhr, srcQueueFamilyIndex: Vk.QueueFamilyIgnored, dstQueueFamilyIndex: Vk.QueueFamilyIgnored, image: _targetImages.Span[imageIndex], subresourceRange: new ImageSubresourceRange(ImageAspectFlags.ImageAspectColorBit, 0, 1, 0, 1))); _vk.EndCommandBuffer(commandBuffer); var waitDstStageMask = PipelineStageFlags.PipelineStageTransferBit; _vk.QueueSubmit(Queue, 1, new SubmitInfo(waitSemaphoreCount: 1, pWaitSemaphores: &waitSemaphore, commandBufferCount: 1, pCommandBuffers: &commandBuffer, signalSemaphoreCount: 1, pSignalSemaphores: &signalSemaphore, pWaitDstStageMask: &waitDstStageMask), signal).ThrowCode(); }