Example #1
0
        public BroadPhase(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p)
        {
            var capacity = l.Lifes.count;

            _lifes        = l;
            _positions    = p;
            _kernelInitYs = compute.FindKernel(ShaderConst.KERNEL_INIT_BROADPHASE);
            _kernelSolve  = compute.FindKernel(ShaderConst.KERNEL_SOVLE_BROADPHASE);
            _compute      = compute;
            _sort         = new BitonicMergeSort(computeSort);
            Keys          = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
            _ys           = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(float)));
            Bands         = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Band)));
        }
Example #2
0
        public HashGrid(ComputeShader compute, ComputeShader computeSort, LifeService l, PositionService p, GridService.Grid g)
        {
            var capacity = l.Lifes.count;

            _compute   = compute;
            _lifes     = l;
            _positions = p;

            _kernelSolve  = compute.FindKernel(ShaderConst.KERNEL_SOVLE_COLLISION_DETECTION);
            _sort         = new BitonicMergeSort(computeSort);
            _keys         = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(uint)));
            CollisionData = new Collision[capacity];
            Collisions    = new ComputeBuffer(capacity, Marshal.SizeOf(typeof(Collision)));
            _hashes       = new HashService(compute, l, p);
            _grid         = new GridService(compute, g, _hashes);
        }
Example #3
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"));
    }