1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/transform/renamer.h"
16
17 #include <memory>
18
19 #include "gmock/gmock.h"
20 #include "src/transform/test_helper.h"
21
22 namespace tint {
23 namespace transform {
24 namespace {
25
26 using ::testing::ContainerEq;
27
28 using RenamerTest = TransformTest;
29
TEST_F(RenamerTest,EmptyModule)30 TEST_F(RenamerTest, EmptyModule) {
31 auto* src = "";
32 auto* expect = "";
33
34 auto got = Run<Renamer>(src);
35
36 EXPECT_EQ(expect, str(got));
37
38 auto* data = got.data.Get<Renamer::Data>();
39
40 ASSERT_EQ(data->remappings.size(), 0u);
41 }
42
TEST_F(RenamerTest,BasicModuleVertexIndex)43 TEST_F(RenamerTest, BasicModuleVertexIndex) {
44 auto* src = R"(
45 fn test(vert_idx : u32) -> u32 {
46 return vert_idx;
47 }
48
49 [[stage(vertex)]]
50 fn entry([[builtin(vertex_index)]] vert_idx : u32
51 ) -> [[builtin(position)]] vec4<f32> {
52 ignore(test(vert_idx));
53 return vec4<f32>();
54 }
55 )";
56
57 auto* expect = R"(
58 fn tint_symbol(tint_symbol_1 : u32) -> u32 {
59 return tint_symbol_1;
60 }
61
62 [[stage(vertex)]]
63 fn tint_symbol_2([[builtin(vertex_index)]] tint_symbol_1 : u32) -> [[builtin(position)]] vec4<f32> {
64 ignore(tint_symbol(tint_symbol_1));
65 return vec4<f32>();
66 }
67 )";
68
69 auto got = Run<Renamer>(src);
70
71 EXPECT_EQ(expect, str(got));
72
73 auto* data = got.data.Get<Renamer::Data>();
74
75 ASSERT_NE(data, nullptr);
76 Renamer::Data::Remappings expected_remappings = {
77 {"vert_idx", "tint_symbol_1"},
78 {"test", "tint_symbol"},
79 {"entry", "tint_symbol_2"},
80 };
81 EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
82 }
83
TEST_F(RenamerTest,PreserveSwizzles)84 TEST_F(RenamerTest, PreserveSwizzles) {
85 auto* src = R"(
86 [[stage(vertex)]]
87 fn entry() -> [[builtin(position)]] vec4<f32> {
88 var v : vec4<f32>;
89 var rgba : f32;
90 var xyzw : f32;
91 return v.zyxw + v.rgab;
92 }
93 )";
94
95 auto* expect = R"(
96 [[stage(vertex)]]
97 fn tint_symbol() -> [[builtin(position)]] vec4<f32> {
98 var tint_symbol_1 : vec4<f32>;
99 var tint_symbol_2 : f32;
100 var tint_symbol_3 : f32;
101 return (tint_symbol_1.zyxw + tint_symbol_1.rgab);
102 }
103 )";
104
105 auto got = Run<Renamer>(src);
106
107 EXPECT_EQ(expect, str(got));
108
109 auto* data = got.data.Get<Renamer::Data>();
110
111 ASSERT_NE(data, nullptr);
112 Renamer::Data::Remappings expected_remappings = {
113 {"entry", "tint_symbol"},
114 {"v", "tint_symbol_1"},
115 {"rgba", "tint_symbol_2"},
116 {"xyzw", "tint_symbol_3"},
117 };
118 EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
119 }
120
TEST_F(RenamerTest,PreserveIntrinsics)121 TEST_F(RenamerTest, PreserveIntrinsics) {
122 auto* src = R"(
123 [[stage(vertex)]]
124 fn entry() -> [[builtin(position)]] vec4<f32> {
125 var blah : vec4<f32>;
126 return abs(blah);
127 }
128 )";
129
130 auto* expect = R"(
131 [[stage(vertex)]]
132 fn tint_symbol() -> [[builtin(position)]] vec4<f32> {
133 var tint_symbol_1 : vec4<f32>;
134 return abs(tint_symbol_1);
135 }
136 )";
137
138 auto got = Run<Renamer>(src);
139
140 EXPECT_EQ(expect, str(got));
141
142 auto* data = got.data.Get<Renamer::Data>();
143
144 ASSERT_NE(data, nullptr);
145 Renamer::Data::Remappings expected_remappings = {
146 {"entry", "tint_symbol"},
147 {"blah", "tint_symbol_1"},
148 };
149 EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
150 }
151
TEST_F(RenamerTest,PreserveBuiltinTypes)152 TEST_F(RenamerTest, PreserveBuiltinTypes) {
153 auto* src = R"(
154 [[stage(compute), workgroup_size(1)]]
155 fn entry() {
156 var a = modf(1.0).whole;
157 var b = modf(1.0).fract;
158 var c = frexp(1.0).sig;
159 var d = frexp(1.0).exp;
160 }
161 )";
162
163 auto* expect = R"(
164 [[stage(compute), workgroup_size(1)]]
165 fn tint_symbol() {
166 var tint_symbol_1 = modf(1.0).whole;
167 var tint_symbol_2 = modf(1.0).fract;
168 var tint_symbol_3 = frexp(1.0).sig;
169 var tint_symbol_4 = frexp(1.0).exp;
170 }
171 )";
172
173 auto got = Run<Renamer>(src);
174
175 EXPECT_EQ(expect, str(got));
176
177 auto* data = got.data.Get<Renamer::Data>();
178
179 ASSERT_NE(data, nullptr);
180 Renamer::Data::Remappings expected_remappings = {
181 {"entry", "tint_symbol"}, {"a", "tint_symbol_1"}, {"b", "tint_symbol_2"},
182 {"c", "tint_symbol_3"}, {"d", "tint_symbol_4"},
183 };
184 EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
185 }
186
TEST_F(RenamerTest,AttemptSymbolCollision)187 TEST_F(RenamerTest, AttemptSymbolCollision) {
188 auto* src = R"(
189 [[stage(vertex)]]
190 fn entry() -> [[builtin(position)]] vec4<f32> {
191 var tint_symbol : vec4<f32>;
192 var tint_symbol_2 : vec4<f32>;
193 var tint_symbol_4 : vec4<f32>;
194 return tint_symbol + tint_symbol_2 + tint_symbol_4;
195 }
196 )";
197
198 auto* expect = R"(
199 [[stage(vertex)]]
200 fn tint_symbol() -> [[builtin(position)]] vec4<f32> {
201 var tint_symbol_1 : vec4<f32>;
202 var tint_symbol_2 : vec4<f32>;
203 var tint_symbol_3 : vec4<f32>;
204 return ((tint_symbol_1 + tint_symbol_2) + tint_symbol_3);
205 }
206 )";
207
208 auto got = Run<Renamer>(src);
209
210 EXPECT_EQ(expect, str(got));
211
212 auto* data = got.data.Get<Renamer::Data>();
213
214 ASSERT_NE(data, nullptr);
215 Renamer::Data::Remappings expected_remappings = {
216 {"entry", "tint_symbol"},
217 {"tint_symbol", "tint_symbol_1"},
218 {"tint_symbol_2", "tint_symbol_2"},
219 {"tint_symbol_4", "tint_symbol_3"},
220 };
221 EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
222 }
223
224 using RenamerTestGlsl = TransformTestWithParam<std::string>;
225 using RenamerTestHlsl = TransformTestWithParam<std::string>;
226 using RenamerTestMsl = TransformTestWithParam<std::string>;
227
TEST_P(RenamerTestGlsl,Keywords)228 TEST_P(RenamerTestGlsl, Keywords) {
229 auto keyword = GetParam();
230
231 auto src = R"(
232 [[stage(fragment)]]
233 fn frag_main() {
234 var )" + keyword +
235 R"( : i32;
236 }
237 )";
238
239 auto* expect = R"(
240 [[stage(fragment)]]
241 fn frag_main() {
242 var tint_symbol : i32;
243 }
244 )";
245
246 DataMap inputs;
247 inputs.Add<Renamer::Config>(Renamer::Target::kGlslKeywords);
248 auto got = Run<Renamer>(src, inputs);
249
250 EXPECT_EQ(expect, str(got));
251 }
252
TEST_P(RenamerTestHlsl,Keywords)253 TEST_P(RenamerTestHlsl, Keywords) {
254 auto keyword = GetParam();
255
256 auto src = R"(
257 [[stage(fragment)]]
258 fn frag_main() {
259 var )" + keyword +
260 R"( : i32;
261 }
262 )";
263
264 auto* expect = R"(
265 [[stage(fragment)]]
266 fn frag_main() {
267 var tint_symbol : i32;
268 }
269 )";
270
271 DataMap inputs;
272 inputs.Add<Renamer::Config>(Renamer::Target::kHlslKeywords);
273 auto got = Run<Renamer>(src, inputs);
274
275 EXPECT_EQ(expect, str(got));
276 }
277
TEST_P(RenamerTestMsl,Keywords)278 TEST_P(RenamerTestMsl, Keywords) {
279 auto keyword = GetParam();
280
281 auto src = R"(
282 [[stage(fragment)]]
283 fn frag_main() {
284 var )" + keyword +
285 R"( : i32;
286 }
287 )";
288
289 auto* expect = R"(
290 [[stage(fragment)]]
291 fn frag_main() {
292 var tint_symbol : i32;
293 }
294 )";
295
296 DataMap inputs;
297 inputs.Add<Renamer::Config>(Renamer::Target::kMslKeywords);
298 auto got = Run<Renamer>(src, inputs);
299
300 EXPECT_EQ(expect, str(got));
301 }
302
303 INSTANTIATE_TEST_SUITE_P(RenamerTestGlsl,
304 RenamerTestGlsl,
305 testing::Values("active",
306 // "asm", // WGSL keyword
307 "atomic_uint",
308 "attribute",
309 // "bool", // WGSL keyword
310 // "break", // WGSL keyword
311 "buffer",
312 "bvec2",
313 "bvec3",
314 "bvec4",
315 // "case", // WGSL keyword
316 "cast",
317 "centroid",
318 "class",
319 "coherent",
320 "common",
321 // "const", // WGSL keyword
322 // "continue", // WGSL keyword
323 // "default", // WGSL keyword
324 // "discard", // WGSL keyword
325 "dmat2",
326 "dmat2x2",
327 "dmat2x3",
328 "dmat2x4",
329 "dmat3",
330 "dmat3x2",
331 "dmat3x3",
332 "dmat3x4",
333 "dmat4",
334 "dmat4x2",
335 "dmat4x3",
336 "dmat4x4",
337 // "do", // WGSL keyword
338 "double",
339 "dvec2",
340 "dvec3",
341 "dvec4",
342 // "else" // WGSL keyword
343 // "enum", // WGSL keyword
344 "extern",
345 "external",
346 // "false", // WGSL keyword
347 "filter",
348 "fixed",
349 "flat",
350 "float",
351 // "for", // WGSL keyword
352 "fvec2",
353 "fvec3",
354 "fvec4",
355 "gl_BaseInstance",
356 "gl_BaseVertex",
357 "gl_ClipDistance",
358 "gl_DepthRangeParameters",
359 "gl_DrawID",
360 "gl_FragCoord",
361 "gl_FragDepth",
362 "gl_FrontFacing",
363 "gl_GlobalInvocationID",
364 "gl_InstanceID",
365 "gl_LocalInvocationID",
366 "gl_LocalInvocationIndex",
367 "gl_NumSamples",
368 "gl_NumWorkGroups",
369 "gl_PerVertex",
370 "gl_PointCoord",
371 "gl_PointSize",
372 "gl_Position",
373 "gl_PrimitiveID",
374 "gl_SampleID",
375 "gl_SampleMask",
376 "gl_SampleMaskIn",
377 "gl_SamplePosition",
378 "gl_VertexID",
379 "gl_WorkGroupID",
380 "gl_WorkGroupSize",
381 "goto",
382 "half",
383 "highp",
384 "hvec2",
385 "hvec3",
386 "hvec4",
387 // "if", // WGSL keyword
388 "iimage1D",
389 "iimage1DArray",
390 "iimage2D",
391 "iimage2DArray",
392 "iimage2DMS",
393 "iimage2DMSArray",
394 "iimage2DRect",
395 "iimage3D",
396 "iimageBuffer",
397 "iimageCube",
398 "iimageCubeArray",
399 "image1D",
400 "image1DArray",
401 "image2D",
402 "image2DArray",
403 "image2DMS",
404 "image2DMSArray",
405 "image2DRect",
406 "image3D",
407 "imageBuffer",
408 "imageCube",
409 "imageCubeArray",
410 "in",
411 "inline",
412 "inout",
413 "input",
414 "int",
415 "interface",
416 "invariant",
417 "isampler1D",
418 "isampler1DArray",
419 "isampler2D",
420 "isampler2DArray",
421 "isampler2DMS",
422 "isampler2DMSArray",
423 "isampler2DRect",
424 "isampler3D",
425 "isamplerBuffer",
426 "isamplerCube",
427 "isamplerCubeArray",
428 "ivec2",
429 "ivec3",
430 "ivec4",
431 "layout",
432 "long",
433 "lowp",
434 // "mat2x2", // WGSL keyword
435 // "mat2x3", // WGSL keyword
436 // "mat2x4", // WGSL keyword
437 // "mat2",
438 "mat3",
439 // "mat3x2", // WGSL keyword
440 // "mat3x3", // WGSL keyword
441 // "mat3x4", // WGSL keyword
442 "mat4",
443 // "mat4x2", // WGSL keyword
444 // "mat4x3", // WGSL keyword
445 // "mat4x4", // WGSL keyword
446 "mediump",
447 "namespace",
448 "noinline",
449 "noperspective",
450 "out",
451 "output",
452 "partition",
453 "patch",
454 "precise",
455 "precision",
456 "public",
457 "readonly",
458 "resource",
459 "restrict",
460 // "return", // WGSL keyword
461 "sample",
462 "sampler1D",
463 "sampler1DArray",
464 "sampler1DArrayShadow",
465 "sampler1DShadow",
466 "sampler2D",
467 "sampler2DArray",
468 "sampler2DArrayShadow",
469 "sampler2DMS",
470 "sampler2DMSArray",
471 "sampler2DRect",
472 "sampler2DRectShadow",
473 "sampler2DShadow",
474 "sampler3D",
475 "sampler3DRect",
476 "samplerBuffer",
477 "samplerCube",
478 "samplerCubeArray",
479 "samplerCubeArrayShadow",
480 "samplerCubeShadow",
481 "shared",
482 "short",
483 "sizeof",
484 "smooth",
485 "static",
486 // "struct", // WGSL keyword
487 "subroutine",
488 "superp",
489 // "switch", // WGSL keyword
490 "template",
491 "this",
492 // "true", // WGSL keyword
493 // "typedef", // WGSL keyword
494 "uimage1D",
495 "uimage1DArray",
496 "uimage2D",
497 "uimage2DArray",
498 "uimage2DMS",
499 "uimage2DMSArray",
500 "uimage2DRect",
501 "uimage3D",
502 "uimageBuffer",
503 "uimageCube",
504 "uimageCubeArray",
505 "uint",
506 // "uniform", // WGSL keyword
507 "union",
508 "unsigned",
509 "usampler1D",
510 "usampler1DArray",
511 "usampler2D",
512 "usampler2DArray",
513 "usampler2DMS",
514 "usampler2DMSArray",
515 "usampler2DRect",
516 "usampler3D",
517 "usamplerBuffer",
518 "usamplerCube",
519 "usamplerCubeArray",
520 // "using", // WGSL keyword
521 "uvec2",
522 "uvec3",
523 "uvec4",
524 "varying",
525 // "vec2", // WGSL keyword
526 // "vec3", // WGSL keyword
527 // "vec4", // WGSL keyword
528 // "void", // WGSL keyword
529 "volatile",
530 // "while", // WGSL keyword
531 "writeonly"));
532
533 INSTANTIATE_TEST_SUITE_P(RenamerTestHlsl,
534 RenamerTestHlsl,
535 testing::Values("AddressU",
536 "AddressV",
537 "AddressW",
538 "AllMemoryBarrier",
539 "AllMemoryBarrierWithGroupSync",
540 "AppendStructuredBuffer",
541 "BINORMAL",
542 "BLENDINDICES",
543 "BLENDWEIGHT",
544 "BlendState",
545 "BorderColor",
546 "Buffer",
547 "ByteAddressBuffer",
548 "COLOR",
549 "CheckAccessFullyMapped",
550 "ComparisonFunc",
551 "CompileShader",
552 "ComputeShader",
553 "ConsumeStructuredBuffer",
554 "D3DCOLORtoUBYTE4",
555 "DEPTH",
556 "DepthStencilState",
557 "DepthStencilView",
558 "DeviceMemoryBarrier",
559 "DeviceMemroyBarrierWithGroupSync",
560 "DomainShader",
561 "EvaluateAttributeAtCentroid",
562 "EvaluateAttributeAtSample",
563 "EvaluateAttributeSnapped",
564 "FOG",
565 "Filter",
566 "GeometryShader",
567 "GetRenderTargetSampleCount",
568 "GetRenderTargetSamplePosition",
569 "GroupMemoryBarrier",
570 "GroupMemroyBarrierWithGroupSync",
571 "Hullshader",
572 "InputPatch",
573 "InterlockedAdd",
574 "InterlockedAnd",
575 "InterlockedCompareExchange",
576 "InterlockedCompareStore",
577 "InterlockedExchange",
578 "InterlockedMax",
579 "InterlockedMin",
580 "InterlockedOr",
581 "InterlockedXor",
582 "LineStream",
583 "MaxAnisotropy",
584 "MaxLOD",
585 "MinLOD",
586 "MipLODBias",
587 "NORMAL",
588 "NULL",
589 "Normal",
590 "OutputPatch",
591 "POSITION",
592 "POSITIONT",
593 "PSIZE",
594 "PixelShader",
595 "PointStream",
596 "Process2DQuadTessFactorsAvg",
597 "Process2DQuadTessFactorsMax",
598 "Process2DQuadTessFactorsMin",
599 "ProcessIsolineTessFactors",
600 "ProcessQuadTessFactorsAvg",
601 "ProcessQuadTessFactorsMax",
602 "ProcessQuadTessFactorsMin",
603 "ProcessTriTessFactorsAvg",
604 "ProcessTriTessFactorsMax",
605 "ProcessTriTessFactorsMin",
606 "RWBuffer",
607 "RWByteAddressBuffer",
608 "RWStructuredBuffer",
609 "RWTexture1D",
610 "RWTexture1DArray",
611 "RWTexture2D",
612 "RWTexture2DArray",
613 "RWTexture3D",
614 "RasterizerState",
615 "RenderTargetView",
616 "SV_ClipDistance",
617 "SV_Coverage",
618 "SV_CullDistance",
619 "SV_Depth",
620 "SV_DepthGreaterEqual",
621 "SV_DepthLessEqual",
622 "SV_DispatchThreadID",
623 "SV_DomainLocation",
624 "SV_GSInstanceID",
625 "SV_GroupID",
626 "SV_GroupIndex",
627 "SV_GroupThreadID",
628 "SV_InnerCoverage",
629 "SV_InsideTessFactor",
630 "SV_InstanceID",
631 "SV_IsFrontFace",
632 "SV_OutputControlPointID",
633 "SV_Position",
634 "SV_PrimitiveID",
635 "SV_RenderTargetArrayIndex",
636 "SV_SampleIndex",
637 "SV_StencilRef",
638 "SV_Target",
639 "SV_TessFactor",
640 "SV_VertexArrayIndex",
641 "SV_VertexID",
642 "Sampler",
643 "Sampler1D",
644 "Sampler2D",
645 "Sampler3D",
646 "SamplerCUBE",
647 "SamplerComparisonState",
648 "SamplerState",
649 "StructuredBuffer",
650 "TANGENT",
651 "TESSFACTOR",
652 "TEXCOORD",
653 "Texcoord",
654 "Texture",
655 "Texture1D",
656 "Texture1DArray",
657 "Texture2D",
658 "Texture2DArray",
659 "Texture2DMS",
660 "Texture2DMSArray",
661 "Texture3D",
662 "TextureCube",
663 "TextureCubeArray",
664 "TriangleStream",
665 "VFACE",
666 "VPOS",
667 "VertexShader",
668 "abort",
669 // "abs", // WGSL intrinsic
670 // "acos", // WGSL intrinsic
671 // "all", // WGSL intrinsic
672 "allow_uav_condition",
673 // "any", // WGSL intrinsic
674 "asdouble",
675 "asfloat",
676 // "asin", // WGSL intrinsic
677 "asint",
678 // "asm", // WGSL keyword
679 "asm_fragment",
680 "asuint",
681 // "atan", // WGSL intrinsic
682 // "atan2", // WGSL intrinsic
683 "auto",
684 // "bool", // WGSL keyword
685 "bool1",
686 "bool1x1",
687 "bool1x2",
688 "bool1x3",
689 "bool1x4",
690 "bool2",
691 "bool2x1",
692 "bool2x2",
693 "bool2x3",
694 "bool2x4",
695 "bool3",
696 "bool3x1",
697 "bool3x2",
698 "bool3x3",
699 "bool3x4",
700 "bool4",
701 "bool4x1",
702 "bool4x2",
703 "bool4x3",
704 "bool4x4",
705 "branch",
706 // "break", // WGSL keyword
707 // "call", // WGSL intrinsic
708 // "case", // WGSL keyword
709 "catch",
710 "cbuffer",
711 // "ceil", // WGSL intrinsic
712 "centroid",
713 "char",
714 // "clamp", // WGSL intrinsic
715 "class",
716 "clip",
717 "column_major",
718 "compile",
719 "compile_fragment",
720 // "const", // WGSL keyword
721 "const_cast",
722 // "continue", // WGSL keyword
723 // "cos", // WGSL intrinsic
724 // "cosh", // WGSL intrinsic
725 "countbits",
726 // "cross", // WGSL intrinsic
727 "ddx",
728 "ddx_coarse",
729 "ddx_fine",
730 "ddy",
731 "ddy_coarse",
732 "ddy_fine",
733 // "default", // WGSL keyword
734 "degrees",
735 "delete",
736 // "determinant", // WGSL intrinsic
737 // "discard", // WGSL keyword
738 // "distance", // WGSL intrinsic
739 // "do", // WGSL keyword
740 // "dot", // WGSL intrinsic
741 "double",
742 "double1",
743 "double1x1",
744 "double1x2",
745 "double1x3",
746 "double1x4",
747 "double2",
748 "double2x1",
749 "double2x2",
750 "double2x3",
751 "double2x4",
752 "double3",
753 "double3x1",
754 "double3x2",
755 "double3x3",
756 "double3x4",
757 "double4",
758 "double4x1",
759 "double4x2",
760 "double4x3",
761 "double4x4",
762 "dst",
763 "dword",
764 "dword1",
765 "dword1x1",
766 "dword1x2",
767 "dword1x3",
768 "dword1x4",
769 "dword2",
770 "dword2x1",
771 "dword2x2",
772 "dword2x3",
773 "dword2x4",
774 "dword3",
775 "dword3x1",
776 "dword3x2",
777 "dword3x3",
778 "dword3x4",
779 "dword4",
780 "dword4x1",
781 "dword4x2",
782 "dword4x3",
783 "dword4x4",
784 "dynamic_cast",
785 // "else", // WGSL keyword
786 // "enum", // WGSL keyword
787 "errorf",
788 // "exp", // WGSL intrinsic
789 // "exp2", // WGSL intrinsic
790 "explicit",
791 "export",
792 "extern",
793 "f16to32",
794 "f32tof16",
795 // "faceforward", // WGSL intrinsic
796 // "false", // WGSL keyword
797 "fastopt",
798 "firstbithigh",
799 "firstbitlow",
800 "flatten",
801 "float",
802 "float1",
803 "float1x1",
804 "float1x2",
805 "float1x3",
806 "float1x4",
807 "float2",
808 "float2x1",
809 "float2x2",
810 "float2x3",
811 "float2x4",
812 "float3",
813 "float3x1",
814 "float3x2",
815 "float3x3",
816 "float3x4",
817 "float4",
818 "float4x1",
819 "float4x2",
820 "float4x3",
821 "float4x4",
822 // "floor", // WGSL intrinsic
823 // "fma", // WGSL intrinsic
824 "fmod",
825 // "for", // WGSL keyword
826 "forcecase",
827 "frac",
828 // "frexp", // WGSL intrinsic
829 "friend",
830 // "fwidth", // WGSL intrinsic
831 "fxgroup",
832 "goto",
833 "groupshared",
834 "half",
835 "half1",
836 "half1x1",
837 "half1x2",
838 "half1x3",
839 "half1x4",
840 "half2",
841 "half2x1",
842 "half2x2",
843 "half2x3",
844 "half2x4",
845 "half3",
846 "half3x1",
847 "half3x2",
848 "half3x3",
849 "half3x4",
850 "half4",
851 "half4x1",
852 "half4x2",
853 "half4x3",
854 "half4x4",
855 // "if", // WGSL keyword
856 // "in", // WGSL keyword
857 "inline",
858 "inout",
859 "int",
860 "int1",
861 "int1x1",
862 "int1x2",
863 "int1x3",
864 "int1x4",
865 "int2",
866 "int2x1",
867 "int2x2",
868 "int2x3",
869 "int2x4",
870 "int3",
871 "int3x1",
872 "int3x2",
873 "int3x3",
874 "int3x4",
875 "int4",
876 "int4x1",
877 "int4x2",
878 "int4x3",
879 "int4x4",
880 "interface",
881 "isfinite",
882 "isinf",
883 "isnan",
884 // "ldexp", // WGSL intrinsic
885 // "length", // WGSL intrinsic
886 "lerp",
887 "line",
888 "lineadj",
889 "linear",
890 "lit",
891 // "log", // WGSL intrinsic
892 "log10",
893 // "log2", // WGSL intrinsic
894 "long",
895 // "loop", // WGSL keyword
896 "mad",
897 "matrix",
898 // "max", // WGSL intrinsic
899 // "min", // WGSL intrinsic
900 "min10float",
901 "min10float1",
902 "min10float1x1",
903 "min10float1x2",
904 "min10float1x3",
905 "min10float1x4",
906 "min10float2",
907 "min10float2x1",
908 "min10float2x2",
909 "min10float2x3",
910 "min10float2x4",
911 "min10float3",
912 "min10float3x1",
913 "min10float3x2",
914 "min10float3x3",
915 "min10float3x4",
916 "min10float4",
917 "min10float4x1",
918 "min10float4x2",
919 "min10float4x3",
920 "min10float4x4",
921 "min12int",
922 "min12int1",
923 "min12int1x1",
924 "min12int1x2",
925 "min12int1x3",
926 "min12int1x4",
927 "min12int2",
928 "min12int2x1",
929 "min12int2x2",
930 "min12int2x3",
931 "min12int2x4",
932 "min12int3",
933 "min12int3x1",
934 "min12int3x2",
935 "min12int3x3",
936 "min12int3x4",
937 "min12int4",
938 "min12int4x1",
939 "min12int4x2",
940 "min12int4x3",
941 "min12int4x4",
942 "min16float",
943 "min16float1",
944 "min16float1x1",
945 "min16float1x2",
946 "min16float1x3",
947 "min16float1x4",
948 "min16float2",
949 "min16float2x1",
950 "min16float2x2",
951 "min16float2x3",
952 "min16float2x4",
953 "min16float3",
954 "min16float3x1",
955 "min16float3x2",
956 "min16float3x3",
957 "min16float3x4",
958 "min16float4",
959 "min16float4x1",
960 "min16float4x2",
961 "min16float4x3",
962 "min16float4x4",
963 "min16int",
964 "min16int1",
965 "min16int1x1",
966 "min16int1x2",
967 "min16int1x3",
968 "min16int1x4",
969 "min16int2",
970 "min16int2x1",
971 "min16int2x2",
972 "min16int2x3",
973 "min16int2x4",
974 "min16int3",
975 "min16int3x1",
976 "min16int3x2",
977 "min16int3x3",
978 "min16int3x4",
979 "min16int4",
980 "min16int4x1",
981 "min16int4x2",
982 "min16int4x3",
983 "min16int4x4",
984 "min16uint",
985 "min16uint1",
986 "min16uint1x1",
987 "min16uint1x2",
988 "min16uint1x3",
989 "min16uint1x4",
990 "min16uint2",
991 "min16uint2x1",
992 "min16uint2x2",
993 "min16uint2x3",
994 "min16uint2x4",
995 "min16uint3",
996 "min16uint3x1",
997 "min16uint3x2",
998 "min16uint3x3",
999 "min16uint3x4",
1000 "min16uint4",
1001 "min16uint4x1",
1002 "min16uint4x2",
1003 "min16uint4x3",
1004 "min16uint4x4",
1005 // "modf", // WGSL intrinsic
1006 "msad4",
1007 "mul",
1008 "mutable",
1009 "namespace",
1010 "new",
1011 "nointerpolation",
1012 "noise",
1013 "noperspective",
1014 // "normalize", // WGSL intrinsic
1015 "numthreads",
1016 "operator",
1017 // "out", // WGSL keyword
1018 "packoffset",
1019 "pass",
1020 "pixelfragment",
1021 "pixelshader",
1022 "point",
1023 // "pow", // WGSL intrinsic
1024 "precise",
1025 "printf",
1026 // "private", // WGSL keyword
1027 "protected",
1028 "public",
1029 "radians",
1030 "rcp",
1031 // "reflect", // WGSL intrinsic
1032 "refract",
1033 "register",
1034 "reinterpret_cast",
1035 // "return", // WGSL keyword
1036 // "reversebits", // WGSL intrinsic
1037 // "round", // WGSL intrinsic
1038 "row_major",
1039 "rsqrt",
1040 "sample",
1041 "sampler1D",
1042 "sampler2D",
1043 "sampler3D",
1044 "samplerCUBE",
1045 "sampler_state",
1046 "saturate",
1047 "shared",
1048 "short",
1049 // "sign", // WGSL intrinsic
1050 "signed",
1051 // "sin", // WGSL intrinsic
1052 "sincos",
1053 // "sinh", // WGSL intrinsic
1054 "sizeof",
1055 // "smoothstep", // WGSL intrinsic
1056 "snorm",
1057 // "sqrt", // WGSL intrinsic
1058 "stateblock",
1059 "stateblock_state",
1060 "static",
1061 "static_cast",
1062 // "step", // WGSL intrinsic
1063 "string",
1064 // "struct", // WGSL keyword
1065 // "switch", // WGSL keyword
1066 // "tan", // WGSL intrinsic
1067 // "tanh", // WGSL intrinsic
1068 "tbuffer",
1069 "technique",
1070 "technique10",
1071 "technique11",
1072 "template",
1073 "tex1D",
1074 "tex1Dbias",
1075 "tex1Dgrad",
1076 "tex1Dlod",
1077 "tex1Dproj",
1078 "tex2D",
1079 "tex2Dbias",
1080 "tex2Dgrad",
1081 "tex2Dlod",
1082 "tex2Dproj",
1083 "tex3D",
1084 "tex3Dbias",
1085 "tex3Dgrad",
1086 "tex3Dlod",
1087 "tex3Dproj",
1088 "texCUBE",
1089 "texCUBEbias",
1090 "texCUBEgrad",
1091 "texCUBElod",
1092 "texCUBEproj",
1093 "texture",
1094 "texture1D",
1095 "texture1DArray",
1096 "texture2D",
1097 "texture2DArray",
1098 "texture2DMS",
1099 "texture2DMSArray",
1100 "texture3D",
1101 "textureCube",
1102 "textureCubeArray",
1103 "this",
1104 "throw",
1105 "transpose",
1106 "triangle",
1107 "triangleadj",
1108 // "true", // WGSL keyword
1109 // "trunc", // WGSL intrinsic
1110 "try",
1111 // "typedef", // WGSL keyword
1112 "typename",
1113 "uint",
1114 "uint1",
1115 "uint1x1",
1116 "uint1x2",
1117 "uint1x3",
1118 "uint1x4",
1119 "uint2",
1120 "uint2x1",
1121 "uint2x2",
1122 "uint2x3",
1123 "uint2x4",
1124 "uint3",
1125 "uint3x1",
1126 "uint3x2",
1127 "uint3x3",
1128 "uint3x4",
1129 "uint4",
1130 "uint4x1",
1131 "uint4x2",
1132 "uint4x3",
1133 "uint4x4",
1134 // "uniform", // WGSL keyword
1135 "union",
1136 "unorm",
1137 "unroll",
1138 "unsigned",
1139 // "using", // WGSL reserved keyword
1140 "vector",
1141 "vertexfragment",
1142 "vertexshader",
1143 "virtual",
1144 // "void", // WGSL keyword
1145 "volatile"));
1146 // "while" // WGSL reserved keyword
1147
1148 INSTANTIATE_TEST_SUITE_P(
1149 RenamerTestMsl,
1150 RenamerTestMsl,
1151 testing::Values(
1152 // c++14 spec
1153 "alignas",
1154 "alignof",
1155 "and",
1156 "and_eq",
1157 // "asm", // Also reserved in WGSL
1158 "auto",
1159 "bitand",
1160 "bitor",
1161 // "bool", // Also used in WGSL
1162 // "break", // Also used in WGSL
1163 // "case", // Also used in WGSL
1164 "catch",
1165 "char",
1166 "char16_t",
1167 "char32_t",
1168 "class",
1169 "compl",
1170 // "const", // Also used in WGSL
1171 "const_cast",
1172 "constexpr",
1173 // "continue", // Also used in WGSL
1174 "decltype",
1175 // "default", // Also used in WGSL
1176 "delete",
1177 // "do", // Also used in WGSL
1178 "double",
1179 "dynamic_cast",
1180 // "else", // Also used in WGSL
1181 // "enum", // Also used in WGSL
1182 "explicit",
1183 "extern",
1184 // "false", // Also used in WGSL
1185 "final",
1186 "float",
1187 // "for", // Also used in WGSL
1188 "friend",
1189 "goto",
1190 // "if", // Also used in WGSL
1191 "inline",
1192 "int",
1193 "long",
1194 "mutable",
1195 "namespace",
1196 "new",
1197 "noexcept",
1198 "not",
1199 "not_eq",
1200 "nullptr",
1201 "operator",
1202 "or",
1203 "or_eq",
1204 "override",
1205 // "private", // Also used in WGSL
1206 "protected",
1207 "public",
1208 "register",
1209 "reinterpret_cast",
1210 // "return", // Also used in WGSL
1211 "short",
1212 "signed",
1213 "sizeof",
1214 "static",
1215 "static_assert",
1216 "static_cast",
1217 // "struct", // Also used in WGSL
1218 // "switch", // Also used in WGSL
1219 "template",
1220 "this",
1221 "thread_local",
1222 "throw",
1223 // "true", // Also used in WGSL
1224 "try",
1225 // "typedef", // Also used in WGSL
1226 "typeid",
1227 "typename",
1228 "union",
1229 "unsigned",
1230 // "using", // WGSL reserved keyword
1231 "virtual",
1232 // "void", // Also used in WGSL
1233 "volatile",
1234 "wchar_t",
1235 // "while", // WGSL reserved keyword
1236 "xor",
1237 "xor_eq",
1238
1239 // Metal Spec
1240 "access",
1241 // "array", // Also used in WGSL
1242 "array_ref",
1243 "as_type",
1244 // "atomic", // Also used in WGSL
1245 "atomic_bool",
1246 "atomic_int",
1247 "atomic_uint",
1248 "bool2",
1249 "bool3",
1250 "bool4",
1251 "buffer",
1252 "char2",
1253 "char3",
1254 "char4",
1255 "const_reference",
1256 "constant",
1257 "depth2d",
1258 "depth2d_array",
1259 "depth2d_ms",
1260 "depth2d_ms_array",
1261 "depthcube",
1262 "depthcube_array",
1263 "device",
1264 "discard_fragment",
1265 "float2",
1266 "float2x2",
1267 "float2x3",
1268 "float2x4",
1269 "float3",
1270 "float3x2",
1271 "float3x3",
1272 "float3x4",
1273 "float4",
1274 "float4x2",
1275 "float4x3",
1276 "float4x4",
1277 "fragment",
1278 "half",
1279 "half2",
1280 "half2x2",
1281 "half2x3",
1282 "half2x4",
1283 "half3",
1284 "half3x2",
1285 "half3x3",
1286 "half3x4",
1287 "half4",
1288 "half4x2",
1289 "half4x3",
1290 "half4x4",
1291 "imageblock",
1292 "int16_t",
1293 "int2",
1294 "int3",
1295 "int32_t",
1296 "int4",
1297 "int64_t",
1298 "int8_t",
1299 "kernel",
1300 "long2",
1301 "long3",
1302 "long4",
1303 "main", // No functions called main
1304 "matrix",
1305 "metal", // The namespace
1306 "packed_bool2",
1307 "packed_bool3",
1308 "packed_bool4",
1309 "packed_char2",
1310 "packed_char3",
1311 "packed_char4",
1312 "packed_float2",
1313 "packed_float3",
1314 "packed_float4",
1315 "packed_half2",
1316 "packed_half3",
1317 "packed_half4",
1318 "packed_int2",
1319 "packed_int3",
1320 "packed_int4",
1321 "packed_short2",
1322 "packed_short3",
1323 "packed_short4",
1324 "packed_uchar2",
1325 "packed_uchar3",
1326 "packed_uchar4",
1327 "packed_uint2",
1328 "packed_uint3",
1329 "packed_uint4",
1330 "packed_ushort2",
1331 "packed_ushort3",
1332 "packed_ushort4",
1333 "patch_control_point",
1334 "ptrdiff_t",
1335 "r16snorm",
1336 "r16unorm",
1337 // "r8unorm", // Also used in WGSL
1338 "reference",
1339 "rg11b10f",
1340 "rg16snorm",
1341 "rg16unorm",
1342 // "rg8snorm", // Also used in WGSL
1343 // "rg8unorm", // Also used in WGSL
1344 "rgb10a2",
1345 "rgb9e5",
1346 "rgba16snorm",
1347 "rgba16unorm",
1348 // "rgba8snorm", // Also used in WGSL
1349 // "rgba8unorm", // Also used in WGSL
1350 // "sampler", // Also used in WGSL
1351 "short2",
1352 "short3",
1353 "short4",
1354 "size_t",
1355 "srgba8unorm",
1356 "texture",
1357 "texture1d",
1358 "texture1d_array",
1359 "texture2d",
1360 "texture2d_array",
1361 "texture2d_ms",
1362 "texture2d_ms_array",
1363 "texture3d",
1364 "texture_buffer",
1365 "texturecube",
1366 "texturecube_array",
1367 "thread",
1368 "threadgroup",
1369 "threadgroup_imageblock",
1370 "uchar",
1371 "uchar2",
1372 "uchar3",
1373 "uchar4",
1374 "uint",
1375 "uint16_t",
1376 "uint2",
1377 "uint3",
1378 "uint32_t",
1379 "uint4",
1380 "uint64_t",
1381 "uint8_t",
1382 "ulong2",
1383 "ulong3",
1384 "ulong4",
1385 // "uniform", // Also used in WGSL
1386 "ushort",
1387 "ushort2",
1388 "ushort3",
1389 "ushort4",
1390 // "vec", // WGSL reserved keyword
1391 "vertex",
1392
1393 // https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
1394 // Table 6.5. Constants for single-precision floating-point math
1395 // functions
1396 "MAXFLOAT",
1397 "HUGE_VALF",
1398 "INFINITY",
1399 "infinity",
1400 "NAN",
1401 "M_E_F",
1402 "M_LOG2E_F",
1403 "M_LOG10E_F",
1404 "M_LN2_F",
1405 "M_LN10_F",
1406 "M_PI_F",
1407 "M_PI_2_F",
1408 "M_PI_4_F",
1409 "M_1_PI_F",
1410 "M_2_PI_F",
1411 "M_2_SQRTPI_F",
1412 "M_SQRT2_F",
1413 "M_SQRT1_2_F",
1414 "MAXHALF",
1415 "HUGE_VALH",
1416 "M_E_H",
1417 "M_LOG2E_H",
1418 "M_LOG10E_H",
1419 "M_LN2_H",
1420 "M_LN10_H",
1421 "M_PI_H",
1422 "M_PI_2_H",
1423 "M_PI_4_H",
1424 "M_1_PI_H",
1425 "M_2_PI_H",
1426 "M_2_SQRTPI_H",
1427 "M_SQRT2_H",
1428 "M_SQRT1_2_H"));
1429
1430 } // namespace
1431 } // namespace transform
1432 } // namespace tint
1433