Exemplo n.º 1
0
        public void Run(ITexture orgTex, ITexture dstTex, ITexture tmpTex, LayerMipmapSlice lm, UploadBuffer uploadBuffer)
        {
            Debug.Assert(dstTex.Format == Format.R8_UInt);
            Debug.Assert(tmpTex.Format == Format.R8_UInt);

            var size = orgTex.Size.GetMip(lm.Mipmap);
            var dev  = Device.Get();

            // remember for debugging
            var originalDst = dstTex;

            initTexShader.Run(orgTex, dstTex, lm, uploadBuffer);
            initTexShader.Run(orgTex, tmpTex, lm, uploadBuffer);

            dev.Compute.Set(compute.Compute);

            ImageFramework.DirectX.Query.SyncQuery syncQuery = new ImageFramework.DirectX.Query.SyncQuery();
            //var watch = new Stopwatch();
            //watch.Start();
            for (int i = 0; i < 127; i++)
            {
                BindAndSwapTextures(ref dstTex, ref tmpTex, lm);
                Dispatch(new Int3(1, 0, 0), i, size, uploadBuffer);

                BindAndSwapTextures(ref dstTex, ref tmpTex, lm);
                Dispatch(new Int3(0, 1, 0), i, size, uploadBuffer);

                BindAndSwapTextures(ref dstTex, ref tmpTex, lm);
                Dispatch(new Int3(0, 0, 1), i, size, uploadBuffer);

#if DEBUG
                if (i % 8 == 0)
                {
                    syncQuery.Set();
                    syncQuery.WaitForGpu();
                    Console.WriteLine("Iteration: " + i);
                }
#endif
            }


            /*syncQuery.Set();
             * syncQuery.WaitForGpu();
             * watch.Stop();
             *
             * Console.WriteLine($"Time: {watch.ElapsedMilliseconds}ms");
             */
            // unbind
            dev.Compute.SetShaderResource(0, null);
            dev.Compute.SetUnorderedAccessView(0, null);
            dev.Compute.Set(null);

            Debug.Assert(ReferenceEquals(originalDst, tmpTex));
            endShader.Run(dstTex, tmpTex, lm, uploadBuffer);
            syncQuery?.Dispose();
        }
Exemplo n.º 2
0
        public void Run(ITexture src, ITexture dst, ITexture tmpTex, LayerMipmapSlice lm, UploadBuffer upload)
        {
            var size = src.Size.GetMip(lm.Mipmap);
            var dev  = Device.Get();
            // debugging
            var originalDst = dst;

            initTexShader.Run(src, dst, lm, upload);
            initTexShader.Run(src, tmpTex, lm, upload);

            ImageFramework.DirectX.Query.SyncQuery syncQuery = new ImageFramework.DirectX.Query.SyncQuery();
            //var watch = new Stopwatch();
            //watch.Start();
            for (int i = 0; i < 254; ++i)
            {
                // bind textures
                dev.Compute.SetShaderResource(0, dst.GetSrView(lm));
                dev.Compute.SetUnorderedAccessView(0, tmpTex.GetUaView(lm.Mipmap));

                dev.Compute.Set(compute.Compute);
                upload.SetData(new BufferData
                {
                    Size      = size,
                    Iteration = i
                });
                dev.Compute.SetConstantBuffer(0, upload.Handle);

                // execute
                dev.Dispatch(
                    Utility.DivideRoundUp(size.X, workgroupSize.X),
                    Utility.DivideRoundUp(size.Y, workgroupSize.Y),
                    Utility.DivideRoundUp(size.Z, workgroupSize.Z)
                    );

                // unbind texture
                dev.Compute.SetShaderResource(0, null);
                dev.Compute.SetUnorderedAccessView(0, null);

                // swap textures
                var tmp = tmpTex;
                tmpTex = dst;
                dst    = tmp;

#if DEBUG
                if (i % 16 == 0)
                {
                    syncQuery.Set();
                    syncQuery.WaitForGpu();
                    Console.WriteLine("Iteration: " + i);
                }
#endif
            }

            /*syncQuery.Set();
             * syncQuery.WaitForGpu();
             * watch.Stop();
             *
             * Console.WriteLine($"Time: {watch.ElapsedMilliseconds}ms");
             */
            dev.Compute.Set(null);

            Debug.Assert(ReferenceEquals(originalDst, dst));
            syncQuery?.Dispose();
        }
Exemplo n.º 3
0
        public void Execute(ITexture orgTex, ITexture helpTex, LayerMipmapSlice lm, UploadBuffer uploadBuffer)
        {
            var size = orgTex.Size.GetMip(lm.Mipmap);
            var dev  = Device.Get();


            initTexShader.Run(orgTex, helpTex, lm, uploadBuffer);

            Texture3D pong = new Texture3D(helpTex.NumMipmaps, helpTex.Size, Format.R8_UInt, true, false);

            bool readHelpTex = false;

            dev.Compute.Set(compute.Compute);

            ImageFramework.DirectX.Query.SyncQuery syncQuery = new ImageFramework.DirectX.Query.SyncQuery();

            for (int i = 0; i < 127; i++)
            {
                swapTextures(ref readHelpTex, helpTex, pong, lm);

                //x-direction
                uploadBuffer.SetData(new DirBufferData
                {
                    dir = new Int3(1, 0, 0),
                    dim = size
                });
                dev.Compute.SetConstantBuffer(0, uploadBuffer.Handle);
                dev.Dispatch(Utility.DivideRoundUp(size.X, workgroupSize.X), Utility.DivideRoundUp(size.Y, workgroupSize.Y), Utility.DivideRoundUp(size.Z, workgroupSize.Z));


                swapTextures(ref readHelpTex, helpTex, pong, lm);

                //y-direction
                uploadBuffer.SetData(new DirBufferData
                {
                    dir = new Int3(0, 1, 0),
                    dim = size
                });
                dev.Compute.SetConstantBuffer(0, uploadBuffer.Handle);
                dev.Dispatch(Utility.DivideRoundUp(size.X, workgroupSize.X), Utility.DivideRoundUp(size.Y, workgroupSize.Y), Utility.DivideRoundUp(size.Z, workgroupSize.Z));

                swapTextures(ref readHelpTex, helpTex, pong, lm);

                //z-direction
                uploadBuffer.SetData(new DirBufferData
                {
                    dir = new Int3(0, 0, 1),
                    dim = size
                });
                dev.Compute.SetConstantBuffer(0, uploadBuffer.Handle);
                dev.Dispatch(Utility.DivideRoundUp(size.X, workgroupSize.X), Utility.DivideRoundUp(size.Y, workgroupSize.Y), Utility.DivideRoundUp(size.Z, workgroupSize.Z));

#if DEBUG
                if (i % 8 == 0)
                {
                    syncQuery.Set();
                    syncQuery.WaitForGpu();
                    Console.WriteLine("Iteration: " + i);
                }
#endif
            }

            // unbind
            dev.Compute.SetShaderResource(0, null);
            dev.Compute.SetUnorderedAccessView(0, null);
            dev.Compute.Set(null);


            endShader.Run(pong, helpTex, lm, uploadBuffer);
            pong?.Dispose();
        }