-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariable_rasterization_rate_map.patch
1433 lines (1371 loc) · 64.6 KB
/
variable_rasterization_rate_map.patch
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/doc/ExtensionSupport.md b/doc/ExtensionSupport.md
index e85bc81fa2..47d174017d 100644
--- a/doc/ExtensionSupport.md
+++ b/doc/ExtensionSupport.md
@@ -267,6 +267,7 @@ using data from registry_xml.py and gl.xml.
| [GL_ANGLE_texture_external_update](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_texture_external_update.txt) | | | | | | | |
| [GL_ANGLE_texture_multisample](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_texture_multisample.txt) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| [GL_ANGLE_texture_rectangle](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_texture_rectangle.txt) | | | | | | | |
+| [GL_ANGLE_variable_rasterization_rate_metal](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_variable_rasterization_rate_metal.txt) | | | | | | | |
| [GL_ANGLE_vulkan_image](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_vulkan_image.txt) | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
| [GL_ANGLE_webgl_compatibility](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_webgl_compatibility.txt) | | | | | | | |
| [GL_ANGLE_yuv_internal_format](https://chromium.googlesource.com/angle/angle/+/refs/heads/main/extensions/ANGLE_yuv_internal_format.txt) | ✔ | | ✔ | ✔ | ✔ | ✔ | ✔ |
diff --git a/extensions/ANGLE_variable_rasterization_rate_metal.txt b/extensions/ANGLE_variable_rasterization_rate_metal.txt
new file mode 100644
index 0000000000..661d204d57
--- /dev/null
+++ b/extensions/ANGLE_variable_rasterization_rate_metal.txt
@@ -0,0 +1,95 @@
+Name
+
+ ANGLE_variable_rasterization_rate_metal
+
+Name Strings
+
+ GL_ANGLE_variable_rasterization_rate_metal
+
+Contributors
+
+ Dan Glastonbury, Apple Inc.
+
+Contact
+
+ Dan Glastonbury, Apple Inc. (djg 'at' apple 'dot' com)
+
+Status
+
+ Incomplete
+
+Version
+
+ Last Modified Date: May 5, 2023
+ Author Revision: 1
+
+Number
+
+ OpenGL ES Extension XX
+
+Dependencies
+
+Overview
+
+IP Status
+
+ No known IP claims.
+
+New Types
+
+ /*
+ * GLMTLRasterizationRateMapANGLE is an opaque handle to an id<MTLRasterizationRateMap>
+ */
+ typedef void* GLMTLRasterizationRateMapANGLE;
+
+New Procedures and Functions
+
+ void BindMetalRasterizationRateMapANGLE(GLMTLRasterizationRateMapANGLE map);
+
+New Tokens
+
+ Accepted by the <cap> parameter of Enable, Disable, and IsEnabled, by the
+ <target> parameter of Enablei, Disablei, IsEnabledi, GetBooleani_v, GetIntegeri_v, GetInteger64i_v, and by the <pname> parameter
+ of GetBooleanv, GetIntegerv, GetInteger64v, GetFloatv,
+
+ VARIABLE_RASTERIZATION_RATE_ANGLE 0x96BC
+
+ Accepted by the <pname> parameter of GetPointerv:
+
+ METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE 0x96BD
+
+Issues
+
+ 1) Specify behavior of BindMetalRaterizationRateMap(...)
+
+ - Though this extension's incomplete and being prototyped, would you
+ like to mention anything about the semantics of this new binding
+ point?
+
+ - Should this define ownership of the MTLRasterizationRateMap?
+
+ - MTLRasterizationRateMap needs to define multiple layer maps if
+ performing layered rendering - which I assume would mean using
+ multiple draw buffers in OpenGL ES semantics.
+
+ - Should this mention errors, for example that subsequent draw calls
+ will fail with INVALID_OPERATION if the number of color attachments on
+ the bound framebuffer doesn't match the number of layer maps in the
+ rasterization rate map?
+
+ - Does passing nullptr restore the GL state to its original value?
+
+ - Does binding a rasterization rate map created with a different Metal
+ device to that of ANGLE cause an error? If not, should it?
+
+ 2) Specify behavior of glEnable(GL_VARIABLE_RASTERIZATION_RATE_ANGLE)
+
+ - What happens if GL_VARIABLE_RASTERIZATION_RATE_ANGLE is enabled, but
+ no rasterization rate map is bound?
+
+ In the current implementation, if the feature is enable but no map is
+ bound the GL renders as normal and no error is generated.
+
+ 3) Does this feature require a GLSL extension to allow access to
+ rasterization_rate_map_decoder when rendering with an enabled map? Should
+ gl_FragCoord automatically be adjusted when rendering with a map?
diff --git a/include/GLES2/gl2ext_angle.h b/include/GLES2/gl2ext_angle.h
index e86dfd066c..75924f8c00 100644
--- a/include/GLES2/gl2ext_angle.h
+++ b/include/GLES2/gl2ext_angle.h
@@ -727,6 +727,18 @@ GL_APICALL void GL_APIENTRY glLogicOpANGLE (GLenum);
#endif
#endif /* GL_ANGLE_logic_op */
+#ifndef GL_ANGLE_variable_rasterization_rate_metal
+#define GL_ANGLE_variable_rasterization_rate_metal 1
+
+#define GL_VARIABLE_RASTERIZATION_RATE_ANGLE 0x96BC
+#define GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE 0x96BD
+typedef void *GLMTLRasterizationRateMapANGLE;
+typedef void (GL_APIENTRYP PFNGLBINDMETALRASTERIZATIONRATEMAPANGLEPROC) (GLMTLRasterizationRateMapANGLE);
+#ifdef GL_GLEXT_PROTOTYPES
+GL_APICALL void GL_APIENTRY glBindMetalRasterizationRateMapANGLE(GLMTLRasterizationRateMapANGLE map);
+#endif
+#endif /* GL_ANGLE_variable_rasterization_rate_metal */
+
#ifndef GL_ANGLE_program_binary_readiness_query
#define GL_ANGLE_program_binary_readiness_query
#define GL_PROGRAM_BINARY_READY_ANGLE 0x96BE
diff --git a/include/platform/autogen/FeaturesMtl_autogen.h b/include/platform/autogen/FeaturesMtl_autogen.h
index 61c9f3ebed..3e73853164 100644
--- a/include/platform/autogen/FeaturesMtl_autogen.h
+++ b/include/platform/autogen/FeaturesMtl_autogen.h
@@ -74,6 +74,12 @@ struct FeaturesMtl : FeatureSetBase
&members,
};
+ FeatureInfo hasVariableRasterizationRate = {
+ "hasVariableRasterizationRate",
+ FeatureCategory::MetalFeatures,
+ &members,
+ };
+
FeatureInfo allowInlineConstVertexData = {
"allowInlineConstVertexData",
FeatureCategory::MetalFeatures,
diff --git a/include/platform/mtl_features.json b/include/platform/mtl_features.json
index e3b71dc8ef..e2943e1a2a 100644
--- a/include/platform/mtl_features.json
+++ b/include/platform/mtl_features.json
@@ -70,6 +70,13 @@
"The renderer supports MTL(Shared)Event"
]
},
+ {
+ "name": "has_variable_rasterization_rate",
+ "category": "Features",
+ "description": [
+ "The renderer supports variable rasterization rate"
+ ]
+ },
{
"name": "allow_inline_const_vertex_data",
"category": "Features",
diff --git a/scripts/generate_entry_points.py b/scripts/generate_entry_points.py
index f2ce5d4374..e7fe58c886 100755
--- a/scripts/generate_entry_points.py
+++ b/scripts/generate_entry_points.py
@@ -1084,6 +1084,7 @@ FORMAT_DICT = {
"GLint": "%d",
"GLintptr": UNSIGNED_LONG_LONG_FORMAT,
"GLSETBLOBPROCANGLE": POINTER_FORMAT,
+ "GLMTLRasterizationRateMapANGLE": POINTER_FORMAT,
"GLshort": "%d",
"GLsizei": "%d",
"GLsizeiptr": UNSIGNED_LONG_LONG_FORMAT,
diff --git a/scripts/gl_angle_ext.xml b/scripts/gl_angle_ext.xml
index 44c6dea45f..b667e00bae 100644
--- a/scripts/gl_angle_ext.xml
+++ b/scripts/gl_angle_ext.xml
@@ -13,6 +13,7 @@
<types>
<type>typedef GLsizeiptr (<apientry/> *<name>GLGETBLOBPROCANGLE</name>)(const void *key, GLsizeiptr keySize, void *value, GLsizeiptr valueSize, const void *userParam);</type>
<type>typedef void (<apientry/> *<name>GLSETBLOBPROCANGLE</name>)(const void *key, GLsizeiptr keySize, const void *value, GLsizeiptr valueSize, const void *userParam);</type>
+ <type>typedef void *<name>GLMTLRasterizationRateMapANGLE</name>;</type>
</types>
<!-- SECTION: GL parameter class type definitions. -->
@@ -1066,6 +1067,10 @@
<param len="1">void **<name>params</name></param>
<alias name="glGetPointerv"/>
</command>
+ <command>
+ <proto>void <name>glBindMetalRasterizationRateMapANGLE</name></proto>
+ <param><ptype>GLMTLRasterizationRateMapANGLE</ptype> <name>map</name></param>
+ </command>
</commands>
<!-- SECTION: ANGLE extension interface definitions -->
@@ -1473,6 +1478,13 @@
<command name="glGetPointervANGLE"/>
</require>
</extension>
+ <extension name="GL_ANGLE_variable_rasterization_rate_metal" supported="gles2">
+ <require>
+ <enum name="GL_VARIABLE_RASTERIZATION_RATE_ANGLE"/>
+ <enum name="GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE"/>
+ <command name="glBindMetalRasterizationRateMapANGLE"/>
+ </require>
+ </extension>
</extensions>
<!-- SECTION: GL enumerant (token) definitions. -->
@@ -1657,4 +1669,9 @@
<enum value="0x96EF" name="GL_BLOB_CACHE_SET_FUNCTION_ANGLE"/>
<enum value="0x972D" name="GL_BLOB_CACHE_USER_PARAM_ANGLE"/>
</enums>
+
+ <enums namespace="GL" start="0x96BC" end="0x96BD" vendor="ANGLE">
+ <enum value="0x96BC" name="GL_VARIABLE_RASTERIZATION_RATE_ANGLE"/>
+ <enum value="0x96BD" name="GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE"/>
+ </enums>
</registry>
diff --git a/scripts/registry_xml.py b/scripts/registry_xml.py
index 3f2deac8b8..26a1aaa197 100644
--- a/scripts/registry_xml.py
+++ b/scripts/registry_xml.py
@@ -74,6 +74,7 @@ angle_requestable_extensions = [
"GL_ANGLE_texture_compression_dxt5",
"GL_ANGLE_texture_external_update",
"GL_ANGLE_texture_multisample",
+ "GL_ANGLE_variable_rasterization_rate_metal",
"GL_ANGLE_vulkan_image",
"GL_ANGLE_yuv_internal_format",
"GL_CHROMIUM_color_buffer_float_rgb",
diff --git a/src/common/entry_points_enum_autogen.cpp b/src/common/entry_points_enum_autogen.cpp
index 7d3beb4fe3..cd405476dd 100644
--- a/src/common/entry_points_enum_autogen.cpp
+++ b/src/common/entry_points_enum_autogen.cpp
@@ -524,6 +524,8 @@ const char *GetEntryPointName(EntryPoint ep)
return "glBindFramebufferOES";
case EntryPoint::GLBindImageTexture:
return "glBindImageTexture";
+ case EntryPoint::GLBindMetalRasterizationRateMapANGLE:
+ return "glBindMetalRasterizationRateMapANGLE";
case EntryPoint::GLBindProgramPipeline:
return "glBindProgramPipeline";
case EntryPoint::GLBindProgramPipelineEXT:
diff --git a/src/common/entry_points_enum_autogen.h b/src/common/entry_points_enum_autogen.h
index e09617166d..8d90b87f8a 100644
--- a/src/common/entry_points_enum_autogen.h
+++ b/src/common/entry_points_enum_autogen.h
@@ -268,6 +268,7 @@ enum class EntryPoint
GLBindFramebuffer,
GLBindFramebufferOES,
GLBindImageTexture,
+ GLBindMetalRasterizationRateMapANGLE,
GLBindProgramPipeline,
GLBindProgramPipelineEXT,
GLBindRenderbuffer,
diff --git a/src/common/frame_capture_utils_autogen.cpp b/src/common/frame_capture_utils_autogen.cpp
index 0606442008..fd7e7c6c45 100644
--- a/src/common/frame_capture_utils_autogen.cpp
+++ b/src/common/frame_capture_utils_autogen.cpp
@@ -230,6 +230,10 @@ void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const Pa
WriteParamValueReplay<ParamType::TGLSETBLOBPROCANGLE>(
os, call, param.value.GLSETBLOBPROCANGLEVal);
break;
+ case ParamType::TGLMTLRasterizationRateMapANGLE:
+ WriteParamValueReplay<ParamType::TGLMTLRasterizationRateMapANGLE>(
+ os, call, param.value.GLMTLRasterizationRateMapANGLEVal);
+ break;
case ParamType::TGLbitfield:
WriteParamValueReplay<ParamType::TGLbitfield>(os, call, param.value.GLbitfieldVal);
break;
@@ -1003,6 +1007,8 @@ const char *ParamTypeToString(ParamType paramType)
return "GLGETBLOBPROCANGLE";
case ParamType::TGLSETBLOBPROCANGLE:
return "GLSETBLOBPROCANGLE";
+ case ParamType::TGLMTLRasterizationRateMapANGLE:
+ return "GLMTLRasterizationRateMapANGLE";
case ParamType::TGLbitfield:
return "GLbitfield";
case ParamType::TGLboolean:
diff --git a/src/common/frame_capture_utils_autogen.h b/src/common/frame_capture_utils_autogen.h
index b9b0171613..5bc2791e3d 100644
--- a/src/common/frame_capture_utils_autogen.h
+++ b/src/common/frame_capture_utils_autogen.h
@@ -102,6 +102,7 @@ enum class ParamType
TGLDEBUGPROCKHR,
TGLGETBLOBPROCANGLE,
TGLSETBLOBPROCANGLE,
+ TGLMTLRasterizationRateMapANGLE,
TGLbitfield,
TGLboolean,
TGLbooleanPointer,
@@ -272,7 +273,7 @@ enum class ParamType
TvoidPointerPointer,
};
-constexpr uint32_t kParamTypeCount = 235;
+constexpr uint32_t kParamTypeCount = 236;
union ParamValue
{
@@ -337,6 +338,7 @@ union ParamValue
GLDEBUGPROCKHR GLDEBUGPROCKHRVal;
GLGETBLOBPROCANGLE GLGETBLOBPROCANGLEVal;
GLSETBLOBPROCANGLE GLSETBLOBPROCANGLEVal;
+ GLMTLRasterizationRateMapANGLE GLMTLRasterizationRateMapANGLEVal;
GLbitfield GLbitfieldVal;
GLboolean GLbooleanVal;
GLboolean *GLbooleanPointerVal;
@@ -907,6 +909,14 @@ inline GLSETBLOBPROCANGLE GetParamVal<ParamType::TGLSETBLOBPROCANGLE, GLSETBLOBP
return value.GLSETBLOBPROCANGLEVal;
}
+template <>
+inline GLMTLRasterizationRateMapANGLE
+GetParamVal<ParamType::TGLMTLRasterizationRateMapANGLE, GLMTLRasterizationRateMapANGLE>(
+ const ParamValue &value)
+{
+ return value.GLMTLRasterizationRateMapANGLEVal;
+}
+
template <>
inline GLbitfield GetParamVal<ParamType::TGLbitfield, GLbitfield>(const ParamValue &value)
{
@@ -2224,6 +2234,8 @@ T AccessParamValue(ParamType paramType, const ParamValue &value)
return GetParamVal<ParamType::TGLGETBLOBPROCANGLE, T>(value);
case ParamType::TGLSETBLOBPROCANGLE:
return GetParamVal<ParamType::TGLSETBLOBPROCANGLE, T>(value);
+ case ParamType::TGLMTLRasterizationRateMapANGLE:
+ return GetParamVal<ParamType::TGLMTLRasterizationRateMapANGLE, T>(value);
case ParamType::TGLbitfield:
return GetParamVal<ParamType::TGLbitfield, T>(value);
case ParamType::TGLboolean:
@@ -2942,6 +2954,14 @@ inline void SetParamVal<ParamType::TGLSETBLOBPROCANGLE>(GLSETBLOBPROCANGLE value
valueOut->GLSETBLOBPROCANGLEVal = valueIn;
}
+template <>
+inline void SetParamVal<ParamType::TGLMTLRasterizationRateMapANGLE>(
+ GLMTLRasterizationRateMapANGLE valueIn,
+ ParamValue *valueOut)
+{
+ valueOut->GLMTLRasterizationRateMapANGLEVal = valueIn;
+}
+
template <>
inline void SetParamVal<ParamType::TGLbitfield>(GLbitfield valueIn, ParamValue *valueOut)
{
@@ -4300,6 +4320,9 @@ void InitParamValue(ParamType paramType, T valueIn, ParamValue *valueOut)
case ParamType::TGLSETBLOBPROCANGLE:
SetParamVal<ParamType::TGLSETBLOBPROCANGLE>(valueIn, valueOut);
break;
+ case ParamType::TGLMTLRasterizationRateMapANGLE:
+ SetParamVal<ParamType::TGLMTLRasterizationRateMapANGLE>(valueIn, valueOut);
+ break;
case ParamType::TGLbitfield:
SetParamVal<ParamType::TGLbitfield>(valueIn, valueOut);
break;
diff --git a/src/common/gl_enum_utils_autogen.cpp b/src/common/gl_enum_utils_autogen.cpp
index 416b30b290..ad25872b3e 100644
--- a/src/common/gl_enum_utils_autogen.cpp
+++ b/src/common/gl_enum_utils_autogen.cpp
@@ -2818,6 +2818,10 @@ const char *GLenumToString(GLESEnum enumGroup, unsigned int value)
return "GL_RGBX8_ANGLE";
case 0x96BB:
return "GL_SHADER_BINARY_ANGLE";
+ case 0x96BC:
+ return "GL_VARIABLE_RASTERIZATION_RATE_ANGLE";
+ case 0x96BD:
+ return "GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE";
case 0x96BE:
return "GL_PROGRAM_BINARY_READY_ANGLE";
case 0x96C0:
@@ -22274,6 +22278,7 @@ static StringEnumEntry g_stringEnumTable[] = {
{"GL_MESH_SUBROUTINE_UNIFORM_NV", 0x957E},
{"GL_MESH_VERTICES_OUT_NV", 0x9579},
{"GL_MESH_WORK_GROUP_SIZE_NV", 0x953E},
+ {"GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE", 0x96BD},
{"GL_MIN", 0x8007},
{"GL_MINMAX", 0x802E},
{"GL_MINMAX_EXT", 0x802E},
@@ -24925,6 +24930,7 @@ static StringEnumEntry g_stringEnumTable[] = {
{"GL_VARIABLE_E_NV", 0x8527},
{"GL_VARIABLE_F_NV", 0x8528},
{"GL_VARIABLE_G_NV", 0x8529},
+ {"GL_VARIABLE_RASTERIZATION_RATE_ANGLE", 0x96BC},
{"GL_VARIANT_ARRAY_EXT", 0x87E8},
{"GL_VARIANT_ARRAY_POINTER_EXT", 0x87E9},
{"GL_VARIANT_ARRAY_STRIDE_EXT", 0x87E6},
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp
index 35085108ad..d01deccaa4 100644
--- a/src/common/utilities.cpp
+++ b/src/common/utilities.cpp
@@ -6,6 +6,12 @@
// utilities.cpp: Conversion functions and other utility routines.
+// Older clang versions have a false positive on this warning here.
+// TODO(dino): Is this still necessary?
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wglobal-constructors"
+#endif
+
#include "common/utilities.h"
#include "GLES3/gl3.h"
#include "common/mathutil.h"
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index 9f5518b00e..0f6123d46a 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -10063,6 +10063,12 @@ size_t Context::getMemoryUsage() const
return memoryUsage;
}
+void Context::bindMetalRasterizationRateMap(GLMTLRasterizationRateMapANGLE map)
+{
+ ANGLE_CONTEXT_TRY(mImplementation->bindMetalRasterizationRateMap(this, map));
+ getMutablePrivateState()->setVariableRasterizationRateMap(map);
+}
+
// ErrorSet implementation.
ErrorSet::ErrorSet(Debug *debug,
const angle::FrontendFeatures &frontendFeatures,
diff --git a/src/libANGLE/Context_gles_ext_autogen.h b/src/libANGLE/Context_gles_ext_autogen.h
index a2293df8f5..1c7d72c6d3 100644
--- a/src/libANGLE/Context_gles_ext_autogen.h
+++ b/src/libANGLE/Context_gles_ext_autogen.h
@@ -648,6 +648,8 @@
void invalidateTexture(TextureType targetPacked); \
/* GL_ANGLE_texture_multisample */ \
/* GL_ANGLE_texture_rectangle */ \
+ /* GL_ANGLE_variable_rasterization_rate_metal */ \
+ void bindMetalRasterizationRateMap(GLMTLRasterizationRateMapANGLE map); \
/* GL_ANGLE_vulkan_image */ \
void acquireTextures(GLuint numTextures, const TextureID *texturesPacked, \
const GLenum *layouts); \
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp
index 6be85b5742..ff3c420a05 100644
--- a/src/libANGLE/State.cpp
+++ b/src/libANGLE/State.cpp
@@ -6,6 +6,9 @@
// State.cpp: Implements the State class, encapsulating raw GL state.
+// Older clang versions have a false positive on this warning here.
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
#include "libANGLE/State.h"
#include <string.h>
@@ -367,6 +370,8 @@ PrivateState::PrivateState(const Version &clientVersion,
mLogicOp(LogicalOperation::Copy),
mPatchVertices(3),
mPixelLocalStorageActivePlanes(0),
+ mVariableRasterizationRateEnabled(false),
+ mVariableRasterizationRateMap(nullptr),
mNoSimultaneousConstantColorAndAlphaBlendFunc(false),
mSetBlendIndexedInvoked(false),
mSetBlendFactorsIndexedInvoked(false),
@@ -1302,6 +1307,26 @@ void PrivateState::setLogicOp(LogicalOperation opcode)
}
}
+void PrivateState::setVariableRasterizationRateEnabled(bool enabled)
+{
+ if (mVariableRasterizationRateEnabled != enabled)
+ {
+ mVariableRasterizationRateEnabled = enabled;
+ mDirtyBits.set(state::DIRTY_BIT_EXTENDED);
+ mExtendedDirtyBits.set(state::EXTENDED_DIRTY_BIT_VARIABLE_RASTERIZATION_RATE);
+ }
+}
+
+void PrivateState::setVariableRasterizationRateMap(GLMTLRasterizationRateMapANGLE map)
+{
+ if (mVariableRasterizationRateMap != map)
+ {
+ mVariableRasterizationRateMap = map;
+ mDirtyBits.set(state::DIRTY_BIT_EXTENDED);
+ mExtendedDirtyBits.set(state::EXTENDED_DIRTY_BIT_VARIABLE_RASTERIZATION_RATE);
+ }
+}
+
void PrivateState::setVertexAttribf(GLuint index, const GLfloat values[4])
{
ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size());
@@ -1434,6 +1459,9 @@ void PrivateState::setEnableFeature(GLenum feature, bool enabled)
case GL_FETCH_PER_SAMPLE_ARM:
mFetchPerSample = enabled;
return;
+ case GL_VARIABLE_RASTERIZATION_RATE_ANGLE:
+ setVariableRasterizationRateEnabled(enabled);
+ return;
default:
break;
}
@@ -1600,6 +1628,8 @@ bool PrivateState::getEnableFeature(GLenum feature) const
return mShadingRatePreserveAspectRatio;
case GL_FETCH_PER_SAMPLE_ARM:
return mFetchPerSample;
+ case GL_VARIABLE_RASTERIZATION_RATE_ANGLE:
+ return mVariableRasterizationRateEnabled;
}
ASSERT(mClientVersion.major == 1);
@@ -3485,6 +3515,9 @@ void State::getPointerv(const Context *context, GLenum pname, void **params) con
case GL_BLOB_CACHE_USER_PARAM_ANGLE:
*params = const_cast<void *>(getBlobCacheCallbacks().userParam);
break;
+ case GL_METAL_RASTERIZATION_RATE_MAP_BINDING_ANGLE:
+ *params = privateState().getVariableRasterizationRateMap();
+ break;
default:
UNREACHABLE();
break;
diff --git a/src/libANGLE/State.h b/src/libANGLE/State.h
index 4f360a49d5..c5ec62d999 100644
--- a/src/libANGLE/State.h
+++ b/src/libANGLE/State.h
@@ -180,6 +180,7 @@ enum ExtendedDirtyBitType
EXTENDED_DIRTY_BIT_LOGIC_OP_ENABLED, // ANGLE_logic_op
EXTENDED_DIRTY_BIT_LOGIC_OP, // ANGLE_logic_op
EXTENDED_DIRTY_BIT_BLEND_ADVANCED_COHERENT, // KHR_blend_operation_advanced_coherent
+ EXTENDED_DIRTY_BIT_VARIABLE_RASTERIZATION_RATE, // ANGLE_variable_rasterization_rate_metal
EXTENDED_DIRTY_BIT_INVALID,
EXTENDED_DIRTY_BIT_MAX = EXTENDED_DIRTY_BIT_INVALID,
@@ -480,6 +481,15 @@ class PrivateState : angle::NonCopyable
bool hasActivelyOverriddenPLSDrawBuffers(GLint *firstActivePLSDrawBuffer) const;
bool isActivelyOverriddenPLSDrawBuffer(GLint drawbuffer) const;
+ // GL_ANGLE_variable_rasterization_rate_metal
+ void setVariableRasterizationRateEnabled(bool enabled);
+ bool isVariableRasterizationRateEnabled() const { return mVariableRasterizationRateEnabled; }
+ void setVariableRasterizationRateMap(GLMTLRasterizationRateMapANGLE map);
+ GLMTLRasterizationRateMapANGLE getVariableRasterizationRateMap() const
+ {
+ return mVariableRasterizationRateMap;
+ }
+
// Line width state setter
void setLineWidth(GLfloat width);
float getLineWidth() const { return mLineWidth; }
@@ -710,6 +720,10 @@ class PrivateState : angle::NonCopyable
// GL_ANGLE_shader_pixel_local_storage
GLsizei mPixelLocalStorageActivePlanes;
+ // GL_ANGLE_variable_rasterization_rate_metal
+ bool mVariableRasterizationRateEnabled;
+ GLMTLRasterizationRateMapANGLE mVariableRasterizationRateMap;
+
// GLES1 emulation: state specific to GLES1
GLES1State mGLES1State;
diff --git a/src/libANGLE/capture/capture_gles_ext_autogen.cpp b/src/libANGLE/capture/capture_gles_ext_autogen.cpp
index e510fed316..7aff3b9609 100644
--- a/src/libANGLE/capture/capture_gles_ext_autogen.cpp
+++ b/src/libANGLE/capture/capture_gles_ext_autogen.cpp
@@ -5221,6 +5221,18 @@ CallCapture CaptureGetTranslatedShaderSourceANGLE(const State &glState,
return CallCapture(angle::EntryPoint::GLGetTranslatedShaderSourceANGLE, std::move(paramBuffer));
}
+CallCapture CaptureBindMetalRasterizationRateMapANGLE(const State &glState,
+ bool isCallValid,
+ GLMTLRasterizationRateMapANGLE map)
+{
+ ParamBuffer paramBuffer;
+
+ paramBuffer.addValueParam("map", ParamType::TGLMTLRasterizationRateMapANGLE, map);
+
+ return CallCapture(angle::EntryPoint::GLBindMetalRasterizationRateMapANGLE,
+ std::move(paramBuffer));
+}
+
CallCapture CaptureAcquireTexturesANGLE(const State &glState,
bool isCallValid,
GLuint numTextures,
diff --git a/src/libANGLE/capture/capture_gles_ext_autogen.h b/src/libANGLE/capture/capture_gles_ext_autogen.h
index a0d195afea..cb205f7cdf 100644
--- a/src/libANGLE/capture/capture_gles_ext_autogen.h
+++ b/src/libANGLE/capture/capture_gles_ext_autogen.h
@@ -1007,6 +1007,11 @@ angle::CallCapture CaptureGetTranslatedShaderSourceANGLE(const State &glState,
GLsizei *length,
GLchar *source);
+// GL_ANGLE_variable_rasterization_rate_metal
+angle::CallCapture CaptureBindMetalRasterizationRateMapANGLE(const State &glState,
+ bool isCallValid,
+ GLMTLRasterizationRateMapANGLE map);
+
// GL_ANGLE_vulkan_image
angle::CallCapture CaptureAcquireTexturesANGLE(const State &glState,
bool isCallValid,
diff --git a/src/libANGLE/gles_extensions_autogen.cpp b/src/libANGLE/gles_extensions_autogen.cpp
index dab7ecf2b7..355cd4008b 100644
--- a/src/libANGLE/gles_extensions_autogen.cpp
+++ b/src/libANGLE/gles_extensions_autogen.cpp
@@ -279,6 +279,7 @@ const ExtensionInfoMap &GetExtensionInfoMap()
map["GL_ANGLE_texture_external_update"] = enableableExtension(&Extensions::textureExternalUpdateANGLE);
map["GL_ANGLE_texture_multisample"] = enableableExtension(&Extensions::textureMultisampleANGLE);
map["GL_ANGLE_texture_rectangle"] = enableableDisablableExtension(&Extensions::textureRectangleANGLE);
+ map["GL_ANGLE_variable_rasterization_rate_metal"] = enableableExtension(&Extensions::variableRasterizationRateMetalANGLE);
map["GL_ANGLE_vulkan_image"] = enableableExtension(&Extensions::vulkanImageANGLE);
map["GL_ANGLE_webgl_compatibility"] = esOnlyExtension(&Extensions::webglCompatibilityANGLE);
map["GL_ANGLE_yuv_internal_format"] = enableableExtension(&Extensions::yuvInternalFormatANGLE);
diff --git a/src/libANGLE/gles_extensions_autogen.h b/src/libANGLE/gles_extensions_autogen.h
index fb1a993e02..09c549ff69 100644
--- a/src/libANGLE/gles_extensions_autogen.h
+++ b/src/libANGLE/gles_extensions_autogen.h
@@ -797,6 +797,9 @@ struct Extensions
// GL_ANGLE_texture_rectangle
bool textureRectangleANGLE = false;
+ // GL_ANGLE_variable_rasterization_rate_metal
+ bool variableRasterizationRateMetalANGLE = false;
+
// GL_ANGLE_vulkan_image
bool vulkanImageANGLE = false;
diff --git a/src/libANGLE/renderer/ContextImpl.cpp b/src/libANGLE/renderer/ContextImpl.cpp
index 122dd5364a..8230c75443 100644
--- a/src/libANGLE/renderer/ContextImpl.cpp
+++ b/src/libANGLE/renderer/ContextImpl.cpp
@@ -103,4 +103,12 @@ const angle::PerfMonitorCounterGroups &ContextImpl::getPerfMonitorCounters()
static angle::base::NoDestructor<angle::PerfMonitorCounterGroups> sCounters;
return *sCounters;
}
+
+angle::Result ContextImpl::bindMetalRasterizationRateMap(gl::Context *,
+ GLMTLRasterizationRateMapANGLE map)
+{
+ UNREACHABLE();
+ return angle::Result::Stop;
+}
+
} // namespace rx
diff --git a/src/libANGLE/renderer/ContextImpl.h b/src/libANGLE/renderer/ContextImpl.h
index 1cd8e4f396..8424ad25be 100644
--- a/src/libANGLE/renderer/ContextImpl.h
+++ b/src/libANGLE/renderer/ContextImpl.h
@@ -281,6 +281,10 @@ class ContextImpl : public GLImplFactory
// AMD_performance_monitor
virtual const angle::PerfMonitorCounterGroups &getPerfMonitorCounters();
+ // GL_ANGLE_variable_rasterization_rate_metal
+ virtual angle::Result bindMetalRasterizationRateMap(gl::Context *,
+ GLMTLRasterizationRateMapANGLE map);
+
protected:
const gl::State &mState;
gl::MemoryProgramCache *mMemoryProgramCache;
diff --git a/src/libANGLE/renderer/gl/StateManagerGL.cpp b/src/libANGLE/renderer/gl/StateManagerGL.cpp
index 9d9f67b0cb..039489a8d2 100644
--- a/src/libANGLE/renderer/gl/StateManagerGL.cpp
+++ b/src/libANGLE/renderer/gl/StateManagerGL.cpp
@@ -2518,6 +2518,10 @@ angle::Result StateManagerGL::syncState(const gl::Context *context,
case gl::state::EXTENDED_DIRTY_BIT_BLEND_ADVANCED_COHERENT:
setBlendAdvancedCoherent(state.isBlendAdvancedCoherentEnabled());
break;
+ case gl::state::EXTENDED_DIRTY_BIT_VARIABLE_RASTERIZATION_RATE:
+ // Nothing to do until ANGLE_variable_rasterization_rate_metal is
+ // implemented.
+ break;
default:
UNREACHABLE();
break;
diff --git a/src/libANGLE/renderer/metal/ContextMtl.h b/src/libANGLE/renderer/metal/ContextMtl.h
index 91da728d1a..4c82979562 100644
--- a/src/libANGLE/renderer/metal/ContextMtl.h
+++ b/src/libANGLE/renderer/metal/ContextMtl.h
@@ -272,6 +272,9 @@ class ContextMtl : public ContextImpl, public mtl::Context
angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override;
angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override;
+ angle::Result bindMetalRasterizationRateMap(gl::Context *context,
+ GLMTLRasterizationRateMapANGLE map) override;
+
// override mtl::ErrorHandler
void handleError(GLenum error,
const char *message,
@@ -550,6 +553,7 @@ class ContextMtl : public ContextImpl, public mtl::Context
DIRTY_BIT_RENDER_PIPELINE,
DIRTY_BIT_UNIFORM_BUFFERS_BINDING,
DIRTY_BIT_RASTERIZER_DISCARD,
+ DIRTY_BIT_VARIABLE_RASTERIZATION_RATE,
DIRTY_BIT_INVALID,
DIRTY_BIT_MAX = DIRTY_BIT_INVALID,
@@ -643,6 +647,8 @@ class ContextMtl : public ContextImpl, public mtl::Context
IncompleteTextureSet mIncompleteTextures;
ProvokingVertexHelper mProvokingVertexHelper;
+ mtl::RasterizationRateMapRef mRasterizationRateMap;
+
mtl::ContextDevice mContextDevice;
};
diff --git a/src/libANGLE/renderer/metal/ContextMtl.mm b/src/libANGLE/renderer/metal/ContextMtl.mm
index e477f9ae3a..799130a9ad 100644
--- a/src/libANGLE/renderer/metal/ContextMtl.mm
+++ b/src/libANGLE/renderer/metal/ContextMtl.mm
@@ -260,6 +260,7 @@ void ContextMtl::onDestroy(const gl::Context *context)
mIncompleteTextures.onDestroy(context);
mProvokingVertexHelper.onDestroy(this);
mDummyXFBRenderTexture = nullptr;
+ mRasterizationRateMap.reset();
mContextDevice.reset();
}
@@ -1408,6 +1409,9 @@ void ContextMtl::updateExtendedState(const gl::State &glState,
case gl::state::EXTENDED_DIRTY_BIT_POLYGON_OFFSET_LINE_ENABLED:
mDirtyBits.set(DIRTY_BIT_DEPTH_BIAS);
break;
+ case gl::state::EXTENDED_DIRTY_BIT_VARIABLE_RASTERIZATION_RATE:
+ mDirtyBits.set(DIRTY_BIT_VARIABLE_RASTERIZATION_RATE);
+ break;
default:
break;
}
@@ -1662,6 +1666,19 @@ angle::Result ContextMtl::memoryBarrierByRegion(const gl::Context *context, GLbi
return angle::Result::Stop;
}
+angle::Result ContextMtl::bindMetalRasterizationRateMap(gl::Context *context,
+ GLMTLRasterizationRateMapANGLE map)
+{
+ id<MTLRasterizationRateMap> rateMap = (__bridge id<MTLRasterizationRateMap>)(map);
+ if (rateMap && rateMap.device != mContextDevice.get())
+ {
+ return angle::Result::Stop;
+ }
+
+ mRasterizationRateMap = std::move(rateMap);
+ return angle::Result::Continue;
+}
+
// override mtl::ErrorHandler
void ContextMtl::handleError(GLenum glErrorCode,
const char *message,
@@ -2084,7 +2101,11 @@ void ContextMtl::updateViewport(FramebufferMtl *framebufferMtl,
float nearPlane,
float farPlane)
{
- mViewport = mtl::GetViewport(viewport, framebufferMtl->getState().getDimensions().height,
+ int screenHeight = framebufferMtl->getState().getDimensions().height;
+ id<MTLRasterizationRateMap> rateMap = mRasterizationRateMap.get();
+ if (rateMap != nil)
+ screenHeight = (int)ceilf([rateMap mapPhysicalToScreenCoordinates:MTLCoordinate2DMake(0, screenHeight) forLayer:0].y);
+ mViewport = mtl::GetViewport(viewport, screenHeight,
framebufferMtl->flipY(), nearPlane, farPlane);
mDirtyBits.set(DIRTY_BIT_VIEWPORT);
@@ -2608,7 +2629,7 @@ angle::Result ContextMtl::setupDrawImpl(const gl::Context *context,
mRenderEncoder.setViewport(mViewport);
break;
case DIRTY_BIT_SCISSOR:
- mRenderEncoder.setScissorRect(mScissorRect);
+ mRenderEncoder.setScissorRect(mScissorRect, mRasterizationRateMap);
break;
case DIRTY_BIT_DRAW_FRAMEBUFFER:
// Already handled.
@@ -2633,6 +2654,13 @@ angle::Result ContextMtl::setupDrawImpl(const gl::Context *context,
case DIRTY_BIT_RASTERIZER_DISCARD:
// Already handled.
break;
+ case DIRTY_BIT_VARIABLE_RASTERIZATION_RATE:
+ if (getState().privateState().isVariableRasterizationRateEnabled() &&
+ mRasterizationRateMap)
+ {
+ mRenderEncoder.setRasterizationRateMap(mRasterizationRateMap);
+ }
+ break;
default:
UNREACHABLE();
break;
diff --git a/src/libANGLE/renderer/metal/DisplayMtl.h b/src/libANGLE/renderer/metal/DisplayMtl.h
index c8b8ac3a69..f601b88620 100644
--- a/src/libANGLE/renderer/metal/DisplayMtl.h
+++ b/src/libANGLE/renderer/metal/DisplayMtl.h
@@ -140,6 +140,7 @@ class DisplayMtl : public DisplayImpl
bool supportsDepth24Stencil8PixelFormat() const;
bool supports32BitFloatFiltering() const;
bool supportsBCTextureCompression() const;
+ bool supportsVariableRasterizationRate() const;
bool isAMD() const;
bool isAMDBronzeDriver() const;
bool isAMDFireProDevice() const;
diff --git a/src/libANGLE/renderer/metal/DisplayMtl.mm b/src/libANGLE/renderer/metal/DisplayMtl.mm
index 7cfb9d98e1..24bb19ebe7 100644
--- a/src/libANGLE/renderer/metal/DisplayMtl.mm
+++ b/src/libANGLE/renderer/metal/DisplayMtl.mm
@@ -1138,6 +1138,11 @@ void DisplayMtl::initializeExtensions() const
mNativeCaps.maxImageUnits = gl::IMPLEMENTATION_MAX_PIXEL_LOCAL_STORAGE_PLANES;
}
}
+
+ // GL_ANGLE_variable_rasterization_rate_metal
+ mNativeExtensions.variableRasterizationRateMetalANGLE =
+ mFeatures.hasVariableRasterizationRate.enabled;
+
// "The GPUs in Apple3 through Apple8 families only support memory barriers for compute command
// encoders, and for vertex-to-vertex and vertex-to-fragment stages of render command encoders."
mHasFragmentMemoryBarriers = !supportsAppleGPUFamily(3);
@@ -1209,6 +1214,8 @@ void DisplayMtl::initializeFeatures()
ANGLE_FEATURE_CONDITION((&mFeatures), hasExplicitMemBarrier, (isOSX || isCatalyst) && !isARM);
ANGLE_FEATURE_CONDITION((&mFeatures), hasDepthAutoResolve, supportsEitherGPUFamily(3, 2));
ANGLE_FEATURE_CONDITION((&mFeatures), hasStencilAutoResolve, supportsEitherGPUFamily(5, 2));
+ ANGLE_FEATURE_CONDITION((&mFeatures), hasVariableRasterizationRate,
+ supportsVariableRasterizationRate());
ANGLE_FEATURE_CONDITION((&mFeatures), allowMultisampleStoreAndResolve,
supportsEitherGPUFamily(3, 1));
@@ -1399,6 +1406,17 @@ bool DisplayMtl::supportsDepth24Stencil8PixelFormat() const
return false;
#endif
}
+
+bool DisplayMtl::supportsVariableRasterizationRate() const
+{
+ if (@available(iOS 13.0, macOS 10.15.4, macCatalyst 13.4, tvOS 16.0, visionOS 1.0, *))
+ {
+ return [mMetalDevice supportsRasterizationRateMapWithLayerCount:1];
+ }
+
+ return false;
+}
+
bool DisplayMtl::isAMD() const
{
return angle::IsAMD(mMetalDeviceVendorId);
diff --git a/src/libANGLE/renderer/metal/FrameBufferMtl.mm b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
index f2f438cbf2..30938de5a7 100644
--- a/src/libANGLE/renderer/metal/FrameBufferMtl.mm
+++ b/src/libANGLE/renderer/metal/FrameBufferMtl.mm
@@ -617,6 +617,8 @@ angle::Result FramebufferMtl::blitWithDraw(const gl::Context *context,
ANGLE_TRY(ensureRenderPassStarted(context, &renderEncoder));
}
+ renderEncoder->setRasterizationRateMap(nil);
+
// Blit color
if (blitColorBuffer)
{
diff --git a/src/libANGLE/renderer/metal/mtl_command_buffer.h b/src/libANGLE/renderer/metal/mtl_command_buffer.h
index a4786802ae..7231a2f515 100644
--- a/src/libANGLE/renderer/metal/mtl_command_buffer.h
+++ b/src/libANGLE/renderer/metal/mtl_command_buffer.h
@@ -437,7 +437,8 @@ class RenderCommandEncoder final : public CommandEncoder
RenderCommandEncoder &setStencilRefVal(uint32_t ref);
RenderCommandEncoder &setViewport(const MTLViewport &viewport);
- RenderCommandEncoder &setScissorRect(const MTLScissorRect &rect);
+ RenderCommandEncoder &setScissorRect(const MTLScissorRect &rect,
+ id<MTLRasterizationRateMap> map);
RenderCommandEncoder &setBlendColor(float r, float g, float b, float a);
@@ -586,6 +587,8 @@ class RenderCommandEncoder final : public CommandEncoder
RenderCommandEncoder &setDepthLoadAction(MTLLoadAction action, double clearValue);
RenderCommandEncoder &setStencilLoadAction(MTLLoadAction action, uint32_t clearValue);
+ RenderCommandEncoder &setRasterizationRateMap(id<MTLRasterizationRateMap> map);
+
void setLabel(NSString *label);
void pushDebugGroup(NSString *label) override;
diff --git a/src/libANGLE/renderer/metal/mtl_command_buffer.mm b/src/libANGLE/renderer/metal/mtl_command_buffer.mm
index ab7d4b54ee..f3d9d8009a 100644
--- a/src/libANGLE/renderer/metal/mtl_command_buffer.mm
+++ b/src/libANGLE/renderer/metal/mtl_command_buffer.mm
@@ -1837,12 +1837,20 @@ RenderCommandEncoder &RenderCommandEncoder::setViewport(const MTLViewport &viewp
return *this;
}
-RenderCommandEncoder &RenderCommandEncoder::setScissorRect(const MTLScissorRect &rect)
+RenderCommandEncoder &RenderCommandEncoder::setScissorRect(const MTLScissorRect &rect,
+ id<MTLRasterizationRateMap> map)
{
+ auto maxScissorRect =
+ MTLCoordinate2DMake(mRenderPassMaxScissorRect.width, mRenderPassMaxScissorRect.height);
+ if (map)
+ {
+ maxScissorRect = [map mapPhysicalToScreenCoordinates:maxScissorRect forLayer:0];
+ }
+
NSUInteger clampedWidth =
- rect.x > mRenderPassMaxScissorRect.width ? 0 : mRenderPassMaxScissorRect.width - rect.x;
+ rect.x > maxScissorRect.x ? 0 : (NSUInteger)ceilf(maxScissorRect.x) - rect.x;
NSUInteger clampedHeight =
- rect.y > mRenderPassMaxScissorRect.height ? 0 : mRenderPassMaxScissorRect.height - rect.y;
+ rect.y > maxScissorRect.y ? 0 : (NSUInteger)ceilf(maxScissorRect.y) - rect.y;
MTLScissorRect clampedRect = {rect.x, rect.y, std::min(rect.width, clampedWidth),
std::min(rect.height, clampedHeight)};
@@ -1854,6 +1862,22 @@ RenderCommandEncoder &RenderCommandEncoder::setScissorRect(const MTLScissorRect
mStateCache.scissorRect = clampedRect;
+ if (map)
+ {
+ auto adjustedOrigin =
+ [map mapPhysicalToScreenCoordinates:MTLCoordinate2DMake(clampedRect.x, clampedRect.y)
+ forLayer:0];
+ auto adjustedSize =
+ [map mapPhysicalToScreenCoordinates:MTLCoordinate2DMake(clampedRect.width,
+ clampedRect.height)
+ forLayer:0];
+
+ clampedRect.x = (NSUInteger)floorf(adjustedOrigin.x);
+ clampedRect.y = (NSUInteger)floorf(adjustedOrigin.y);
+ clampedRect.width = (NSUInteger)ceilf(adjustedSize.x);
+ clampedRect.height = (NSUInteger)ceilf(adjustedSize.y);
+ }
+
mCommands.push(CmdType::SetScissorRect).push(clampedRect);
return *this;
@@ -2354,6 +2378,15 @@ RenderCommandEncoder &RenderCommandEncoder::setStencilLoadAction(MTLLoadAction a
return *this;
}
+RenderCommandEncoder &RenderCommandEncoder::setRasterizationRateMap(id<MTLRasterizationRateMap> map)
+{
+ if (mCachedRenderPassDescObjC.get().rasterizationRateMap != map)
+ {
+ mCachedRenderPassDescObjC.get().rasterizationRateMap = map;
+ }
+ return *this;
+}
+
void RenderCommandEncoder::setLabel(NSString *label)
{
mLabel = std::move(label);
diff --git a/src/libANGLE/renderer/metal/mtl_common.h b/src/libANGLE/renderer/metal/mtl_common.h
index 434a8b56fa..6afdb1d0ac 100644
--- a/src/libANGLE/renderer/metal/mtl_common.h
+++ b/src/libANGLE/renderer/metal/mtl_common.h
@@ -265,6 +265,8 @@ class WrappedObject
T mMetalObject = nil;
};
+using RasterizationRateMapRef = angle::ObjCPtr<id<MTLRasterizationRateMap>>;
+
// The native image index used by Metal back-end, the image index uses native mipmap level instead
// of "virtual" level modified by OpenGL's base level.
using MipmapNativeLevel = gl::LevelIndexWrapper<uint32_t>;
diff --git a/src/libANGLE/renderer/metal/mtl_render_utils.mm b/src/libANGLE/renderer/metal/mtl_render_utils.mm
index 5745d4e39d..c543abdcda 100644
--- a/src/libANGLE/renderer/metal/mtl_render_utils.mm
+++ b/src/libANGLE/renderer/metal/mtl_render_utils.mm
@@ -676,8 +676,10 @@ void SetupCommonBlitWithDrawStates(const gl::Context *context,
GetViewport(params.dstRect, params.dstTextureSize.height, params.dstFlipY);
MTLScissorRect scissorRectMtl =
GetScissorRect(params.dstScissorRect, params.dstTextureSize.height, params.dstFlipY);
+ // TODO(djg): Should the rasterization rate map affect blit operations?
+ // Would this require changes to the shader to apply transformation
cmdEncoder->setViewport(viewportMtl);
- cmdEncoder->setScissorRect(scissorRectMtl);
+ cmdEncoder->setScissorRect(scissorRectMtl, nil);
if (params.src)
{
@@ -1169,7 +1171,7 @@ angle::Result ClearUtils::setupClearWithDraw(const gl::Context *context,
scissorRect = GetScissorRect(params.clearArea, params.dstTextureSize.height, params.flipY);
cmdEncoder->setViewport(viewport);
- cmdEncoder->setScissorRect(scissorRect);
+ cmdEncoder->setScissorRect(scissorRect, nil);
// uniform
ClearParamsUniform uniformParams;
diff --git a/src/libANGLE/renderer/metal/shaders/create_mtl_internal_shaders.py b/src/libANGLE/renderer/metal/shaders/create_mtl_internal_shaders.py
new file mode 100644
index 0000000000..23e8295bcc
--- /dev/null
+++ b/src/libANGLE/renderer/metal/shaders/create_mtl_internal_shaders.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python3
+# Copyright 2021 The ANGLE Project Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# create_mtl_internal_shaders.py:
+# Script to compile a metalLib into NSData, for including the compilded
+# library in the ANGLE dylib.
+
+import os
+import sys
+import json