void DrawFrame()
        {
            var renderPassDescriptor = new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[]
            {
                new GpuRenderPassColorAttachment(SwapChain.GetCurrentTexture().CreateView(), new GpuColorDict {
                    R = 0, G = 0, B = 0, A = 0
                })
            });

            renderPassDescriptor.DepthStencilAttachment = new GpuRenderPassDepthStencilAttachment(DepthTexture.CreateView(), 1.0f, GpuStoreOp.Store, null, GpuStoreOp.Store);
            var commandEncoder = Device.CreateCommandEncoder();
            var cpass          = commandEncoder.BeginComputePass();

            cpass.SetPipeline(ComputePipeline);
            cpass.SetBindGroup(0, ParticleBindGroups[T % 2]);
            cpass.Dispatch(NumParticles, 1, 1);
            cpass.EndPass();
            var rpass = commandEncoder.BeginRenderPass(renderPassDescriptor);

            rpass.SetPipeline(RenderPipeline);
            rpass.SetVertexBuffer(0, ParticleBuffers[(T + 1) % 2], 0, ParticleBuffers[(T + 1) % 2].Size);
            rpass.SetVertexBuffer(1, VerticesBuffer, 0, VerticesBuffer.Size);
            rpass.Draw(3, NumParticles, 0, 0);
            rpass.EndPass();
            Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { commandEncoder.Finish() });
            SwapChain.Present();
            ++T;
        }
Пример #2
0
        void DrawFrame()
        {
            WriteMatrixToBuffer(UniformCpuBuffer, GetTransformationMatrix());
            Device.DefaultQueue.WriteBuffer(UniformBuffer, 0, UniformCpuBuffer);
            var swapChainTexture = SwapChain.GetCurrentTexture();
            GpuRenderPassDescriptor renderPassDescriptor = new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[] { new GpuRenderPassColorAttachment(swapChainTexture.CreateView(), new GpuColorDict {
                    R = 0.5f, G = 0.5f, B = 0.5f, A = 1.0f
                }) })
            {
                DepthStencilAttachment = new GpuRenderPassDepthStencilAttachment(DepthTexture.CreateView(), 1.0f, GpuStoreOp.Store, null, GpuStoreOp.Store)
            };
            var commandEncoder = Device.CreateCommandEncoder();
            var passEncoder    = commandEncoder.BeginRenderPass(renderPassDescriptor);

            passEncoder.SetPipeline(Pipeline);
            passEncoder.SetBindGroup(0, UniformBindGroup);
            passEncoder.SetVertexBuffer(0, VerticesBuffer, 0, VerticesBuffer.Size);
            passEncoder.Draw(36, 1, 0, 0);
            passEncoder.EndPass();
            commandEncoder.CopyTextureToTexture(new GpuImageCopyTexture(swapChainTexture), new GpuImageCopyTexture(CubeTexture), new GpuExtend3DDict {
                Width = SwapChainDescriptor.Width, Height = SwapChainDescriptor.Height, Depth = 1
            });
            Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { commandEncoder.Finish() });
            SwapChain.Present();
        }
Пример #3
0
        void DrawFrame(Settings settings)
        {
            //Device.DefaultQueue.WriteBuffer()
            var blockDim = TileDim - (settings.FilterSize - 1);

            if (_LastSettings.FilterSize == settings.FilterSize && _LastSettings.Iterations == settings.Iterations)
            {
            }
            else
            {
                Device.DefaultQueue.WriteBuffer(BlurParamsBuffer, 0, CreateBufferFromArray(new UInt32[] { settings.FilterSize, blockDim }));
                _LastSettings = settings;
            }


            var commandEncoder = Device.CreateCommandEncoder();
            var computePass    = commandEncoder.BeginComputePass();

            computePass.SetPipeline(BlurPipeline);
            computePass.SetBindGroup(0, ComputeConstants);
            computePass.SetBindGroup(1, ComputeBindGroup0);
            computePass.Dispatch((uint)MathF.Ceiling(SrcWidth / ((float)blockDim)), (uint)MathF.Ceiling(SrcHeight / ((float)Batch[1])), 1);
            computePass.Dispatch(2, (uint)MathF.Ceiling(SrcHeight / ((float)Batch[1])), 1);
            computePass.SetBindGroup(1, ComputeBindGroup1);
            computePass.Dispatch((uint)MathF.Ceiling(SrcHeight / ((float)blockDim)), (uint)MathF.Ceiling(SrcWidth / ((float)Batch[1])), 1);
            for (int i = 0; i < settings.Iterations - 1; ++i)
            {
                computePass.SetBindGroup(1, ComputeBindGroup2);
                computePass.Dispatch((uint)MathF.Ceiling(SrcWidth / ((float)blockDim)), (uint)MathF.Ceiling(SrcHeight / ((float)Batch[1])), 1);

                computePass.SetBindGroup(1, ComputeBindGroup1);
                computePass.Dispatch((uint)MathF.Ceiling(SrcHeight / ((float)blockDim)), (uint)MathF.Ceiling(SrcWidth / ((float)Batch[1])), 1);
            }
            computePass.EndPass();
            var passEncoder = commandEncoder.BeginRenderPass(new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[]
            {
                new GpuRenderPassColorAttachment(SwapChain.GetCurrentTexture().CreateView(), new GpuColorDict()
                {
                    R = 0, G = 0, B = 0, A = 1
                })
            }));

            passEncoder.SetPipeline(Pipeline);
            passEncoder.SetVertexBuffer(0, VerticesBuffer, 0, VerticesBuffer.Size);
            passEncoder.SetBindGroup(0, UniformBindGroup);
            passEncoder.Draw(6, 1, 0, 0);
            passEncoder.EndPass();
            Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { commandEncoder.Finish() });
        }
Пример #4
0
        void DrawFrame()
        {
            var encoder              = Device.CreateCommandEncoder();
            var textureView          = SwapChain.GetCurrentTexture().CreateView();
            var renderpassDescriptor = new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[]
            {
                new GpuRenderPassColorAttachment(textureView, new GpuColorDict {
                    R = 0, G = 0, B = 0, A = 1
                })
            });
            var passEncoder = encoder.BeginRenderPass(renderpassDescriptor);

            passEncoder.SetPipeline(Pipeline);
            passEncoder.Draw(3, 1, 0, 0);
            passEncoder.EndPass();
            Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { encoder.Finish() });
            SwapChain.Present();
        }
Пример #5
0
        void DrawFrame()
        {
            UpdateTransformationMatrix();
            WriteMatricesToBuffer(UniformCpuBuffer, MvpMatrices);
            Device.DefaultQueue.WriteBuffer(UniformBuffer, 0, UniformCpuBuffer);

            GpuRenderPassDescriptor renderPassDescriptor = new GpuRenderPassDescriptor(new GpuRenderPassColorAttachment[] { new GpuRenderPassColorAttachment(SwapChain.GetCurrentTexture().CreateView(), new GpuColorDict {
                    R = 0.5f, G = 0.5f, B = 0.5f, A = 1.0f
                }) })
            {
                DepthStencilAttachment = new GpuRenderPassDepthStencilAttachment(DepthTexture.CreateView(), 1.0f, GpuStoreOp.Store, null, GpuStoreOp.Store)
            };
            var commandEncoder = Device.CreateCommandEncoder();
            var passEncoder    = commandEncoder.BeginRenderPass(renderPassDescriptor);

            passEncoder.SetPipeline(Pipeline);
            passEncoder.SetBindGroup(0, UniformBindGroup);
            passEncoder.SetVertexBuffer(0, VerticesBuffer, 0, VerticesBuffer.Size);
            passEncoder.Draw(36, NumInstances, 0, 0);
            passEncoder.EndPass();
            Device.DefaultQueue.Sumit(new GpuCommandBuffer[] { commandEncoder.Finish() });
            SwapChain.Present();
        }