public static ComputeBuffer Alloc <ty>(ty[] data, ComputeBufferType cbt = ComputeBufferType.Default) { ComputeBuffer buff = Alloc <ty>(data.Length, cbt); buff.SetData(data); return(buff); }
public static ComputeBuffer Alloc <ty>(List <ty> data, ComputeBufferType cbt = ComputeBufferType.Default) { ComputeBuffer buff = Alloc <ty>(data.Count, cbt); buff.SetData(data); return(buff); }
/// <summary> /// ComputeBufferDesc constructor. /// </summary> /// <param name="count">Number of elements in the buffer.</param> /// <param name="stride">Size of one element in the buffer.</param> /// <param name="type">Type of the buffer.</param> public ComputeBufferDesc(int count, int stride, ComputeBufferType type) : this() { this.count = count; this.stride = stride; this.type = type; }
/// <summary> /// ComputeBufferDesc constructor. /// </summary> /// <param name="count">Number of elements in the buffer.</param> /// <param name="stride">Size of one element in the buffer.</param> public ComputeBufferDesc(int count, int stride) : this() { this.count = count; this.stride = stride; type = ComputeBufferType.Default; }
public static ComputeBuffer GetTempPropertyBuffer(int length, int stride, ComputeBufferType type = ComputeBufferType.Default) { if (!allTempBuffers.isCreated) { allTempBuffers = new NativeDictionary <BufferKey, int, BufferKey.Equal>(11, Allocator.Persistent, new BufferKey.Equal()); } ComputeBuffer target; int targetIndex; if (allTempBuffers.Get(new BufferKey { size = stride, type = type }, out targetIndex)) { target = MUnsafeUtility.GetHookedObject(targetIndex) as ComputeBuffer; if (target.count < length) { target.Dispose(); target = new ComputeBuffer(length, stride, type); MUnsafeUtility.SetHookedObject(targetIndex, target); } return(target); } else { target = new ComputeBuffer(length, stride); allTempBuffers[new BufferKey { size = stride, type = type }] = MUnsafeUtility.HookObject(target); return(target); } }
static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); ComputeBufferType o = (ComputeBufferType)arg0; LuaScriptMgr.PushEnum(L, o); return(1); }
public GPUList(int capacity, ComputeBufferType cbtype) { this.count = 0; this.capacity = 0; this.dataChanged = true; this.cbtype = cbtype; Resize(capacity); }
/// <summary> /// Initializes a compute buffer, releasing and disposing it first if necessary. /// </summary> /// <param name="buffer">The buffer to be initialized - can be null</param> /// <param name="count">The buffer count</param> /// <param name="stride">The buffer stride in bytes</param> protected virtual void InitializeBuffer(ref ComputeBuffer buffer, int count, int stride) { if (buffer != null) { buffer.Release(); } BufferType = ComputeBufferType.Default; buffer = new ComputeBuffer(count, stride, ComputeBufferType.Default); }
/// <summary> /// Constuctor. /// </summary> /// <param name="capacity">Capacity(number of elemets) of memory block.</param> /// <param name="stride">Stride of memory block.</param> /// <param name="type">Type of memory block.</param> /// <param name="bufferCount">Number of buffers in swap buffer. Default: 2.</param> public SwapBuffer(int capacity, int stride, ComputeBufferType type, int bufferCount = 2) { mBufferCount = bufferCount; mBuffers = new ComputeBuffer[mBufferCount]; for (int i = 0; i < mBufferCount; ++i) { mBuffers[i] = new ComputeBuffer(capacity, stride, type); } }
public ComputeBufferPool(int count, int stride, ComputeBufferType type, string name = null) { _available = new Stack <ComputeBuffer>(); _used = new Stack <ComputeBuffer>(); _count = count; _stride = stride; _type = type; _name = name; _rentedCount = 0; }
public BufferPool(int count, int stride, ComputeBufferType type = ComputeBufferType.Default, ComputeBufferMode mode = ComputeBufferMode.Immutable) { m_Buffers = new List <ComputeBuffer>(); m_FreeBufferIds = new Stack <int>(); m_Count = count; m_Stride = stride; m_Type = type; m_Mode = mode; }
public GPUList( int capacity = DEFAULT_CAPACITY, ComputeBufferType cbtype = ComputeBufferType.Default) { this.count = 0; this.capacity = 0; this.dirty = DirtyFlag.Data; this.cbtype = cbtype; Resize(capacity); }
public GPUList( IEnumerable <T> iter, int capacity = DEFAULT_CAPACITY, ComputeBufferType cbtype = ComputeBufferType.Default) : this(capacity, cbtype) { foreach (var v in iter) { Add(v); } }
public static ComputeBufferPool GetShared(ComputeBufferType type = ComputeBufferType.Default) { Pools = Pools ?? new Dictionary <ComputeBufferType, ComputeBufferPool> (); ComputeBufferPool pool; if (!Pools.TryGetValue(type, out pool)) { pool = new ComputeBufferPool(type); Pools.Add(type, pool); } return(pool); }
/// <summary> /// <para>Create a Compute Buffer.</para> /// </summary> /// <param name="count">Number of elements in the buffer.</param> /// <param name="stride">Size of one element in the buffer. Has to match size of buffer type in the shader. See for cross-platform compatibility information.</param> /// <param name="type">Type of the buffer, default is ComputeBufferType.Default.</param> public ComputeBuffer(int count, int stride, ComputeBufferType type) { if (count <= 0) { throw new ArgumentException("Attempting to create a zero length compute buffer", "count"); } if (stride < 0) { throw new ArgumentException("Attempting to create a compute buffer with a negative stride", "stride"); } this.m_Ptr = IntPtr.Zero; InitBuffer(this, count, stride, type); }
public virtual void InitBuffer(int size, bool cpuData = false, bool autoSet = true, ComputeBufferType type = ComputeBufferType.Default) { LogTool.AssertIsTrue(size > 0); this.Release(); this.size = size; this.type = type; this.autoSet = autoSet; this.cpuData = cpuData ? new T[this.size] : null; this.inited = true; }
internal ComputeBuffer(int count, int stride, ComputeBufferType type, int stackDepth) { if (count <= 0) { throw new ArgumentException("Attempting to create a zero length compute buffer", "count"); } if (stride < 0) { throw new ArgumentException("Attempting to create a compute buffer with a negative stride", "stride"); } this.m_Ptr = IntPtr.Zero; ComputeBuffer.InitBuffer(this, count, stride, type); this.SaveCallstack(stackDepth); }
ComputeBuffer GetOrUpdateBuffer(int count, int stride, bool isConstantBuffer) { ComputeBufferType type = isConstantBuffer ? ComputeBufferType.Constant : ComputeBufferType.Structured; #if UNITY_SWITCH // currently maxQueuedFrames returns -1 int maxQueuedFrames = 3; #else int maxQueuedFrames = QualitySettings.maxQueuedFrames; Assertions.Assert.IsTrue(maxQueuedFrames >= 1, "invalid QualitySettings.maxQueuedFrames"); #endif for (int i = 0; i < m_BufferCount; ++i) { int bufferIndex = (m_CachedBufferIndex + i + 1) % m_BufferCount; if (IsLessCircular(m_BufferInfos[bufferIndex].frameUsed + (uint)maxQueuedFrames, m_FrameIndex) && m_BufferInfos[bufferIndex].type == type && m_Buffers[bufferIndex].count == count && m_Buffers[bufferIndex].stride == stride) { m_BufferInfos[bufferIndex].frameUsed = m_FrameIndex; m_CachedBufferIndex = bufferIndex; return(m_Buffers[bufferIndex]); } } if (m_BufferCount == m_Buffers.Length) // If all buffers used: allocate more space. { ComputeBuffer[] newBuffers = new ComputeBuffer[m_BufferCount * 2]; for (int i = 0; i < m_BufferCount; ++i) { newBuffers[i] = m_Buffers[i]; } m_Buffers = newBuffers; ComputeBufferInfo[] newBufferInfos = new ComputeBufferInfo[m_BufferCount * 2]; for (int i = 0; i < m_BufferCount; ++i) { newBufferInfos[i] = m_BufferInfos[i]; } m_BufferInfos = newBufferInfos; } // Create new buffer. m_Buffers[m_BufferCount] = new ComputeBuffer(count, stride, type, ComputeBufferMode.Immutable); m_BufferInfos[m_BufferCount].frameUsed = m_FrameIndex; m_BufferInfos[m_BufferCount].type = type; m_CachedBufferIndex = m_BufferCount; return(m_Buffers[m_BufferCount++]); }
public ComputeBuffer Buffer(string name, int count, int stride, ComputeBufferType kind = ComputeBufferType.Default) { ComputeBuffer buffer = buffers.ContainsKey(name) ? buffers[name] : (buffers[name] = new ComputeBuffer(count, stride, kind)); // Replace buffer existing named buffer if (buffer.count != count || buffer.stride != stride) { buffer.Release(); buffer = new ComputeBuffer(count, stride, kind); buffers[name] = buffer; return(buffer); } return(buffer); }
internal ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage, int stackDepth) { if (count <= 0) { throw new ArgumentException("Attempting to create a zero length compute buffer", "count"); } if (stride <= 0) { throw new ArgumentException("Attempting to create a compute buffer with a negative or null stride", "stride"); } m_Ptr = InitBuffer(count, stride, type, usage); SaveCallstack(stackDepth); }
internal ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage, int stackDepth) { bool flag = count <= 0; if (flag) { throw new ArgumentException("Attempting to create a zero length compute buffer", "count"); } bool flag2 = stride <= 0; if (flag2) { throw new ArgumentException("Attempting to create a compute buffer with a negative or null stride", "stride"); } this.m_Ptr = ComputeBuffer.InitBuffer(count, stride, type, usage); this.SaveCallstack(stackDepth); }
public void UpdateBuffer(GPUBufferVariable <T> other) { this.size = other.size; this.type = other.type; this.autoSet = other.autoSet; if (other.cpuData != null) { if (this.cpuData == null || this.cpuData.Length != other.cpuData.Length) { this.cpuData = new T[this.size]; } Array.Copy(other.cpuData, this.cpuData, this.size); } this.gpuBuffer = other.Data; this.inited = true; }
public virtual void InitBuffer(GPUBufferVariable <T> other) { LogTool.AssertIsTrue(other.Size > 0); LogTool.AssertIsTrue(this != other);//self assignment is dangerous this.Release(); this.size = other.Size; this.type = other.type; this.autoSet = other.autoSet; if (other.cpuData != null) { if (this.cpuData == null || this.cpuData.Length != other.cpuData.Length) { this.cpuData = new T[this.size]; } Array.Copy(other.cpuData, this.cpuData, this.size); } this.gpuBuffer = other.Data; this.inited = true; }
ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage, int stackDepth) { if (count <= 0) { throw new ArgumentException("Attempting to create a zero length compute buffer", "count"); } if (stride <= 0) { throw new ArgumentException("Attempting to create a compute buffer with a negative or null stride", "stride"); } var bufferSize = (long)count * stride; var maxBufferSize = SystemInfo.maxGraphicsBufferSize; if (bufferSize > maxBufferSize) { throw new ArgumentException($"The total size of the compute buffer ({bufferSize} bytes) exceeds the maximum buffer size. Maximum supported buffer size: {maxBufferSize} bytes."); } m_Ptr = InitBuffer(count, stride, type, usage); SaveCallstack(stackDepth); }
public PingPongBuffer(int count, int stride, ComputeBufferType type = ComputeBufferType.Default) { buffer0 = new ComputeBuffer(count, stride, type); buffer1 = new ComputeBuffer(count, stride, type); }
private static extern void InitBuffer(ComputeBuffer buf, int count, int stride, ComputeBufferType type);
public ComputeBuffer(int count, int stride, ComputeBufferType type) { this.m_Ptr = IntPtr.Zero; InitBuffer(this, count, stride, type); }
public ComputeBuffer(int count, int stride, ComputeBufferType type) { this.m_Ptr = IntPtr.Zero; ComputeBuffer.InitBuffer(this, count, stride, type); }
[FreeFunction] // 0x0000000180100E30-0x0000000180100E60 private static IntPtr InitBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage) => default; // 0x0000000180965110-0x0000000180965170
} // 0x0000000180965510-0x0000000180965540 internal ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage, int stackDepth) { } // 0x00000001809653D0-0x00000001809654E0
} // 0x00000001809654E0-0x0000000180965510 public ComputeBuffer(int count, int stride, ComputeBufferType type) { } // 0x0000000180965510-0x0000000180965540
public ComputeBuffer(int count, int stride, ComputeBufferType type){}