Exemple #1
0
        public override void Update()
        {
            initGpuBuffers();

            using (CommandPool cmdPoolCompute = new CommandPool(dev, computeQ.qFamIndex)) {
                PrimaryCommandBuffer 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();
        }
Exemple #2
0
        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();
        }