-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathSampler.bindings.cs
124 lines (105 loc) · 3.87 KB
/
Sampler.bindings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
using Unity.Profiling.LowLevel;
using Unity.Profiling.LowLevel.Unsafe;
using Unity.Profiling;
namespace UnityEngine.Profiling
{
[UsedByNativeCode]
[NativeHeader("Runtime/Profiler/ScriptBindings/Sampler.bindings.h")]
public class Sampler
{
internal IntPtr m_Ptr;
internal static Sampler s_InvalidSampler = new Sampler();
// This class can't be explicitly created
internal Sampler() {}
internal Sampler(IntPtr ptr) { m_Ptr = ptr; }
public bool isValid
{
get { return m_Ptr != IntPtr.Zero; }
}
public Recorder GetRecorder()
{
var handle = new ProfilerRecorderHandle((ulong)m_Ptr.ToInt64());
return new Recorder(handle);
}
public static Sampler Get(string name)
{
IntPtr nativeSampler = ProfilerUnsafeUtility.GetMarker(name);
if (nativeSampler == IntPtr.Zero)
return s_InvalidSampler;
return new Sampler(nativeSampler);
}
public static int GetNames(List<string> names)
{
var availableMarkers = new List<ProfilerRecorderHandle>();
ProfilerRecorderHandle.GetAvailable(availableMarkers);
if (names != null)
{
if (names.Count < availableMarkers.Count)
{
names.Capacity = availableMarkers.Count;
for (int i = names.Count; i < availableMarkers.Count; i++)
names.Add(null);
}
int index = 0;
foreach (var h in availableMarkers)
{
var statDesc = ProfilerRecorderHandle.GetDescription(h);
names[index] = statDesc.Name;
index++;
}
}
return availableMarkers.Count;
}
public string name
{
get { return ProfilerUnsafeUtility.Internal_GetName(m_Ptr); }
}
}
[UsedByNativeCode]
[NativeHeader("Runtime/Profiler/ScriptBindings/Sampler.bindings.h")]
[NativeHeader("Runtime/Profiler/Marker.h")]
public sealed class CustomSampler : Sampler
{
internal static CustomSampler s_InvalidCustomSampler = new CustomSampler();
// This class can't be explicitly created
internal CustomSampler() {}
private CustomSampler(IntPtr ptr) : base(ptr) { }
public static CustomSampler Create(string name, bool collectGpuData = false)
{
IntPtr nativeSampler = ProfilerUnsafeUtility.CreateMarker(name, ProfilerUnsafeUtility.CategoryScripts, MarkerFlags.AvailabilityNonDevelopment | (collectGpuData ? MarkerFlags.SampleGPU : 0), 0);
if (nativeSampler == IntPtr.Zero)
return s_InvalidCustomSampler;
return new CustomSampler(nativeSampler);
}
[Conditional("ENABLE_PROFILER")]
[IgnoredByDeepProfiler]
public void Begin()
{
ProfilerUnsafeUtility.BeginSample(m_Ptr);
}
[Conditional("ENABLE_PROFILER")]
[IgnoredByDeepProfiler]
public void Begin(Object targetObject)
{
ProfilerUnsafeUtility.Internal_BeginWithObject(m_Ptr, targetObject);
}
[Conditional("ENABLE_PROFILER")]
[IgnoredByDeepProfiler]
public void End()
{
ProfilerUnsafeUtility.EndSample(m_Ptr);
}
internal static class BindingsMarshaller
{
public static IntPtr ConvertToNative(CustomSampler customSampler) => customSampler.m_Ptr;
}
}
}