forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconversions.mm
More file actions
604 lines (521 loc) · 20.5 KB
/
conversions.mm
File metadata and controls
604 lines (521 loc) · 20.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
//
// Copyright 2020 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "pxr/imaging/hgiMetal/conversions.h"
#include "pxr/base/tf/iterator.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/base/tf/stringUtils.h"
PXR_NAMESPACE_OPEN_SCOPE
//
// HgiFormat
//
static const MTLPixelFormat _PIXEL_FORMAT_DESC[] =
{
MTLPixelFormatR8Unorm, // HgiFormatUNorm8,
MTLPixelFormatRG8Unorm, // HgiFormatUNorm8Vec2,
//MTLPixelFormatInvalid, // Unsupported by HgiFormat
MTLPixelFormatRGBA8Unorm, // HgiFormatUNorm8Vec4,
MTLPixelFormatR8Snorm, // HgiFormatSNorm8,
MTLPixelFormatRG8Snorm, // HgiFormatSNorm8Vec2,
//MTLPixelFormatInvalid, // Unsupported by HgiFormat
MTLPixelFormatRGBA8Snorm, // HgiFormatSNorm8Vec4,
MTLPixelFormatR16Float, // HgiFormatFloat16,
MTLPixelFormatRG16Float, // HgiFormatFloat16Vec2,
MTLPixelFormatInvalid, // Unsupported by Metal
MTLPixelFormatRGBA16Float, // HgiFormatFloat16Vec4,
MTLPixelFormatR32Float, // HgiFormatFloat32,
MTLPixelFormatRG32Float, // HgiFormatFloat32Vec2,
MTLPixelFormatInvalid, // Unsupported by Metal
MTLPixelFormatRGBA32Float, // HgiFormatFloat32Vec4,
MTLPixelFormatR16Sint, // HgiFormatInt16,
MTLPixelFormatRG16Sint, // HgiFormatInt16Vec2,
MTLPixelFormatInvalid, // Unsupported by Metal
MTLPixelFormatRGBA16Sint, // HgiFormatInt16Vec4,
MTLPixelFormatR16Uint, // HgiFormatUInt16,
MTLPixelFormatRG16Uint, // HgiFormatUInt16Vec2,
MTLPixelFormatInvalid, // Unsupported by Metal
MTLPixelFormatRGBA16Uint, // HgiFormatUInt16Vec4,
MTLPixelFormatR32Sint, // HgiFormatInt32,
MTLPixelFormatRG32Sint, // HgiFormatInt32Vec2,
MTLPixelFormatInvalid, // Unsupported by Metal
MTLPixelFormatRGBA32Sint, // HgiFormatInt32Vec4,
//MTLPixelFormatRGB8Unorm_sRGB, // Unsupported by HgiFormat
MTLPixelFormatRGBA8Unorm_sRGB, // HgiFormatUNorm8Vec4srgb,
#if defined(ARCH_OS_IPHONE)
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
#else
MTLPixelFormatBC6H_RGBFloat, // HgiFormatBC6FloatVec3
MTLPixelFormatBC6H_RGBUfloat, // HgiFormatBC6UFloatVec3
MTLPixelFormatBC7_RGBAUnorm, // HgiFormatBC7UNorm8Vec4
MTLPixelFormatBC7_RGBAUnorm_sRGB, // HgiFormatBC7UNorm8Vec4srgb
MTLPixelFormatBC1_RGBA, // HgiFormatBC1UNorm8Vec4
MTLPixelFormatBC3_RGBA, // HgiFormatBC3UNorm8Vec4
#endif
MTLPixelFormatDepth32Float_Stencil8, // HgiFormatFloat32UInt8
MTLPixelFormatInvalid, // Unsupported by Metal
// Note: Update _VERTEX_FORMAT_DESC as well.
};
// A few random format validations to make sure out GL table stays aligned
// with the HgiFormat table.
constexpr bool _CompileTimeValidateHgiFormatTable() {
return (TfArraySize(_PIXEL_FORMAT_DESC) == HgiFormatCount &&
HgiFormatUNorm8 == 0 &&
HgiFormatFloat16Vec4 == 9 &&
HgiFormatFloat32Vec4 == 13 &&
HgiFormatUInt16Vec4 == 21 &&
HgiFormatUNorm8Vec4srgb == 26 &&
HgiFormatBC3UNorm8Vec4 == 32) ? true : false;
}
static_assert(_CompileTimeValidateHgiFormatTable(),
"_PIXEL_FORMAT_DESC array out of sync with HgiFormat enum");
//
// MTLVertexFormat
//
static const MTLVertexFormat _VERTEX_FORMAT_DESC[] =
{
MTLVertexFormatUCharNormalized, // HgiFormatUNorm8,
MTLVertexFormatUChar2Normalized, // HgiFormatUNorm8Vec2,
//MTLVertexFormatUChar3Normalized, // Unsupported by HgiFormat,
MTLVertexFormatUChar4Normalized, // HgiFormatUNorm8Vec4,
MTLVertexFormatCharNormalized, // HgiFormatSNorm8,
MTLVertexFormatChar2Normalized, // HgiFormatSNorm8Vec2,
//MTLVertexFormatChar3Normalized, // Unsupported by HgiFormat,
MTLVertexFormatChar4Normalized, // HgiFormatSNorm8Vec4,
MTLVertexFormatHalf, // HgiFormatFloat16,
MTLVertexFormatHalf2, // HgiFormatFloat16Vec2,
MTLVertexFormatHalf3, // HgiFormatFloat16Vec3,
MTLVertexFormatHalf4, // HgiFormatFloat16Vec4,
MTLVertexFormatFloat, // HgiFormatFloat32,
MTLVertexFormatFloat2, // HgiFormatFloat32Vec2,
MTLVertexFormatFloat3, // HgiFormatFloat32Vec3,
MTLVertexFormatFloat4, // HgiFormatFloat32Vec4,
MTLVertexFormatShort, // HgiFormatInt16,
MTLVertexFormatShort2, // HgiFormatInt16Vec2,
MTLVertexFormatShort3, // HgiFormatInt16Vec3,
MTLVertexFormatShort4, // HgiFormatInt16Vec4,
MTLVertexFormatUShort, // HgiFormatUInt16,
MTLVertexFormatUShort2, // HgiFormatUInt16Vec2,
MTLVertexFormatUShort3, // HgiFormatUInt16Vec3,
MTLVertexFormatUShort4, // HgiFormatUInt16Vec4,
MTLVertexFormatInt, // HgiFormatInt32,
MTLVertexFormatInt2, // HgiFormatInt32Vec2,
MTLVertexFormatInt3, // HgiFormatInt32Vec3,
MTLVertexFormatInt4, // HgiFormatInt32Vec4,
//MTLVertexFormatUChar4Normalized, // Unsupported by HgiFormat
MTLVertexFormatUChar4Normalized, // HgiFormatUNorm8Vec4sRGB,
MTLVertexFormatInvalid, // HgiFormatBC6FloatVec3
MTLVertexFormatInvalid, // HgiFormatBC6UFloatVec3
MTLVertexFormatInvalid, // HgiFormatBC7UNorm8Vec4
MTLVertexFormatInvalid, // HgiFormatBC7UNorm8Vec4srgb
MTLVertexFormatInvalid, // HgiFormatBC1UNorm8Vec4
MTLVertexFormatInvalid, // HgiFormatBC3UNorm8Vec4
MTLVertexFormatInvalid, // HgiFormatFloat32UInt8
MTLVertexFormatInt1010102Normalized,// HgiFormatPackedInt1010102
};
constexpr bool _CompileTimeValidateHgiVertexFormatTable() {
return (TfArraySize(_VERTEX_FORMAT_DESC) == HgiFormatCount &&
HgiFormatUNorm8 == 0 &&
HgiFormatFloat16Vec4 == 9 &&
HgiFormatFloat32Vec4 == 13 &&
HgiFormatUInt16Vec4 == 21 &&
HgiFormatUNorm8Vec4srgb == 26 &&
HgiFormatBC3UNorm8Vec4 == 32) ? true : false;
}
static_assert(_CompileTimeValidateHgiVertexFormatTable(),
"_VertexFormatDesc array out of sync with HgiFormat enum");
//
// HgiCullMode
//
struct {
HgiCullMode hgiCullMode;
MTLCullMode metalCullMode;
} static const _CullModeTable[] =
{
{HgiCullModeNone, MTLCullModeNone},
{HgiCullModeFront, MTLCullModeFront},
{HgiCullModeBack, MTLCullModeBack},
{HgiCullModeFrontAndBack, MTLCullModeNone} // Unsupported
};
static_assert(TfArraySize(_CullModeTable) == HgiCullModeCount,
"_CullModeTable array out of sync with HgiFormat enum");
//
// HgiPolygonMode
//
struct {
HgiPolygonMode hgiFillMode;
MTLTriangleFillMode metalFillMode;
} static const _PolygonModeTable[] =
{
{HgiPolygonModeFill, MTLTriangleFillModeFill},
{HgiPolygonModeLine, MTLTriangleFillModeLines},
{HgiPolygonModePoint, MTLTriangleFillModeFill}, // Unsupported
};
static_assert(TfArraySize(_PolygonModeTable) == HgiPolygonModeCount,
"_PolygonModeTable array out of sync with HgiFormat enum");
//
// HgiBlendOp
//
struct {
HgiBlendOp hgiBlendOp;
MTLBlendOperation metalBlendOp;
} static const _blendEquationTable[] =
{
{HgiBlendOpAdd, MTLBlendOperationAdd},
{HgiBlendOpSubtract, MTLBlendOperationSubtract},
{HgiBlendOpReverseSubtract, MTLBlendOperationReverseSubtract},
{HgiBlendOpMin, MTLBlendOperationMin},
{HgiBlendOpMax, MTLBlendOperationMax},
};
static_assert(TfArraySize(_blendEquationTable) == HgiBlendOpCount,
"_blendEquationTable array out of sync with HgiFormat enum");
//
// HgiBlendFactor
//
struct {
HgiBlendFactor hgiBlendFactor;
MTLBlendFactor metalBlendFactor;
} static const _blendFactorTable[] =
{
{HgiBlendFactorZero, MTLBlendFactorZero},
{HgiBlendFactorOne, MTLBlendFactorOne},
{HgiBlendFactorSrcColor, MTLBlendFactorSourceColor},
{HgiBlendFactorOneMinusSrcColor, MTLBlendFactorOneMinusSourceColor},
{HgiBlendFactorDstColor, MTLBlendFactorDestinationColor},
{HgiBlendFactorOneMinusDstColor, MTLBlendFactorOneMinusDestinationColor},
{HgiBlendFactorSrcAlpha, MTLBlendFactorSourceAlpha},
{HgiBlendFactorOneMinusSrcAlpha, MTLBlendFactorOneMinusSourceAlpha},
{HgiBlendFactorDstAlpha, MTLBlendFactorDestinationAlpha},
{HgiBlendFactorOneMinusDstAlpha, MTLBlendFactorOneMinusDestinationAlpha},
{HgiBlendFactorConstantColor, MTLBlendFactorZero}, // Unsupported
{HgiBlendFactorOneMinusConstantColor, MTLBlendFactorZero}, // Unsupported
{HgiBlendFactorConstantAlpha, MTLBlendFactorZero}, // Unsupported
{HgiBlendFactorOneMinusConstantAlpha, MTLBlendFactorZero}, // Unsupported
{HgiBlendFactorSrcAlphaSaturate, MTLBlendFactorSourceAlphaSaturated},
{HgiBlendFactorSrc1Color, MTLBlendFactorSource1Color},
{HgiBlendFactorOneMinusSrc1Color, MTLBlendFactorOneMinusSource1Color},
{HgiBlendFactorSrc1Alpha, MTLBlendFactorSourceAlpha},
{HgiBlendFactorOneMinusSrc1Alpha, MTLBlendFactorOneMinusSource1Alpha},
};
static_assert(TfArraySize(_blendFactorTable) == HgiBlendFactorCount,
"_blendFactorTable array out of sync with HgiFormat enum");
//
// HgiWinding
//
struct {
HgiWinding hgiWinding;
MTLWinding metalWinding;
} static const _windingTable[] =
{
// Winding order is inverted because our viewport is inverted.
// This combination allows us to emulate the OpenGL coordinate space on
// Metal
{HgiWindingClockwise, MTLWindingCounterClockwise},
{HgiWindingCounterClockwise, MTLWindingClockwise},
};
static_assert(TfArraySize(_windingTable) == HgiWindingCount,
"_windingTable array out of sync with HgiFormat enum");
//
// HgiAttachmentLoadOp
//
struct {
HgiAttachmentLoadOp hgiAttachmentLoadOp;
MTLLoadAction metalLoadOp;
} static const _attachmentLoadOpTable[] =
{
{HgiAttachmentLoadOpDontCare, MTLLoadActionDontCare},
{HgiAttachmentLoadOpClear, MTLLoadActionClear},
{HgiAttachmentLoadOpLoad, MTLLoadActionLoad},
};
static_assert(TfArraySize(_attachmentLoadOpTable) == HgiAttachmentLoadOpCount,
"_attachmentLoadOpTable array out of sync with HgiFormat enum");
//
// HgiAttachmentStoreOp
//
struct {
HgiAttachmentStoreOp hgiAttachmentStoreOp;
MTLStoreAction metalStoreOp;
} static const _attachmentStoreOpTable[] =
{
{HgiAttachmentStoreOpDontCare, MTLStoreActionDontCare},
{HgiAttachmentStoreOpStore, MTLStoreActionStore},
};
static_assert(TfArraySize(_attachmentStoreOpTable) == HgiAttachmentStoreOpCount,
"_attachmentStoreOpTable array out of sync with HgiFormat enum");
//
// HgiCompareFunction
//
struct {
HgiCompareFunction hgiCompareFunction;
MTLCompareFunction metalCF;
} static const _compareFnTable[] =
{
{HgiCompareFunctionNever, MTLCompareFunctionNever},
{HgiCompareFunctionLess, MTLCompareFunctionLess},
{HgiCompareFunctionEqual, MTLCompareFunctionEqual},
{HgiCompareFunctionLEqual, MTLCompareFunctionLessEqual},
{HgiCompareFunctionGreater, MTLCompareFunctionGreater},
{HgiCompareFunctionNotEqual, MTLCompareFunctionNotEqual},
{HgiCompareFunctionGEqual, MTLCompareFunctionGreaterEqual},
{HgiCompareFunctionAlways, MTLCompareFunctionAlways},
};
static_assert(TfArraySize(_compareFnTable) == HgiCompareFunctionCount,
"_compareFnTable array out of sync with HgiFormat enum");
//
// HgiStencilOp
//
struct {
HgiStencilOp hgiStencilOp;
MTLStencilOperation metalStencilOp;
} static const _stencilOpTable[] =
{
{HgiStencilOpKeep, MTLStencilOperationKeep},
{HgiStencilOpZero, MTLStencilOperationZero},
{HgiStencilOpReplace, MTLStencilOperationReplace},
{HgiStencilOpIncrementClamp, MTLStencilOperationIncrementClamp},
{HgiStencilOpDecrementClamp, MTLStencilOperationDecrementClamp},
{HgiStencilOpInvert, MTLStencilOperationInvert},
{HgiStencilOpIncrementWrap, MTLStencilOperationIncrementWrap},
{HgiStencilOpDecrementWrap, MTLStencilOperationDecrementWrap},
};
static_assert(TfArraySize(_stencilOpTable) == HgiStencilOpCount,
"_stencilOpTable array out of sync with HgiStencilOp enum");
struct {
HgiTextureType hgiTextureType;
MTLTextureType metalTT;
} static const _textureTypeTable[HgiTextureTypeCount] =
{
{HgiTextureType1D, MTLTextureType1D},
{HgiTextureType2D, MTLTextureType2D},
{HgiTextureType3D, MTLTextureType3D},
{HgiTextureType1DArray, MTLTextureType1DArray},
{HgiTextureType2DArray, MTLTextureType2DArray},
};
static_assert(TfArraySize(_compareFnTable) == HgiCompareFunctionCount,
"_compareFnTable array out of sync with HgiFormat enum");
struct {
HgiSamplerAddressMode hgiAddressMode;
MTLSamplerAddressMode metalAM;
} static const _samplerAddressModeTable[HgiSamplerAddressModeCount] =
{
{HgiSamplerAddressModeClampToEdge, MTLSamplerAddressModeClampToEdge},
{HgiSamplerAddressModeMirrorClampToEdge, MTLSamplerAddressModeMirrorClampToEdge},
{HgiSamplerAddressModeRepeat, MTLSamplerAddressModeRepeat},
{HgiSamplerAddressModeMirrorRepeat, MTLSamplerAddressModeMirrorRepeat},
{HgiSamplerAddressModeClampToBorderColor, MTLSamplerAddressModeClampToBorderColor}
};
struct {
HgiSamplerFilter hgiSamplerFilter;
MTLSamplerMinMagFilter metalSF;
} static const _samplerFilterTable[HgiSamplerFilterCount] =
{
{HgiSamplerFilterNearest, MTLSamplerMinMagFilterNearest},
{HgiSamplerFilterLinear, MTLSamplerMinMagFilterLinear}
};
struct {
HgiMipFilter hgiMipFilter;
MTLSamplerMipFilter metalMF;
} static const _mipFilterTable[HgiMipFilterCount] =
{
{HgiMipFilterNotMipmapped, MTLSamplerMipFilterNotMipmapped},
{HgiMipFilterNearest, MTLSamplerMipFilterNearest},
{HgiMipFilterLinear, MTLSamplerMipFilterLinear}
};
struct {
HgiBorderColor hgiBorderColor;
MTLSamplerBorderColor metalBC;
} static const _borderColorTable[HgiBorderColorCount] =
{
{HgiBorderColorTransparentBlack, MTLSamplerBorderColorTransparentBlack},
{HgiBorderColorOpaqueBlack, MTLSamplerBorderColorOpaqueBlack},
{HgiBorderColorOpaqueWhite, MTLSamplerBorderColorOpaqueWhite}
};
#if (defined(__MAC_10_15) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_15) \
|| __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
struct {
HgiComponentSwizzle hgiComponentSwizzle;
MTLTextureSwizzle metalCS;
} static const _componentSwizzleTable[HgiComponentSwizzleCount] =
{
{HgiComponentSwizzleZero, MTLTextureSwizzleZero},
{HgiComponentSwizzleOne, MTLTextureSwizzleOne},
{HgiComponentSwizzleR, MTLTextureSwizzleRed},
{HgiComponentSwizzleG, MTLTextureSwizzleGreen},
{HgiComponentSwizzleB, MTLTextureSwizzleBlue},
{HgiComponentSwizzleA, MTLTextureSwizzleAlpha}
};
#endif
struct {
HgiPrimitiveType hgiPrimitiveType;
MTLPrimitiveTopologyClass metalTC;
} static const _primitiveClassTable[HgiPrimitiveTypeCount] =
{
{HgiPrimitiveTypePointList, MTLPrimitiveTopologyClassPoint},
{HgiPrimitiveTypeLineList, MTLPrimitiveTopologyClassLine},
{HgiPrimitiveTypeLineStrip, MTLPrimitiveTopologyClassLine},
{HgiPrimitiveTypeTriangleList, MTLPrimitiveTopologyClassTriangle},
{HgiPrimitiveTypePatchList, MTLPrimitiveTopologyClassTriangle},
{HgiPrimitiveTypeLineListWithAdjacency,
MTLPrimitiveTopologyClassUnspecified}
};
struct {
HgiPrimitiveType hgiPrimitiveType;
MTLPrimitiveType metalPT;
} static const _primitiveTypeTable[HgiPrimitiveTypeCount] =
{
{HgiPrimitiveTypePointList, MTLPrimitiveTypePoint},
{HgiPrimitiveTypeLineList, MTLPrimitiveTypeLine},
{HgiPrimitiveTypeLineStrip, MTLPrimitiveTypeLineStrip},
{HgiPrimitiveTypeTriangleList, MTLPrimitiveTypeTriangle},
{HgiPrimitiveTypePatchList, MTLPrimitiveTypeTriangle /*Invalid*/},
{HgiPrimitiveTypeLineListWithAdjacency,
MTLPrimitiveTypeTriangle /*Invalid*/}
};
MTLPixelFormat
HgiMetalConversions::GetPixelFormat(HgiFormat inFormat, HgiTextureUsage inUsage)
{
if (inFormat == HgiFormatInvalid) {
return MTLPixelFormatInvalid;
}
if ((inFormat < 0) || (inFormat >= HgiFormatCount))
{
TF_CODING_ERROR("Unexpected HgiFormat %d", inFormat);
return MTLPixelFormatRGBA8Unorm;
}
if (inUsage & HgiTextureUsageBitsDepthTarget) {
if (inFormat == HgiFormatFloat32UInt8) {
return MTLPixelFormatDepth32Float_Stencil8;
} else {
return MTLPixelFormatDepth32Float;
}
}
MTLPixelFormat outFormat = _PIXEL_FORMAT_DESC[inFormat];
if (outFormat == MTLPixelFormatInvalid)
{
TF_CODING_ERROR("Unsupported HgiFormat %d", inFormat);
return MTLPixelFormatRGBA8Unorm;
}
return outFormat;
}
MTLVertexFormat
HgiMetalConversions::GetVertexFormat(HgiFormat inFormat)
{
if ((inFormat < 0) || (inFormat >= HgiFormatCount))
{
TF_CODING_ERROR("Unexpected HgiFormat %d", inFormat);
return MTLVertexFormatFloat4;
}
MTLVertexFormat outFormat = _VERTEX_FORMAT_DESC[inFormat];
if (outFormat == MTLVertexFormatInvalid)
{
TF_CODING_ERROR("Unsupported HgiFormat %d", inFormat);
return MTLVertexFormatFloat4;
}
return outFormat;
}
MTLCullMode
HgiMetalConversions::GetCullMode(HgiCullMode cm)
{
return _CullModeTable[cm].metalCullMode;
}
MTLTriangleFillMode
HgiMetalConversions::GetPolygonMode(HgiPolygonMode pm)
{
return _PolygonModeTable[pm].metalFillMode;
}
MTLBlendFactor
HgiMetalConversions::GetBlendFactor(HgiBlendFactor bf)
{
return _blendFactorTable[bf].metalBlendFactor;
}
MTLBlendOperation
HgiMetalConversions::GetBlendEquation(HgiBlendOp bo)
{
return _blendEquationTable[bo].metalBlendOp;
}
MTLWinding
HgiMetalConversions::GetWinding(HgiWinding winding)
{
return _windingTable[winding].metalWinding;
}
MTLLoadAction
HgiMetalConversions::GetAttachmentLoadOp(HgiAttachmentLoadOp loadOp)
{
return _attachmentLoadOpTable[loadOp].metalLoadOp;
}
MTLStoreAction
HgiMetalConversions::GetAttachmentStoreOp(HgiAttachmentStoreOp storeOp)
{
return _attachmentStoreOpTable[storeOp].metalStoreOp;
}
MTLCompareFunction
HgiMetalConversions::GetCompareFunction(HgiCompareFunction cf)
{
return _compareFnTable[cf].metalCF;
}
MTLStencilOperation
HgiMetalConversions::GetStencilOp(HgiStencilOp op)
{
return _stencilOpTable[op].metalStencilOp;
}
MTLTextureType
HgiMetalConversions::GetTextureType(HgiTextureType tt)
{
return _textureTypeTable[tt].metalTT;
}
MTLSamplerAddressMode
HgiMetalConversions::GetSamplerAddressMode(HgiSamplerAddressMode a)
{
return _samplerAddressModeTable[a].metalAM;
}
MTLSamplerMinMagFilter
HgiMetalConversions::GetMinMagFilter(HgiSamplerFilter mf)
{
return _samplerFilterTable[mf].metalSF;
}
MTLSamplerMipFilter
HgiMetalConversions::GetMipFilter(HgiMipFilter mf)
{
return _mipFilterTable[mf].metalMF;
}
MTLSamplerBorderColor
HgiMetalConversions::GetBorderColor(HgiBorderColor bc)
{
return _borderColorTable[bc].metalBC;
}
#if (defined(__MAC_10_15) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_15) \
|| __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
MTLTextureSwizzle
HgiMetalConversions::GetComponentSwizzle(HgiComponentSwizzle componentSwizzle)
{
return _componentSwizzleTable[componentSwizzle].metalCS;
}
#endif
MTLPrimitiveTopologyClass
HgiMetalConversions::GetPrimitiveClass(HgiPrimitiveType pt)
{
return _primitiveClassTable[pt].metalTC;
}
MTLPrimitiveType
HgiMetalConversions::GetPrimitiveType(HgiPrimitiveType pt)
{
return _primitiveTypeTable[pt].metalPT;
}
MTLColorWriteMask
HgiMetalConversions::GetColorWriteMask(HgiColorMask mask)
{
MTLColorWriteMask mtlMask;
mtlMask = ((mask & HgiColorMaskRed) ? MTLColorWriteMaskRed : 0)
| ((mask & HgiColorMaskGreen) ? MTLColorWriteMaskGreen : 0)
| ((mask & HgiColorMaskBlue) ? MTLColorWriteMaskBlue : 0)
| ((mask & HgiColorMaskAlpha) ? MTLColorWriteMaskAlpha : 0);
return mtlMask;
}
PXR_NAMESPACE_CLOSE_SCOPE