public override void Update() { initGpuBuffers(); using (CommandPool cmdPoolCompute = new CommandPool(dev, computeQ.qFamIndex)) { CommandBuffer cmd = cmdPoolCompute.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); pong = false; uint stepSize = imgDim / 2; plCompute.Bind(cmd); cmd.PushConstant(plCompute.Layout, VkShaderStageFlags.Compute, imgDim, sizeof(int)); int pass = 0; while (stepSize > 0 && pass < invocationCount) { cmd.PushConstant(plCompute.Layout, VkShaderStageFlags.Compute, stepSize); if (pong) { plCompute.BindDescriptorSet(cmd, dsetPong); } else { plCompute.BindDescriptorSet(cmd, dsetPing); } cmd.Dispatch(imgDim, imgDim); VkMemoryBarrier memBar = VkMemoryBarrier.New(); memBar.srcAccessMask = VkAccessFlags.ShaderWrite; memBar.dstAccessMask = VkAccessFlags.ShaderRead; Vk.vkCmdPipelineBarrier(cmd.Handle, VkPipelineStageFlags.ComputeShader, VkPipelineStageFlags.ComputeShader, VkDependencyFlags.ByRegion, 1, ref memBar, 0, IntPtr.Zero, 0, IntPtr.Zero); pong = !pong; stepSize /= 2; pass++; } plNormalize.Bind(cmd); if (pong) { plNormalize.BindDescriptorSet(cmd, dsetPong); } else { plNormalize.BindDescriptorSet(cmd, dsetPing); } cmd.Dispatch(imgDim, imgDim); pong = !pong; cmd.End(); computeQ.Submit(cmd); computeQ.WaitIdle(); } printResults(); }
public void Run() { using (CommandPool cmdPool = new CommandPool(dev, computeQ.qFamIndex)) { CommandBuffer cmd = cmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); bool pong = false; plCompute.Bind(cmd); cmd.PushConstant(plCompute.Layout, VkShaderStageFlags.Compute, imgDim); for (int i = 0; i < 4; i++) { if (pong) { plCompute.BindDescriptorSet(cmd, dsetPong); } else { plCompute.BindDescriptorSet(cmd, dsetPing); } cmd.Dispatch(imgDim, imgDim); } cmd.End(); computeQ.Submit(cmd); computeQ.WaitIdle(); } }
public void Run() { using (CommandPool cmdPool = new CommandPool(dev, computeQ.qFamIndex)) { PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart(VkCommandBufferUsageFlags.OneTimeSubmit); plCompute.Bind(cmd); plCompute.BindDescriptorSet(cmd, dset); cmd.Dispatch(data_size * sizeof(int)); cmd.End(); computeQ.Submit(cmd); computeQ.WaitIdle(); } printResults(); }