示例#1
0
    /// <summary>
    /// Remove GPUMemoryBlock.
    /// </summary>
    /// <param name="hash">Hash of memory block to remove.</param>
    public void RemoveGPUMemoryBlock(int hash)
    {
        Debug.Assert(mGPUMemoryBlockDictionary.ContainsKey(hash), "Name(hash) doesn't exist.");
        GPUMemoryBlock block = mGPUMemoryBlockDictionary[hash];

        block.Release();
        mGPUMemoryBlockDictionary.Remove(hash);
        mINVGPUMemoryBlockDictionary.Remove(block);
    }
示例#2
0
    /// <summary>
    /// Create GPUMemoryBlock.
    /// </summary>
    /// <param name="name">Name of memory block. Enables access to block if reference is lost. Name must be unique.</param>
    /// <param name="capacity">Capacity(number of elements) of memory block.</param>
    /// <param name="stride">Stride or each element in memory block.</param>
    /// <param name="type">Type of memory block.</param>
    public GPUMemoryBlock CreateGPUMemoryBlock(string name, int capacity, int stride, ComputeBufferType type)
    {
        int hash = name.GetHashCode();

        Debug.Assert(!mGPUMemoryBlockDictionary.ContainsKey(hash), "Name(hash) already exist.");
        GPUMemoryBlock block = new GPUMemoryBlock(capacity, stride, type);

        mGPUMemoryBlockDictionary.Add(hash, block);
        mINVGPUMemoryBlockDictionary.Add(block, hash);
        return(block);
    }
示例#3
0
    void Start()
    {
        GPUMemoryManager.Instance.StartUp();

        GPUMemoryBlock positionBlock = GPUMemoryManager.Instance.CreateGPUMemoryBlock("PositionBlock", 16, System.Runtime.InteropServices.Marshal.SizeOf(typeof(Vector4)), ComputeBufferType.Default);


        Debug.Log("EndIndex: " + positionBlock.EndIndex);

        GPUMemoryBlock.Handle emitter1 = positionBlock.Allocate(2);
        emitter1.SetData(GPUMemoryBlock.SWAPBUFFER.WRITE, new Vector4[] { new Vector4(1, 1, 1, 1), new Vector4(2, 2, 2, 2) });
        Debug.Log("EndIndex: " + positionBlock.EndIndex);
        {
            Vector4[] dataArray = emitter1.GetData <Vector4>(GPUMemoryBlock.SWAPBUFFER.WRITE);
            for (int i = 0; i < dataArray.GetLength(0); ++i)
            {
                Debug.Log(dataArray[i]);
            }
        }

        GPUMemoryBlock.Handle emitter2 = positionBlock.Allocate(2);
        emitter2.SetData(GPUMemoryBlock.SWAPBUFFER.WRITE, new Vector4[] { new Vector4(3, 3, 3, 3), new Vector4(4, 4, 4, 4) });
        Debug.Log("EndIndex: " + positionBlock.EndIndex);
        {
            Vector4[] dataArray = emitter2.GetData <Vector4>(GPUMemoryBlock.SWAPBUFFER.WRITE);
            for (int i = 0; i < dataArray.GetLength(0); ++i)
            {
                Debug.Log(dataArray[i]);
            }
        }


        positionBlock.Free(emitter1);
        Debug.Log("EndIndex: " + positionBlock.EndIndex);
        positionBlock.Defragment();
        Debug.Log("EndIndex: " + positionBlock.EndIndex);;
        {
            Vector4[] dataArray = emitter2.GetData <Vector4>(GPUMemoryBlock.SWAPBUFFER.WRITE);
            for (int i = 0; i < dataArray.GetLength(0); ++i)
            {
                Debug.Log(dataArray[i]);
            }
        }
    }
示例#4
0
 /// <summary>
 /// Remove GPUMemoryBlock.
 /// </summary>
 /// <param name="block">Block to remove.</param>
 public void RemoveGPUMemoryBlock(GPUMemoryBlock block)
 {
     Debug.Assert(mINVGPUMemoryBlockDictionary.ContainsKey(block), "Block doesn't exist.");
     RemoveGPUMemoryBlock(mINVGPUMemoryBlockDictionary[block]);
 }
示例#5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="block">Memory block this handle maps to.</param>
 public Handle(GPUMemoryBlock block)
 {
     mBlock = block;
 }