Example #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();
        }
Example #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();
        }