private void LoadBufferWithGeometryInstances(
            SceneParseResult sceneParseResult,
            ref ComputeBuffer bvhBuffer,
            ref ComputeBuffer primitiveBuffer,
            ref ComputeBuffer worldToPrimitiveBuffer,
            ref SortedList <ISIdx, ComputeBuffer> gemoetryInstanceBuffers)
        {
            foreach (var item in gemoetryInstanceBuffers)
            {
                item.Value?.Release();
            }
            gemoetryInstanceBuffers.Clear();

            var geoInsIter = sceneParseResult.GeometryInstances.GetEnumerator();

            while (geoInsIter.MoveNext())
            {
                var buffer = new ComputeBuffer(sceneParseResult.GetGeometryInstancesCount(geoInsIter.Current.Key),
                                               sceneParseResult.GetGeometryInstancesStride(geoInsIter.Current.Key));
                buffer.SetData(geoInsIter.Current.Value);
                gemoetryInstanceBuffers.Add(geoInsIter.Current.Key, buffer);
            }

            sceneParseResult.TopLevelBVH.Flatten(
                scenePrimitives: sceneParseResult.Primitives,
                flatten: out List <RTBoundingBox> flattenBVH,
                reorderedPrimitives: out List <Primitive> reorderedPrimitives);
            bvhBuffer = new ComputeBuffer(flattenBVH.Count, RTBoundingBox.stride);
            bvhBuffer.SetData(flattenBVH);
            primitiveBuffer = new ComputeBuffer(reorderedPrimitives.Count, Primitive.GetStride());
            primitiveBuffer.SetData(reorderedPrimitives);
            worldToPrimitiveBuffer = new ComputeBuffer(reorderedPrimitives.Count, sizeof(float) * 16);
            worldToPrimitiveBuffer.SetData(sceneParseResult.WorldToPrimitive);
        }
        private void LoadBufferWithGeometryInstances(SceneParseResult sceneParseResult,
                                                     ref TopLevelAccelerationBuffer bvhBuffer,
                                                     ref SortedList <ISIdx, ObjectLevelAccelerationGeometryBuffer> objectLvAccGeoBuffers,
                                                     ref SortedList <ISIdx, ObjectLevelAccelerationGeometryMappingCollectionBuffer> objectLvAccGeoMapBuffers,
                                                     ref PrimitiveBuffer primitiveBuffer,
                                                     ref WorldToLocalBuffer worldToPrimitiveBuffer,
                                                     ref SortedList <ISIdx, GeometryInstanceBuffer> gemoetryInstanceBuffers,
                                                     ref TopLevelAccelerationGeometryMappingCollectionBuffer topLevelAccGeoMapColBuffer)
        {
            gemoetryInstanceBuffers.Clear();
            objectLvAccGeoBuffers.Clear();
            objectLvAccGeoMapBuffers.Clear();

            var geoInsIter = sceneParseResult.GeometryInstances.GetEnumerator();

            while (geoInsIter.MoveNext())
            {
                var buffer = new GeometryInstanceBuffer(sceneParseResult.GetGeometryInstancesCount(geoInsIter.Current.Key), sceneParseResult.GetGeometryInstancesStride(geoInsIter.Current.Key));
                buffer.SetData(geoInsIter.Current.Value);
                gemoetryInstanceBuffers.Add(geoInsIter.Current.Key, buffer);
            }

            var objectLevelAccGeoIter = sceneParseResult.ObjectLevelAccelerationGeometries.GetEnumerator();

            while (objectLevelAccGeoIter.MoveNext())
            {
                var buffer = new ObjectLevelAccelerationGeometryBuffer(objectLevelAccGeoIter.Current.Value.Count, sizeof(float));
                buffer.SetData(objectLevelAccGeoIter.Current.Value);
                objectLvAccGeoBuffers.Add(objectLevelAccGeoIter.Current.Key, buffer);
            }

            var objectLvAccGeoMapIter = sceneParseResult.ObjectLevelAccelerationGeometryMapping.GetEnumerator();

            while (objectLvAccGeoMapIter.MoveNext())
            {
                var buffer = new ObjectLevelAccelerationGeometryMappingCollectionBuffer(objectLvAccGeoMapIter.Current.Value.Count, sizeof(int));
                buffer.SetData(objectLvAccGeoMapIter.Current.Value);
                objectLvAccGeoMapBuffers.Add(objectLvAccGeoMapIter.Current.Key, buffer);
            }

            var objectLevelAccStrInsIter = sceneParseResult.ObjectLevelAccelerationStructures.GetEnumerator();

            while (objectLevelAccStrInsIter.MoveNext())
            {
                var buffer = new GeometryInstanceBuffer(objectLevelAccStrInsIter.Current.Value.Count, sizeof(float));
                buffer.SetData(objectLevelAccStrInsIter.Current.Value);
                gemoetryInstanceBuffers.Add(objectLevelAccStrInsIter.Current.Key, buffer);
            }

            sceneParseResult.TopLevelBVH.Flatten(
                flatten: out List <RTBoundingBoxToGPU> _flattenBVH,
                accelerationGeometryMapping: out List <int> _topLevelAccelerationGeometryMapping);
            bvhBuffer = new TopLevelAccelerationBuffer(_flattenBVH.Count, RTBoundingBox.stride);
            bvhBuffer.SetData(_flattenBVH);
            primitiveBuffer = new PrimitiveBuffer(sceneParseResult.Primitives.Count, Primitive.GetStride());
            primitiveBuffer.SetData(sceneParseResult.Primitives);
            topLevelAccGeoMapColBuffer = new TopLevelAccelerationGeometryMappingCollectionBuffer(_topLevelAccelerationGeometryMapping.Count, sizeof(int));
            topLevelAccGeoMapColBuffer.SetData(_topLevelAccelerationGeometryMapping);
            worldToPrimitiveBuffer = new WorldToLocalBuffer(sceneParseResult.WorldToPrimitive.Count, sizeof(float) * 16);
            worldToPrimitiveBuffer.SetData(sceneParseResult.WorldToPrimitive);
        }