public override void InitBuffer(GPUBufferVariable <T> other) { LogTool.Log("Use InitAppendBuffer(GPUBufferAppendConsume<T> other)", LogLevel.Warning); LogTool.AssertIsTrue(other is GPUBufferAppendConsume <T>); this.InitAppendBuffer(other as GPUBufferAppendConsume <T>); }
protected const int MIN_INDIRECT_BUFFER_SIZE = 5;//5 ints public static void SwapBuffer(GPUBufferVariable <T> lhs, GPUBufferVariable <T> rhs) { LogTool.AssertIsTrue(lhs.Size == rhs.Size); LogTool.AssertIsTrue(lhs.type == rhs.type); var temp = lhs.gpuBuffer; lhs.gpuBuffer = rhs.gpuBuffer; rhs.gpuBuffer = temp; }
protected void SetupIndirectBuffer(GPUBufferVariable <uint> buffer, Mesh mesh, int count) { var args = buffer.CPUData; var subIndex = 0; args[0] = (uint)mesh.GetIndexCount(subIndex); args[1] = (uint)count; args[2] = (uint)mesh.GetIndexStart(subIndex); args[3] = (uint)mesh.GetBaseVertex(subIndex); buffer.SetToGPUBuffer(); }
protected void Draw(Mesh mesh, Material material, GPUBufferVariable <uint> indirectBuffer) { if (mesh == null || material == null || indirectBuffer == null) { LogTool.Log("Draw buffer is null, nothing to draw", LogLevel.Warning); return; } this.data.UpdateGPU(material); var b = new Bounds(Vector3.zero, Vector3.one * 10000); Graphics.DrawMeshInstancedIndirect(mesh, 0, material, b, indirectBuffer, 0); }
public void BuildSortedParticleGridIndex(GPUBufferVariable <ObjectType> source, out GPUBufferVariable <ObjectType> sortedBuffer) { sortedBuffer = default; this.CheckBufferChanged(source); this.dispatcher.Dispatch(Kernel.ObjectToGridIndex, source.Size); this.Sort.Sort(ref this.gridbuffer.objectGridIndexBuffer); var s = this.gridData.gridSize; this.dispatcher.Dispatch(Kernel.ClearGridIndex, s.x, s.y, s.z); this.dispatcher.Dispatch(Kernel.BuildGridIndex, source.Size); this.dispatcher.Dispatch(Kernel.BuildSortedObject, source.Size); sortedBuffer = this.gridbuffer.objectBufferSorted; }
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; }
protected void CheckBufferChanged(GPUBufferVariable <ObjectType> source) { if (this.gridbuffer.objectBufferSorted == null || this.gridbuffer.objectBufferSorted.Size != source.Size) { //use source as object buffer this.gridbuffer.objectBuffer.InitBuffer(source); //create new buffer for sorted data this.gridbuffer.objectBufferSorted.InitBuffer(source.Size); //create new buffer for object index this.gridbuffer.objectGridIndexBuffer.InitBuffer(source.Size); this.dispatcher = new ComputeShaderDispatcher <Kernel>(this.gridCS); foreach (Kernel k in Enum.GetValues(typeof(Kernel))) { this.dispatcher.AddParameter(k, this.gridData); this.dispatcher.AddParameter(k, this.gridbuffer); } } else { this.gridbuffer.objectBuffer.UpdateBuffer(source); } }
public override void Release() { base.Release(); this.counterBuffer?.Release(); this.counterBuffer = null; }