protected override void OnUpdate() { var job = new AABBJob() { LocalToWorldTypeInfo = GetArchetypeChunkComponentType <LocalToWorld>(true), ChunkAABBTypeInfo = GetArchetypeChunkComponentType <ChunkAABB>(false), L2WChangeVersion = this.LastSystemVersion }; this.Dependency = job.Schedule(queryWithChunkComponent, this.Dependency); }
private void ContainsPoint() { ProfilerSample.BeginSample("ContainsPoint"); for (int i = 0, length = centers.Length; i < length; i++) { result[i] = ContainsPoint(centers[i]) ? 1 : 0; } ProfilerSample.EndSample(); ProfilerSample.BeginSample("ContainsPointJobSystem"); // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes AABBJob job = new AABBJob(); job.max = max; job.min = min; pointArray.CopyFrom(centers); job.points = pointArray; job.result = rs; // Schedule the job JobHandle handle = job.Schedule(); // Wait for the job to complete handle.Complete(); rs.CopyTo(result); ProfilerSample.EndSample(); ProfilerSample.BeginSample("ContainsPointComputeShader"); computeShader.SetVector(Shader.PropertyToID("box_min"), min); //cpu->gpu computeShader.SetVector(Shader.PropertyToID("box_max"), max); //cpu->gpu computeShader.SetInt(Shader.PropertyToID("size"), count); //cpu->gpu pointsBuffer.SetData(centers); computeShader.SetBuffer(_kernel, Shader.PropertyToID("points"), pointsBuffer); //cpu->gpu computeShader.SetBuffer(_kernel, Shader.PropertyToID("output"), output); ////cpu->gpu->cpu //Debug.Log(output.count + " " + result.Length); computeShader.Dispatch(_kernel, 1024, 1, 1); //调用核函数 output.GetData(result); //获取compute shader中计算后的结果数据 ProfilerSample.EndSample(); }