示例#1
0
    public bool Sort(float[] _datas, SortMethod _method)
    {
        if (_datas.Length < 2)
        {
            return(false);
        }
        if (!cs)
        {
            return(false);
        }

        GraphicsBuffer buffer;
        int            count = CreateBuffer(_datas, out buffer);

        System.Action <GraphicsBuffer, int> process;
        switch (_method)
        {
        case SortMethod.fastest:
            process = Bitonic_fastest;
            break;

        case SortMethod.NoUsedSharedMemory:
            process = Bitonic_NoUseSharedMemort;
            break;

        default:
            process = Bitonic_fastest;
            break;
        }

        process(buffer, count);
        BitonicSortData[] stream = new BitonicSortData[count];

        buffer.GetData(stream);
        buffer.Release();

        for (int i = 0; i < _datas.Length; ++i)
        {
            _datas[i] = stream[i].key;
        }

        return(true);
    }
示例#2
0
    int CreateBuffer(float[] _datas, out GraphicsBuffer _buffer)
    {
        int len = Mathf.NextPowerOfTwo(_datas.Length);

        BitonicSortData[] stream = new BitonicSortData[len];
        for (int i = 0; i < _datas.Length; ++i)
        {
            stream[i].index = (uint)i;
            stream[i].key   = _datas[i];
        }

        for (int i = _datas.Length; i < len; ++i)
        {
            stream[i].index = (uint)i;
            stream[i].key   = MIN_FLOAT;
        }

        _buffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, len, System.Runtime.InteropServices.Marshal.SizeOf(stream[0]));
        _buffer.SetData(stream);
        return(len);
    }