예제 #1
0
        public void TestUnalignedSizes(int count)
        {
            using (StructuredBuffer <int> buffer = new StructuredBuffer <int>(count)) {
                int   sum           = 0;
                int[] testData      = new int[count];
                int[] referenceScan = new int[count];
                for (int i = 0; i < count; i++)
                {
                    testData[i]      = 1;
                    referenceScan[i] = sum;
                    sum += testData[i];
                }
                buffer.SetData(testData);

                NaiveScan scanner = new NaiveScan();
                scanner.Scan(buffer, buffer.Count);

                int[] result = buffer.GetData();
                for (int i = 0; i < referenceScan.Length; i++)
                {
                    Assert.AreEqual(result[i], referenceScan[i]);
                }
            }
        }
예제 #2
0
    public void Compact(ComputeBufferBase <int> buffer, ComputeBufferBase <int> keys, int count)
    {
        var scan = new NaiveScan();

        scan.Scan(keys, count);

        uint gx, gy, gz;

        shader.GetKernelThreadGroupSizes(compactKernel, out gx, out gy, out gz);
        int numGroupsX = Mathf.CeilToInt((float)count / gx);

        using (var tmp = new StructuredBuffer <int>(count)) {
            shader.SetInt("count", count);

            shader.SetBuffer(compactKernel, "data", buffer.Buffer);
            shader.SetBuffer(compactKernel, "output", tmp.Buffer);
            shader.SetBuffer(compactKernel, "keys", keys.Buffer);
            shader.Dispatch(compactKernel, numGroupsX, 1, 1);

            shader.SetBuffer(copyBackKernel, "data", tmp.Buffer);
            shader.SetBuffer(copyBackKernel, "output", buffer.Buffer);
            shader.Dispatch(copyBackKernel, numGroupsX, 1, 1);
        }
    }