コード例 #1
0
    void Start()
    {
        var count = 1 << powOfSize;

        Debug.LogFormat("Count={0}", count);

        _sort   = new BitonicMergeSort(compute);
        _keys   = new DisposableBuffer <uint>(count);
        _values = new DisposableBuffer <int>(count);

        Random.seed = seed;
        var data = new int[count];

        for (var i = 0; i < count; i++)
        {
            data[i] = i;
        }
        for (var i = 0; i < count; i++)
        {
            var j   = Random.Range(0, count);
            var k   = Random.Range(0, count);
            var tmp = data[j]; data[j] = data[k]; data[k] = tmp;
        }
        System.Array.Copy(data, _values.Data, count);
        _values.Upload();

        _sort.Init(_keys.Buffer);
        _sort.SortInt(_keys.Buffer, _values.Buffer);

        _keys.Download();
        var failed = false;

        for (var i = 0; i < count; i++)
        {
            var j = _values.Data[_keys.Data[i]];
            if (j != i)
            {
                failed = true;
                Debug.LogErrorFormat("Unexpected Key {0} at {1}", j, i);
            }
        }
        Debug.LogFormat("Sort Test Result = {0}", (failed ? "Wrong" : "Correct"));
    }
コード例 #2
0
        public void Detect(float distance)
        {
            int x = _lifes.SimSizeX, y = _lifes.SimSizeY, z = _lifes.SimSizeZ;

            _hashes.Init(_grid);

            _sort.Init(_keys);
            _sort.SortInt(_keys, _hashes.Hashes);

            _grid.Construct(_keys);

            _grid.SetParams(_compute);
            _compute.SetFloat(ShaderConst.PROP_BROADPHASE_SQR_DISTANCE, distance * distance);
            _compute.SetBuffer(_kernelSolve, ShaderConst.BUF_BROADPHASE_KEYS, _keys);
            _positions.SetBuffer(_compute, _kernelSolve);
            _lifes.SetBuffer(_compute, _kernelSolve);
            _grid.SetBuffer(_compute, _kernelSolve);
            SetBuffer(_compute, _kernelSolve);
            _compute.Dispatch(_kernelSolve, x, y, z);
        }