예제 #1
0
 public T *CommandData <T>() where T : unmanaged, ISpawnCommandData
 {
     return((T *)UnsafeUtility.AddressOf(ref spawnCommandData));
 }
예제 #2
0
        unsafe public static JobHandle Schedule <T>(this T jobData, int arrayLength, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelFor
        {
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForJobStruct <T> .jobReflectionData, dependsOn, ScheduleMode.Parallel);

            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, innerloopBatchCount));
        }
예제 #3
0
            public unsafe void Execute()
            {
                if (DummyRun)
                {
                    return;
                }

                CollisionPairWriter.BeginForEachIndex(0);

                CollisionFilter *bodyFilters             = (CollisionFilter *)Filter.GetUnsafePtr();
                bool *           bodyrespondsToCollision = (bool *)RespondsToCollision.GetUnsafePtr();
                var pairBuffer = new Broadphase.BodyPairWriter((NativeStream.Writer *)UnsafeUtility.AddressOf(ref CollisionPairWriter),
                                                               bodyFilters, bodyFilters, bodyrespondsToCollision, bodyrespondsToCollision, 0, 0);

                Node *nodesPtr = (Node *)Nodes.GetUnsafePtr();

                BoundingVolumeHierarchy.TreeOverlap(ref pairBuffer, nodesPtr, nodesPtr);

                pairBuffer.Close();

                CollisionPairWriter.EndForEachIndex();
            }
예제 #4
0
 public unsafe void SetValue(ref TContainer container, TValue value)
 => *(TValue *)((byte *)UnsafeUtility.AddressOf(ref container) + m_Offset) = value;
        unsafe public static void Run <T>(this T jobData, int arrayLength) where T : struct, IJobFor
        {
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), JobProducer <T> .Initialize(), new JobHandle(), ScheduleMode.Run);

            JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, arrayLength);
        }
 unsafe internal static JobsUtility.JobScheduleParameters CreateScheduleParams <T>(ref T jobData, ParticleSystem ps, JobHandle dependsOn, IntPtr jobReflectionData) where T : struct
 {
     dependsOn = JobHandle.CombineDependencies(ps.GetManagedJobHandle(), dependsOn);
     return(new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), jobReflectionData, dependsOn, ScheduleMode.Parallel));
 }
예제 #7
0
 private static unsafe bool Equals(Scene lhs, Scene rhs)
 {
     return(UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref lhs), UnsafeUtility.AddressOf(ref rhs), UnsafeUtility.SizeOf <Scene>()) == 0);
 }
예제 #8
0
        public static unsafe void Execute(ref JobNativeMultiHashMapMergedSharedKeyIndicesProducer <TJob> jobProducer, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
        {
            while (true)
            {
                int begin;
                int end;

                if (!JobsUtility.GetWorkStealingRange(ref ranges, jobIndex, out begin, out end))
                {
                    return;
                }

                var bucketData = jobProducer.HashMap.GetUnsafeBucketData();
                var buckets    = (int *)bucketData.buckets;
                var nextPtrs   = (int *)bucketData.next;
                var keys       = bucketData.keys;
                var values     = bucketData.values;

                for (int i = begin; i < end; i++)
                {
                    int entryIndex = buckets[i];

                    while (entryIndex != -1)
                    {
                        var key   = UnsafeUtility.ReadArrayElement <int>(keys, entryIndex);
                        var value = UnsafeUtility.ReadArrayElement <int>(values, entryIndex);
                        int firstValue;

                        NativeMultiHashMapIterator <int> it;
                        jobProducer.HashMap.TryGetFirstValue(key, out firstValue, out it);

                        // [macton] Didn't expect a usecase for this with multiple same values
                        // (since it's intended use was for unique indices.)
                        // https://forum.unity.com/threads/ijobnativemultihashmapmergedsharedkeyindices-unexpected-behavior.569107/#post-3788170
                        if (entryIndex == it.GetEntryIndex())
                        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref jobProducer), value, 1);
#endif
                            jobProducer.JobData.ExecuteFirst(value);
                        }
                        else
                        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            var startIndex  = math.min(firstValue, value);
                            var lastIndex   = math.max(firstValue, value);
                            var rangeLength = (lastIndex - startIndex) + 1;

                            JobsUtility.PatchBufferMinMaxRanges(bufferRangePatchData, UnsafeUtility.AddressOf(ref jobProducer), startIndex, rangeLength);
#endif
                            jobProducer.JobData.ExecuteNext(firstValue, value);
                        }

                        entryIndex = nextPtrs[entryIndex];
                    }
                }
            }
        }
예제 #9
0
 public static BlobAssetReference <T> Create(T value)
 {
     return(Create(UnsafeUtility.AddressOf(ref value), UnsafeUtility.SizeOf <T>()));
 }
                public T GetRequestParameters()
                {
                    T request = new T();

                    unsafe
                    {
                        Binding.GetRequestParameters((IntPtr)UnsafeUtility.AddressOf(ref this), (IntPtr)UnsafeUtility.AddressOf(ref request), 1);
                    }
                    return(request);
                }
 public static JobHandle Schedule <T>(this T jobData, EudiReplicaTransformAccessArray transforms, JobHandle dependsOn = default(JobHandle)) where T : struct, IEudiReplicaJobParallelForTransform
 {
     JobsUtility.JobScheduleParameters parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf <T>(ref jobData), TransformParallelForLoopStruct <T> .Initialize(), dependsOn, ScheduleMode.Batched);
     return(JobsUtility.ScheduleParallelForTransform(ref parameters, transforms.GetTransformAccessArrayForSchedule()));
 }
 public void CompleteRequest(RequestStatus status, CommandBuffer fenceBuffer)
 {
     unsafe
     {
         Binding.UpdateRequestStateWithCommandBuffer((IntPtr)UnsafeUtility.AddressOf(ref this), (IntPtr)UnsafeUtility.AddressOf(ref status), 1, fenceBuffer);
     }
 }
 public void CompleteRequest(RequestStatus status)
 {
     unsafe
     {
         Binding.UpdateRequestState((IntPtr)UnsafeUtility.AddressOf(ref this), (IntPtr)UnsafeUtility.AddressOf(ref status), 1);
     }
 }
예제 #14
0
 public static unsafe void *ConstructRootPtr <T>(this BlobBuilder builder) where T : struct
 {
     return(UnsafeUtility.AddressOf(ref builder.ConstructRoot <T>()));
 }
 public void InitializeHierarchy(ref CompactHierarchy hierarchy)
 {
     compactHierarchyPtr = (CompactHierarchy *)UnsafeUtility.AddressOf(ref hierarchy);
 }
예제 #16
0
 public void Allocate <T>(int length, ref BlobArray <T> ptr) where T : struct
 {
     ptr.m_OffsetPtr = Allocate(UnsafeUtility.SizeOf <T>() * length, UnsafeUtility.AddressOf(ref ptr));
     ptr.m_Length    = length;
 }
예제 #17
0
        public static void RunNoCheck(ref T data)
        {
            var objAddr = UnsafeUtility.AddressOf(ref System.Runtime.CompilerServices.Unsafe.AsRef(data));

            Burst <T> .cacheDelegate.Invoke(ref objAddr);
        }
예제 #18
0
 public void Allocate <T>(ref BlobPtr <T> ptr) where T : struct
 {
     ptr.m_OffsetPtr = Allocate(UnsafeUtility.SizeOf <T>(), UnsafeUtility.AddressOf(ref ptr));
 }
예제 #19
0
        /// <inheritdoc />
        public override unsafe void WriteValueIntoState(TouchState value, void *statePtr)
        {
            var valuePtr = (TouchState *)((byte *)statePtr + (int)m_StateBlock.byteOffset);

            UnsafeUtility.MemCpy(valuePtr, UnsafeUtility.AddressOf(ref value), UnsafeUtility.SizeOf <TouchState>());
        }
예제 #20
0
    // Creates a Unity mesh from the decoded Draco mesh.
    public unsafe Mesh CreateUnityMesh(DracoMesh *dracoMesh)
    {
        float startTime = Time.realtimeSinceStartup;
        int   numFaces  = dracoMesh->numFaces;

        int[]     newTriangles = new int[dracoMesh->numFaces * 3];
        Vector3[] newVertices  = new Vector3[dracoMesh->numVertices];
        Vector2[] newUVs       = null;
        Vector3[] newNormals   = null;
        Color[]   newColors    = null;
        byte[]    newGenerics  = null;

        // Copy face indices.
        DracoData *indicesData;

        GetMeshIndices(dracoMesh, &indicesData);
        int elementSize =
            DataTypeSize((DracoMeshLoader.DataType)indicesData->dataType);
        int *indices    = (int *)(indicesData->data);
        var  indicesPtr = UnsafeUtility.AddressOf(ref newTriangles[0]);

        UnsafeUtility.MemCpy(indicesPtr, indices,
                             newTriangles.Length * elementSize);
        ReleaseDracoData(&indicesData);

        // Copy positions.
        DracoAttribute *attr = null;

        GetAttributeByType(dracoMesh, AttributeType.POSITION, 0, &attr);
        DracoData *posData = null;

        GetAttributeData(dracoMesh, attr, &posData);
        elementSize = DataTypeSize((DracoMeshLoader.DataType)posData->dataType) *
                      attr->numComponents;
        var newVerticesPtr = UnsafeUtility.AddressOf(ref newVertices[0]);

        UnsafeUtility.MemCpy(newVerticesPtr, (void *)posData->data,
                             dracoMesh->numVertices * elementSize);
        ReleaseDracoData(&posData);
        ReleaseDracoAttribute(&attr);

        // Copy normals.
        if (GetAttributeByType(dracoMesh, AttributeType.NORMAL, 0, &attr))
        {
            DracoData *normData = null;
            if (GetAttributeData(dracoMesh, attr, &normData))
            {
                elementSize =
                    DataTypeSize((DracoMeshLoader.DataType)normData->dataType) *
                    attr->numComponents;
                newNormals = new Vector3[dracoMesh->numVertices];
                var newNormalsPtr = UnsafeUtility.AddressOf(ref newNormals[0]);
                UnsafeUtility.MemCpy(newNormalsPtr, (void *)normData->data,
                                     dracoMesh->numVertices * elementSize);
                Debug.Log("Decoded mesh normals.");
                ReleaseDracoData(&normData);
                ReleaseDracoAttribute(&attr);
            }
        }

        // Copy texture coordinates.
        if (GetAttributeByType(dracoMesh, AttributeType.TEX_COORD, 0, &attr))
        {
            DracoData *texData = null;
            if (GetAttributeData(dracoMesh, attr, &texData))
            {
                elementSize =
                    DataTypeSize((DracoMeshLoader.DataType)texData->dataType) *
                    attr->numComponents;
                newUVs = new Vector2[dracoMesh->numVertices];
                var newUVsPtr = UnsafeUtility.AddressOf(ref newUVs[0]);
                UnsafeUtility.MemCpy(newUVsPtr, (void *)texData->data,
                                     dracoMesh->numVertices * elementSize);
                Debug.Log("Decoded mesh texcoords.");
                ReleaseDracoData(&texData);
                ReleaseDracoAttribute(&attr);
            }
        }

        // Copy colors.
        if (GetAttributeByType(dracoMesh, AttributeType.COLOR, 0, &attr))
        {
            DracoData *colorData = null;
            if (GetAttributeData(dracoMesh, attr, &colorData))
            {
                elementSize =
                    DataTypeSize((DracoMeshLoader.DataType)colorData->dataType) *
                    attr->numComponents;
                newColors = new Color[dracoMesh->numVertices];
                var newColorsPtr = UnsafeUtility.AddressOf(ref newColors[0]);
                UnsafeUtility.MemCpy(newColorsPtr, (void *)colorData->data,
                                     dracoMesh->numVertices * elementSize);
                Debug.Log("Decoded mesh colors.");
                ReleaseDracoData(&colorData);
                ReleaseDracoAttribute(&attr);
            }
        }

        // Copy generic data. This script does not do anyhting with the generic
        // data.
        if (GetAttributeByType(dracoMesh, AttributeType.GENERIC, 0, &attr))
        {
            DracoData *genericData = null;
            if (GetAttributeData(dracoMesh, attr, &genericData))
            {
                elementSize =
                    DataTypeSize((DracoMeshLoader.DataType)genericData->dataType) *
                    attr->numComponents;
                newGenerics = new byte[dracoMesh->numVertices * elementSize];
                var newGenericPtr = UnsafeUtility.AddressOf(ref newGenerics[0]);
                UnsafeUtility.MemCpy(newGenericPtr, (void *)genericData->data,
                                     dracoMesh->numVertices * elementSize);
                Debug.Log("Decoded mesh generic data.");
                ReleaseDracoData(&genericData);
                ReleaseDracoAttribute(&attr);
            }
        }

        float copyDecodedDataTimeMilli =
            (Time.realtimeSinceStartup - startTime) * 1000.0f;

        Debug.Log("copyDecodedDataTimeMilli: " +
                  copyDecodedDataTimeMilli.ToString());

        startTime = Time.realtimeSinceStartup;
        Mesh mesh = new Mesh();

#if UNITY_2017_3_OR_NEWER
        mesh.indexFormat = (newVertices.Length > System.UInt16.MaxValue)
        ? UnityEngine.Rendering.IndexFormat.UInt32
        : UnityEngine.Rendering.IndexFormat.UInt16;
#else
        if (newVertices.Length > System.UInt16.MaxValue)
        {
            throw new System.Exception("Draco meshes with more than 65535 vertices are only supported from Unity 2017.3 onwards.");
        }
#endif

        mesh.vertices = newVertices;
        mesh.SetTriangles(newTriangles, 0, true);
        if (newUVs != null)
        {
            mesh.uv = newUVs;
        }
        if (newNormals != null)
        {
            mesh.normals = newNormals;
        }
        else
        {
            mesh.RecalculateNormals();
            Debug.Log("Mesh doesn't have normals, recomputed.");
        }
        if (newColors != null)
        {
            mesh.colors = newColors;
        }

        float convertTimeMilli =
            (Time.realtimeSinceStartup - startTime) * 1000.0f;
        Debug.Log("convertTimeMilli: " + convertTimeMilli.ToString());
        return(mesh);
    }
예제 #21
0
 public unsafe TValue GetValue(ref TContainer container)
 => *(TValue *)((byte *)UnsafeUtility.AddressOf(ref container) + m_Offset);
예제 #22
0
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            float shadowDist = clamp(shadowDistance, 0, cam.cam.farClipPlane);

            if (SunLight.current && SunLight.current.enabled && SunLight.current.gameObject.activeSelf)
            {
                data.buffer.EnableShaderKeyword("ENABLE_SUN");
                data.buffer.SetKeyword("ENABLE_SUNSHADOW", SunLight.current.enableShadow);
            }
            else
            {
                data.buffer.DisableShaderKeyword("ENABLE_SUN");
            }
            var visLights = proper.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            foreach (var i in visLights)
            {
                allLights.Add(i.light);
            }
            shadowCheckJob.Init(cam.cam, shadowDistance);
            shadowCullHandle = shadowCheckJob.ScheduleRef();
            addMLightCommandList.Clear();
            LightFilter.allMLightCommandList = addMLightCommandList;
            pointLightArray               = new NativeArray <PointLightStruct>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            spotLightArray                = new NativeArray <SpotLight>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            cubemapVPMatrices             = new NativeList <CubemapViewProjMatrix>(CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT, Allocator.Temp);
            spotLightMatrices             = new NativeList <SpotLightMatrix>(CBDRSharedData.MAXIMUMSPOTLIGHTCOUNT, Allocator.Temp);
            LightFilter.allLights         = allLights;
            LightFilter.pointLightArray   = pointLightArray;
            LightFilter.spotLightArray    = spotLightArray;
            LightFilter.cubemapVPMatrices = cubemapVPMatrices;
            LightFilter.spotLightMatrices = spotLightMatrices;
            Transform camTrans = cam.cam.transform;

            needCheckedShadows.Clear();
            needCheckedShadows.AddCapacityTo(allLights.Count);
            lightingHandle = (new LightFilter
            {
                camPos = cam.cam.transform.position,
                shadowDist = shadowDist,
                lightDist = cbdrDistance,
                needCheckLight = needCheckedShadows
            }).Schedule(allLights.Count, 1, shadowCullHandle);
            if (SunLight.current != null && SunLight.current.enabled && SunLight.current.enableShadow)
            {
                clipDistances = (float *)UnsafeUtility.Malloc(SunLight.CASCADECLIPSIZE * sizeof(float), 16, Allocator.Temp);
                staticFit     = DirectionalShadowStaticFit(cam.cam, SunLight.current, clipDistances);
                sunShadowCams = MUnsafeUtility.Malloc <OrthoCam>(SunLight.CASCADELEVELCOUNT * sizeof(OrthoCam), Allocator.Temp);
                Matrix4x4 proj = cam.cam.projectionMatrix;
                //      cam.cam.projectionMatrix = cam.cam.nonJitteredProjectionMatrix;
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                //   cam.cam.projectionMatrix = proj;
                csmStruct = new CascadeShadowmap
                {
                    cascadeShadowmapVPs = (float4x4 *)cascadeShadowMapVP.Ptr(),
                    results             = sunShadowCams,
                    orthoCam            = (OrthoCam *)UnsafeUtility.AddressOf(ref SunLight.current.shadCam),
                    farClipPlane        = SunLight.current.farestZ,
                    frustumCorners      = staticFit.frustumCorners.Ptr(),
                    resolution          = staticFit.resolution,
                    isD3D = GraphicsUtility.platformIsD3D
                };
                csmHandle = csmStruct.ScheduleRefBurst(SunLight.CASCADELEVELCOUNT, 1);
            }
            decalEvt.PreRenderFrame(cam, ref data);
        }
        unsafe public static JobHandle ScheduleParallel <T>(this T jobData, int arrayLength, int innerloopBatchCount, JobHandle dependency) where T : struct, IJobFor
        {
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), JobProducer <T> .Initialize(), dependency, ScheduleMode.Parallel);

            return(JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, innerloopBatchCount));
        }
예제 #24
0
        protected override unsafe void WriteUnprocessedValueInto(IntPtr statePtr, TouchState value)
        {
            var valuePtr = (TouchState *)new IntPtr(statePtr.ToInt64() + (int)m_StateBlock.byteOffset);

            UnsafeUtility.MemCpy(valuePtr, UnsafeUtility.AddressOf(ref value), UnsafeUtility.SizeOf <TouchState>());
        }
 public static unsafe long DeviceCommand <TCommand>(this IInputRuntime runtime, int deviceId, ref TCommand command)
     where TCommand : struct, IInputDeviceCommandInfo
 {
     return(runtime.DeviceCommand(deviceId, (InputDeviceCommand *)UnsafeUtility.AddressOf(ref command)));
 }
 // C# doesn't allow taking the address of a value type because of pinning requirements for the heap.
 // And our bindings generator doesn't support overloading. So ugly code following here...
 public static unsafe void QueueInputEvent <TInputEvent>(ref TInputEvent inputEvent)
     where TInputEvent : struct
 {
     QueueInputEvent((IntPtr)UnsafeUtility.AddressOf <TInputEvent>(ref inputEvent));
 }
예제 #27
0
        unsafe public static void Run <T>(this T jobData, int arrayLength) where T : struct, IJobParallelFor
        {
            var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), ParallelForJobStruct <T> .jobReflectionData, new JobHandle(), ScheduleMode.Run);

            JobsUtility.ScheduleParallelFor(ref scheduleParams, arrayLength, arrayLength);
        }
예제 #28
0
 public static JobHandle DisposeHotFix <T>(ref NativeList <T> list, JobHandle dep)
     where T : struct
 {
     var     ptr     = UnsafeUtility.AddressOf(ref list);
     ref var listRef = ref UnsafeUtility.AsRef <NativeListTemp>(ptr);
예제 #29
0
            public unsafe void WriteBack(Entity entity, ref T lambdaComponent, ref T originalComponent)
            {
                var access = _manager.GetCheckedEntityDataAccess();
                var ecs    = access->EntityComponentStore;

                // MemCmp check is necessary to ensure we only write-back the value if we changed it in the lambda (or a called function)
                if (UnsafeUtility.MemCmp(UnsafeUtility.AddressOf(ref lambdaComponent), UnsafeUtility.AddressOf(ref originalComponent), UnsafeUtility.SizeOf <T>()) != 0 &&
                    ecs->HasComponent(entity, _typeIndex))
                {
                    UnsafeUtility.CopyStructureToPtr(ref lambdaComponent, ecs->GetComponentDataWithTypeRW(entity, _typeIndex, ecs->GlobalSystemVersion));
                }
            }
예제 #30
0
 public static unsafe void W <T, TT>(ref TT t, int i, T value) where TT : struct
 {
     UnsafeUtility.WriteArrayElement(UnsafeUtility.AddressOf(ref t), i, value);
 }