-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemorySizes.cs
More file actions
325 lines (320 loc) · 14.5 KB
/
MemorySizes.cs
File metadata and controls
325 lines (320 loc) · 14.5 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using System;
using System.Runtime.InteropServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UsefulUtilities
{
public static class MemorySizes
{
public static int GetStructSizeInBytes<T>() where T : struct
{
int stride = -1;
try
{
stride = Marshal.SizeOf<T>();
}
catch (Exception e)
{
Debug.LogError("Unable to get stride value of struct: " + typeof(T).Name + ", " + e.Message);
}
return stride;
}
public static int GetStructSizeInBytes(Type type)
{
int stride = -1;
if (!type.IsStruct())
{
Debug.LogError("Unable to get stride value of Type: " + type.Name + ", type is not a struct");
}
try
{
stride = Marshal.SizeOf(type);
}
catch (Exception e)
{
Debug.LogError("Unable to get stride value of Type: " + type.Name + ", " + e.Message);
}
return stride;
}
/// <param name="renderTextureDepthBits">The precision of the render textures depth buffer in bits (only used if the RenderTextureFormat is set to Depth)</param>
public static int GetBitsPerPixel(RenderTextureFormat renderTextureFormat, int renderTextureDepthBits = 16)
{
#pragma warning disable CS0618 // Type or member is obsolete
switch (renderTextureFormat)
{
case RenderTextureFormat.Shadowmap:
case RenderTextureFormat.Depth:
return renderTextureDepthBits;
case RenderTextureFormat.R8:
return 8;
case RenderTextureFormat.ARGB1555:
case RenderTextureFormat.ARGB4444:
case RenderTextureFormat.R16:
case RenderTextureFormat.RG16:
case RenderTextureFormat.RGB565:
case RenderTextureFormat.RHalf:
return 16;
case RenderTextureFormat.BGR101010_XR:
return 30;
case RenderTextureFormat.ARGB2101010:
case RenderTextureFormat.ARGB32:
case RenderTextureFormat.BGRA32:
case RenderTextureFormat.RFloat:
case RenderTextureFormat.RG32:
case RenderTextureFormat.RGB111110Float:
case RenderTextureFormat.RGHalf:
case RenderTextureFormat.RInt:
return 32;
case RenderTextureFormat.BGRA10101010_XR:
return 40;
case RenderTextureFormat.ARGB64:
case RenderTextureFormat.ARGBHalf:
case RenderTextureFormat.RGBAUShort:
case RenderTextureFormat.RGFloat:
case RenderTextureFormat.RGInt:
return 64;
case RenderTextureFormat.ARGBFloat:
case RenderTextureFormat.ARGBInt:
return 128;
}
#pragma warning restore CS0618 // Type or member is obsolete
return 0;
}
public static int GetBitsPerPixel(TextureFormat format)
{
#pragma warning disable CS0618 // Type or member is obsolete
switch (format)
{
case TextureFormat.EAC_R:
case TextureFormat.EAC_R_SIGNED:
case TextureFormat.BC4:
case TextureFormat.DXT1:
case TextureFormat.DXT1Crunched:
case TextureFormat.ETC2_RGB:
case TextureFormat.ETC_RGB4:
case TextureFormat.ETC_RGB4Crunched:
case TextureFormat.ETC2_RGBA1:
return 4;
case TextureFormat.Alpha8:
case TextureFormat.R8:
case TextureFormat.R8_SIGNED:
case TextureFormat.BC5:
case TextureFormat.BC6H:
case TextureFormat.BC7:
case TextureFormat.DXT5:
case TextureFormat.DXT5Crunched:
case TextureFormat.ETC2_RGBA8:
case TextureFormat.ETC2_RGBA8Crunched:
case TextureFormat.EAC_RG:
case TextureFormat.EAC_RG_SIGNED:
return 8;
case TextureFormat.ARGB4444:
case TextureFormat.R16:
case TextureFormat.R16_SIGNED:
case TextureFormat.RG16:
case TextureFormat.RG16_SIGNED:
case TextureFormat.RGB565:
case TextureFormat.RGBA4444:
case TextureFormat.YUY2:
return 16;
case TextureFormat.RGB24:
case TextureFormat.RGB24_SIGNED:
return 24;
case TextureFormat.RGB9e5Float:
return 27;
case TextureFormat.ARGB32:
case TextureFormat.BGRA32:
case TextureFormat.RFloat:
case TextureFormat.RG32:
case TextureFormat.RG32_SIGNED:
case TextureFormat.RGBA32:
case TextureFormat.RGBA32_SIGNED:
case TextureFormat.RGHalf:
return 32;
case TextureFormat.RGB48:
case TextureFormat.RGB48_SIGNED:
return 48;
case TextureFormat.RGBA64:
case TextureFormat.RGBA64_SIGNED:
case TextureFormat.RGBAHalf:
case TextureFormat.RGFloat:
return 64;
case TextureFormat.ASTC_10x10:
case TextureFormat.ASTC_12x12:
case TextureFormat.ASTC_4x4:
case TextureFormat.ASTC_5x5:
case TextureFormat.ASTC_6x6:
case TextureFormat.ASTC_8x8:
case TextureFormat.ASTC_HDR_10x10:
case TextureFormat.ASTC_HDR_12x12:
case TextureFormat.ASTC_HDR_4x4:
case TextureFormat.ASTC_HDR_5x5:
case TextureFormat.ASTC_HDR_6x6:
case TextureFormat.ASTC_HDR_8x8:
case TextureFormat.RGBAFloat:
return 128;
}
#pragma warning restore CS0618 // Type or member is obsolete
return 0;
}
public static int GetBitsPerPixel(GraphicsFormat format)
{
#pragma warning disable CS0618 // Type or member is obsolete
switch (format)
{
case GraphicsFormat.R8_SInt:
case GraphicsFormat.R8_SNorm:
case GraphicsFormat.R8_SRGB:
case GraphicsFormat.R8_UInt:
case GraphicsFormat.R8_UNorm:
case GraphicsFormat.S8_UInt:
case GraphicsFormat.YUV2:
return 8;
case GraphicsFormat.D16_UNorm:
case GraphicsFormat.R16_SFloat:
case GraphicsFormat.R16_SInt:
case GraphicsFormat.R16_SNorm:
case GraphicsFormat.R16_UInt:
case GraphicsFormat.R16_UNorm:
case GraphicsFormat.R8G8_SInt:
case GraphicsFormat.R8G8_SNorm:
case GraphicsFormat.R8G8_SRGB:
case GraphicsFormat.R8G8_UInt:
case GraphicsFormat.R8G8_UNorm:
case GraphicsFormat.A1R5G5B5_UNormPack16:
case GraphicsFormat.B4G4R4A4_UNormPack16:
case GraphicsFormat.B5G5R5A1_UNormPack16:
case GraphicsFormat.B5G6R5_UNormPack16:
case GraphicsFormat.R4G4B4A4_UNormPack16:
case GraphicsFormat.R5G5B5A1_UNormPack16:
case GraphicsFormat.R5G6B5_UNormPack16:
return 16;
case GraphicsFormat.B8G8R8_SInt:
case GraphicsFormat.B8G8R8_SNorm:
case GraphicsFormat.B8G8R8_SRGB:
case GraphicsFormat.B8G8R8_UInt:
case GraphicsFormat.B8G8R8_UNorm:
case GraphicsFormat.R8G8B8_SInt:
case GraphicsFormat.R8G8B8_SNorm:
case GraphicsFormat.R8G8B8_SRGB:
case GraphicsFormat.R8G8B8_UInt:
case GraphicsFormat.R8G8B8_UNorm:
return 24;
case GraphicsFormat.A2B10G10R10_SIntPack32:
case GraphicsFormat.A2B10G10R10_UIntPack32:
case GraphicsFormat.A2B10G10R10_UNormPack32:
case GraphicsFormat.A2R10G10B10_SIntPack32:
case GraphicsFormat.A2R10G10B10_UIntPack32:
case GraphicsFormat.A2R10G10B10_UNormPack32:
case GraphicsFormat.A2R10G10B10_XRSRGBPack32:
case GraphicsFormat.A2R10G10B10_XRUNormPack32:
case GraphicsFormat.B10G11R11_UFloatPack32:
case GraphicsFormat.B8G8R8A8_SInt:
case GraphicsFormat.B8G8R8A8_SNorm:
case GraphicsFormat.B8G8R8A8_SRGB:
case GraphicsFormat.B8G8R8A8_UInt:
case GraphicsFormat.B8G8R8A8_UNorm:
case GraphicsFormat.D24_UNorm:
case GraphicsFormat.D24_UNorm_S8_UInt:
case GraphicsFormat.D32_SFloat:
case GraphicsFormat.E5B9G9R9_UFloatPack32:
case GraphicsFormat.R10G10B10_XRSRGBPack32:
case GraphicsFormat.R10G10B10_XRUNormPack32:
case GraphicsFormat.R16G16_SFloat:
case GraphicsFormat.R16G16_SInt:
case GraphicsFormat.R16G16_SNorm:
case GraphicsFormat.R16G16_UInt:
case GraphicsFormat.R16G16_UNorm:
case GraphicsFormat.R32_SFloat:
case GraphicsFormat.R32_SInt:
case GraphicsFormat.R32_UInt:
case GraphicsFormat.R8G8B8A8_SInt:
case GraphicsFormat.R8G8B8A8_SNorm:
case GraphicsFormat.R8G8B8A8_SRGB:
case GraphicsFormat.R8G8B8A8_UInt:
case GraphicsFormat.R8G8B8A8_UNorm:
return 32;
case GraphicsFormat.R16G16B16_SFloat:
case GraphicsFormat.R16G16B16_SInt:
case GraphicsFormat.R16G16B16_SNorm:
case GraphicsFormat.R16G16B16_UInt:
case GraphicsFormat.R16G16B16_UNorm:
return 48;
case GraphicsFormat.A10R10G10B10_XRSRGBPack32:
case GraphicsFormat.A10R10G10B10_XRUNormPack32:
case GraphicsFormat.D32_SFloat_S8_UInt:
case GraphicsFormat.R16G16B16A16_SFloat:
case GraphicsFormat.R16G16B16A16_SInt:
case GraphicsFormat.R16G16B16A16_SNorm:
case GraphicsFormat.R16G16B16A16_UInt:
case GraphicsFormat.R16G16B16A16_UNorm:
case GraphicsFormat.R32G32_SFloat:
case GraphicsFormat.R32G32_SInt:
case GraphicsFormat.R32G32_UInt:
case GraphicsFormat.RGBA_DXT1_SRGB:
case GraphicsFormat.RGBA_DXT1_UNorm:
case GraphicsFormat.RGBA_PVRTC_2Bpp_SRGB:
case GraphicsFormat.RGBA_PVRTC_2Bpp_UNorm:
case GraphicsFormat.RGBA_PVRTC_4Bpp_SRGB:
case GraphicsFormat.RGBA_PVRTC_4Bpp_UNorm:
case GraphicsFormat.RGB_A1_ETC2_SRGB:
case GraphicsFormat.RGB_A1_ETC2_UNorm:
case GraphicsFormat.RGB_ETC2_SRGB:
case GraphicsFormat.RGB_ETC2_UNorm:
case GraphicsFormat.RGB_ETC_UNorm:
case GraphicsFormat.RGB_PVRTC_2Bpp_SRGB:
case GraphicsFormat.RGB_PVRTC_2Bpp_UNorm:
case GraphicsFormat.RGB_PVRTC_4Bpp_SRGB:
case GraphicsFormat.RGB_PVRTC_4Bpp_UNorm:
case GraphicsFormat.R_BC4_SNorm:
case GraphicsFormat.R_BC4_UNorm:
case GraphicsFormat.R_EAC_SNorm:
case GraphicsFormat.R_EAC_UNorm:
return 64;
case GraphicsFormat.R32G32B32_SFloat:
case GraphicsFormat.R32G32B32_SInt:
case GraphicsFormat.R32G32B32_UInt:
return 96;
case GraphicsFormat.R32G32B32A32_SFloat:
case GraphicsFormat.R32G32B32A32_SInt:
case GraphicsFormat.R32G32B32A32_UInt:
case GraphicsFormat.RGBA_ASTC10X10_SRGB:
case GraphicsFormat.RGBA_ASTC10X10_UFloat:
case GraphicsFormat.RGBA_ASTC10X10_UNorm:
case GraphicsFormat.RGBA_ASTC12X12_SRGB:
case GraphicsFormat.RGBA_ASTC12X12_UFloat:
case GraphicsFormat.RGBA_ASTC12X12_UNorm:
case GraphicsFormat.RGBA_ASTC4X4_SRGB:
case GraphicsFormat.RGBA_ASTC4X4_UFloat:
case GraphicsFormat.RGBA_ASTC4X4_UNorm:
case GraphicsFormat.RGBA_ASTC5X5_SRGB:
case GraphicsFormat.RGBA_ASTC5X5_UFloat:
case GraphicsFormat.RGBA_ASTC5X5_UNorm:
case GraphicsFormat.RGBA_ASTC6X6_SRGB:
case GraphicsFormat.RGBA_ASTC6X6_UFloat:
case GraphicsFormat.RGBA_ASTC6X6_UNorm:
case GraphicsFormat.RGBA_ASTC8X8_SRGB:
case GraphicsFormat.RGBA_ASTC8X8_UFloat:
case GraphicsFormat.RGBA_ASTC8X8_UNorm:
case GraphicsFormat.RGBA_BC7_SRGB:
case GraphicsFormat.RGBA_BC7_UNorm:
case GraphicsFormat.RGBA_DXT3_SRGB:
case GraphicsFormat.RGBA_DXT3_UNorm:
case GraphicsFormat.RGBA_DXT5_SRGB:
case GraphicsFormat.RGBA_DXT5_UNorm:
case GraphicsFormat.RGBA_ETC2_SRGB:
case GraphicsFormat.RGBA_ETC2_UNorm:
case GraphicsFormat.RGB_BC6H_SFloat:
case GraphicsFormat.RGB_BC6H_UFloat:
case GraphicsFormat.RG_BC5_SNorm:
case GraphicsFormat.RG_BC5_UNorm:
case GraphicsFormat.RG_EAC_SNorm:
case GraphicsFormat.RG_EAC_UNorm:
return 128;
}
#pragma warning restore CS0618 // Type or member is obsolete
return 0;
}
}
}